ATLAS Offline Software
Loading...
Searching...
No Matches
dqi::ConditionsSingleton Class Reference

#include <ConditionsSingleton.h>

Collaboration diagram for dqi::ConditionsSingleton:

Public Member Functions

void makeConditionMap (std::map< std::string, std::string > &cmap, const std::string &condition)
bool conditionsMatch (std::map< std::string, std::string > &refConds, std::map< std::string, std::string > &currentConds) const
std::string conditionalSelect (std::string inp, const std::string &condition)
void setCondition (const std::string &c)
const std::string & getCondition () const
int getNumReferenceHistos () const
std::string getNewRefHistoName ()
std::vector< std::string > getAllReferenceNames (std::string inp) const
std::vector< std::pair< std::string, std::string > > getConditionReferencePairs (std::string inp) const
void setNewReferenceName (const std::string &, const std::string &)
std::string getNewReferenceName (const std::string &, bool quiet=false) const
void setRefSourceMapping (const TMap *refsourcedata)
std::string getRefSourceData (const std::string &rawref) const

Static Public Member Functions

static ConditionsSingletongetInstance ()

Private Member Functions

 ConditionsSingleton ()=default
 ~ConditionsSingleton ()=default
 ConditionsSingleton (const ConditionsSingleton &)=delete
ConditionsSingletonoperator= (const ConditionsSingleton &)=delete

Private Attributes

int m_numRefHisto {0}
std::string m_currentConditions
std::map< std::string, std::string > m_referenceMap
const TMap * m_refsourcedata {nullptr}

Detailed Description

Definition at line 17 of file ConditionsSingleton.h.

Constructor & Destructor Documentation

◆ ConditionsSingleton() [1/2]

dqi::ConditionsSingleton::ConditionsSingleton ( )
privatedefault

◆ ~ConditionsSingleton()

dqi::ConditionsSingleton::~ConditionsSingleton ( )
privatedefault

◆ ConditionsSingleton() [2/2]

dqi::ConditionsSingleton::ConditionsSingleton ( const ConditionsSingleton & )
privatedelete

Member Function Documentation

◆ conditionalSelect()

std::string dqi::ConditionsSingleton::conditionalSelect ( std::string inp,
const std::string & condition )

Definition at line 153 of file ConditionsSingleton.cxx.

153 {
154 std::string cleanCond(condition);
155 std::erase(cleanCond,' ');//delete all spaces
156 std::map<std::string, std::string> condition_map, reference_map;
157 makeConditionMap(condition_map, condition);
158 std::erase(inp,' ');
159 // if(cleanCond.empty())return inp;
160 if(inp.find('=')!=std::string::npos){//we have conditions defined on reference
161 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
162 boost::char_separator<char> refSep(";");//field seperator for conditional references
163 boost::char_separator<char> condSep(",:"); //filed seperator for conditions and respective reference
164 tokenizer referenceConditionPairs(inp, refSep);
165 std::string defaultRef("");
166 std::map<std::string,std::string> conditionalReferences;
167 for(tokenizer::iterator tok_iter=referenceConditionPairs.begin();
168 tok_iter!=referenceConditionPairs.end();++tok_iter){//look at each condition reference pair
169 if(std::string((*tok_iter)).find('=')!=std::string::npos){//have conditions defined
170 if(std::string(*tok_iter).find(':')!=std::string::npos){//do a reference split
171 std::vector<std::string> conds;
172 boost::split(conds,*tok_iter,boost::is_any_of(std::string(":")));
173 if(conds.size()>2){
174 std::cerr<<"Warning malformed reference \""<<inp<<"\""<<std::endl;
175 }else if(conds.size()<2){
176 std::cerr<<"Warning malformed reference \""<<inp<<"\""<<std::endl;
177 continue;
178 }
179// std::cout<<"Conditions = \""<<conds.at(conds.size()-2)
180// <<"\",reference= "<<conds.at(conds.size()-1)<<std::endl;
181 reference_map.clear();
182 makeConditionMap(reference_map, conds.at(conds.size()-2));
183 if (conditionsMatch(reference_map, condition_map)) {
184 return conds.at(conds.size()-1);
185 }
186 //conditionalReferences[conds.at(conds.size()-2)]=conds.at(conds.size()-1);
187 }
188 }else{// no = sign. Then this should be a default reference.
189 if(defaultRef.empty()){
190 defaultRef=*tok_iter;
191 }else{
192 std::cout<<"WARNING! overwriting old default reference \""
193 <<defaultRef<<"\" with \""
194 <<*tok_iter<<"\""<<std::endl;
195 defaultRef=*tok_iter;
196 }
197// std::cout<<"Default reference = "<<defaultRef<<std::endl;
198 }
199 }
200 // if(cleanCond.empty()||conditionalReferences.find(cleanCond)==conditionalReferences.end()){
201// std::cout<<"returning default reference "<<defaultRef<<std::endl;
202// return defaultRef;
203// }
204// std::cout<<"returning reference "<<conditionalReferences[cleanCond]<<std::endl;
205// return conditionalReferences[cleanCond];
206 return defaultRef;
207 }else{
208 return inp;
209 }
210 }
void makeConditionMap(std::map< std::string, std::string > &cmap, const std::string &condition)
bool conditionsMatch(std::map< std::string, std::string > &refConds, std::map< std::string, std::string > &currentConds) const
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138

◆ conditionsMatch()

bool dqi::ConditionsSingleton::conditionsMatch ( std::map< std::string, std::string > & refConds,
std::map< std::string, std::string > & currentConds ) const

Definition at line 141 of file ConditionsSingleton.cxx.

142 {
143 for (std::map<std::string, std::string>::const_iterator cond_iter = refConds.begin();
144 cond_iter != refConds.end(); ++cond_iter) {
145 // reject if reference key is not in current conditions
146 if (currentConds.find((*cond_iter).first) == currentConds.end()) return false;
147 if ((*cond_iter).second != currentConds[(*cond_iter).first]) return false;
148 }
149 // all specified reference conditions match
150 return true;
151 }

◆ getAllReferenceNames()

std::vector< std::string > dqi::ConditionsSingleton::getAllReferenceNames ( std::string inp) const

Definition at line 65 of file ConditionsSingleton.cxx.

65 {
66 std::erase(inp,' ');
67 // if(cleanCond.empty())return inp;
68 //std::set<std::string> referenceSet;
69 std::vector<std::string> refs;
70
71 if(inp.find('=')!=std::string::npos){//we have conditions defined on reference
72 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
73 boost::char_separator<char> refSep(";");//field seperator for conditional references
74 boost::char_separator<char> condSep(",:"); //filed seperator for conditions and respective reference
75 tokenizer referenceConditionPairs(inp, refSep);
76 std::string defaultRef("");
77 for(tokenizer::iterator tok_iter=referenceConditionPairs.begin();
78 tok_iter!=referenceConditionPairs.end();++tok_iter){//look at each condition reference pair
79 if(std::string((*tok_iter)).find('=')!=std::string::npos){//have conditions defined
80 if(std::string(*tok_iter).find(':')!=std::string::npos){//do a reference split
81 std::vector<std::string> conds;
82 boost::split(conds,*tok_iter,boost::is_any_of(std::string(":")));
83 if(conds.size()>2){
84 std::cerr<<"Warning malformed reference \""<<inp<<"\""<<std::endl;
85 }else if(conds.size()<2){
86 std::cerr<<"Warning malformed reference \""<<inp<<"\""<<std::endl;
87 continue;
88 }
89 refs.push_back(conds.at(conds.size()-1));
90 //referenceSet.insert(conds.at(conds.size()-1));
91 }
92 }else{// no = sign. Then this should be a default reference.
93 if(defaultRef.empty()){
94 defaultRef=*tok_iter;
95 }else{
96 std::cout<<"WARNING! overwriting old default reference \""
97 <<defaultRef<<"\" with \""
98 <<*tok_iter<<"\""<<std::endl;
99 defaultRef=*tok_iter;
100 }
101 std::cout<<"Default reference = "<<defaultRef<<std::endl;
102 }
103
104 }
105 // for(std::set<std::string>::iterator it=referenceSet.begin();it!=referenceSet.end();++it){
106 // refs.push_back(*it);
107 // }
108 if(!defaultRef.empty())refs.push_back(std::move(defaultRef));
109 return refs;
110 }else{
111 refs.push_back(std::move(inp));
112 return refs;
113 }
114 }

◆ getCondition()

const std::string & dqi::ConditionsSingleton::getCondition ( ) const

Definition at line 28 of file ConditionsSingleton.cxx.

28 {
30 }

◆ getConditionReferencePairs()

std::vector< std::pair< std::string, std::string > > dqi::ConditionsSingleton::getConditionReferencePairs ( std::string inp) const

Definition at line 216 of file ConditionsSingleton.cxx.

216 {
217 std::vector<std::pair<std::string,std::string> > condPairs;
218 std::map<std::string,std::string> pairMap;//unique condition-reference pairs;
219 std::erase(inp,' ');
220 std::string defaultRef("");
221 if(inp.find('=')!=std::string::npos){//we have conditions defined on reference
222 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
223 boost::char_separator<char> refSep(";");//field seperator for conditional references
224 boost::char_separator<char> condSep(",:"); //filed seperator for conditions and respective reference
225 tokenizer referenceConditionPairs(inp, refSep);
226 std::map<std::string,std::string> conditionalReferences;
227 for(tokenizer::iterator tok_iter=referenceConditionPairs.begin();
228 tok_iter!=referenceConditionPairs.end();++tok_iter){//look at each condition reference pair
229 if(std::string((*tok_iter)).find('=')!=std::string::npos){//have conditions defined
230 if(std::string(*tok_iter).find(':')!=std::string::npos){//do a reference split
231 std::vector<std::string> conds;
232 boost::split(conds,*tok_iter,boost::is_any_of(std::string(":")));
233 if(conds.size()>2){
234 std::cerr<<"Warning malformed reference \""<<inp<<"\""<<std::endl;
235 }else if(conds.size()<2){
236 std::cerr<<"Warning malformed reference \""<<inp<<"\""<<std::endl;
237 continue;
238 }
239 condPairs.push_back(std::make_pair(conds.at(conds.size()-2),conds.at(conds.size()-1)));
240 //pairMap[conds.at(conds.size()-2)]=conds.at(conds.size()-1);
241 }
242 }else{// no = sign. Then this should be a default reference.
243 if(defaultRef.empty()){
244 defaultRef=*tok_iter;
245 }else{
246 std::cout<<"WARNING! overwriting old default reference \""
247 <<defaultRef<<"\" with \""
248 <<*tok_iter<<"\""<<std::endl;
249 defaultRef=*tok_iter;
250 }
251 // std::cout<<"Default reference = "<<defaultRef<<std::endl;
252 }
253 }
254 // for(std::map<std::string,std::string>::iterator it=pairMap.begin();it!=pairMap.end();++it){
255 // condPairs.push_back(std::make_pair<std::string,std::string>(it->first,it->second));
256 // }
257 if(!defaultRef.empty())condPairs.push_back(std::make_pair("",defaultRef));
258 //return condPairs;
259 }else{
260 condPairs.push_back(std::make_pair("",inp));
261 }
262 return condPairs;
263 }

◆ getInstance()

ConditionsSingleton & dqi::ConditionsSingleton::getInstance ( )
static

Definition at line 19 of file ConditionsSingleton.cxx.

19 {
21 return instance;
22 }
std::map< std::string, double > instance

◆ getNewReferenceName()

std::string dqi::ConditionsSingleton::getNewReferenceName ( const std::string & oldName,
bool quiet = false ) const

Definition at line 281 of file ConditionsSingleton.cxx.

281 {
282 if(oldName.empty()){
283 std::cerr<<"Reference must have a name"<<std::endl;
284 return {};
285 }
286
287 const auto itr = m_referenceMap.find(oldName);
288 if(itr==m_referenceMap.end()){
289 if(!quiet)std::cerr<<"Non-existent reference\""<<oldName<<"\". Returning empty string"<<std::endl;
290 return {};
291 }
292 return itr->second;
293 }
std::map< std::string, std::string > m_referenceMap

◆ getNewRefHistoName()

std::string dqi::ConditionsSingleton::getNewRefHistoName ( )

Definition at line 57 of file ConditionsSingleton.cxx.

57 {
58 std::stringstream oss;
59 oss<<"reference-"<<std::setfill('0')<<std::setw(9)<<m_numRefHisto;
61 //std::cout<<__PRETTY_FUNCTION__<<"new histo name"<<oss.str()<<std::endl;
62 return oss.str();
63 }

◆ getNumReferenceHistos()

int dqi::ConditionsSingleton::getNumReferenceHistos ( ) const

Definition at line 31 of file ConditionsSingleton.cxx.

31 {
32 return m_numRefHisto;
33 }

◆ getRefSourceData()

std::string dqi::ConditionsSingleton::getRefSourceData ( const std::string & rawref) const

Definition at line 42 of file ConditionsSingleton.cxx.

42 {
43 if (! m_refsourcedata) {
44 // Suppress error message as it will occur in cases of backwards compatibility
45 // std::cerr << "Null refsourcedata: THIS IS REALLY BAD!!!" << std::endl;
46 return "";
47 }
48 const TObjString* value = dynamic_cast<TObjString*>(m_refsourcedata->GetValue(rawref.c_str()));
49 if (!value) {
50 std::cerr << "Unable to figure out refsource mapping: THIS IS ALSO REALLY BAD!!!" << std::endl;
51 std::cerr << "This happened for reference " << rawref << std::endl;
52 return "";
53 }
54 return value->GetName();
55 }

◆ makeConditionMap()

void dqi::ConditionsSingleton::makeConditionMap ( std::map< std::string, std::string > & cmap,
const std::string & condition )

Definition at line 116 of file ConditionsSingleton.cxx.

117 {
118 if (condition.empty()) return;
119
120 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
121 std::string cleanCond(condition);
122 std::erase(cleanCond,' ');//delete all spaces
123 boost::char_separator<char> condSep(","); //filed seperator for conditions and respective reference
124 tokenizer conditionPairs(condition, condSep);
125 for (tokenizer::const_iterator tok_iter = conditionPairs.begin();
126 tok_iter != conditionPairs.end(); ++tok_iter) {
127 std::vector<std::string> splitpairs;
128 boost::split(splitpairs, *tok_iter, boost::is_any_of(std::string("=")));
129 if (splitpairs.size() != 2) {
130 std::cerr << "WARNING: malformed condition \"" << *tok_iter << "\"" << std::endl;
131 continue;
132 } else {
133 if (cmap.find(splitpairs[0]) != cmap.end()) {
134 std::cerr << "WARNING: redefinition of condition " << splitpairs[0] << std::endl;
135 }
136 cmap[splitpairs[0]] = splitpairs[1];
137 }
138 }
139 }

◆ operator=()

ConditionsSingleton & dqi::ConditionsSingleton::operator= ( const ConditionsSingleton & )
privatedelete

◆ setCondition()

void dqi::ConditionsSingleton::setCondition ( const std::string & c)

Definition at line 24 of file ConditionsSingleton.cxx.

24 {
26 }

◆ setNewReferenceName()

void dqi::ConditionsSingleton::setNewReferenceName ( const std::string & oldName,
const std::string & newName )

Definition at line 264 of file ConditionsSingleton.cxx.

264 {
265 if(oldName.empty()){
266 std::cerr<<"Warning old name of the reference is empty. New name is \""<<newName<<"\""<<std::endl;
267 return;
268 }
269 if(newName.empty()){
270 std::cerr<<"Warning new name of the reference is empty. Old name is \""<<oldName<<"\""<<std::endl;
271 return;
272 }
273 if(m_referenceMap.find(oldName)==m_referenceMap.end()){
274 m_referenceMap[oldName]=newName;
275 }else{
276 std::cerr<<"Warning reference \""<<oldName<<"\" is added to map before as \""
277 << m_referenceMap[oldName]<<"\". New name is \""<<newName<<"\""<<std::endl;
278 return;
279 }
280 }

◆ setRefSourceMapping()

void dqi::ConditionsSingleton::setRefSourceMapping ( const TMap * refsourcedata)

Definition at line 35 of file ConditionsSingleton.cxx.

35 {
36 if (! refsourcedata) {
37 std::cerr << "You are setting a bad refsourcedata! This will cause you trouble later!" << std::endl;
38 }
39 m_refsourcedata = refsourcedata;
40 }

Member Data Documentation

◆ m_currentConditions

std::string dqi::ConditionsSingleton::m_currentConditions
private

Definition at line 25 of file ConditionsSingleton.h.

◆ m_numRefHisto

int dqi::ConditionsSingleton::m_numRefHisto {0}
private

Definition at line 24 of file ConditionsSingleton.h.

24{0};

◆ m_referenceMap

std::map<std::string,std::string> dqi::ConditionsSingleton::m_referenceMap
private

Definition at line 26 of file ConditionsSingleton.h.

◆ m_refsourcedata

const TMap* dqi::ConditionsSingleton::m_refsourcedata {nullptr}
private

Definition at line 27 of file ConditionsSingleton.h.

27{nullptr};

The documentation for this class was generated from the following files: