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