ATLAS Offline Software
Loading...
Searching...
No Matches
HanConfigAssessor.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// **********************************************************************
6// **********************************************************************
7
11#include <cstring>
12#include <utility>
13
14#include <TKey.h>
15#include <TH1F.h>
16#include <TClass.h>
17
19ATLAS_NO_CHECK_FILE_THREAD_SAFETY; // standalone application
20
21//Get rid of Root macros that confuse Doxygen
25
26
27
28namespace dqi {
29
30// *********************************************************************
31// Public Methods
32// *********************************************************************
33
36 : m_algPars( newTObjArray( "algPars" ) )
37 , m_algStrPars( newTObjArray( "algStrPars" ) )
38 , m_algLimits( newTObjArray( "algLimits" ) )
39 , m_annotations( newTObjArray( "annotations" ) )
40 , m_weight( 1 )
41 , m_isRegex( false )
42{ }
43
44
47 : TObject(other)
48 , m_name(other.m_name)
49 , m_algName(other.m_algName)
52 , m_algPars( newTObjArray( "algPars", 0, other.m_algPars->GetEntries() ) )
53 , m_algStrPars( newTObjArray( "algStrPars", 0, other.m_algStrPars->GetEntries() ) )
54 , m_algLimits( newTObjArray( "algLimits", 0, other.m_algLimits->GetEntries() ) )
55 , m_annotations( newTObjArray( "annotations", 0, other.m_annotations->GetEntries() ) )
56 , m_weight(other.m_weight)
57 , m_isRegex(other.m_isRegex)
58{
59 TIter nextPar( other.m_algPars );
60 HanConfigAlgPar* otherPar;
61 while( (otherPar = dynamic_cast<HanConfigAlgPar*>( nextPar() )) != 0 ) {
62 HanConfigAlgPar* par = new HanConfigAlgPar( *otherPar );
63 m_algPars->Add( par );
64 }
65
66 TIter nextStrPar( other.m_algStrPars );
67 HanConfigParMap* otherStrPar;
68 while( (otherStrPar = dynamic_cast<HanConfigParMap*>( nextStrPar() )) != 0 ) {
69 HanConfigParMap* strPar = new HanConfigParMap( *otherStrPar );
70 m_algStrPars->Add( strPar );
71 }
72
73 TIter nextLim( other.m_algLimits );
74 HanConfigAlgLimit* otherLim;
75 while( (otherLim = dynamic_cast<HanConfigAlgLimit*>( nextLim() )) != 0 ) {
76 HanConfigAlgLimit* lim = new HanConfigAlgLimit( *otherLim );
77 m_algLimits->Add( lim );
78 }
79
80 TIter nextParMap( other.m_annotations );
81 HanConfigParMap* otherParMap;
82 while( (otherParMap = dynamic_cast<HanConfigParMap*>( nextParMap() )) != 0 ) {
83 HanConfigParMap* parMap = new HanConfigParMap( *otherParMap );
84 m_annotations->Add( parMap );
85 }
86}
87
88
91operator=( const HanConfigAssessor& other )
92{
93 if (this == &other) return *this;
94
95 m_name = other.m_name;
96 m_algName = other.m_algName;
97 m_algLibName = other.m_algLibName;
98 m_algRefName = other.m_algRefName;
99 m_weight = other.m_weight;
100 m_isRegex = other.m_isRegex;
101
102 m_algPars->Delete();
103 TIter nextPar( other.m_algPars );
104 HanConfigAlgPar* otherPar;
105 while( (otherPar = dynamic_cast<HanConfigAlgPar*>( nextPar() )) != 0 ) {
106 HanConfigAlgPar* par = new HanConfigAlgPar( *otherPar );
107 m_algPars->Add( par );
108 }
109
110 m_algStrPars->Delete();
111 TIter nextStrPar( other.m_algStrPars );
112 HanConfigParMap* otherStrPar;
113 while( (otherStrPar = dynamic_cast<HanConfigParMap*>( nextStrPar() )) != 0 ) {
114 HanConfigParMap* strPar = new HanConfigParMap( *otherStrPar );
115 m_algStrPars->Add( strPar );
116 }
117
118 m_algLimits->Delete();
119 TIter nextLim( other.m_algLimits );
120 HanConfigAlgLimit* otherLim;
121 while( (otherLim = dynamic_cast<HanConfigAlgLimit*>( nextLim() )) != 0 ) {
122 HanConfigAlgLimit* lim = new HanConfigAlgLimit( *otherLim );
123 m_algLimits->Add( lim );
124 }
125
126 m_annotations->Delete();
127 TIter nextParMap( other.m_annotations );
128 HanConfigParMap* otherParMap;
129 while( (otherParMap = dynamic_cast<HanConfigParMap*>( nextParMap() )) != 0 ) {
130 HanConfigParMap* parMap = new HanConfigParMap( *otherParMap );
131 m_annotations->Add( parMap );
132 }
133
134 return *this;
135}
136
137
140{
141 m_algPars->Delete();
142 m_algStrPars->Delete();
143 m_algLimits->Delete();
144 m_annotations->Delete();
145 delete m_algPars;
146 delete m_algStrPars;
147 delete m_algLimits;
148 delete m_annotations;
149}
150
151
152std::string
154GetUniqueName() const
155{
156 return std::string( GetName() );
157}
158
159
160void
162SetName( std::string name_ )
163{
164 m_name.SetString( name_.c_str() );
165}
166
167
168const char*
170GetName() const
171{
172 return m_name.GetName();
173}
174
175const char*
177GetHistPath() const
178{
179 const HanConfigParMap* parmap = GetAnnotation("inputname");
180 if (!parmap) {
181 return GetName();
182 } else {
183 return parmap->GetValue();
184 }
185}
186
187void
189SetAlgName( std::string name_ )
190{
191 m_algName.SetString( name_.c_str() );
192}
193
194
195const char*
197GetAlgName() const
198{
199 return m_algName.GetName();
200}
201
202
203void
205SetAlgLibName( std::string name_ )
206{
207 m_algLibName.SetString( name_.c_str() );
208}
209
210
211const char*
213GetAlgLibName() const
214{
215 return m_algLibName.GetName();
216}
217
218
219void
221SetAlgRefName( std::string name_ )
222{
223 m_algRefName.SetString( name_.c_str() );
224}
225
226
227std::string
229GetAlgRefName() const
230{
232 return condSingleton.conditionalSelect(std::string(m_algRefName.GetName()),std::string(condSingleton.getCondition()));
233}
234
235
236const char*
238GetAlgRefString() const
239{
240 return m_algRefName.GetName();
241}
242
243
244void
246AddAlgPar( const HanConfigAlgPar& algPar_ )
247{
248 HanConfigAlgPar* par = new HanConfigAlgPar( algPar_ );
249 m_algPars->Add( par );
250}
251
252
255GetAlgPar( std::string name_ ) const
256{
257 HanConfigAlgPar* par = dynamic_cast<HanConfigAlgPar*>( m_algPars->FindObject(name_.c_str()) );
258 if( par == 0 ) {
259 return HanConfigAlgPar();
260 }
261
262 return *par;
263}
264
265
266TIter
268GetAllAlgPars() const
269{
270 return TIter( m_algPars );
271}
272
273
274void
276AddAlgStrPar( const HanConfigParMap& algStrPar_ )
277{
278 HanConfigParMap* strPar = new HanConfigParMap( algStrPar_ );
279 m_algStrPars->Add( strPar );
280}
281
282
285GetAlgStrPar( std::string name_ ) const
286{
287 HanConfigParMap* strPar = dynamic_cast<HanConfigParMap*>( m_algStrPars->FindObject(name_.c_str()) );
288 if( strPar == 0 ) {
289 return HanConfigParMap();
290 }
291
292 return *strPar;
293}
294
295
296TIter
298GetAllAlgStrPars() const
299{
300 return TIter( m_algStrPars );
301}
302
303
304void
306AddAlgLimit( const HanConfigAlgLimit& algLim_ )
307{
308 HanConfigAlgLimit* lim = new HanConfigAlgLimit( algLim_ );
309 m_algLimits->Add( lim );
310}
311
312
315GetAlgLimit( std::string name_ ) const
316{
317 HanConfigAlgLimit* lim = dynamic_cast<HanConfigAlgLimit*>( m_algLimits->FindObject(name_.c_str()) );
318 if( lim == 0 ) {
319 return HanConfigAlgLimit();
320 }
321
322 return *lim;
323}
324
325
326TIter
328GetAllAlgLimits() const
329{
330 return TIter( m_algLimits );
331}
332
333void
335AddAnnotation( const HanConfigParMap& annotation_ )
336{
337 HanConfigParMap* parMap = new HanConfigParMap( annotation_ );
338 m_annotations->Add( parMap );
339}
340
341
342const HanConfigParMap*
344GetAnnotation( std::string name_ ) const
345{
346 HanConfigParMap* parMap = dynamic_cast<HanConfigParMap*>( m_annotations->FindObject(name_.c_str()) );
347 if( parMap == 0 ) {
348 //std::cerr << "WARNING: attempt to access non-existent annotation " << name_ << " on assessor " << GetName() << std::endl;
349 return 0;
350 }
351 return parMap;
352}
353
354
355TIter
357GetAllAnnotations() const
358{
359 return TIter( m_annotations );
360}
361
362void
364SetWeight( float weight_ )
365{
366 m_weight = weight_;
367}
368
369float
371GetWeight() const
372{
373 return m_weight;
374}
375
376void
378SetIsRegex( bool isRegex_ )
379{
380 m_isRegex = isRegex_;
381}
382
383bool
385GetIsRegex() const
386{
387 return m_isRegex;
388}
389
390TSeqCollection *
392GetList( TDirectory* basedir, std::map<std::string,TSeqCollection*>& mp )
393{
394 TSeqCollection *ret = newTList( (std::string(this->m_name.GetName())+std::string("_")).c_str());
395 TSeqCollection *configList = newTList("Config");
396 TSeqCollection *resultsList = newTList("Results");
397 TSeqCollection *nameList = newTObjArray("name", new TObjString(m_algName), 1);
398
399 std::string nameString = GetUniqueName();
400
401 mp[nameString] = ret;
402
403 // fill the configList
404 configList->Add(nameList);
405 if (m_algPars == 0)
406 std::cerr << "HanConfigAssessor::GetList(): Warning: m_algPars == 0\n";
407 else {
408 TIter nextAlgPar( m_algPars );
409 HanConfigAlgPar *par;
410 TSeqCollection *algParList = newTObjArray("algPars", 0, m_algPars->GetEntries());
411 while( (par = dynamic_cast<HanConfigAlgPar*>( nextAlgPar() )) != 0 )
412 algParList->Add(par->GetList());
413
414 if (algParList->IsEmpty())
415 delete algParList;
416 else
417 configList->Add(algParList);
418 }
419
420 if (m_algStrPars == 0)
421 std::cerr << "HanConfigAssessor::GetList(): Warning: m_algStrPars == 0\n";
422 else {
423 TIter nextAlgStrPar( m_algStrPars );
424 HanConfigParMap *strPar;
425 TSeqCollection *algStrParList = newTObjArray("algStrPars", 0, m_algStrPars->GetEntries());
426 while( (strPar = dynamic_cast<HanConfigParMap*>( nextAlgStrPar() )) != 0 )
427 algStrParList->Add(strPar->GetList());
428
429 if (algStrParList->IsEmpty())
430 delete algStrParList;
431 else
432 configList->Add(algStrParList);
433 }
434
435 if (m_algLimits == 0)
436 std::cerr << "HanConfigAssessor::GetList(): Warning: m_algLimits == 0\n";
437 else {
438 TIter nextAlgLim( m_algLimits );
440 TSeqCollection *algLimitList = newTObjArray("algLimits", 0, m_algLimits->GetEntries());
441 while( (lim = dynamic_cast<HanConfigAlgLimit*>( nextAlgLim() )) != 0 )
442 algLimitList->Add(lim->GetList());
443 if(algLimitList->IsEmpty())
444 delete algLimitList;
445 else
446 configList->Add(algLimitList);
447 }
448
449 TSeqCollection *parMapList(0);
450 if (m_annotations == 0)
451 std::cerr << "HanConfigAssessor::GetList(): Warning: annotations == 0\n";
452 else {
453 TIter nextParMap( m_annotations );
454 HanConfigParMap *parMap;
455 parMapList = newTObjArray("annotations", 0, m_annotations->GetEntries()+2);
456 while( (parMap = dynamic_cast<HanConfigParMap*>( nextParMap() )) != 0 )
457 parMapList->Add(parMap->GetList());
458 }
459 std::string usedAlgRef = GetAlgRefName();
460 if ( parMapList && usedAlgRef.size() ) {
461 TList* refSourceList = new TList();
462 std::string refOrigin(ConditionsSingleton::getInstance().getRefSourceData(usedAlgRef));
463 refSourceList->SetName("refSource");
464 refSourceList->Add(new TObjString(refOrigin.c_str()));
465 parMapList->Add(refSourceList);
466 if (refOrigin != "Multiple references") {
467 std::string refInfo(ConditionsSingleton::getInstance().getRefSourceData(refOrigin));
468 if (refInfo != "") {
469 refSourceList = new TList();
470 refSourceList->SetName("refInfo");
471 refSourceList->Add(new TObjString(refInfo.c_str()));
472 parMapList->Add(refSourceList);
473 }
474 }
475 }
476 if(!parMapList || parMapList->IsEmpty())
477 delete parMapList;
478 else
479 configList->Add(parMapList);
480
481 // Get the histogram
482 if (! GetIsRegex()) {
483 TKey* key = getObjKey( basedir, GetHistPath() );
484 if( key != 0 ) {
485 const char* className = key->GetClassName();
486 if( (strncmp(className, "TH", 2) == 0)
487 || (strncmp(className, "TGraph", 6) == 0)
488 || (strncmp(className, "TProfile", 8) == 0)
489 || (strncmp(className, "TEfficiency", 11) == 0) ) {
490 // TNamed* transobj = dynamic_cast<TNamed*>(key->ReadObj());
491 // if (transobj != NULL) {
492 std::string::size_type rslash = nameString.rfind('/');
493 if (rslash == std::string::npos) {
494 rslash = 0;
495 } else {
496 rslash += 1;
497 }
498 HanHistogramLink* hhl = new HanHistogramLink(basedir, GetHistPath());
499 hhl->SetName( nameString.substr(rslash, std::string::npos).c_str() );
500 ret->Add(hhl);
501 // transobj->SetName( nameString.substr(rslash, std::string::npos).c_str() );
502 // } else {
503 // std::cerr << "TNamed* cast failed for " << GetHistPath()
504 // << std::endl;
505 // ret->Add(transobj);
506 // }
507
508 }
509 }
510 }
511
512
513 // fill the list that we return
514 ret->Add(configList);
515 ret->Add(resultsList);
516
517 return ret;
518}
519
520
521void
523Accept( Visitor& visitor, boost::shared_ptr<dqm_core::Region> dqParent ) const
524{
525 visitor.Visit( this, std::move(dqParent) );
526}
527
528
529void
531PrintIOStream( std::ostream& o ) const
532{
533 o << "\nHanConfigAssessor: " << GetName() << "\n"
534 << " Algorithm Name = \"" << GetAlgName() << "\"\n"
535 << " Algorithm Library = \"" << GetAlgLibName() << "\"\n"
536 << " Algorithm Reference = \"" << GetAlgRefString() << "\"\n"
537 << " Weight = " << GetWeight() << "\n";
538
539 if (m_isRegex) {
540 o << " Is a regular expression" << std::endl;
541 }
542
543 if( !m_algPars->IsEmpty() ) {
544 o << " Algorithm Parameters = {\n";
545 TIter nextPar( m_algPars );
546 HanConfigAlgPar* par;
547 while( (par = dynamic_cast<HanConfigAlgPar*>( nextPar() )) != 0 ) {
548 o << " " << par;
549 }
550 TIter nextStrPar( m_algStrPars );
551 HanConfigParMap* strPar;
552 while( (strPar = dynamic_cast<HanConfigParMap*>( nextStrPar() )) != 0 ) {
553 o << " " << strPar;
554 }
555 o << " }\n";
556 }
557
558 if( !m_algLimits->IsEmpty() ) {
559 o << " Algorithm Limits = {\n";
560 TIter nextLim( m_algLimits );
562 while( (lim = dynamic_cast<HanConfigAlgLimit*>( nextLim() )) != 0 ) {
563 o << " " << lim;
564 }
565 o << " }\n";
566 }
567
568 if( !m_annotations->IsEmpty() ) {
569 o << " Annotations = {\n";
570 TIter nextParMap( m_annotations );
571 HanConfigParMap* parMap;
572 while( (parMap = dynamic_cast<HanConfigParMap*>( nextParMap() )) != 0 ) {
573 o << " " << parMap;
574 }
575 o << " }\n";
576 }
577
578
579}
580
581void HanConfigAssessor::Streamer(TBuffer &R__b)
582{
583 // Stream an object of class HanConfigAssessor.
584
585 if (R__b.IsReading()) {
586 UInt_t R__s, R__c;
587 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
588 // Automatic schema evolution is kind of broken
589 TObject::Streamer(R__b);
590 m_name.Streamer(R__b);
591 m_algName.Streamer(R__b);
592 m_algLibName.Streamer(R__b);
593 m_algRefName.Streamer(R__b);
594 delete m_algPars;
595 R__b >> m_algPars;
596 if (R__v >= 6) {
597 delete m_algStrPars;
598 R__b >> m_algStrPars;
599 }
600 delete m_algLimits;
601 R__b >> m_algLimits;
602 if (R__v >= 2) {
603 delete m_annotations;
604 R__b >> m_annotations;
605 }
606 if (R__v >= 3) {
607 R__b >> m_weight;
608 }
609 if (R__v >= 4) {
610 R__b >> m_isRegex;
611 }
612
613 R__b.CheckByteCount(R__s, R__c, HanConfigAssessor::IsA());
614 } else {
615 HanConfigAssessor::Class()->WriteBuffer(R__b, this);
616 }
617}
618
619} // namespace dqi
620
621
622std::ostream& operator<<( std::ostream& o, const dqi::HanConfigAssessor& p )
623{
624 p.PrintIOStream(o);
625 return o;
626}
627
628
629std::ostream& operator<<( std::ostream& o, const dqi::HanConfigAssessor* p )
630{
631 p->PrintIOStream(o);
632 return o;
633}
634
std::ostream & operator<<(std::ostream &o, const dqi::HanConfigAssessor &p)
ClassImp(xAOD::Experimental::RFileChecker) namespace xAOD
TGraphErrors * GetEntries(TH2F *histo)
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
static ConditionsSingleton & getInstance()
const std::string & getCondition() const
std::string conditionalSelect(std::string inp, const std::string &condition)
virtual TSeqCollection * GetList()
virtual boost::shared_ptr< dqm_core::Node > Visit(const HanConfigAssessor *node, boost::shared_ptr< dqm_core::Region > dqParent)=0
virtual HanConfigAlgLimit GetAlgLimit(std::string name_) const
virtual void AddAlgPar(const HanConfigAlgPar &algPar_)
TSeqCollection * m_algLimits
virtual float GetWeight() const
virtual const char * GetAlgName() const
virtual std::string GetUniqueName() const
virtual TIter GetAllAlgStrPars() const
virtual const char * GetHistPath() const
virtual TIter GetAllAlgLimits() const
virtual void SetAlgName(std::string name_)
virtual const char * GetAlgLibName() const
TSeqCollection * m_annotations
virtual void SetIsRegex(bool isRegex_)
virtual const HanConfigParMap * GetAnnotation(std::string name_) const
virtual TSeqCollection * GetList(TDirectory *basedir, std::map< std::string, TSeqCollection * > &mp)
virtual bool GetIsRegex() const
virtual void SetAlgRefName(std::string name_)
virtual void SetWeight(float weight_)
HanConfigAssessor & operator=(const HanConfigAssessor &other)
virtual HanConfigParMap GetAlgStrPar(std::string name_) const
virtual void SetAlgLibName(std::string name_)
virtual void AddAlgLimit(const HanConfigAlgLimit &algLim_)
virtual void AddAlgStrPar(const HanConfigParMap &algPar_)
TSeqCollection * m_algStrPars
virtual std::string GetAlgRefName() const
virtual void Accept(Visitor &visitor, boost::shared_ptr< dqm_core::Region > dqParent) const
virtual void AddAnnotation(const HanConfigParMap &annotation_)
virtual void SetName(std::string name_)
virtual TIter GetAllAlgPars() const
virtual void PrintIOStream(std::ostream &o) const
virtual const char * GetName() const
virtual TIter GetAllAnnotations() const
virtual const char * GetAlgRefString() const
virtual HanConfigAlgPar GetAlgPar(std::string name_) const
virtual const char * GetValue() const
virtual TList * GetList()
TSeqCollection * newTObjArray(const char *name, TObject *obj=0, Int_t size=TCollection::kInitCapacity)
Definition HanUtils.cxx:27
TKey * getObjKey(TDirectory *dir, const std::string &path)
Definition HanUtils.cxx:36
TSeqCollection * newTList(const char *name, TObject *obj=0)
Definition HanUtils.cxx:18