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:128
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 393 of file HanOutput.cxx.

393 { //Check if object a hist or include hist
394 bool result = false;
395
396 if ((strncmp(obj->ClassName(), "TH", 2) == 0) || (strncmp(obj->ClassName(), "TGraph", 6) == 0) ||
397 (strncmp(obj->ClassName(), "TProfile", 8) == 0) || (strncmp(obj->ClassName(), "TEfficiency", 11) == 0))
398 {
399 return true;
400 }
401
402 TSeqCollection* tmpList{};
403 tmpList = dynamic_cast<TSeqCollection*>(obj);
404 if (tmpList != 0)
405 { //If it is collection - check, that it contains histograms or not
406 TIter nextElem(tmpList);
407 TObject* tmpobj{};
408 while ((tmpobj = nextElem()) != 0)
409 {
410 result = include_hist(tmpobj);
411 if (result == true)
412 {
413 return result;
414 }
415 }
416 }
417 return result;
418 }
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 543 of file HanOutput.cxx.

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

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