ATLAS Offline Software
Loading...
Searching...
No Matches
HanConfig.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <cstring> // strncmp()
8
9#include <iostream>
10
11#include <sstream>
12
13#include <TCollection.h>
14#include <TDirectory.h>
15#include <TFile.h>
16#include <TGraph.h>
17#include <TH1.h>
18#include <TKey.h>
19#include <TBox.h>
20#include <TLine.h>
21#include <TROOT.h>
22#include <TEfficiency.h>
23#include <TPython.h>
24
40#include "dqm_core/LibraryManager.h"
41#include "dqm_core/Parameter.h"
42#include "dqm_core/ParameterConfig.h"
43#include "dqm_core/Region.h"
44#include "dqm_core/RegionConfig.h"
45#include <boost/algorithm/string/classification.hpp>
46#include <boost/algorithm/string/split.hpp>
47#include <boost/algorithm/string/join.hpp>
48#include <boost/algorithm/string/trim.hpp>
49#include <utility>
50#include <cctype>
51#include <ranges>
52
54
55ATLAS_NO_CHECK_FILE_THREAD_SAFETY; // standalone application
56
58
59namespace{
60 const std::string inputNameStr{"inputname"};
61}
62
63namespace dqi {
64
65// *********************************************************************
66// Public Methods
67// *********************************************************************
68
71 : m_config(0)
72 , m_dqRoot()
73 , m_top_level(0)
74 , m_metadata(0)
75{
76}
77
78
81{
82 delete m_config;
83 /* delete m_dqRoot; */
84 delete m_top_level;
85 if (m_metadata) m_metadata->Delete();
86 delete m_metadata;
87}
88
89namespace {
90 bool TestMiniNodeIsRegex(const MiniConfigTreeNode* node) {
91 std::string regexflag(node->GetAttribute("regex"));
92 std::ranges::transform(regexflag, regexflag.begin(), [](unsigned char c) { return std::tolower(c); });
93 if (regexflag == "1" || regexflag == "true" || regexflag == "yes") {
94 return true;
95 }
96 return false;
97 }
98}
99
100void
102AssembleAndSave( const std::string & infileName, const std::string & outfileName, const std::string & connectionString, long runNumber, bool bulk)
103{
104 std::unique_ptr< TFile > outfile( TFile::Open( outfileName.c_str(),
105 "RECREATE" ) );
107
108 // Collect reference histograms and copy to config file
109 MiniConfig refconfig;
110 refconfig.AddKeyword("reference");
111 refconfig.ReadFile(infileName);
112 TMap refsourcedata;
113 refsourcedata.SetOwnerKeyValue();
114 RefVisitor refvisitor( outfile.get(), directories, &refsourcedata );
115 refconfig.SendVisitor( refvisitor );
116
117 DatabaseConfig databaseConfig(connectionString, runNumber);
118 RefWriter refwriter(databaseConfig, bulk);
119 refconfig.SendWriter( refwriter );
120 databaseConfig.Disconnect();
121
122 // Collect threshold definitions
123 MiniConfig thrconfig;
124 thrconfig.AddKeyword("thresholds");
125 thrconfig.AddAttributeKeyword("limits");
126 thrconfig.ReadFile(infileName);
127
128 // Collect algorithm definitions
129 MiniConfig algconfig;
130 algconfig.AddKeyword("algorithm");
131 algconfig.ReadFile(infileName);
132
133 // Collect region definitions
134 MiniConfig regconfig;
135 regconfig.AddKeyword("output");
136 regconfig.ReadFile(infileName);
137
138 // Collect histogram definitions
139 MiniConfig histconfig;
140 histconfig.AddKeyword("dir");
141 histconfig.AddAttributeKeyword("hist");
142 histconfig.SetAttribKeywordPropagateDown(false);
143 histconfig.ReadFile(infileName);
144
145 // Collect and write composite-algorithm definitions
146 MiniConfig compalgconfig;
147 compalgconfig.AddKeyword("compositealgorithm");
148 compalgconfig.ReadFile(infileName);
149 CompAlgVisitor compalgvisitor(outfile.get(), compalgconfig);
150 compalgconfig.SendVisitor(compalgvisitor);
151
152 MiniConfig metadataconfig;
153 metadataconfig.AddKeyword("metadata");
154 metadataconfig.ReadFile(infileName);
155 MetadataVisitor metadatavisitor(outfile.get(), metadataconfig);
156 metadataconfig.SendVisitor(metadatavisitor);
157
158 // Assemble into a hierarchical configuration
159 outfile->cd();
160 std::unique_ptr< HanConfigGroup > root( new HanConfigGroup() );
161
162 RegionVisitor regvisitor( root.get(), algconfig, thrconfig, refconfig, directories );
163 regconfig.SendVisitor( regvisitor );
164
165 AssessmentVisitor histvisitor( root.get(), algconfig, thrconfig, refconfig, outfile.get(),
166 directories, &refsourcedata );
167 histconfig.SendVisitor( histvisitor );
168
169 outfile->WriteTObject(&refsourcedata, "refsourcedata");
170 outfile->cd();
171 root->Write();
172 outfile->Write();
173 outfile->Close();
174}
175
176void
178BuildMonitors( std::string configName, HanInputRootFile& input, HanOutput& output )
179{
180 bool isInitialized = Initialize( configName );
181 if( !isInitialized ) {
182 return;
183 }
184
185 m_dqRoot = BuildMonitorsNewRoot( std::move(configName), input, output );
186
187 output.setConfig( this );
188}
189
190boost::shared_ptr<dqm_core::Region>
192BuildMonitorsNewRoot( std::string configName, HanInputRootFile& input, dqm_core::Output& output )
193{
194 bool isInitialized = Initialize( configName );
195 if( !isInitialized ) {
196 return boost::shared_ptr<dqm_core::Region>();
197 }
198
199 TDirectory* topdir = const_cast<TDirectory*>(input.getBasedir());
200 TPython::Bind(m_config, "config");
201 TPython::Bind(m_top_level, "top_level");
202 TPython::Bind(topdir, "path");
203 TPython::Exec("from DataQualityInterfaces.han import FixRegion, logLevel");
204 const char* debugflag = std::getenv("HANDEBUG");
205 if (!debugflag) {
206 TPython::Exec("logLevel('INFO')");
207 } else {
208 TPython::Exec("logLevel('DEBUG')");
209 }
210
211#if ROOT_VERSION_CODE >= ROOT_VERSION(6,33,01)
212 std::any result;
213 TPython::Exec ("_anyresult = ROOT.std.make_any['dqi::HanConfigGroup'](FixRegion(config, top_level, path))", &result);
214 auto new_top_level = new dqi::HanConfigGroup (std::any_cast<HanConfigGroup>(result));
215#else
216 HanConfigGroup* new_top_level = TPython::Eval("FixRegion(config, top_level, path)");
217#endif
218 delete m_top_level;
219 m_top_level = new_top_level;
220
221 std::string algName( m_top_level->GetAlgName() );
222 std::string algLibName( m_top_level->GetAlgLibName() );
223 if( algLibName != "" ) {
224 try {
225 dqm_core::LibraryManager::instance().loadLibrary( algLibName );
226 }
227 catch ( dqm_core::Exception& ex ) {
228 //std::cout << "Can't load library " << algLibName << ". Continuing regardless ..." << std::endl;
229 }
230 }
231 dqm_core::RegionConfig regc( algName, 1.0 );
232 boost::shared_ptr<dqm_core::Region> retval(dqm_core::Region::createRootRegion( "top_level", input, output, regc ));
233
234 ConfigVisitor confvisitor( m_config, &output );
235 m_top_level->Accept( confvisitor, retval );
236 return retval;
237}
238
239void
241BuildConfigOutput( std::string configName, TFile* inputFile, const std::string & path,
242 HanOutput::DQOutputMap_t* outputMap, TSeqCollection* outputList )
243{
244 bool isInitialized = Initialize( configName );
245 if( !isInitialized ) {
246 return;
247 }
248
249 if( inputFile == 0 ) {
250 return;
251 }
252
253 TDirectory* basedir(0);
254 if( path != "" ) {
255 std::string pathForSearch = path + "/dummyName";
256 basedir = ChangeInputDir( inputFile, std::move(pathForSearch) );
257 }
258
259 if( basedir == 0 )
260 basedir = inputFile;
261
262 TIter mdIter(m_metadata);
263 TSeqCollection* mdList = newTList("HanMetadata_");
264 HanConfigMetadata* md(0);
265 while ((md = dynamic_cast<HanConfigMetadata*>(mdIter()))) {
266 mdList->Add( md->GetList(basedir,*outputMap) );
267 }
268 TSeqCollection* top_level_list = m_top_level->GetList(basedir,*outputMap);
269 top_level_list->Add( mdList );
270 outputList->Add( top_level_list );
271}
272
273
274TObject*
276GetReference( std::string& groupName, std::string& name )
277{
278 /* if( m_top_level == 0 ) {
279 return 0;
280 }
281
282 HanConfigGroup* parent = m_top_level->GetNode(groupName);
283 if( parent == 0 ) {
284 parent = m_top_level;
285 } */
286
287 std::unique_ptr<const HanConfigAssessor> a(GetAssessor( groupName, name ));
288 if (!a.get()) return 0;
289 std::string refName( a->GetAlgRefName() );
290 if( refName != "" ) {
291 TKey* key = getObjKey( m_config, refName );
292 if( key != 0 ) {
293 //TObject* ref = m_config->Get(refName.c_str());
294 TObject* ref = key->ReadObj();
295 if (ref)
296 return ref;
297 }
298 }
299
300 return 0;
301}
302
303std::string
304SplitReference(std::string refPath, const std::string& refName )
305{
306 // this will never be run in a multithread environment
307 static std::map<std::string, std::string> mappingCache;
308
309 //Split comma sepated inputs into individual file names
310 std::vector<std::string> refFileDirList;
311 boost::split(refFileDirList, refPath, boost::is_any_of(","));
312
313 // construct vector of files (& clean up leading/trailing spaces)
314 std::vector<std::string> refFileList;
315 for (const auto& dir : refFileDirList ) {
316 refFileList.push_back(boost::algorithm::trim_copy(dir+refName));
317 }
318
319 // Use TFile::Open | syntax to try opening the files in sequence
320 std::string tfilestring = boost::algorithm::join(refFileList, "|");
321 // have we already resolved?
322 const auto& cachehit = mappingCache.find(tfilestring);
323 if (cachehit != mappingCache.end()) {
324 return cachehit->second;
325 }
326 // if not, do lookup
327 if (const auto* f = TFile::Open(tfilestring.c_str())) {
328 mappingCache[tfilestring] = f->GetName();
329 } else {
330 std::cerr << "Unable to open any reference files in " << tfilestring << ", reference will not be included" << std::endl;
331 mappingCache[tfilestring] = "";
332 }
333 return mappingCache[tfilestring];
334}
335
336const HanConfigAssessor*
338GetAssessor( std::string& groupName, std::string& name ) const
339{
340 if( m_top_level == 0 ) {
341 return 0;
342 }
343
344 HanConfigGroup* parent = m_top_level->GetNode(groupName);
345 if( parent == 0 ) {
346 parent = m_top_level;
347 }
348
349 const HanConfigAssessor& a = parent->GetAssessor(name);
350
351 return new HanConfigAssessor(a);
352}
353
354void
356GetRegexList(std::set<std::string>& regexlist)
357{
358 RegexVisitor rv(regexlist);
359 m_top_level->Accept(rv, boost::shared_ptr<dqm_core::Region>());
360}
361
362// *********************************************************************
363// Protected Methods
364// *********************************************************************
365
367RefVisitor( TFile* outfile_, HanConfig::DirMap_t& directories_, TMap* refsourcedata_ )
368 : m_outfile(outfile_)
369 , m_directories(directories_)
370 , m_refsourcedata(refsourcedata_)
371{
372}
373
374
375void
378{
379 TObject* obj;
380 std::string name = node->GetAttribute("name");
381 std::string fileName = node->GetAttribute("file");
382 if( fileName != "" && name != "" && name != "same_name" ) {
383 fileName = SplitReference(node->GetAttribute("location"), fileName);
384 std::string refInfo = node->GetAttribute("info");
385 if (refInfo == "") {
386 std::cerr << "INFO: Reference " << name << " is defined without an \"info\" attribute. Consider adding one"
387 << std::endl;
388 }
389 std::unique_ptr<TFile> infile( TFile::Open(fileName.c_str()) );
390 TKey* key = getObjKey( infile.get(), name );
391 if( key == 0 ) {
392 std::cerr << "WARNING: HanConfig::RefVisitor::Visit(): Reference not found: \"" << name << "\"\n";
393 return;
394 }
395// TDirectory* dir = ChangeOutputDir( m_outfile, name, m_directories );
396// dir->cd();
397 //sami
398 m_outfile->cd();
399 obj = key->ReadObj();
400 // obj->Write();
402 //node->SetAttribute("newname",newHistoName,false);//add new name to tree
403 // std::cout<<"Writing \""<<name<<"\" in \""<<fileName<<"\" with new name \""<<newHistoName<<"\""<<std::endl;
404 dqi::ConditionsSingleton::getInstance().setNewReferenceName(fileName+":/"+name,newHistoName);
405 obj->Write(newHistoName.c_str());
406 delete obj;
407 TObjString* fnameostr = new TObjString(fileName.c_str());
408 m_refsourcedata->Add(new TObjString(newHistoName.c_str()),
409 fnameostr);
410 if (! m_refsourcedata->FindObject(fileName.c_str())) {
411 m_refsourcedata->Add(fnameostr->Clone(), refInfo != "" ? new TObjString(refInfo.c_str())
412 : new TObjString("Reference"));
413 }
414 }
415}
416
418RefWriter( DatabaseConfig& databaseConfig_, const bool bulk)
419 : m_databaseConfig(databaseConfig_),
420 m_bulk(bulk)
421{
422}
423
424
425void
428{
429 std::string database = node->GetAttribute("database");
430
431 if(database != "") {
432 database += (m_bulk ? "-physics-UPD4" : "-express-UPD1");
433 nlohmann::json jsonPayload = m_databaseConfig.GetPayload(database);
434 std::string reference = node->GetName();
435
436 if(jsonPayload.find(reference) != jsonPayload.end()) {
437 nlohmann::json referenceJson = jsonPayload[std::move(reference)];
438 for (nlohmann::json::iterator it = referenceJson.begin(); it != referenceJson.end(); ++it) {
439 node->SetAttribute(it.key(), it.value(), false);
440 }
441 } else {
442 std::cerr << "Unable to find reference definition in database: " << reference << '\n';
443 }
444 }
445}
446
448AssessmentVisitorBase( HanConfigGroup* root_, const MiniConfig& algConfig_,
449 const MiniConfig& thrConfig_, const MiniConfig& refConfig_,
450 TFile* outfile_, HanConfig::DirMap_t& directories_,
451 TMap* refsourcedata_ )
452 : m_root(root_)
453 , m_algConfig(algConfig_)
454 , m_thrConfig(thrConfig_)
455 , m_refConfig(refConfig_)
456 , m_outfile(outfile_)
457 , m_directories(directories_)
458 , m_refsourcedata(refsourcedata_)
459{
460}
461
462std::shared_ptr<TFile>
464GetROOTFile( std::string& fname )
465{
466 auto it = m_filecache.find(fname);
467 if (it != end(m_filecache)) {
468 return it->second;
469 } else {
470 if (m_badPaths.find(fname) != m_badPaths.end()) {
471 return std::shared_ptr<TFile>(nullptr);
472 }
473 std::shared_ptr<TFile> thisptr(TFile::Open(fname.c_str()));
474 if (thisptr.get()) {
475 return ( m_filecache[fname] = std::move(thisptr) );
476 } else {
477 m_badPaths.insert(fname);
478 return thisptr;
479 }
480 }
481}
482
483void
485PopulateKeyCache(const std::string& fname, std::shared_ptr<TFile> & file) {
486 auto& vec = m_keycache[fname];
487 dolsr(file.get(), vec);
488}
489
490void
492EnsureKeyCache(std::string& fname) {
494 auto file = GetROOTFile(fname);
495 if (file) {
496 if (m_keycache.find(fname) != m_keycache.end()) {
497 return;
498 } else {
499 m_keycache[fname].reserve(100000);
500 PopulateKeyCache(fname, file);
501 }
502 }
503}
504
505float AttribToFloat(const MiniConfigTreeNode* node, const std::string& attrib,
506 const std::string& warningString, bool local=false)
507{
508 std::istringstream valstream;
509 if (local) {
510 valstream.str(node->GetAttributeLocal(attrib));
511 } else {
512 valstream.str(node->GetAttribute(attrib));
513 }
514 float val;
515 valstream >> val;
516 if (! valstream) {
517 std::cerr << warningString << std::endl;
518 return 0;
519 } else {
520 return val;
521 }
522}
523
524void
526GetAlgorithmConfiguration( HanConfigAssessor* dqpar, const std::string& algID,
527 const std::string& assessorName )
528{
529 // bool hasName(false);
530 std::set<std::string> algAtt;
531 m_algConfig.GetAttributeNames( algID, algAtt );
532 std::set<std::string>::const_iterator algAttEnd = algAtt.end();
533 for( std::set<std::string>::const_iterator i = algAtt.begin(); i != algAttEnd; ++i ) {
534 std::string trail("");
535 std::string::size_type pos = (*i).find('|');
536 if (pos != std::string::npos) {
537 trail = (*i).substr(pos + 1, std::string::npos);
538 }
539 if( *i == "name" ) {
540 // hasName = true;
541 std::string algName( m_algConfig.GetStringAttribute(algID,"name") );
542 dqpar->SetAlgName( std::move(algName) );
543 }
544 else if( *i == "libname" ) {
545 std::string algLibName( m_algConfig.GetStringAttribute(algID,"libname") );
546 dqpar->SetAlgLibName( std::move(algLibName) );
547 }
548 else if( *i == "thresholds" || trail == "thresholds" ) {
549 std::string thrID( m_algConfig.GetStringAttribute(algID,*i) );
550 std::set<std::string> thrAtt;
551 m_thrConfig.GetAttributeNames( thrID, thrAtt );
552 std::set<std::string>::const_iterator thrAttEnd = thrAtt.end();
553 for( std::set<std::string>::const_iterator t = thrAtt.begin(); t != thrAttEnd; ++t ) {
554 std::string thrAttName = *t;
555 std::string thrAttVal = m_thrConfig.GetStringAttribute( thrID, thrAttName );
556 std::string limName = thrAttVal + std::string("/") + thrAttName;
557 HanConfigAlgLimit algLim;
558 if (pos != std::string::npos) {
559 algLim.SetName( (*i).substr(0, pos) + std::string("|") + *t );
560 } else {
561 algLim.SetName( *t );
562 }
563 algLim.SetGreen( m_thrConfig.GetFloatAttribute(limName,"warning") );
564 algLim.SetRed( m_thrConfig.GetFloatAttribute(std::move(limName),"error") );
565 dqpar->AddAlgLimit( algLim );
566 }
567 }
568 else if( *i == "reference" ) {
569 // structure: if regex, store TMap of matching hist name -> names of reference objects
570 // if not regex, just store names of reference objects
571 // reference objects are TObjArrays if multiple references, else some kind of TObject
572 std::string tmpRefID=m_algConfig.GetStringAttribute(algID,"reference");
573 //std::cout<<"Got tmpRefID=\""<<tmpRefID<<"\""<<std::endl;
575 //parses
576 std::vector<std::pair<std::string,std::string> > condPairs=CS.getConditionReferencePairs(std::move(tmpRefID));
577 std::stringstream newRefString;
578 // for each condition ...
579 for(size_t t=0;t<condPairs.size();t++){
580 bool refsuccess(false);
581 std::string refID=condPairs.at(t).second;
582 std::string cond=condPairs.at(t).first;
583 std::vector<std::string> refIDVec;
584 // the following allows us to accumulate objects as necessary
585 std::vector<std::vector<std::pair<std::string, std::shared_ptr<TObject>>>> objects;
586 std::string newRefId("");
587 bool isMultiRef(false);
588 std::vector<std::string> sourceMatches;
589 if (refID[0] == '[') {
590 std::string cleanedRefID = refID;
591 boost::algorithm::trim_if(cleanedRefID, boost::is_any_of("[] "));
592 isMultiRef = true;
593 boost::split(refIDVec, cleanedRefID, boost::is_any_of(","));
594 // toarray = new TObjArray();
595 // toarray->SetOwner(kTRUE);
596 } else {
597 refIDVec.push_back(refID);
598 }
599
600 // special case: not same_name, and is not a multiple reference
601 // in these cases, things have been copied into file already
602 std::string algRefName( m_refConfig.GetStringAttribute(refID,"name") );
603 std::string algRefInfo( m_refConfig.GetStringAttribute(refID,"info") );
604 std::string algRefFile( m_refConfig.GetStringAttribute(refID,"file") );
605 if (algRefName != "same_name" && !isMultiRef) {
606 newRefId=CS.getNewReferenceName(algRefFile+":/"+algRefName,true);
607
608 if(newRefId.empty()){
609 std::string algRefPath( m_refConfig.GetStringAttribute(refID,"path") );
610 std::cerr<<"Warning New reference id is empty for refId=\""
611 <<refID<<"\", cond=\""<<cond<<"\", assessorName=\""
612 <<assessorName<<"\", algRefName=\""
613 <<algRefName<<"\""<<std::endl;
614 std::cerr << "AlgRefPath=" << algRefPath << " AlgRefInfo=" << algRefInfo << std::endl;
615 } else {
616 refsuccess = true;
617 }
618 } else {
619 // is same_name, or a regex multiple reference
620 objects.resize(refIDVec.size());
621 std::string absAlgRefName, algRefPath, algRefInfo;
622 for (size_t iRefID = 0; iRefID < refIDVec.size(); ++iRefID) {
623 const auto& thisRefID = refIDVec[iRefID];
624 algRefName = m_refConfig.GetStringAttribute(thisRefID,"name");
625 algRefPath = m_refConfig.GetStringAttribute(thisRefID,"path");
626 algRefInfo = m_refConfig.GetStringAttribute(thisRefID,"info");
627 algRefFile = m_refConfig.GetStringAttribute(thisRefID,"file");
628 if (algRefInfo == "") {
629 std::cerr << "INFO: Reference " << thisRefID << " is defined without an \"info\" attribute. Consider adding one"
630 << std::endl;
631 }
632 absAlgRefName = "";
633 if( algRefPath != "" ) {
634 absAlgRefName += algRefPath;
635 absAlgRefName += "/";
636 }
637 if( algRefName == "same_name" ) {//sameName reference
638 algRefName = assessorName;
639 absAlgRefName += algRefName;
640 algRefFile = SplitReference( m_refConfig.GetStringAttribute(thisRefID,"location"), algRefFile);
641
642 if( algRefFile != "" ) {
643 std::shared_ptr<TFile> infile = GetROOTFile(algRefFile);
644 if ( ! infile.get() ) {
645 std::cerr << "HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile << " not found" << std::endl;
646 continue;
647 }
648 std::vector<std::string> localMatches;
649 if (dqpar->GetIsRegex()) {
650 if (! sourceMatches.empty()) {
651 std::cerr << "same_name appears twice in a reference request???" << std::endl;
652 } else {
653 // change Python to Boost syntax for named captures
654 std::string regexPattern = boost::regex_replace(absAlgRefName, boost::regex("\\(\\?P=([^)]*)\\)"), "\\\\k<\\1>", boost::format_all);
655 boost::regex re(boost::replace_all_copy(regexPattern, "(?P", "(?"));
656 EnsureKeyCache(algRefFile);
657 for (const auto& iKey: m_keycache[algRefFile]) {
658 if (boost::regex_match(iKey, re)) {
659 sourceMatches.push_back(iKey);
660 TKey* key = getObjKey(infile.get(), iKey);
661 m_outfile->cd(); //we are writing to the / folder of file
662 objects[iRefID].emplace_back(iKey, key->ReadObj());
663 }
664 }
665 }
666 } else {
667 TKey* key = getObjKey( infile.get(), absAlgRefName );
668 if( key == 0 ) {
669 // no reference
670 continue;
671 }
672 m_outfile->cd(); //we are writing to the / folder of file
673 std::shared_ptr<TObject> q(key->ReadObj());
674 objects[iRefID].emplace_back(absAlgRefName, q);
675 }
676 }
677 } else {
678 absAlgRefName += algRefName;
679 algRefFile = SplitReference( m_refConfig.GetStringAttribute(thisRefID,"location"), algRefFile);
680
681 if( algRefFile != "" ) {
682 std::shared_ptr<TFile> infile = GetROOTFile(algRefFile);
683 if ( ! infile.get() ) {
684 std::cerr << "HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile << " not found" << std::endl;
685 continue;
686 }
687
688 TKey* key = getObjKey( infile.get(), absAlgRefName );
689 if( key == 0 ) {
690 // no reference
691 std::cerr << "Couldn't find reference " << absAlgRefName << std::endl;
692 continue;
693 }
694 m_outfile->cd(); //we are writing to the / folder of file
695 std::shared_ptr<TObject> q(key->ReadObj());
696 TNamed* qn = dynamic_cast<TNamed*>(q.get());
697 if (isMultiRef && qn) {
698 std::string multirefname = thisRefID; // fallback
699 if (algRefInfo != "") {
700 multirefname = algRefInfo;
701 } else if (algRefFile != "") {
702 multirefname = algRefFile;
703 }
704 qn->SetName(multirefname.c_str());
705 }
706 objects[iRefID].emplace_back(absAlgRefName, q);
707 } else {
708 std::cerr << "No file specified for " << absAlgRefName << " ?" << std::endl;
709 }
710 }
711 }
712
713 std::shared_ptr<TObject> toWriteOut;
714 std::string algRefUniqueName;
715 std::string algRefSourceInfo = (algRefInfo != "" ? algRefInfo.c_str() : "Reference");
716
717 if (!isMultiRef) {
718 // is this a regex?
719 if (dqpar->GetIsRegex() && !objects[0].empty()) {
720 refsuccess = true;
721 TMap* tmapobj = new TMap();
722 tmapobj->SetOwnerKeyValue();
723 for (const auto& thisPair: objects[0]) {
724 std::unique_ptr<TObject> cobj(thisPair.second->Clone());
725 TNamed* hobj = dynamic_cast<TNamed*>(cobj.get());
726 if (hobj) {
727 hobj->SetName(refID.c_str());
728 }
729 algRefUniqueName = algRefFile+":/"+thisPair.first;
730 newRefId=CS.getNewReferenceName(algRefUniqueName,true);
731 if(newRefId.empty()){
732 newRefId=CS.getNewRefHistoName();
733 CS.setNewReferenceName(algRefUniqueName,newRefId);
734 m_refsourcedata->Add(new TObjString(newRefId.c_str()),
735 new TObjString(algRefFile.c_str()));
736 cobj->Write(newRefId.c_str(), 1);
737 }
738 m_outfile->cd();
739 std::string maprefstring(thisPair.first);
740 if (algRefPath != "") {
741 boost::replace_first(maprefstring, algRefPath + "/", "");
742 }
743 tmapobj->Add(new TObjString(maprefstring.c_str()),
744 new TObjString(newRefId.c_str()));
745 }
746 toWriteOut.reset(tmapobj);
747 algRefUniqueName = algRefFile+"_regex:/"+dqpar->GetUniqueName();
748 }
749 else {
750 algRefUniqueName = algRefFile+":/"+absAlgRefName;
751 if (! objects[0].empty()) {
752 refsuccess = true;
753 toWriteOut = objects[0][0].second;
754 }
755 }
756 } else { // is multiref
757 algRefUniqueName=cond+"_multiple:/"+absAlgRefName;
758 algRefSourceInfo="Multiple references";
759 // is this a regex?
760 if (dqpar->GetIsRegex()) {
761 // not implemented for now
762 } else {
763 TObjArray* toarray = new TObjArray();
764 toarray->SetOwner(true);
765 for (size_t iRef = 0; iRef < objects.size(); ++iRef) {
766 // check that object is actually valid (might be missing a reference)
767 if (! objects[iRef].empty()) {
768 toarray->Add(objects[iRef][0].second->Clone());
769 }
770 }
771 toWriteOut.reset(toarray);
772 refsuccess = true;
773 }
774 }
775
776 if (refsuccess && toWriteOut) {
777 // register top level object
778 newRefId=CS.getNewReferenceName(algRefUniqueName,true);
779 if(newRefId.empty()){
780 newRefId=CS.getNewRefHistoName();
781 CS.setNewReferenceName(algRefUniqueName,newRefId);
782 if (! isMultiRef) {
783 // ref to file
784 m_refsourcedata->Add(new TObjString(newRefId.c_str()),
785 new TObjString(algRefFile.c_str()));
786 // file to further info
787 if (! m_refsourcedata->FindObject(algRefFile.c_str())) {
788 m_refsourcedata->Add(new TObjString(algRefFile.c_str()),
789 new TObjString(algRefSourceInfo.c_str()));
790 }
791 } else {
792 // ref to "Multiple references"
793 m_refsourcedata->Add(new TObjString(newRefId.c_str()),
794 new TObjString(algRefSourceInfo.c_str()));
795 }
796 }
797 m_outfile->cd();
798 toWriteOut->Write(newRefId.c_str(), 1);
799 }
800 }
801
802 if (!newRefId.empty()) {
803 if(!cond.empty()){
804 newRefString<<cond<<":"<<newRefId<<";";
805 }else{
806 newRefString<<newRefId;
807 }
808 }
809 }
810 dqpar->SetAlgRefName((newRefString.str()));
811
812 }else {
813 std::string stringValue = m_algConfig.GetStringAttribute( algID, *i );
814 float numberValue;
815 std::istringstream parser( stringValue );
816 parser >> numberValue;
817 if ( ! parser ) {
818 HanConfigParMap algPar;
819 algPar.SetName( *i );
820 algPar.SetValue( stringValue );
821 dqpar->AddAlgStrPar( algPar );
822 } else {
823 HanConfigAlgPar algPar;
824 algPar.SetName( *i );
825 algPar.SetValue( numberValue );
826 dqpar->AddAlgPar( algPar );
827 }
828 }
829 }
830}
831
832
834RegionVisitor( HanConfigGroup* root_, const MiniConfig& algConfig_,
835 const MiniConfig& thrConfig_, const MiniConfig& refConfig_,
836 HanConfig::DirMap_t& directories_ )
837 : AssessmentVisitorBase( root_, algConfig_, thrConfig_, refConfig_, 0, directories_, nullptr )
838{
839}
840
841
842void
845{
846 const MiniConfigTreeNode* parent = node->GetParent();
847 if( parent == 0 )
848 return;
849
850 const MiniConfigTreeNode* grandparent = parent->GetParent();
851 auto alloc = std::make_unique<HanConfigGroup>();
852 HanConfigGroup* reg = (grandparent==0) ? m_root : alloc.get();
853
854
855
856 reg->SetName( node->GetName() );
857 reg->SetPathName( node->GetPathName() );
858
859 std::string algID( node->GetAttribute("algorithm") );
860 if( algID != "" ) {
861 GetAlgorithmConfiguration( reg, algID );
862 } else {
863 std::cerr << "Warning: no summary algorithm specified for " << node->GetPathName() << std::endl
864 << "This is probably not what you want" << std::endl;
865 }
866
867 if (node->GetAttributeLocal("weight") != "") {
868 std::ostringstream err;
869 err << "Weight is not a floating point attribute for " << node->GetPathName() << "; setting to 0";
870 reg->SetWeight(AttribToFloat(node, "weight", err.str(), true));
871 }
872
873 if( grandparent != 0 ) {
874 std::string path( parent->GetPathName() );
875 HanConfigGroup* parentReg = m_root->GetNode( path );
876 parentReg = (parentReg==0) ? m_root : parentReg;
877 if( parentReg != 0 ) {
878 parentReg->AddGroup( *reg );
879 }
880 }
881}
882
884RegexVisitor( std::set<std::string>& regexes_ )
885 : m_regexes(regexes_)
886{
887}
888
889boost::shared_ptr<dqm_core::Node>
891Visit( const HanConfigAssessor* node, boost::shared_ptr<dqm_core::Region> )
892{
893 // ignore Groups
894 if (dynamic_cast<const HanConfigGroup*>(node) != NULL) {
895 return boost::shared_ptr<dqm_core::Parameter>();
896 }
897 if (node->GetIsRegex()) {
898 m_regexes.insert(node->GetName());
899 }
900 return boost::shared_ptr<dqm_core::Parameter>();
901}
902
904AssessmentVisitor( HanConfigGroup* root_, const MiniConfig& algConfig_,
905 const MiniConfig& thrConfig_, const MiniConfig& refConfig_,
906 TFile* outfile_, HanConfig::DirMap_t& directories_,
907 TMap* refsourcedata_ )
908 : AssessmentVisitorBase( root_, algConfig_, thrConfig_, refConfig_, outfile_, directories_, refsourcedata_ )
909{
910}
911
912void
915{
916 std::set<std::string> histAtt;
917 node->GetAttributeNames( histAtt );
918 std::set<std::string> defined;
919 std::string regID("");
920 std::string algID("");
921 std::set<std::string>::const_iterator histAttEnd = histAtt.end();
922 for( std::set<std::string>::const_iterator h = histAtt.begin(); h != histAttEnd; ++h ) {
923 const MiniConfigTreeNode* histNode = node->GetDaughter( *h );
924 if( histNode == 0 )
925 continue;
926
927 algID = histNode->GetAttribute("algorithm");
928 regID = histNode->GetAttribute("output");
929
930 if( algID == "" ) {
931 std::cerr << "No \"algorithm\" defined for " << histNode->GetPathName() << "\n";
932 continue;
933 }
934
935 if( regID == "" )
936 regID = "top_level";
937
938 std::string strNodeName(histNode->GetName());
939 std::string strHistName, strFullHistName;
940 std::string::size_type atsign = strNodeName.find('@');
941 if (atsign == std::string::npos) {
942 strHistName = std::move(strNodeName);
943 strFullHistName = histNode->GetPathName();
944 } else {
945 strHistName = strNodeName.substr(0, atsign);
946 strFullHistName = histNode->GetPathName();
947 strFullHistName.resize(strFullHistName.find('@'));
948 }
949
950 if( strHistName == "all_in_dir" )
951 continue;
952
953 if( defined.find(histNode->GetPathName()) != defined.end() )
954 continue;
955
956 HanConfigAssessor dqpar;
957 dqpar.SetName( histNode->GetPathName() );
958
959 dqpar.SetIsRegex(TestMiniNodeIsRegex(histNode));
960
961 if (histNode->GetAttribute("weight") != "") {
962 std::ostringstream err;
963 err << "Weight attribute not a floating point type for " << histNode->GetPathName() << "; setting to zero";
964 dqpar.SetWeight(AttribToFloat(histNode, "weight",
965 err.str()));
966 }
967
968 GetAlgorithmConfiguration( &dqpar, algID, strFullHistName );
969
970 std::set<std::string> histAtt2;
971 histNode->GetAttributeNames( histAtt2 );
972 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
973 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
974 if (node->GetDaughter( *h2 )
975 || *h2 == "algorithm" || *h2 == "output" || *h2 == "reference"
976 || *h2 == "weight" || *h2 == "regex") {
977 continue;
978 }
979 HanConfigParMap parMap;
980 parMap.SetName(*h2); parMap.SetValue(histNode->GetAttribute(*h2));
981 dqpar.AddAnnotation(parMap);
982 }
983
984 // Add the histogram name
985 HanConfigParMap parMap;
986 parMap.SetName(inputNameStr); parMap.SetValue( strFullHistName );
987 dqpar.AddAnnotation(parMap);
988
989 HanConfigGroup* dqreg = m_root->GetNode( regID );
990 dqreg = (dqreg==0) ? m_root : dqreg;
991 if( dqreg != 0 ) {
992 dqreg->AddAssessor( dqpar );
993 }
994 defined.insert( std::move(strFullHistName) );
995 }
996
997 for( std::set<std::string>::const_iterator h = histAtt.begin(); h != histAttEnd; ++h ) {
998 const MiniConfigTreeNode* histNode = node->GetDaughter( *h );
999 if( histNode == 0 )
1000 continue;
1001
1002 algID = histNode->GetAttribute("algorithm");
1003 regID = histNode->GetAttribute("output");
1004
1005 if( algID == "" ) {
1006 std::cerr << "No \"algorithm\" defined for " << histNode->GetPathName() << "\n";
1007 continue;
1008 }
1009
1010 if( regID == "" )
1011 regID = "top_level";
1012
1013 std::string strNodeName(histNode->GetName());
1014 std::string strHistName, strFullHistName, extension;
1015 std::string::size_type atsign = strNodeName.find('@');
1016 if (atsign == std::string::npos) {
1017 strHistName = std::move(strNodeName);
1018 strFullHistName = histNode->GetPathName();
1019 extension = "";
1020 } else {
1021 strHistName = strNodeName.substr(0, atsign);
1022 extension = strNodeName.substr(atsign, std::string::npos);
1023 strFullHistName = histNode->GetPathName();
1024 strFullHistName.resize(strFullHistName.find('@'));
1025 }
1026
1027 if( strHistName == "all_in_dir" ) {
1028
1029 std::string regexflag(histNode->GetAttribute("regex"));
1030 if (histNode->GetAttribute("regex") != "") {
1031 std::cerr << "WARNING: all_in_dir and regex are incompatible; ignoring regex flag for " << histNode->GetPathName()
1032 << "/all_in_dir" << std::endl;
1033 }
1034
1035 std::string refID( histNode->GetAttribute("reference") );
1036 if( refID == "" ) {
1037 std::cerr << "WARNING: No \"reference\" defined for " << histNode->GetPathName() << "\n";
1038 continue;
1039 }
1040 std::string refFile( m_refConfig.GetStringAttribute(refID,"file") );
1041 if( refFile == "" ) {
1042 std::cerr << "WARNING: No \"file\" defined for " << histNode->GetPathName() << "\n";
1043 continue;
1044 }
1045
1046 std::string refPath( m_refConfig.GetStringAttribute(refID,"path") );
1047
1048 std::string objPath("");
1049 std::string absObjPath("");
1050
1051 refFile = SplitReference( m_refConfig.GetStringAttribute(std::move(refID),"location"), refFile);
1052 std::shared_ptr<TFile> infile( GetROOTFile(refFile) );
1053 TDirectory* basedir(0);
1054 TDirectory* dir(0);
1055 TKey* key;
1056
1057 if( refPath != "" ) {
1058 //std::cout << "Searching under path \"" << refPath << "\" for " << "\"" << histNode->GetPathName() << "\"\n";
1059 absObjPath += refPath;
1060 absObjPath += "/";
1061 std::string refPathForSearch = refPath;
1062 refPathForSearch += "/dummyName";
1063 basedir = ChangeInputDir( infile.get(), refPathForSearch );
1064 if( basedir == 0 ) {
1065 std::cerr << "INFO: Cannot find path \"" << refPath << "\" in reference file\n";
1066 continue;
1067 }
1068 }
1069
1070 if( basedir == 0 )
1071 basedir = infile.get();
1072
1073 std::string allPathName( histNode->GetPathName() );
1074 std::string::size_type i = allPathName.find_last_of('/');
1075 if( i != std::string::npos ) {
1076 objPath = std::string( allPathName, 0, i );
1077 objPath += "/";
1078 absObjPath += std::string( allPathName, 0, i );
1079 absObjPath += "/";
1080 }
1081
1082 dir = ChangeInputDir( basedir, histNode->GetPathName() );
1083 if( dir == 0 ) {
1084 std::cerr << "INFO: Cannot find path \"" << absObjPath << "\" in reference file\n";
1085 continue;
1086 }
1087
1088 TIter next( dir->GetListOfKeys() );
1089 std::string objName;
1090 std::string absObjName;
1091 // we might have multiple loops through 'all_in_dir', but each should
1092 // have unique objects
1093 std::set<std::string> localdefined;
1094 while( (key = dynamic_cast<TKey*>(next())) != 0 ) {
1095 TObject* tmpobj = key->ReadObj();
1096 TH1* tmph = dynamic_cast<TH1*>(tmpobj);
1097 TGraph* tmpg = dynamic_cast<TGraph*>(tmpobj);
1098 TEfficiency* tmpe = dynamic_cast<TEfficiency*>(tmpobj);
1099 if( tmph == 0 && tmpg == 0 && tmpe == 0 )
1100 continue;
1101
1102 objName = objPath;
1103 objName += std::string( tmpobj->GetName() );
1104 absObjName = absObjPath;
1105 absObjName += std::string( tmpobj->GetName() );
1106 delete tmpobj;
1107
1108 if( defined.find(objName) != defined.end() ||
1109 localdefined.find(objName) != localdefined.end() )
1110 continue;
1111
1112 TKey* test = getObjKey( infile.get(), absObjName );
1113 if( test == 0 )
1114 continue;
1115
1116 HanConfigAssessor dqpar;
1117 dqpar.SetName( objName + extension );
1118 GetAlgorithmConfiguration( &dqpar, algID, objName );
1119
1120 if (histNode->GetAttribute("weight") != "") {
1121 std::ostringstream err;
1122 err << "Weight attribute not a floating point type for " << objName << "; setting to zero";
1123 dqpar.SetWeight(AttribToFloat(histNode, "weight",
1124 err.str()));
1125 }
1126
1127 std::set<std::string> histAtt2;
1128 histNode->GetAttributeNames( histAtt2 );
1129 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
1130 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
1131 if (node->GetDaughter( *h2 )
1132 || *h2 == "algorithm" || *h2 == "output" || *h2 == "reference"
1133 || *h2 == "weight" || *h2 == "regex") {
1134 continue;
1135 }
1136 HanConfigParMap parMap;
1137 parMap.SetName(*h2); parMap.SetValue(histNode->GetAttribute(*h2));
1138 dqpar.AddAnnotation(parMap);
1139 }
1140
1141 // Add the histogram name
1142 HanConfigParMap parMap;
1143 parMap.SetName(inputNameStr); parMap.SetValue( objName );
1144 dqpar.AddAnnotation(parMap);
1145
1146 HanConfigGroup* dqreg = m_root->GetNode( regID );
1147 dqreg = (dqreg==0) ? m_root : dqreg;
1148 if( dqreg != 0 ) {
1149 dqreg->AddAssessor( dqpar );
1150 }
1151 localdefined.insert( objName );
1152 }
1153
1154 continue;
1155 }
1156 }
1157}
1158
1159
1161ConfigVisitor( TFile* file_, dqm_core::Output* output_ )
1162 : m_file(file_),
1163 m_output(output_)
1164{
1165}
1166
1167
1168boost::shared_ptr<dqm_core::Node>
1170Visit( const HanConfigAssessor* node, boost::shared_ptr<dqm_core::Region> dqParent )
1171{
1172 const HanConfigGroup* gnode = dynamic_cast<const HanConfigGroup*>( node );
1173 std::string algName( node->GetAlgName() );
1174 std::string algLibName( node->GetAlgLibName() );
1175 if( algLibName != "" ) {
1176 try {
1177 dqm_core::LibraryManager::instance().loadLibrary( algLibName );
1178 }
1179 catch ( dqm_core::Exception& ex ) {
1180 //std::cout << "Can't load library " << algLibName << ". Continuing regardless ..." << std::endl;
1181 }
1182 }
1183
1184 if( gnode != 0 ) {
1185 dqm_core::RegionConfig regc( algName, node->GetWeight() );
1186 std::string regName( gnode->GetPathName() );
1187 boost::shared_ptr<dqm_core::Region> reg(dqParent->addRegion( regName, regc ));
1188 m_output->addListener(regName, dqParent.get());
1189 return reg;
1190 }
1191
1192 std::string inputData( node->GetHistPath() );
1193 HanAlgorithmConfig* algConfig = new HanAlgorithmConfig( *node, m_file );
1194 dqm_core::ParameterConfig parc( inputData, algName, node->GetWeight(),
1195 std::shared_ptr<HanAlgorithmConfig>(algConfig), node->GetIsRegex() );
1196 boost::shared_ptr<dqm_core::Node> par(dqParent->addParameter( node->GetName(), parc ));
1197 m_output->addListener(node->GetName(), dqParent.get());
1198 return par;
1199}
1200
1201
1203CompAlgVisitor(TFile* outfile_, const MiniConfig& compAlgConfig_)
1204 : m_outfile(outfile_)
1205 , m_compAlgConfig(compAlgConfig_)
1206{
1207}
1208
1209
1210void
1213{
1214 m_outfile->cd();
1215 std::map<std::string,MiniConfigTreeNode*> daughters = node->GetDaughters();
1216 std::map<std::string,MiniConfigTreeNode*>::const_iterator nodeiterEnd = daughters.end();
1217 for( std::map<std::string,MiniConfigTreeNode*>::const_iterator iter = daughters.begin(); iter != nodeiterEnd; ++iter ) {
1218 std::string compAlgID = iter->second->GetName();
1219 std::string compAlgKey = iter->first;
1220
1221 HanConfigCompAlg* compAlg = new HanConfigCompAlg();
1222 std::set<std::string> compAlgAtt;
1223 m_compAlgConfig.GetAttributeNames(compAlgID, compAlgAtt);
1224 std::set<std::string>::const_iterator compAlgAttEnd = compAlgAtt.end();
1225 //std::cout << "Configuring composite algorithm: " << compAlgID << std::endl;
1226 compAlg->SetName(compAlgID);
1227 for( std::set<std::string>::const_iterator i = compAlgAtt.begin(); i != compAlgAttEnd; ++i ) {
1228 if( *i == "subalgs" ) {
1229 std::string subAlgs( m_compAlgConfig.GetStringAttribute(compAlgID,"subalgs") );
1230 std::string::size_type pos = subAlgs.find(',');
1231 for(int size=subAlgs.size(), sizeOld=-8;
1232 size != sizeOld;
1233 subAlgs.erase(0, pos+1), pos = subAlgs.find(','),sizeOld=size, size=subAlgs.size()) {
1234 //std::cout << " --> adding component algorithm: " << subAlgs.substr(0,pos) << std::endl;
1235 compAlg->AddAlg( subAlgs.substr(0,pos));
1236 }
1237 }
1238 else if( *i == "libnames" ) {
1239 std::string libs( m_compAlgConfig.GetStringAttribute(compAlgID,"libnames") );
1240 std::string::size_type pos = libs.find(',');
1241 for(int size=libs.size(), sizeOld=-8;
1242 size != sizeOld;
1243 libs.erase(0, pos+1), pos = libs.find(','),sizeOld=size, size=libs.size()) {
1244 //std::cout << " --> using library: " << libs.substr(0,pos) << std::endl;
1245 compAlg->AddLib( libs.substr(0,pos));
1246 }
1247 }
1248 }
1249 compAlg->Write();
1250 }
1251}
1252
1254MetadataVisitor(TFile* outfile_, const MiniConfig& metadataConfig_)
1255 : m_outfile(outfile_)
1256 , m_metadataConfig(metadataConfig_)
1257{
1258}
1259
1260
1261void
1264{
1265 // maybe already existing?
1266 if (m_outfile->Get("HanMetadata")) {
1267 m_outfile->cd("HanMetadata");
1268 } else {
1269 // try to make it
1270 TDirectory* mdir = m_outfile->mkdir("HanMetadata");
1271 if (mdir) {
1272 mdir->cd();
1273 } else {
1274 // all fail
1275 m_outfile->cd();
1276 }
1277 }
1278
1279 std::map<std::string,MiniConfigTreeNode*> daughters = node->GetDaughters();
1280 std::map<std::string,MiniConfigTreeNode*>::const_iterator nodeiterEnd = daughters.end();
1281 for( std::map<std::string,MiniConfigTreeNode*>::const_iterator iter = daughters.begin(); iter != nodeiterEnd; ++iter ) {
1282 std::string metadataID = iter->second->GetName();
1283
1284 std::set<std::string> metadataAtt;
1285 m_metadataConfig.GetAttributeNames(metadataID, metadataAtt);
1286 HanConfigMetadata* metadata = new HanConfigMetadata();
1287 metadata->SetName(metadataID);
1288 for (std::set<std::string>::const_iterator i = metadataAtt.begin(); i != metadataAtt.end(); ++i ) {
1289 HanConfigParMap parMap;
1290 parMap.SetName(*i); parMap.SetValue(m_metadataConfig.GetStringAttribute(metadataID, *i));
1291 metadata->AddKeyVal(parMap);
1292 }
1293 metadata->Write();
1294 delete metadata;
1295 }
1296}
1297
1298
1299bool
1301Initialize( const std::string& configName )
1302{
1303 if( m_config == 0 || m_top_level == 0 ) {
1304
1305 delete m_config;
1306 delete m_top_level;
1307 if (m_metadata) {
1308 m_metadata->Delete();
1309 }
1310 delete m_metadata; m_metadata=newTList("HanMetadata");
1311
1312 m_config = TFile::Open( configName.c_str(), "READ" );
1313 if( m_config == 0 ) {
1314 std::cerr << "HanConfig::Initialize() cannot open file \"" << configName << "\"\n";
1315 return false;
1316 }
1317
1318 TMap* refsourcedata = dynamic_cast<TMap*>(m_config->Get("refsourcedata"));
1319 if (refsourcedata) {
1321 } else {
1322 std::cerr << "Can't retrieve reference source info" << std::endl;
1323 }
1324
1325 TIter nextKey( m_config->GetListOfKeys() );
1326 TKey* compAlgKey(0);
1327 while( (compAlgKey = dynamic_cast<TKey*>( nextKey() )) != 0 ) {
1328 TObject* obj = compAlgKey->ReadObj();
1329 HanConfigCompAlg* compAlg = dynamic_cast<HanConfigCompAlg*>( obj );
1330 if( compAlg != 0 ) {
1331 //std::cout << "Instantiating composite algorithm \"" << compAlg->GetName() << "\"...\n";
1332 new CompositeAlgorithm( *compAlg );
1333 }
1334 delete obj;
1335 }
1336
1337 TKey* key(0);
1338
1339 m_metadata = newTList("HanMetadata");
1340 key = m_config->FindKey("HanMetadata");
1341 if ( key ) {
1342 TDirectory* mdDir = dynamic_cast<TDirectory*>(key->ReadObj());
1343 if (mdDir) {
1344 TIter mdIter(mdDir->GetListOfKeys());
1345 TKey* mdKey(0);
1346 while ((mdKey = dynamic_cast<TKey*>(mdIter()))) {
1347 HanConfigMetadata* md = dynamic_cast<HanConfigMetadata*>(mdKey->ReadObj());
1348 if (md) {
1349 m_metadata->Add(md);
1350 }
1351 }
1352 }
1353 delete mdDir;
1354 }
1355
1356 key = m_config->FindKey("top_level");
1357 if( key == 0 ) {
1358 std::cerr << "HanConfig::Initialize() cannot find configuration in file \"" << configName << "\"\n";
1359 return false;
1360 }
1361
1362 m_top_level = dynamic_cast<HanConfigGroup*>( key->ReadObj() );
1363 if( m_top_level == 0 ) {
1364 std::cerr << "HanConfig::Initialize() cannot find configuration in file \"" << configName << "\"\n";
1365 return false;
1366 }
1367 }
1368
1369 return true;
1370}
1371
1372
1373// *********************************************************************
1374// Private Methods
1375// *********************************************************************
1376
1377
1378TDirectory*
1380ChangeInputDir( TDirectory* dir, const std::string& path )
1381{
1382 if( dir == 0 )
1383 return 0;
1384
1385 TKey* key(0);
1386
1387 std::string::size_type i = path.find_first_of('/');
1388 if( i != std::string::npos ) {
1389 std::string dName( path, 0, i );
1390 std::string pName( path, i+1, std::string::npos );
1391 if( dName != "" ) {
1392 TDirectory* subDir(0);
1393 key = dir->FindKey( dName.c_str() );
1394 if( key != 0 ) {
1395 subDir = dynamic_cast<TDirectory*>( key->ReadObj() );
1396 }
1397 else {
1398 return 0;
1399 }
1400 TDirectory* retval = ChangeInputDir( subDir, pName );
1401 return retval;
1402 }
1403 return ChangeInputDir( dir, pName );
1404 }
1405
1406 return dir;
1407}
1408
1409
1410TDirectory*
1412ChangeOutputDir( TFile* file, const std::string& path, DirMap_t& directories )
1413{
1414 if( file == 0 )
1415 return 0;
1416
1417 std::string::size_type i = path.find_last_of('/');
1418 if( i != std::string::npos ) {
1419 std::string subPath( path, 0, i );
1420 DirMap_t::const_iterator j = directories.find( subPath );
1421 if( j != directories.end() ) {
1422 TDirectory* dir = j->second;
1423 return dir;
1424 }
1425 else {
1426 TDirectory* parDir = ChangeOutputDir( file, subPath, directories );
1427 std::string dirName;
1428 std::string::size_type k = subPath.find_last_of('/');
1429 dirName = (k != std::string::npos) ? std::string( subPath, k+1, std::string::npos ) : subPath;
1430 TDirectory* dir = nullptr;
1431 if (!parDir->FindKey(dirName.c_str())) {
1432 dir = parDir->mkdir( dirName.c_str() );
1433 }
1434 else{
1435 std::cout << "Failed to make directory " << dirName << std::endl;
1436 }
1437 DirMap_t::value_type dirVal( subPath, dir );
1438 directories.insert( std::move(dirVal) );
1439 return dir;
1440 }
1441 }
1442
1443 return file;
1444}
1445
1446} // namespace dqi
const boost::regex ref(r_ef)
const boost::regex re(r_e)
std::vector< size_t > vec
ClassImp(dqi::HanConfig) namespace
Definition HanConfig.cxx:57
static Double_t a
size_t size() const
Number of registered mappings.
static const Attributes_t empty
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Header file for AthHistogramAlgorithm.
static ConditionsSingleton & getInstance()
void setRefSourceMapping(const TMap *refsourcedata)
void setNewReferenceName(const std::string &, const std::string &)
std::vector< std::pair< std::string, std::string > > getConditionReferencePairs(std::string inp) const
std::string getNewReferenceName(const std::string &, bool quiet=false) const
virtual void SetGreen(float value_)
virtual void SetRed(float value_)
virtual void SetName(std::string name_)
virtual void SetValue(float value_)
virtual void SetName(std::string name_)
virtual void AddAlg(std::string alg)
virtual void SetName(std::string name)
virtual void AddLib(std::string lib)
virtual const char * GetPathName() const
virtual void AddGroup(const HanConfigGroup &hcg_)
virtual void AddAssessor(const HanConfigAssessor &hcass_)
virtual TSeqCollection * GetList(const TDirectory *basedir, std::map< std::string, TSeqCollection * > &mp)
virtual void SetValue(const std::string &value_)
virtual void SetName(const std::string &name_)
void EnsureKeyCache(std::string &fname)
std::shared_ptr< TFile > GetROOTFile(std::string &fname)
HanConfig::DirMap_t & m_directories
Definition HanConfig.h:112
void GetAlgorithmConfiguration(HanConfigAssessor *dqpar, const std::string &algID, const std::string &assessorName="")
void PopulateKeyCache(const std::string &fname, std::shared_ptr< TFile > &file)
std::map< std::string, std::shared_ptr< TFile > > m_filecache
Definition HanConfig.h:115
std::unordered_set< std::string > m_badPaths
Definition HanConfig.h:117
AssessmentVisitorBase(HanConfigGroup *root_, const MiniConfig &algConfig_, const MiniConfig &thrConfig_, const MiniConfig &refConfig_, TFile *outfile_, HanConfig::DirMap_t &directories_, TMap *refsourcedata_)
std::map< std::string, std::vector< std::string > > m_keycache
Definition HanConfig.h:120
virtual void Visit(const MiniConfigTreeNode *node)
AssessmentVisitor(HanConfigGroup *root_, const MiniConfig &algConfig_, const MiniConfig &thrConfig_, const MiniConfig &refConfig_, TFile *outfile_, HanConfig::DirMap_t &directories_, TMap *refsourcedata_)
virtual void Visit(const MiniConfigTreeNode *node)
const MiniConfig & m_compAlgConfig
Definition HanConfig.h:172
CompAlgVisitor(TFile *outfile_, const MiniConfig &compAlgConfig_)
virtual boost::shared_ptr< dqm_core::Node > Visit(const HanConfigAssessor *node, boost::shared_ptr< dqm_core::Region > dqParent)
ConfigVisitor(TFile *file_, dqm_core::Output *output_)
dqm_core::Output * m_output
Definition HanConfig.h:162
MetadataVisitor(TFile *outfile_, const MiniConfig &metadataConfig_)
virtual void Visit(const MiniConfigTreeNode *node)
const MiniConfig & m_metadataConfig
Definition HanConfig.h:181
virtual void Visit(const MiniConfigTreeNode *node)
RefVisitor(TFile *outfile_, HanConfig::DirMap_t &directories_, TMap *refsourcedata)
HanConfig::DirMap_t & m_directories
Definition HanConfig.h:82
DatabaseConfig & m_databaseConfig
Definition HanConfig.h:91
virtual void Write(MiniConfigTreeNode *node)
RefWriter(DatabaseConfig &databaseConfig_, const bool bulk)
virtual boost::shared_ptr< dqm_core::Node > Visit(const HanConfigAssessor *node, boost::shared_ptr< dqm_core::Region >)
RegexVisitor(std::set< std::string > &regexes_)
std::set< std::string > & m_regexes
Definition HanConfig.h:152
RegionVisitor(HanConfigGroup *root_, const MiniConfig &algConfig_, const MiniConfig &thrConfig_, const MiniConfig &refConfig_, HanConfig::DirMap_t &directories_)
virtual void Visit(const MiniConfigTreeNode *node)
virtual void GetRegexList(std::set< std::string > &regexlist)
virtual void BuildMonitors(std::string configName, HanInputRootFile &input, HanOutput &output)
std::map< std::string, TDirectory * > DirMap_t
Definition HanConfig.h:73
bool Initialize(const std::string &configName)
static TDirectory * ChangeInputDir(TDirectory *dir, const std::string &path)
boost::shared_ptr< dqm_core::Region > m_dqRoot
Definition HanConfig.h:190
HanConfigGroup * m_top_level
Definition HanConfig.h:192
static TDirectory * ChangeOutputDir(TFile *file, const std::string &path, DirMap_t &directories)
virtual TObject * GetReference(std::string &groupName, std::string &name)
virtual boost::shared_ptr< dqm_core::Region > BuildMonitorsNewRoot(std::string configName, HanInputRootFile &input, dqm_core::Output &output)
virtual void AssembleAndSave(const std::string &infileName, const std::string &outfileName, const std::string &connectionString="sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/dqmdisk1/cherrypy-devel/RefDB.db;dbname=REFDB", long runNumber=2147483646, bool bulk=false)
TFile * m_config
Definition HanConfig.h:188
TSeqCollection * m_metadata
Definition HanConfig.h:193
virtual void BuildConfigOutput(std::string configName, TFile *inputFile, const std::string &path, std::map< std::string, TSeqCollection * > *outputMap, TSeqCollection *outputList)
virtual ~HanConfig()
Definition HanConfig.cxx:80
virtual const HanConfigAssessor * GetAssessor(std::string &groupName, std::string &name) const
std::map< std::string, TSeqCollection * > DQOutputMap_t
Definition HanOutput.h:45
A node of a tree structure holding a configuration, where each node may be given attributes,...
virtual const char * GetName() const
virtual std::string GetAttribute(const std::string &attName, bool calledFromDaughter=false) const
virtual void GetAttributeNames(std::set< std::string > &attSet, bool calledFromDaughter=false) const
virtual std::string GetPathName() const
description
Definition MiniConfig.h:25
virtual bool ReadFile(std::string fileName)
virtual void AddAttributeKeyword(std::string keyword_)
virtual void AddKeyword(std::string keyword_)
virtual void SetAttribKeywordPropagateDown(bool propagateDown)
virtual void SendVisitor(MiniConfigTreeNode::Visitor &visitor) const
virtual void SendWriter(MiniConfigTreeNode::Writer &writer)
Definition node.h:24
std::vector< std::string > directories
Definition listroot.cxx:185
float AttribToFloat(const MiniConfigTreeNode *node, const std::string &attrib, const std::string &warningString, bool local=false)
void dolsr(const TDirectory *dir, std::vector< std::string > &hists, const TDirectory *topdir=nullptr)
Definition HanUtils.cxx:80
std::string SplitReference(std::string refPath, const std::string &refName)
TKey * getObjKey(TDirectory *dir, const std::string &path)
Definition HanUtils.cxx:36
TSeqCollection * newTList(const char *name, TObject *obj=0)
Definition HanUtils.cxx:18
TFile * file