ATLAS Offline Software
Loading...
Searching...
No Matches
dqi::HanConfig::AssessmentVisitorBase Class Referenceabstract

#include <HanConfig.h>

Inheritance diagram for dqi::HanConfig::AssessmentVisitorBase:
Collaboration diagram for dqi::HanConfig::AssessmentVisitorBase:

Public Member Functions

 AssessmentVisitorBase (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)=0

Protected Member Functions

void GetAlgorithmConfiguration (HanConfigAssessor *dqpar, const std::string &algID, const std::string &assessorName="")
std::shared_ptr< TFile > GetROOTFile (std::string &fname)
void PopulateKeyCache (const std::string &fname, std::shared_ptr< TFile > &file)
void EnsureKeyCache (std::string &fname)

Protected Attributes

HanConfigGroupm_root {}
const MiniConfigm_algConfig
const MiniConfigm_thrConfig
const MiniConfigm_refConfig
TFile * m_outfile {}
HanConfig::DirMap_tm_directories
TMap * m_refsourcedata {}
std::map< std::string, std::shared_ptr< TFile > > m_filecache
std::unordered_set< std::string > m_badPaths
std::map< std::string, std::vector< std::string > > m_keycache

Detailed Description

Definition at line 95 of file HanConfig.h.

Constructor & Destructor Documentation

◆ AssessmentVisitorBase()

dqi::HanConfig::AssessmentVisitorBase::AssessmentVisitorBase ( HanConfigGroup * root_,
const MiniConfig & algConfig_,
const MiniConfig & thrConfig_,
const MiniConfig & refConfig_,
TFile * outfile_,
HanConfig::DirMap_t & directories_,
TMap * refsourcedata_ )

Definition at line 447 of file HanConfig.cxx.

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}
HanConfig::DirMap_t & m_directories
Definition HanConfig.h:112

Member Function Documentation

◆ EnsureKeyCache()

void dqi::HanConfig::AssessmentVisitorBase::EnsureKeyCache ( std::string & fname)
protected

Definition at line 491 of file HanConfig.cxx.

492 {
493 DisableMustClean dmc;
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}
std::shared_ptr< TFile > GetROOTFile(std::string &fname)
void PopulateKeyCache(const std::string &fname, std::shared_ptr< TFile > &file)
std::map< std::string, std::vector< std::string > > m_keycache
Definition HanConfig.h:120
TFile * file

◆ GetAlgorithmConfiguration()

void dqi::HanConfig::AssessmentVisitorBase::GetAlgorithmConfiguration ( HanConfigAssessor * dqpar,
const std::string & algID,
const std::string & assessorName = "" )
protected

Definition at line 525 of file HanConfig.cxx.

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;
574 dqi::ConditionsSingleton &CS=dqi::ConditionsSingleton::getInstance();
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}
const boost::regex re(r_e)
static const Attributes_t empty
static ConditionsSingleton & getInstance()
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
void EnsureKeyCache(std::string &fname)
std::string SplitReference(std::string refPath, const std::string &refName)
TKey * getObjKey(TDirectory *dir, const std::string &path)
Definition HanUtils.cxx:36
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.

◆ GetROOTFile()

std::shared_ptr< TFile > dqi::HanConfig::AssessmentVisitorBase::GetROOTFile ( std::string & fname)
protected

Definition at line 463 of file HanConfig.cxx.

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}
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

◆ PopulateKeyCache()

void dqi::HanConfig::AssessmentVisitorBase::PopulateKeyCache ( const std::string & fname,
std::shared_ptr< TFile > & file )
protected

Definition at line 484 of file HanConfig.cxx.

485 {
486 auto& vec = m_keycache[fname];
487 dolsr(file.get(), vec);
488}
std::vector< size_t > vec
void dolsr(const TDirectory *dir, std::vector< std::string > &hists, const TDirectory *topdir=nullptr)
Definition HanUtils.cxx:80

◆ Visit()

virtual void dqi::MiniConfigTreeNode::Visitor::Visit ( const MiniConfigTreeNode * node)
pure virtualinherited

Member Data Documentation

◆ m_algConfig

const MiniConfig& dqi::HanConfig::AssessmentVisitorBase::m_algConfig
protected

Definition at line 108 of file HanConfig.h.

◆ m_badPaths

std::unordered_set<std::string> dqi::HanConfig::AssessmentVisitorBase::m_badPaths
protected

Definition at line 117 of file HanConfig.h.

◆ m_directories

HanConfig::DirMap_t& dqi::HanConfig::AssessmentVisitorBase::m_directories
protected

Definition at line 112 of file HanConfig.h.

◆ m_filecache

std::map<std::string, std::shared_ptr<TFile> > dqi::HanConfig::AssessmentVisitorBase::m_filecache
protected

Definition at line 115 of file HanConfig.h.

◆ m_keycache

std::map<std::string, std::vector<std::string> > dqi::HanConfig::AssessmentVisitorBase::m_keycache
protected

Definition at line 120 of file HanConfig.h.

◆ m_outfile

TFile* dqi::HanConfig::AssessmentVisitorBase::m_outfile {}
protected

Definition at line 111 of file HanConfig.h.

111{};

◆ m_refConfig

const MiniConfig& dqi::HanConfig::AssessmentVisitorBase::m_refConfig
protected

Definition at line 110 of file HanConfig.h.

◆ m_refsourcedata

TMap* dqi::HanConfig::AssessmentVisitorBase::m_refsourcedata {}
protected

Definition at line 113 of file HanConfig.h.

113{};

◆ m_root

HanConfigGroup* dqi::HanConfig::AssessmentVisitorBase::m_root {}
protected

Definition at line 107 of file HanConfig.h.

107{};

◆ m_thrConfig

const MiniConfig& dqi::HanConfig::AssessmentVisitorBase::m_thrConfig
protected

Definition at line 109 of file HanConfig.h.


The documentation for this class was generated from the following files: