528{
529
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);
538 }
539 if( *i == "name" ) {
540
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;
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
570
571
572 std::string tmpRefID=
m_algConfig.GetStringAttribute(algID,
"reference");
573
575
577 std::stringstream newRefString;
578
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
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
595
596 } else {
597 refIDVec.push_back(refID);
598 }
599
600
601
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) {
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
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" ) {
638 algRefName = assessorName;
639 absAlgRefName += algRefName;
641
642 if( algRefFile != "" ) {
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
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);
662 objects[iRefID].emplace_back(iKey,
key->ReadObj());
663 }
664 }
665 }
666 } else {
668 if( key == 0 ) {
669
670 continue;
671 }
673 std::shared_ptr<TObject>
q(
key->ReadObj());
674 objects[iRefID].emplace_back(absAlgRefName, q);
675 }
676 }
677 } else {
678 absAlgRefName += algRefName;
680
681 if( algRefFile != "" ) {
684 std::cerr << "HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile << " not found" << std::endl;
685 continue;
686 }
687
689 if( key == 0 ) {
690
691 std::cerr << "Couldn't find reference " << absAlgRefName << std::endl;
692 continue;
693 }
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;
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
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;
731 if(newRefId.empty()){
735 new TObjString(algRefFile.c_str()));
736 cobj->Write(newRefId.c_str(), 1);
737 }
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 {
757 algRefUniqueName=cond+"_multiple:/"+absAlgRefName;
758 algRefSourceInfo="Multiple references";
759
760 if (
dqpar->GetIsRegex()) {
761
762 } else {
763 TObjArray* toarray = new TObjArray();
764 toarray->SetOwner(true);
765 for (
size_t iRef = 0; iRef <
objects.size(); ++iRef) {
766
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
779 if(newRefId.empty()){
782 if (! isMultiRef) {
783
785 new TObjString(algRefFile.c_str()));
786
789 new TObjString(algRefSourceInfo.c_str()));
790 }
791 } else {
792
794 new TObjString(algRefSourceInfo.c_str()));
795 }
796 }
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 {
814 float numberValue;
815 std::istringstream
parser( stringValue );
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::string getNewRefHistoName()
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)
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.