EIC Software
Reference for
EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
EicNamePatternHub.h
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file EicNamePatternHub.h
1
//
2
// AYK (ayk@bnl.gov), 2014/07/24
3
//
4
// A simple class to store and retrieve information about name pattern matching;
5
//
6
7
#include <TObject.h>
8
#include <TString.h>
9
10
#ifndef _EIC_NAME_PATTERN_HUB_
11
#define _EIC_NAME_PATTERN_HUB_
12
13
template
<
typename
T>
14
class
EicNamePatternHub
:
public
TObject
{
15
public
:
16
EicNamePatternHub
() {};
17
~EicNamePatternHub
() {
18
fExactMatch
.clear();
19
fPrefixMatch
.clear();
20
fSuffixMatch
.clear();
21
fPatternMatch
.clear();
22
};
23
24
// Well, really want to have default value for the 2-d parameter;
25
// let it be 0, type-matched to T;
26
void
AddExactMatch
(
const
char
*match,
T
value
= (
T
)0) {
27
fExactMatch
.push_back (std::pair<TString, T>(TString(match),
value
));
28
};
29
30
void
AddPrefixMatch
(
const
char
*match,
T
value
= (
T
)0) {
31
fPrefixMatch
.push_back(std::pair<TString, T>(TString(match),
value
));
32
};
33
34
void
AddSuffixMatch
(
const
char
*match,
T
value
= (
T
)0) {
35
fSuffixMatch
.push_back(std::pair<TString, T>(TString(match),
value
));
36
};
37
38
void
AddPatternMatch
(
const
char
*match,
T
value
= (
T
)0) {
39
fPatternMatch
.push_back(std::pair<TString, T>(TString(match),
value
));
40
};
41
42
const
std::pair<TString, T> *
ExactMatch
(
const
char
*
name
)
const
{
43
for
(
unsigned
iq=0; iq<
fExactMatch
.size(); iq++)
44
if
(
fExactMatch
[iq].first.EqualTo(name))
45
return
&
fExactMatch
[iq];
46
47
return
0;
48
};
49
50
const
std::pair<TString, T> *
PrefixMatch
(
const
char
*
name
)
const
{
51
for
(
unsigned
iq=0; iq<
fPrefixMatch
.size(); iq++)
52
if
(TString(name).BeginsWith(
fPrefixMatch
[iq].first))
53
return
&
fPrefixMatch
[iq];
54
55
return
0;
56
};
57
58
const
std::pair<TString, T> *
SuffixMatch
(
const
char
*
name
)
const
{
59
for
(
unsigned
iq=0; iq<
fSuffixMatch
.size(); iq++)
60
if
(TString(name).EndsWith(
fSuffixMatch
[iq].first))
61
return
&
fSuffixMatch
[iq];
62
63
return
0;
64
};
65
66
const
std::pair<TString, T> *
PatternMatch
(
const
char
*
name
)
const
{
67
for
(
unsigned
iq=0; iq<
fPatternMatch
.size(); iq++)
68
if
(TString(name).Contains(
fPatternMatch
[iq].first))
69
return
&
fPatternMatch
[iq];
70
71
return
0;
72
};
73
74
const
std::pair<TString, T> *
AnyMatch
(
const
char
*
name
)
const
{
75
// Try exact match first;
76
{
77
const
std::pair<TString, T> *ret =
ExactMatch
(name);
78
if
(ret)
return
ret;
79
}
80
81
// If failed, try prefix match;
82
{
83
const
std::pair<TString, T> *ret =
PrefixMatch
(name);
84
if
(ret)
return
ret;
85
}
86
87
// If failed, try suffix match;
88
{
89
const
std::pair<TString, T> *ret =
SuffixMatch
(name);
90
if
(ret)
return
ret;
91
}
92
93
// Otherwise return pattern match check result;
94
return
PatternMatch
(name);
95
};
96
97
const
bool
IsEmpty
()
const
{
98
return
!
fExactMatch
.size() && !
fPrefixMatch
.size() && !
fSuffixMatch
.size() && !
fPatternMatch
.size();
99
};
100
101
private
:
102
// FIXME: think about efficiency later; for my purposes overhead is negligible
103
// though (called during init phase only) -> std::vector is fine;
104
// NB: it is sometimes handy to store extra info associated with the pattern;
105
std::vector< std::pair<TString, T> >
fExactMatch
;
106
std::vector< std::pair<TString, T> >
fPrefixMatch
;
107
std::vector< std::pair<TString, T> >
fSuffixMatch
;
108
std::vector< std::pair<TString, T> >
fPatternMatch
;
109
110
ClassDef(
EicNamePatternHub<T>
,7)
111
};
112
113
#endif
EicToyModel
blob
master
include
EicNamePatternHub.h
Built by
Jin Huang
. updated:
Mon Jan 22 2024 12:43:33
using
1.8.2 with
EIC GitHub integration