527 const std::string& assessorName )
530 std::set<std::string> 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);
541 std::string algName(
m_algConfig.GetStringAttribute(algID,
"name") );
542 dqpar->SetAlgName( std::move(algName) );
544 else if( *i ==
"libname" ) {
545 std::string algLibName(
m_algConfig.GetStringAttribute(algID,
"libname") );
546 dqpar->SetAlgLibName( std::move(algLibName) );
548 else if( *i ==
"thresholds" || trail ==
"thresholds" ) {
549 std::string thrID(
m_algConfig.GetStringAttribute(algID,*i) );
550 std::set<std::string> 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;
558 if (pos != std::string::npos) {
559 algLim.
SetName( (*i).substr(0, pos) + std::string(
"|") + *t );
565 dqpar->AddAlgLimit( algLim );
568 else if( *i ==
"reference" ) {
572 std::string tmpRefID=
m_algConfig.GetStringAttribute(algID,
"reference");
577 std::stringstream newRefString;
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;
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(
"[] "));
593 boost::split(refIDVec, cleanedRefID, boost::is_any_of(
","));
597 refIDVec.push_back(refID);
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) {
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;
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"
633 if( algRefPath !=
"" ) {
634 absAlgRefName += algRefPath;
635 absAlgRefName +=
"/";
637 if( algRefName ==
"same_name" ) {
638 algRefName = assessorName;
639 absAlgRefName += algRefName;
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;
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;
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",
"(?"));
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);
662 objects[iRefID].emplace_back(iKey, key->ReadObj());
667 TKey* key =
getObjKey( infile.get(), absAlgRefName );
673 std::shared_ptr<TObject> q(key->ReadObj());
674 objects[iRefID].emplace_back(absAlgRefName, q);
678 absAlgRefName += algRefName;
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;
688 TKey* key =
getObjKey( infile.get(), absAlgRefName );
691 std::cerr <<
"Couldn't find reference " << absAlgRefName << std::endl;
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;
699 if (algRefInfo !=
"") {
700 multirefname = algRefInfo;
701 }
else if (algRefFile !=
"") {
702 multirefname = algRefFile;
704 qn->SetName(multirefname.c_str());
706 objects[iRefID].emplace_back(absAlgRefName, q);
708 std::cerr <<
"No file specified for " << absAlgRefName <<
" ?" << std::endl;
713 std::shared_ptr<TObject> toWriteOut;
714 std::string algRefUniqueName;
715 std::string algRefSourceInfo = (algRefInfo !=
"" ? algRefInfo.c_str() :
"Reference");
719 if (dqpar->GetIsRegex() && !objects[0].empty()) {
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());
727 hobj->SetName(refID.c_str());
729 algRefUniqueName = algRefFile+
":/"+thisPair.first;
731 if(newRefId.empty()){
735 new TObjString(algRefFile.c_str()));
736 cobj->Write(newRefId.c_str(), 1);
739 std::string maprefstring(thisPair.first);
740 if (algRefPath !=
"") {
741 boost::replace_first(maprefstring, algRefPath +
"/",
"");
743 tmapobj->Add(
new TObjString(maprefstring.c_str()),
744 new TObjString(newRefId.c_str()));
746 toWriteOut.reset(tmapobj);
747 algRefUniqueName = algRefFile+
"_regex:/"+dqpar->GetUniqueName();
750 algRefUniqueName = algRefFile+
":/"+absAlgRefName;
751 if (! objects[0].
empty()) {
753 toWriteOut = objects[0][0].second;
757 algRefUniqueName=cond+
"_multiple:/"+absAlgRefName;
758 algRefSourceInfo=
"Multiple references";
760 if (dqpar->GetIsRegex()) {
763 TObjArray* toarray =
new TObjArray();
764 toarray->SetOwner(
true);
765 for (
size_t iRef = 0; iRef < objects.size(); ++iRef) {
767 if (! objects[iRef].
empty()) {
768 toarray->Add(objects[iRef][0].second->Clone());
771 toWriteOut.reset(toarray);
776 if (refsuccess && toWriteOut) {
779 if(newRefId.empty()){
785 new TObjString(algRefFile.c_str()));
789 new TObjString(algRefSourceInfo.c_str()));
794 new TObjString(algRefSourceInfo.c_str()));
798 toWriteOut->Write(newRefId.c_str(), 1);
802 if (!newRefId.empty()) {
804 newRefString<<cond<<
":"<<newRefId<<
";";
806 newRefString<<newRefId;
810 dqpar->SetAlgRefName((newRefString.str()));
813 std::string stringValue =
m_algConfig.GetStringAttribute( algID, *i );
815 std::istringstream parser( stringValue );
816 parser >> numberValue;
821 dqpar->AddAlgStrPar( algPar );
826 dqpar->AddAlgPar( algPar );
916 std::set<std::string> histAtt;
917 node->GetAttributeNames( histAtt );
918 std::set<std::string> defined;
919 std::string regID(
"");
920 std::string algID(
"");
921 std::set<std::string>::const_iterator histAttEnd = histAtt.end();
922 for( std::set<std::string>::const_iterator
h = histAtt.begin();
h != histAttEnd; ++
h ) {
931 std::cerr <<
"No \"algorithm\" defined for " << histNode->
GetPathName() <<
"\n";
938 std::string strNodeName(histNode->
GetName());
939 std::string strHistName, strFullHistName;
940 std::string::size_type atsign = strNodeName.find(
'@');
941 if (atsign == std::string::npos) {
942 strHistName = std::move(strNodeName);
945 strHistName = strNodeName.substr(0, atsign);
947 strFullHistName.resize(strFullHistName.find(
'@'));
950 if( strHistName ==
"all_in_dir" )
953 if( defined.find(histNode->
GetPathName()) != defined.end() )
959 dqpar.SetIsRegex(TestMiniNodeIsRegex(histNode));
962 std::ostringstream err;
963 err <<
"Weight attribute not a floating point type for " << histNode->
GetPathName() <<
"; setting to zero";
970 std::set<std::string> histAtt2;
972 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
973 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
974 if (
node->GetDaughter( *h2 )
975 || *h2 ==
"algorithm" || *h2 ==
"output" || *h2 ==
"reference"
976 || *h2 ==
"weight" || *h2 ==
"regex") {
981 dqpar.AddAnnotation(parMap);
987 dqpar.AddAnnotation(parMap);
990 dqreg = (dqreg==0) ?
m_root : dqreg;
994 defined.insert( std::move(strFullHistName) );
997 for( std::set<std::string>::const_iterator
h = histAtt.begin();
h != histAttEnd; ++
h ) {
1006 std::cerr <<
"No \"algorithm\" defined for " << histNode->
GetPathName() <<
"\n";
1011 regID =
"top_level";
1013 std::string strNodeName(histNode->
GetName());
1014 std::string strHistName, strFullHistName, extension;
1015 std::string::size_type atsign = strNodeName.find(
'@');
1016 if (atsign == std::string::npos) {
1017 strHistName = std::move(strNodeName);
1021 strHistName = strNodeName.substr(0, atsign);
1022 extension = strNodeName.substr(atsign, std::string::npos);
1024 strFullHistName.resize(strFullHistName.find(
'@'));
1027 if( strHistName ==
"all_in_dir" ) {
1029 std::string regexflag(histNode->
GetAttribute(
"regex"));
1031 std::cerr <<
"WARNING: all_in_dir and regex are incompatible; ignoring regex flag for " << histNode->
GetPathName()
1032 <<
"/all_in_dir" << std::endl;
1035 std::string refID( histNode->
GetAttribute(
"reference") );
1037 std::cerr <<
"WARNING: No \"reference\" defined for " << histNode->
GetPathName() <<
"\n";
1040 std::string refFile(
m_refConfig.GetStringAttribute(refID,
"file") );
1041 if( refFile ==
"" ) {
1042 std::cerr <<
"WARNING: No \"file\" defined for " << histNode->
GetPathName() <<
"\n";
1046 std::string refPath(
m_refConfig.GetStringAttribute(refID,
"path") );
1048 std::string objPath(
"");
1049 std::string absObjPath(
"");
1052 std::shared_ptr<TFile> infile(
GetROOTFile(refFile) );
1053 TDirectory* basedir(0);
1057 if( refPath !=
"" ) {
1059 absObjPath += refPath;
1061 std::string refPathForSearch = refPath;
1062 refPathForSearch +=
"/dummyName";
1064 if( basedir == 0 ) {
1065 std::cerr <<
"INFO: Cannot find path \"" << refPath <<
"\" in reference file\n";
1071 basedir = infile.get();
1073 std::string allPathName( histNode->
GetPathName() );
1074 std::string::size_type i = allPathName.find_last_of(
'/');
1075 if( i != std::string::npos ) {
1076 objPath = std::string( allPathName, 0, i );
1078 absObjPath += std::string( allPathName, 0, i );
1084 std::cerr <<
"INFO: Cannot find path \"" << absObjPath <<
"\" in reference file\n";
1088 TIter next( dir->GetListOfKeys() );
1089 std::string objName;
1090 std::string absObjName;
1093 std::set<std::string> localdefined;
1094 while( (key =
dynamic_cast<TKey*
>(next())) != 0 ) {
1095 TObject* tmpobj = key->ReadObj();
1096 TH1* tmph =
dynamic_cast<TH1*
>(tmpobj);
1097 TGraph* tmpg =
dynamic_cast<TGraph*
>(tmpobj);
1098 TEfficiency* tmpe =
dynamic_cast<TEfficiency*
>(tmpobj);
1099 if( tmph == 0 && tmpg == 0 && tmpe == 0 )
1103 objName += std::string( tmpobj->GetName() );
1104 absObjName = absObjPath;
1105 absObjName += std::string( tmpobj->GetName() );
1108 if( defined.find(objName) != defined.end() ||
1109 localdefined.find(objName) != localdefined.end() )
1112 TKey* test =
getObjKey( infile.get(), absObjName );
1117 dqpar.SetName( objName + extension );
1121 std::ostringstream err;
1122 err <<
"Weight attribute not a floating point type for " << objName <<
"; setting to zero";
1127 std::set<std::string> histAtt2;
1129 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
1130 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
1131 if (
node->GetDaughter( *h2 )
1132 || *h2 ==
"algorithm" || *h2 ==
"output" || *h2 ==
"reference"
1133 || *h2 ==
"weight" || *h2 ==
"regex") {
1138 dqpar.AddAnnotation(parMap);
1144 dqpar.AddAnnotation(parMap);
1147 dqreg = (dqreg==0) ?
m_root : dqreg;
1151 localdefined.insert( objName );