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 158 of file ConditionsSingleton.cxx.

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

◆ conditionsMatch()

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

Definition at line 146 of file ConditionsSingleton.cxx.

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

◆ getAllReferenceNames()

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

Definition at line 69 of file ConditionsSingleton.cxx.

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

◆ getCondition()

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

Definition at line 32 of file ConditionsSingleton.cxx.

32 {
34 }

◆ getConditionReferencePairs()

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

Definition at line 221 of file ConditionsSingleton.cxx.

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

◆ getInstance()

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

Definition at line 23 of file ConditionsSingleton.cxx.

23 {
25 return instance;
26 }
std::map< std::string, double > instance

◆ getNewReferenceName()

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

Definition at line 286 of file ConditionsSingleton.cxx.

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

◆ getNewRefHistoName()

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

Definition at line 61 of file ConditionsSingleton.cxx.

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

◆ getNumReferenceHistos()

int dqi::ConditionsSingleton::getNumReferenceHistos ( ) const

Definition at line 35 of file ConditionsSingleton.cxx.

35 {
36 return m_numRefHisto;
37 }

◆ getRefSourceData()

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

Definition at line 46 of file ConditionsSingleton.cxx.

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

◆ makeConditionMap()

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

Definition at line 120 of file ConditionsSingleton.cxx.

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

◆ operator=()

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

◆ setCondition()

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

Definition at line 28 of file ConditionsSingleton.cxx.

28 {
30 }

◆ setNewReferenceName()

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

Definition at line 269 of file ConditionsSingleton.cxx.

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

◆ setRefSourceMapping()

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

Definition at line 39 of file ConditionsSingleton.cxx.

39 {
40 if (! refsourcedata) {
41 std::cerr << "You are setting a bad refsourcedata! This will cause you trouble later!" << std::endl;
42 }
43 m_refsourcedata = refsourcedata;
44 }

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: