23 {
34
35 std::vector<std::string> subdefs(2+
NFIELDS);
36 std::string valuesStr;
37
38 std::size_t pos1,pos2;
39 pos1=definition.find('[');
40 if( pos1==std::string::npos) {
42 return false;
43 }
44
45 std::size_t
i,iField=0;
46 for (i=1+pos1;
i<definition.size();
i++) {
48 if (isspace(c)) continue;
49 if (c==']') break;
50 if (c=='/') {
51
52 iField++;
53 if (iField >= subdefs.size()) break;
54 }
55 else
56 subdefs[iField].push_back(c);
57 }
58
59 if (iField!=subdefs.size()-1 || i==definition.size()) {
60 logStr << MSG::ERROR << "Definition String [" << definition << "] malformed. Expect "
62 return false;
63 }
64
65 valuesStr=definition.substr(i+1);
66
67
68
69 std::string& subCaloStr=subdefs[0];
70 size_t len;
71 pos1=0;
72 do {
73 pos2=subCaloStr.find(',',pos1);
74 if (pos2==std::string::npos)
75 len=subCaloStr.size();
76 else {
77 len=pos2-pos1;
78 pos1=pos2+1;
79 }
80 if (subCaloStr.compare(pos1,len,"EMB")==0)
82 else if(subCaloStr.compare(pos1,len,"EMECIW")==0)
84 else if(subCaloStr.compare(pos1,len,"EMECOW")==0)
86 else if(subCaloStr.compare(pos1,len,"HEC")==0)
88 else if(subCaloStr.compare(pos1,len,"FCAL")==0)
90 else {
91 logStr << MSG::ERROR << "Unknown sub-calo name '"<< subCaloStr.substr(pos1,len) <<"'found. "
92 <<
"Allowed values are EMB, EMECIW, EMECOW, HEC and FCAL" <<
endmsg;
93 return false;
94 }
95 }
96 while(pos2!=std::string::npos);
97
98
99 if (subdefs[1].size()!=1) {
101 return false;
102 }
103
104 if (subdefs[1][0]=='A')
106 else if (subdefs[1][0]=='C')
108 else if (subdefs[1][0]=='*')
110 else {
111 logStr << MSG::ERROR <<
"Allowed values for side are: A,C or * (means both), found " << subdefs[1] <<
endmsg;
112 return false;
113 }
114
116 std::string& subdef=subdefs[
i+2];
117 int lower=std::numeric_limits<int>::min();
118 int upper=std::numeric_limits<int>::max();
119 if (subdef.compare("*")!=0) {
120 std::size_t pos1=subdef.find('-');
121 if (pos1==std::string::npos) {
122 if (isdigit(subdef[0]))
123 lower=
upper=atol(subdef.c_str());
124 else
125 logStr << MSG::ERROR <<
"Malformed string [" << subdef <<
"], expected numerical value!" <<
endmsg;
126 }
127 else {
128 std::string lStr=subdef.substr(0,pos1);
129 std::string uStr=subdef.substr(pos1+1);
130 if (!lStr.empty()) {
131 if (isdigit(lStr[0]))
132 lower=atol(lStr.c_str());
133 else
134 logStr << MSG::ERROR <<
"Malformed string [" << subdef <<
"], expected numerical value!" <<
endmsg;
135 }
136 if (!uStr.empty()) {
137 if (isdigit(uStr[0]))
138 upper=atol(uStr.c_str());
139 else
140 logStr << MSG::ERROR <<
"Malformed string [" << subdef <<
"], expected numerical value!" <<
endmsg;
141 }
142 }
143 }
145 }
146
147
148 const char* ptr1=valuesStr.c_str();
149 char* ptr2;
151
152 do {
154 if (ptr1!=ptr2)
156 ptr1=const_cast<const char*>(ptr2+1);
157 }
158 while(*ptr2!='\0');
159
160 logStr << MSG::INFO <<
"Sussefully parsed defintion string" <<
endmsg;
161 return true;
162}
static void complain(MsgStream &, const std::string &)
bool strtof(const std::string &input, T &f)