ATLAS Offline Software
Loading...
Searching...
No Matches
dqi Namespace Reference

Classes

class  CompositeAlgorithm
class  ConditionsSingleton
class  CorrelationYX
class  CountsBinsGreaterThan
class  DatabaseConfig
class  DisableMustClean
class  HanAlgorithmConfig
class  HanApp
class  HanConfig
class  HanConfigAlgLimit
class  HanConfigAlgPar
class  HanConfigAssessor
class  HanConfigCompAlg
class  HanConfigGroup
class  HanConfigParMap
class  HanInputRootFile
class  HanOutput
class  HanRuntimeConfigSingleton
class  MiniConfig
 description More...
class  MiniConfigTreeNode
 A node of a tree structure holding a configuration, where each node may be given attributes, and a node inherits the attributes of parent nodes if those attributes are not redefined. More...

Functions

nlohmann::ordered_json to_JSON (TSeqCollection *tseq)
 Converts sequense, containing TDirectories and strings to JSON file.
TSeqCollection * newTList (const char *name, TObject *obj=0)
TSeqCollection * newTObjArray (const char *name, TObject *obj=0, Int_t size=TCollection::kInitCapacity)
TKey * getObjKey (TDirectory *dir, const std::string &path)
void dolsr (const TDirectory *dir, std::vector< std::string > &hists, const TDirectory *topdir=nullptr)
bool setNameGeneral (TObject *obj, const std::string &name)
static bool include_hist (TObject *obj)
static void WriteListToDirectory (TDirectory *dir, TSeqCollection *list, TFile *file, int level, int HanOutput_FileVersion)

Variables

std::mutex root_mutex

Function Documentation

◆ dolsr()

void dqi::dolsr ( const TDirectory * dir,
std::vector< std::string > & hists,
const TDirectory * topdir = nullptr )

Definition at line 80 of file HanUtils.cxx.

81{
82 // permit calling with two arguments
83 if (topdir == NULL) {
84 topdir = dir;
85 }
86 TIter keys(dir->GetListOfKeys());
87 TKey* key;
88 std::string fullpath(dir->GetPath());
89 std::string toppath(topdir->GetPath());
90 std::string::size_type toppathlen = toppath.length();
91 while ((key = dynamic_cast<TKey*>(keys())) != NULL) {
92 if (std::string(key->GetClassName()).starts_with( "TDirectory")) {
93 TDirectory* newdir = dynamic_cast<TDirectory*>(key->ReadObj());
94 if (!newdir) {
95 std::cerr << "WARNING: cannot read directory "
96 << fullpath << "/" << key->GetName()
97 << "; skipping" << std::endl;
98 } else {
99 dolsr(newdir, hists, topdir);
100 }
101 delete newdir;
102 } else {
103 if (std::string(key->GetName()) == "metadata") {
104 continue;
105 }
106 std::string path;
107 if (fullpath.substr(0, toppathlen) == toppath) {
108 int extra = 1;
109 if (toppath[toppathlen-1] == '/') extra = 0;
110 path = fullpath.substr(toppathlen + extra, std::string::npos);
111 } else {
112 path = fullpath;
113 }
114 hists.push_back(path+"/"+std::string(key->GetName()));
115 }
116 }
117}
path
python interpreter configuration --------------------------------------—
Definition athena.py:126
void dolsr(const TDirectory *dir, std::vector< std::string > &hists, const TDirectory *topdir=nullptr)
Definition HanUtils.cxx:80

◆ getObjKey()

TKey * dqi::getObjKey ( TDirectory * dir,
const std::string & path )

Definition at line 36 of file HanUtils.cxx.

37{
38 if( dir == 0 )
39 return 0;
40
41 std::string::size_type i = path.find_first_of('/');
42 if( i != std::string::npos ) {
43 std::string dName( path, 0, i );
44 std::string pName( path, i+1, std::string::npos );
45 if( dName != "" ) {
46 TDirectory* subDir = dir->GetDirectory(dName.c_str());
47 if (subDir != 0) {
48 TKey* rv = getObjKey( subDir, pName );
49 //delete subDir;
50 return rv;
51 }
52 // TKey* key = dir->FindKey( dName.c_str() );
53 // if( key != 0 ) {
54 // TDirectory* subDir = dynamic_cast<TDirectory*>( key->ReadObj() );
55 // TKey* rv = getObjKey( subDir, pName );
56 // // delete subDir;
57 // return rv;
58 // }
59 return 0;
60 }
61 return getObjKey( dir, pName );
62 }
63
64 return dir->FindKey( path.c_str() );
65}
TKey * getObjKey(TDirectory *dir, const std::string &path)
Definition HanUtils.cxx:36

◆ include_hist()

bool dqi::include_hist ( TObject * obj)
static

Definition at line 398 of file HanOutput.cxx.

398 { //Check if object a hist or include hist
399 bool result = false;
400
401 if ((strncmp(obj->ClassName(), "TH", 2) == 0) || (strncmp(obj->ClassName(), "TGraph", 6) == 0) ||
402 (strncmp(obj->ClassName(), "TProfile", 8) == 0) || (strncmp(obj->ClassName(), "TEfficiency", 11) == 0))
403 {
404 return true;
405 }
406
407 TSeqCollection* tmpList{};
408 tmpList = dynamic_cast<TSeqCollection*>(obj);
409 if (tmpList != 0)
410 { //If it is collection - check, that it contains histograms or not
411 TIter nextElem(tmpList);
412 TObject* tmpobj{};
413 while ((tmpobj = nextElem()) != 0)
414 {
415 result = include_hist(tmpobj);
416 if (result == true)
417 {
418 return result;
419 }
420 }
421 }
422 return result;
423 }
static bool include_hist(TObject *obj)

◆ newTList()

TSeqCollection * dqi::newTList ( const char * name,
TObject * obj = 0 )

Definition at line 18 of file HanUtils.cxx.

19{
20 TList *ret = new TList();
21 ret->SetName(name);
22 if (obj != 0)
23 ret->Add(obj);
24 return ret;
25}

◆ newTObjArray()

TSeqCollection * dqi::newTObjArray ( const char * name,
TObject * obj = 0,
Int_t size = TCollection::kInitCapacity )

Definition at line 27 of file HanUtils.cxx.

28{
29 TObjArray *ret = new TObjArray(size);
30 ret->SetName(name);
31 if (obj != NULL)
32 ret->Add(obj);
33 return ret;
34}

◆ setNameGeneral()

bool dqi::setNameGeneral ( TObject * obj,
const std::string & name )

Definition at line 44 of file HanOutput.cxx.

45 {
46 if (obj != 0)
47 {
48 // some special cases, to avoid interpreter
49 if (TH1* h = dynamic_cast<TH1*>(obj))
50 {
51 h->SetName(name.c_str());
52 return true;
53 }
54 else if (TObjArray* a = dynamic_cast<TObjArray*>(obj))
55 {
56 a->SetName(name.c_str());
57 return true;
58 }
59 else if (TGraph* g = dynamic_cast<TGraph*>(obj))
60 {
61 g->SetName(name.c_str());
62 return true;
63 }
64 else if (TEfficiency* e = dynamic_cast<TEfficiency*>(obj))
65 {
66 e->SetName(name.c_str());
67 return true;
68 }
69 else
70 {
71 TClass* kl = obj->IsA();
72 TMethod* klm = kl->GetMethod("SetName", "\"Reference\"");
73 if (!klm)
74 {
75 std::cerr << "Error: attempt to change object name to " << name << " failed as its name is not settable"
76 << std::endl;
77 }
78 else
79 {
80 std::cout << "Manually doing cast for " << name << " of class " << kl->GetName() << std::endl;
81 obj->Execute("SetName", ("\"" + name + "\"").c_str());
82 return true;
83 }
84 }
85 }
86 return false;
87 }
static Double_t a
Header file for AthHistogramAlgorithm.

◆ to_JSON()

nlohmann::ordered_json dqi::to_JSON ( TSeqCollection * tseq)

Converts sequense, containing TDirectories and strings to JSON file.

Definition at line 548 of file HanOutput.cxx.

549 {
550 using json = nlohmann::ordered_json;
551 json j;
552
553 TIter nextElem(tseq);
554 TObject* obj;
555 while ((obj = nextElem()) != 0)
556 {
557 // If Results (or Config) directory contatins hist - ignore it (do not write in to the file), it
558 // should to be writen to the outer level before
559 if ((strncmp(obj->ClassName(), "TH", 2) == 0) || (strncmp(obj->ClassName(), "TGraph", 6) == 0) ||
560 (strncmp(obj->ClassName(), "TProfile", 8) == 0) || (strncmp(obj->ClassName(), "TEfficiency", 11) == 0) ||
561 (strncmp(obj->GetName(), "Reference", 9) == 0))
562
563 {
564 continue;
565 }
566 TSeqCollection* tmpList = dynamic_cast<TSeqCollection*>(obj);
567 if (tmpList != 0)
568 { // Nested object
569 // Write TSeqCollection_names as keys and content of them as a values
570 // Convert TString to string
571 std::string key_name_string(obj->GetName());
572 j.emplace(key_name_string, to_JSON(tmpList));
573 }
574 else
575 { // leaf
576 j = obj->GetName();
577 }
578 }
579 return j;
580 }
nlohmann::json json
nlohmann::ordered_json to_JSON(TSeqCollection *tseq)
Converts sequense, containing TDirectories and strings to JSON file.

◆ WriteListToDirectory()

void dqi::WriteListToDirectory ( TDirectory * dir,
TSeqCollection * list,
TFile * file,
int level,
int HanOutput_FileVersion )
static

First: we need to know - are there any histograms storing in this dir (e.g. References).

Definition at line 425 of file HanOutput.cxx.

427 {
428 TIter nextElem(list);
429 TObject* obj{};
430 TSeqCollection* tmpList{};
431
432 while ((obj = nextElem()) != 0)
433 {
434 bool delete_when_done = false;
435 HanHistogramLink* hhl = dynamic_cast<HanHistogramLink*>(obj);
436 if (hhl != 0)
437 {
438 obj = hhl->getObject();
439 if (!obj) continue;
440 delete_when_done = true;
441 if (not setNameGeneral(obj, hhl->GetName()))
442 {
443 std::cerr << "HanOutput.cxx, WriteListToDirectory : setNameGeneral failed\n";
444 delete obj;
445 continue;
446 };
447 }
448 if (strncmp(obj->GetName(), "Reference", 9) == 0 || strncmp(obj->GetName(), "ResultObject", 12) == 0)
449 {
450 dir->WriteTObject(obj);
451 if (delete_when_done) delete obj;
452 continue;
453 }
454 tmpList = dynamic_cast<TSeqCollection*>(obj);
455 if (tmpList != 0)
456 {
457 // Find last directory name
458 std::vector<std::string> dirs;
459 std::string str;
460 boost::split(dirs, tmpList->GetName(), boost::is_any_of("/"));
461 if (!dirs.empty())
462 {
463 if (dirs.back().empty()) dirs.pop_back(); // empty item if trailing "/"
464 str = dirs.back();
465 }
466
467 if (HanOutput_FileVersion == 2)
468 {
469 TString listname = tmpList->GetName();
470 if (listname == "Config" || listname == "Results")
471 {
473 //If yes - we should save them in the upper level
474 TIter nextElemConfRes(tmpList);
475 TObject* objInResultConfig;
476 while ((objInResultConfig = nextElemConfRes()) != 0)
477 {
478 if (include_hist(objInResultConfig))
479 {
480 //If the element consist of histograms
481 TSeqCollection* tmpList_ResConf{}; //it should be a collection type
482 tmpList_ResConf = dynamic_cast<TSeqCollection*>(objInResultConfig);
483 if ((tmpList_ResConf != 0) && (strncmp(tmpList_ResConf->GetName(), "TObjArray", 9) == 0))
484 { //Here is the special case. In case the object is an Array with the name "TObjArray", containing histograms,
485 //we should not only store it on the upper level, but also extract all the hists from it.
486 TIter nextEleminTObjArray(tmpList_ResConf);
487 TObject* objInTObjArray;
488 while ((objInTObjArray = nextEleminTObjArray()) != 0){
489 dir->WriteTObject(objInTObjArray);
490 }
491 tmpList->Remove(objInResultConfig); //This Array should not participate in JSON formation
492 }
493 else //If the element is histogram (or other Array, containing hist)- just store this obj in a higher level
494 {
495 dir->WriteTObject(objInResultConfig);
496 }
497 }
498 }
499 // For the rest of the content - Convert them to JSON
500 nlohmann::ordered_json j = to_JSON(tmpList);
501 // Then, save JSON to file as TObjString
502 // Convert json to string
503 std::string string = j.dump(4);
504 // Convert string to char *
505 char* cstr = new char[string.length() + 1];
506 std::strcpy(cstr, string.c_str());
507 // Write JSON to TObjString
508 TObjString string_to_tfile;
509 string_to_tfile.SetString(cstr);
510 dir->cd();
511 string_to_tfile.Write(listname);
512 delete[] cstr;
513 continue;
514 }
515 }
516
517 TDirectory* daughter;
518 if (!dir->FindKey(str.c_str()))
519 {
520 daughter = dir->mkdir(str.c_str());
521 }
522 else
523 {
524 std::cout << "Failed to make " << str << " from " << tmpList->GetName() << std::endl;
525 continue;
526 }
527 WriteListToDirectory(daughter, tmpList, file, level - 1, HanOutput_FileVersion);
528 if (level > 0)
529 {
530 file->Write();
531 delete daughter;
532 }
533 }
534 else if ((strncmp(obj->ClassName(), "TH", 2) == 0) || (strncmp(obj->ClassName(), "TGraph", 6) == 0) ||
535 (strncmp(obj->ClassName(), "TProfile", 8) == 0) || (strncmp(obj->ClassName(), "TEfficiency", 11) == 0))
536 {
537 dir->GetMotherDir()->WriteTObject(obj);
538 }
539 else
540 {
541 // anything else put it in current directory
542 dir->WriteTObject(obj);
543 }
544 if (delete_when_done) delete obj;
545 }
546 }
std::map< std::string, int > dirs
list of directories to be explicitly included, together with corresponding depths of subdirectories
Definition hcg.cxx:102
bool setNameGeneral(TObject *obj, const std::string &name)
Definition HanOutput.cxx:44
static void WriteListToDirectory(TDirectory *dir, TSeqCollection *list, TFile *file, int level, int HanOutput_FileVersion)
TFile * file

Variable Documentation

◆ root_mutex

std::mutex dqi::root_mutex

Definition at line 16 of file HanUtils.cxx.