13 #include <TCollection.h>
14 #include <TDirectory.h>
22 #include <TEfficiency.h>
40 #include "dqm_core/LibraryManager.h"
41 #include "dqm_core/Parameter.h"
42 #include "dqm_core/ParameterConfig.h"
43 #include "dqm_core/Region.h"
44 #include "dqm_core/RegionConfig.h"
45 #include <boost/algorithm/string/case_conv.hpp>
46 #include <boost/algorithm/string/classification.hpp>
47 #include <boost/algorithm/string/split.hpp>
48 #include <boost/algorithm/string/join.hpp>
49 #include <boost/algorithm/string/trim.hpp>
84 bool TestMiniNodeIsRegex(
const MiniConfigTreeNode*
node) {
85 std::string regexflag(
node->GetAttribute(
"regex"));
86 boost::algorithm::to_lower(regexflag);
87 if (regexflag ==
"1" || regexflag ==
"true" || regexflag ==
"yes") {
96 AssembleAndSave( std::string infileName, std::string outfileName, std::string connectionString,
long runNumber,
bool bulk)
98 std::unique_ptr< TFile >
outfile( TFile::Open( outfileName.c_str(),
103 MiniConfig refconfig;
104 refconfig.AddKeyword(
"reference");
105 refconfig.ReadFile(infileName);
107 refsourcedata.SetOwnerKeyValue();
109 refconfig.SendVisitor( refvisitor );
111 DatabaseConfig databaseConfig(std::move(connectionString),
runNumber);
112 RefWriter refwriter(databaseConfig, bulk);
113 refconfig.SendWriter( refwriter );
114 databaseConfig.Disconnect();
117 MiniConfig thrconfig;
118 thrconfig.AddKeyword(
"thresholds");
119 thrconfig.AddAttributeKeyword(
"limits");
120 thrconfig.ReadFile(infileName);
123 MiniConfig algconfig;
124 algconfig.AddKeyword(
"algorithm");
125 algconfig.ReadFile(infileName);
128 MiniConfig regconfig;
129 regconfig.AddKeyword(
"output");
130 regconfig.ReadFile(infileName);
133 MiniConfig histconfig;
134 histconfig.AddKeyword(
"dir");
135 histconfig.AddAttributeKeyword(
"hist");
136 histconfig.SetAttribKeywordPropagateDown(
false);
137 histconfig.ReadFile(infileName);
140 MiniConfig compalgconfig;
141 compalgconfig.AddKeyword(
"compositealgorithm");
142 compalgconfig.ReadFile(infileName);
143 CompAlgVisitor compalgvisitor(
outfile.get(), compalgconfig);
144 compalgconfig.SendVisitor(compalgvisitor);
146 MiniConfig metadataconfig;
147 metadataconfig.AddKeyword(
"metadata");
148 metadataconfig.ReadFile(std::move(infileName));
149 MetadataVisitor metadatavisitor(
outfile.get(), metadataconfig);
150 metadataconfig.SendVisitor(metadatavisitor);
154 std::unique_ptr< HanConfigGroup >
root(
new HanConfigGroup() );
156 RegionVisitor regvisitor(
root.get(), algconfig, thrconfig, refconfig,
directories );
157 regconfig.SendVisitor( regvisitor );
159 AssessmentVisitor histvisitor(
root.get(), algconfig, thrconfig, refconfig,
outfile.get(),
161 histconfig.SendVisitor( histvisitor );
163 outfile->WriteTObject(&refsourcedata,
"refsourcedata");
174 bool isInitialized =
Initialize( configName );
175 if( !isInitialized ) {
184 boost::shared_ptr<dqm_core::Region>
188 bool isInitialized =
Initialize( configName );
189 if( !isInitialized ) {
190 return boost::shared_ptr<dqm_core::Region>();
193 TDirectory* topdir =
const_cast<TDirectory*
>(
input.getBasedir());
196 TPython::Bind(topdir,
"path");
197 TPython::Exec(
"from DataQualityInterfaces.han import FixRegion, logLevel");
200 TPython::Exec(
"logLevel('INFO')");
202 TPython::Exec(
"logLevel('DEBUG')");
205 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,33,01)
207 TPython::Exec (
"_anyresult = ROOT.std.make_any['dqi::HanConfigGroup'](FixRegion(config, top_level, path))", &
result);
210 HanConfigGroup* new_top_level = TPython::Eval(
"FixRegion(config, top_level, path)");
217 if( algLibName !=
"" ) {
221 catch ( dqm_core::Exception& ex ) {
225 dqm_core::RegionConfig regc(
algName, 1.0 );
226 boost::shared_ptr<dqm_core::Region>
retval(dqm_core::Region::createRootRegion(
"top_level",
input,
output, regc ));
238 bool isInitialized =
Initialize( configName );
239 if( !isInitialized ) {
247 TDirectory* basedir(0);
249 std::string pathForSearch =
path;
250 pathForSearch +=
"/dummyName";
258 TSeqCollection* mdList =
newTList(
"HanMetadata_");
259 HanConfigMetadata* md(0);
260 while ((md =
dynamic_cast<HanConfigMetadata*
>(mdIter()))) {
261 mdList->Add( md->GetList(basedir,*outputMap) );
264 top_level_list->Add( mdList );
265 outputList->Add( top_level_list );
283 if (!
a.get())
return 0;
284 std::string refName(
a->GetAlgRefName() );
285 if( refName !=
"" ) {
289 TObject*
ref =
key->ReadObj();
299 SplitReference(std::string
refPath,
const std::string& refName )
302 static std::map<std::string, std::string> mappingCache;
305 std::vector<std::string> refFileDirList;
309 std::vector<std::string> refFileList;
310 for (
const auto&
dir : refFileDirList ) {
311 refFileList.push_back(boost::algorithm::trim_copy(
dir+refName));
317 const auto& cachehit = mappingCache.find(tfilestring);
318 if (cachehit != mappingCache.end()) {
319 return cachehit->second;
322 if (
const auto*
f = TFile::Open(tfilestring.c_str())) {
323 mappingCache[tfilestring] =
f->GetName();
325 std::cerr <<
"Unable to open any reference files in " << tfilestring <<
", reference will not be included" << std::endl;
326 mappingCache[tfilestring] =
"";
328 return mappingCache[tfilestring];
331 const HanConfigAssessor*
344 const HanConfigAssessor&
a =
parent->GetAssessor(
name);
346 return new HanConfigAssessor(
a);
353 RegexVisitor
rv(regexlist);
363 : m_outfile(outfile_)
364 , m_directories(directories_)
365 , m_refsourcedata(refsourcedata_)
375 std::string
name =
node->GetAttribute(
"name");
379 std::string refInfo =
node->GetAttribute(
"info");
381 std::cerr <<
"INFO: Reference " <<
name <<
" is defined without an \"info\" attribute. Consider adding one"
387 std::cerr <<
"WARNING: HanConfig::RefVisitor::Visit(): Reference not found: \"" <<
name <<
"\"\n";
400 obj->Write(newHistoName.c_str());
402 TObjString* fnameostr =
new TObjString(
fileName.c_str());
406 m_refsourcedata->Add(fnameostr->Clone(), refInfo !=
"" ?
new TObjString(refInfo.c_str())
407 :
new TObjString(
"Reference"));
413 RefWriter( DatabaseConfig& databaseConfig_,
const bool bulk)
414 : m_databaseConfig(databaseConfig_),
427 database += (m_bulk ?
"-physics-UPD4" :
"-express-UPD1");
431 if(jsonPayload.find(
reference) != jsonPayload.end()) {
434 node->SetAttribute(
it.key(),
it.value(),
false);
437 std::cerr <<
"Unable to find reference definition in database: " <<
reference <<
'\n';
444 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
446 TMap* refsourcedata_ )
448 , m_algConfig(algConfig_)
449 , m_thrConfig(thrConfig_)
450 , m_refConfig(refConfig_)
451 , m_outfile(outfile_)
452 , m_directories(directories_)
453 , m_refsourcedata(refsourcedata_)
457 std::shared_ptr<TFile>
461 auto it = m_filecache.find(
fname);
462 if (
it !=
end(m_filecache)) {
465 if (m_badPaths.find(
fname) != m_badPaths.end()) {
466 return std::shared_ptr<TFile>(
nullptr);
468 std::shared_ptr<TFile> thisptr(TFile::Open(
fname.c_str()));
470 return ( m_filecache[
fname] = std::move(thisptr) );
472 m_badPaths.insert(
fname);
488 DisableMustClean dmc;
491 if (m_keycache.find(
fname) != m_keycache.end()) {
494 m_keycache[
fname].reserve(100000);
500 float AttribToFloat(
const MiniConfigTreeNode*
node,
const std::string& attrib,
501 const std::string& warningString,
bool local=
false)
503 std::istringstream valstream;
505 valstream.str(
node->GetAttributeLocal(attrib));
507 valstream.str(
node->GetAttribute(attrib));
512 std::cerr << warningString << std::endl;
522 const std::string& assessorName )
525 std::set<std::string> algAtt;
526 m_algConfig.GetAttributeNames( algID, algAtt );
527 std::set<std::string>::const_iterator algAttEnd = algAtt.end();
528 for( std::set<std::string>::const_iterator
i = algAtt.begin();
i != algAttEnd; ++
i ) {
529 std::string trail(
"");
530 std::string::size_type
pos = (*i).find(
'|');
531 if (
pos != std::string::npos) {
532 trail = (*i).substr(
pos + 1, std::string::npos);
536 std::string
algName( m_algConfig.GetStringAttribute(algID,
"name") );
539 else if( *
i ==
"libname" ) {
540 std::string algLibName( m_algConfig.GetStringAttribute(algID,
"libname") );
541 dqpar->SetAlgLibName( std::move(algLibName) );
543 else if( *
i ==
"thresholds" || trail ==
"thresholds" ) {
544 std::string thrID( m_algConfig.GetStringAttribute(algID,*
i) );
545 std::set<std::string> thrAtt;
546 m_thrConfig.GetAttributeNames( thrID, thrAtt );
547 std::set<std::string>::const_iterator thrAttEnd = thrAtt.end();
548 for( std::set<std::string>::const_iterator
t = thrAtt.begin();
t != thrAttEnd; ++
t ) {
549 std::string thrAttName = *
t;
550 std::string thrAttVal = m_thrConfig.GetStringAttribute( thrID, thrAttName );
551 std::string limName = thrAttVal + std::string(
"/") + thrAttName;
552 HanConfigAlgLimit algLim;
553 if (
pos != std::string::npos) {
554 algLim.SetName( (*i).substr(0,
pos) + std::string(
"|") + *
t );
556 algLim.SetName( *
t );
558 algLim.SetGreen( m_thrConfig.GetFloatAttribute(limName,
"warning") );
559 algLim.SetRed( m_thrConfig.GetFloatAttribute(std::move(limName),
"error") );
560 dqpar->AddAlgLimit( algLim );
563 else if( *
i ==
"reference" ) {
567 std::string tmpRefID=m_algConfig.GetStringAttribute(algID,
"reference");
572 std::stringstream newRefString;
574 for(
size_t t=0;
t<condPairs.size();
t++){
575 bool refsuccess(
false);
576 std::string refID=condPairs.at(
t).second;
577 std::string cond=condPairs.at(
t).first;
578 std::vector<std::string> refIDVec;
580 std::vector<std::vector<std::pair<std::string, std::shared_ptr<TObject>>>>
objects;
581 std::string newRefId(
"");
582 bool isMultiRef(
false);
583 std::vector<std::string> sourceMatches;
584 if (refID[0] ==
'[') {
585 std::string cleanedRefID = refID;
586 boost::algorithm::trim_if(cleanedRefID, boost::is_any_of(
"[] "));
588 boost::split(refIDVec, cleanedRefID, boost::is_any_of(
","));
592 refIDVec.push_back(refID);
597 std::string algRefName( m_refConfig.GetStringAttribute(refID,
"name") );
598 std::string algRefInfo( m_refConfig.GetStringAttribute(refID,
"info") );
599 std::string algRefFile( m_refConfig.GetStringAttribute(refID,
"file") );
600 if (algRefName !=
"same_name" && !isMultiRef) {
603 if(newRefId.empty()){
604 std::string algRefPath( m_refConfig.GetStringAttribute(refID,
"path") );
605 std::cerr<<
"Warning New reference id is empty for refId=\""
606 <<refID<<
"\", cond=\""<<cond<<
"\", assessorName=\""
607 <<assessorName<<
"\", algRefName=\""
608 <<algRefName<<
"\""<<std::endl;
609 std::cerr <<
"AlgRefPath=" << algRefPath <<
" AlgRefInfo=" << algRefInfo << std::endl;
615 objects.resize(refIDVec.size());
616 std::string absAlgRefName, algRefPath, algRefInfo;
617 for (
size_t iRefID = 0; iRefID < refIDVec.size(); ++iRefID) {
618 const auto& thisRefID = refIDVec[iRefID];
619 algRefName = m_refConfig.GetStringAttribute(thisRefID,
"name");
620 algRefPath = m_refConfig.GetStringAttribute(thisRefID,
"path");
621 algRefInfo = m_refConfig.GetStringAttribute(thisRefID,
"info");
622 algRefFile = m_refConfig.GetStringAttribute(thisRefID,
"file");
623 if (algRefInfo ==
"") {
624 std::cerr <<
"INFO: Reference " << thisRefID <<
" is defined without an \"info\" attribute. Consider adding one"
628 if( algRefPath !=
"" ) {
629 absAlgRefName += algRefPath;
630 absAlgRefName +=
"/";
632 if( algRefName ==
"same_name" ) {
633 algRefName = assessorName;
634 absAlgRefName += algRefName;
635 algRefFile = SplitReference( m_refConfig.GetStringAttribute(thisRefID,
"location"), algRefFile);
637 if( algRefFile !=
"" ) {
638 std::shared_ptr<TFile>
infile = GetROOTFile(algRefFile);
640 std::cerr <<
"HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile <<
" not found" << std::endl;
643 std::vector<std::string> localMatches;
644 if (
dqpar->GetIsRegex()) {
645 if (! sourceMatches.empty()) {
646 std::cerr <<
"same_name appears twice in a reference request???" << std::endl;
649 std::string regexPattern = boost::regex_replace(absAlgRefName,
boost::regex(
"\\(\\?P=([^)]*)\\)"),
"\\\\k<\\1>", boost::format_all);
650 boost::regex re(boost::replace_all_copy(regexPattern,
"(?P",
"(?"));
651 EnsureKeyCache(algRefFile);
652 for (
const auto& iKey: m_keycache[algRefFile]) {
653 if (boost::regex_match(iKey,
re)) {
654 sourceMatches.push_back(iKey);
657 objects[iRefID].emplace_back(iKey,
key->ReadObj());
668 std::shared_ptr<TObject>
q(
key->ReadObj());
669 objects[iRefID].emplace_back(absAlgRefName,
q);
673 absAlgRefName += algRefName;
674 algRefFile = SplitReference( m_refConfig.GetStringAttribute(thisRefID,
"location"), algRefFile);
676 if( algRefFile !=
"" ) {
677 std::shared_ptr<TFile>
infile = GetROOTFile(algRefFile);
679 std::cerr <<
"HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile <<
" not found" << std::endl;
686 std::cerr <<
"Couldn't find reference " << absAlgRefName << std::endl;
690 std::shared_ptr<TObject>
q(
key->ReadObj());
691 TNamed* qn =
dynamic_cast<TNamed*
>(
q.get());
692 if (isMultiRef && qn) {
693 std::string multirefname = thisRefID;
694 if (algRefInfo !=
"") {
695 multirefname = algRefInfo;
696 }
else if (algRefFile !=
"") {
697 multirefname = algRefFile;
699 qn->SetName(multirefname.c_str());
701 objects[iRefID].emplace_back(absAlgRefName,
q);
703 std::cerr <<
"No file specified for " << absAlgRefName <<
" ?" << std::endl;
708 std::shared_ptr<TObject> toWriteOut;
709 std::string algRefUniqueName;
710 std::string algRefSourceInfo = (algRefInfo !=
"" ? algRefInfo.c_str() :
"Reference");
716 TMap* tmapobj =
new TMap();
717 tmapobj->SetOwnerKeyValue();
718 for (
const auto& thisPair:
objects[0]) {
719 std::unique_ptr<TObject> cobj(thisPair.second->Clone());
720 TNamed* hobj =
dynamic_cast<TNamed*
>(cobj.get());
722 hobj->SetName(refID.c_str());
724 algRefUniqueName = algRefFile+
":/"+thisPair.first;
726 if(newRefId.empty()){
729 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
730 new TObjString(algRefFile.c_str()));
731 cobj->Write(newRefId.c_str(), 1);
734 std::string maprefstring(thisPair.first);
735 if (algRefPath !=
"") {
736 boost::replace_first(maprefstring, algRefPath +
"/",
"");
738 tmapobj->Add(
new TObjString(maprefstring.c_str()),
739 new TObjString(newRefId.c_str()));
741 toWriteOut.reset(tmapobj);
742 algRefUniqueName = algRefFile+
"_regex:/"+
dqpar->GetUniqueName();
745 algRefUniqueName = algRefFile+
":/"+absAlgRefName;
748 toWriteOut =
objects[0][0].second;
752 algRefUniqueName=cond+
"_multiple:/"+absAlgRefName;
753 algRefSourceInfo=
"Multiple references";
755 if (
dqpar->GetIsRegex()) {
758 TObjArray* toarray =
new TObjArray();
759 toarray->SetOwner(
true);
760 for (
size_t iRef = 0; iRef <
objects.size(); ++iRef) {
766 toWriteOut.reset(toarray);
771 if (refsuccess && toWriteOut) {
774 if(newRefId.empty()){
779 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
780 new TObjString(algRefFile.c_str()));
782 if (! m_refsourcedata->FindObject(algRefFile.c_str())) {
783 m_refsourcedata->Add(
new TObjString(algRefFile.c_str()),
784 new TObjString(algRefSourceInfo.c_str()));
788 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
789 new TObjString(algRefSourceInfo.c_str()));
793 toWriteOut->Write(newRefId.c_str(), 1);
797 if (!newRefId.empty()) {
799 newRefString<<cond<<
":"<<newRefId<<
";";
801 newRefString<<newRefId;
805 dqpar->SetAlgRefName((newRefString.str()));
808 std::string
stringValue = m_algConfig.GetStringAttribute( algID, *
i );
813 HanConfigParMap algPar;
814 algPar.SetName( *
i );
816 dqpar->AddAlgStrPar( algPar );
818 HanConfigAlgPar algPar;
819 algPar.SetName( *
i );
820 algPar.SetValue( numberValue );
821 dqpar->AddAlgPar( algPar );
829 RegionVisitor( HanConfigGroup* root_,
const MiniConfig& algConfig_,
830 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
832 : AssessmentVisitorBase( root_, algConfig_, thrConfig_, refConfig_, 0, directories_,
nullptr )
841 const MiniConfigTreeNode*
parent =
node->GetParent();
845 const MiniConfigTreeNode* grandparent =
parent->GetParent();
846 auto alloc = std::make_unique<HanConfigGroup>();
847 HanConfigGroup* reg = (grandparent==0) ? m_root : alloc.get();
851 reg->SetName(
node->GetName() );
852 reg->SetPathName(
node->GetPathName() );
854 std::string algID(
node->GetAttribute(
"algorithm") );
856 GetAlgorithmConfiguration( reg, algID );
858 std::cerr <<
"Warning: no summary algorithm specified for " <<
node->GetPathName() << std::endl
859 <<
"This is probably not what you want" << std::endl;
862 if (
node->GetAttributeLocal(
"weight") !=
"") {
863 std::ostringstream
err;
864 err <<
"Weight is not a floating point attribute for " <<
node->GetPathName() <<
"; setting to 0";
865 reg->SetWeight(AttribToFloat(
node,
"weight",
err.str(),
true));
868 if( grandparent != 0 ) {
870 HanConfigGroup* parentReg = m_root->GetNode(
path );
871 parentReg = (parentReg==0) ? m_root : parentReg;
872 if( parentReg != 0 ) {
873 parentReg->AddGroup( *reg );
880 : m_regexes(regexes_)
884 boost::shared_ptr<dqm_core::Node>
886 Visit(
const HanConfigAssessor*
node, boost::shared_ptr<dqm_core::Region> )
889 if (
dynamic_cast<const HanConfigGroup*
>(
node) != NULL) {
890 return boost::shared_ptr<dqm_core::Parameter>();
892 if (
node->GetIsRegex()) {
893 m_regexes.insert(
node->GetName());
895 return boost::shared_ptr<dqm_core::Parameter>();
900 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
902 TMap* refsourcedata_ )
903 : AssessmentVisitorBase( root_, algConfig_, thrConfig_, refConfig_, outfile_, directories_, refsourcedata_ )
911 std::set<std::string> histAtt;
912 node->GetAttributeNames( histAtt );
913 std::set<std::string> defined;
914 std::string regID(
"");
915 std::string algID(
"");
916 std::set<std::string>::const_iterator histAttEnd = histAtt.end();
917 for( std::set<std::string>::const_iterator
h = histAtt.begin();
h != histAttEnd; ++
h ) {
918 const MiniConfigTreeNode* histNode =
node->GetDaughter( *
h );
922 algID = histNode->GetAttribute(
"algorithm");
923 regID = histNode->GetAttribute(
"output");
926 std::cerr <<
"No \"algorithm\" defined for " << histNode->GetPathName() <<
"\n";
933 std::string strNodeName(histNode->GetName());
934 std::string strHistName, strFullHistName;
935 std::string::size_type atsign = strNodeName.find(
'@');
936 if (atsign == std::string::npos) {
937 strHistName = std::move(strNodeName);
938 strFullHistName = histNode->GetPathName();
940 strHistName = strNodeName.substr(0, atsign);
941 strFullHistName = histNode->GetPathName();
942 strFullHistName.resize(strFullHistName.find(
'@'));
945 if( strHistName ==
"all_in_dir" )
948 if( defined.find(histNode->GetPathName()) != defined.end() )
951 HanConfigAssessor
dqpar;
952 dqpar.SetName( histNode->GetPathName() );
954 dqpar.SetIsRegex(TestMiniNodeIsRegex(histNode));
956 if (histNode->GetAttribute(
"weight") !=
"") {
957 std::ostringstream
err;
958 err <<
"Weight attribute not a floating point type for " << histNode->GetPathName() <<
"; setting to zero";
959 dqpar.SetWeight(AttribToFloat(histNode,
"weight",
963 GetAlgorithmConfiguration( &
dqpar, algID, strFullHistName );
965 std::set<std::string> histAtt2;
966 histNode->GetAttributeNames( histAtt2 );
967 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
968 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
969 if (
node->GetDaughter( *h2 )
970 || *h2 ==
"algorithm" || *h2 ==
"output" || *h2 ==
"reference"
971 || *h2 ==
"weight" || *h2 ==
"regex") {
974 HanConfigParMap parMap;
975 parMap.SetName(*h2); parMap.SetValue(histNode->GetAttribute(*h2));
976 dqpar.AddAnnotation(parMap);
980 HanConfigParMap parMap;
981 parMap.SetName(
"inputname"); parMap.SetValue( strFullHistName );
982 dqpar.AddAnnotation(parMap);
984 HanConfigGroup* dqreg = m_root->GetNode( regID );
985 dqreg = (dqreg==0) ? m_root : dqreg;
987 dqreg->AddAssessor(
dqpar );
989 defined.insert( strFullHistName );
992 for( std::set<std::string>::const_iterator
h = histAtt.begin();
h != histAttEnd; ++
h ) {
993 const MiniConfigTreeNode* histNode =
node->GetDaughter( *
h );
997 algID = histNode->GetAttribute(
"algorithm");
998 regID = histNode->GetAttribute(
"output");
1001 std::cerr <<
"No \"algorithm\" defined for " << histNode->GetPathName() <<
"\n";
1006 regID =
"top_level";
1008 std::string strNodeName(histNode->GetName());
1009 std::string strHistName, strFullHistName, extension;
1010 std::string::size_type atsign = strNodeName.find(
'@');
1011 if (atsign == std::string::npos) {
1012 strHistName = std::move(strNodeName);
1013 strFullHistName = histNode->GetPathName();
1016 strHistName = strNodeName.substr(0, atsign);
1017 extension = strNodeName.substr(atsign, std::string::npos);
1018 strFullHistName = histNode->GetPathName();
1019 strFullHistName.resize(strFullHistName.find(
'@'));
1022 if( strHistName ==
"all_in_dir" ) {
1024 std::string regexflag(histNode->GetAttribute(
"regex"));
1025 if (histNode->GetAttribute(
"regex") !=
"") {
1026 std::cerr <<
"WARNING: all_in_dir and regex are incompatible; ignoring regex flag for " << histNode->GetPathName()
1027 <<
"/all_in_dir" << std::endl;
1030 std::string refID( histNode->GetAttribute(
"reference") );
1032 std::cerr <<
"WARNING: No \"reference\" defined for " << histNode->GetPathName() <<
"\n";
1035 std::string refFile( m_refConfig.GetStringAttribute(refID,
"file") );
1036 if( refFile ==
"" ) {
1037 std::cerr <<
"WARNING: No \"file\" defined for " << histNode->GetPathName() <<
"\n";
1041 std::string
refPath( m_refConfig.GetStringAttribute(refID,
"path") );
1043 std::string objPath(
"");
1044 std::string absObjPath(
"");
1046 refFile = SplitReference( m_refConfig.GetStringAttribute(std::move(refID),
"location"), refFile);
1047 std::shared_ptr<TFile>
infile( GetROOTFile(refFile) );
1048 TDirectory* basedir(0);
1056 std::string refPathForSearch =
refPath;
1057 refPathForSearch +=
"/dummyName";
1059 if( basedir == 0 ) {
1060 std::cerr <<
"INFO: Cannot find path \"" <<
refPath <<
"\" in reference file\n";
1068 std::string allPathName( histNode->GetPathName() );
1069 std::string::size_type
i = allPathName.find_last_of(
'/');
1070 if(
i != std::string::npos ) {
1071 objPath = std::string( allPathName, 0,
i );
1073 absObjPath += std::string( allPathName, 0,
i );
1079 std::cerr <<
"INFO: Cannot find path \"" << absObjPath <<
"\" in reference file\n";
1083 TIter
next(
dir->GetListOfKeys() );
1084 std::string objName;
1085 std::string absObjName;
1088 std::set<std::string> localdefined;
1089 while( (
key =
dynamic_cast<TKey*
>(
next())) != 0 ) {
1090 TObject* tmpobj =
key->ReadObj();
1091 TH1* tmph =
dynamic_cast<TH1*
>(tmpobj);
1092 TGraph* tmpg =
dynamic_cast<TGraph*
>(tmpobj);
1093 TEfficiency* tmpe =
dynamic_cast<TEfficiency*
>(tmpobj);
1094 if( tmph == 0 && tmpg == 0 && tmpe == 0 )
1098 objName += std::string( tmpobj->GetName() );
1099 absObjName = absObjPath;
1100 absObjName += std::string( tmpobj->GetName() );
1103 if( defined.find(objName) != defined.end() ||
1104 localdefined.find(objName) != localdefined.end() )
1111 HanConfigAssessor
dqpar;
1112 dqpar.SetName( objName + extension );
1113 GetAlgorithmConfiguration( &
dqpar, algID, objName );
1115 if (histNode->GetAttribute(
"weight") !=
"") {
1116 std::ostringstream
err;
1117 err <<
"Weight attribute not a floating point type for " << objName <<
"; setting to zero";
1118 dqpar.SetWeight(AttribToFloat(histNode,
"weight",
1122 std::set<std::string> histAtt2;
1123 histNode->GetAttributeNames( histAtt2 );
1124 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
1125 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
1126 if (
node->GetDaughter( *h2 )
1127 || *h2 ==
"algorithm" || *h2 ==
"output" || *h2 ==
"reference"
1128 || *h2 ==
"weight" || *h2 ==
"regex") {
1131 HanConfigParMap parMap;
1132 parMap.SetName(*h2); parMap.SetValue(histNode->GetAttribute(*h2));
1133 dqpar.AddAnnotation(parMap);
1137 HanConfigParMap parMap;
1138 parMap.SetName(
"inputname"); parMap.SetValue( objName );
1139 dqpar.AddAnnotation(parMap);
1141 HanConfigGroup* dqreg = m_root->GetNode( regID );
1142 dqreg = (dqreg==0) ? m_root : dqreg;
1144 dqreg->AddAssessor(
dqpar );
1146 localdefined.insert( objName );
1163 boost::shared_ptr<dqm_core::Node>
1165 Visit(
const HanConfigAssessor*
node, boost::shared_ptr<dqm_core::Region> dqParent )
1167 const HanConfigGroup* gnode =
dynamic_cast<const HanConfigGroup*
>(
node );
1169 std::string algLibName(
node->GetAlgLibName() );
1170 if( algLibName !=
"" ) {
1174 catch ( dqm_core::Exception& ex ) {
1180 dqm_core::RegionConfig regc(
algName,
node->GetWeight() );
1181 std::string regName( gnode->GetPathName() );
1182 boost::shared_ptr<dqm_core::Region> reg(dqParent->addRegion( regName, regc ));
1183 m_output->addListener(regName, dqParent.get());
1187 std::string inputData(
node->GetHistPath() );
1188 HanAlgorithmConfig* algConfig =
new HanAlgorithmConfig( *
node,
m_file );
1189 dqm_core::ParameterConfig parc( inputData,
algName,
node->GetWeight(),
1190 std::shared_ptr<HanAlgorithmConfig>(algConfig),
node->GetIsRegex() );
1191 boost::shared_ptr<dqm_core::Node>
par(dqParent->addParameter(
node->GetName(), parc ));
1192 m_output->addListener(
node->GetName(), dqParent.get());
1198 CompAlgVisitor(TFile* outfile_,
const MiniConfig& compAlgConfig_)
1199 : m_outfile(outfile_)
1200 , m_compAlgConfig(compAlgConfig_)
1210 std::map<std::string,MiniConfigTreeNode*> daughters =
node->GetDaughters();
1211 std::map<std::string,MiniConfigTreeNode*>::const_iterator nodeiterEnd = daughters.end();
1212 for( std::map<std::string,MiniConfigTreeNode*>::const_iterator iter = daughters.begin(); iter != nodeiterEnd; ++iter ) {
1213 std::string compAlgID = iter->second->GetName();
1214 std::string compAlgKey = iter->first;
1216 HanConfigCompAlg* compAlg =
new HanConfigCompAlg();
1217 std::set<std::string> compAlgAtt;
1218 m_compAlgConfig.GetAttributeNames(compAlgID, compAlgAtt);
1219 std::set<std::string>::const_iterator compAlgAttEnd = compAlgAtt.end();
1221 compAlg->SetName(compAlgID);
1222 for( std::set<std::string>::const_iterator
i = compAlgAtt.begin();
i != compAlgAttEnd; ++
i ) {
1223 if( *
i ==
"subalgs" ) {
1224 std::string subAlgs( m_compAlgConfig.GetStringAttribute(compAlgID,
"subalgs") );
1225 std::string::size_type
pos = subAlgs.find(
',');
1226 for(
int size=subAlgs.size(), sizeOld=-8;
1228 subAlgs.erase(0,
pos+1),
pos = subAlgs.find(
','),sizeOld=
size,
size=subAlgs.size()) {
1230 compAlg->AddAlg( subAlgs.substr(0,
pos));
1233 else if( *
i ==
"libnames" ) {
1234 std::string
libs( m_compAlgConfig.GetStringAttribute(compAlgID,
"libnames") );
1235 std::string::size_type
pos =
libs.find(
',');
1236 for(
int size=
libs.size(), sizeOld=-8;
1240 compAlg->AddLib(
libs.substr(0,
pos));
1250 : m_outfile(outfile_)
1251 , m_metadataConfig(metadataConfig_)
1261 if (m_outfile->Get(
"HanMetadata")) {
1262 m_outfile->cd(
"HanMetadata");
1265 TDirectory* mdir = m_outfile->mkdir(
"HanMetadata");
1274 std::map<std::string,MiniConfigTreeNode*> daughters =
node->GetDaughters();
1275 std::map<std::string,MiniConfigTreeNode*>::const_iterator nodeiterEnd = daughters.end();
1276 for( std::map<std::string,MiniConfigTreeNode*>::const_iterator iter = daughters.begin(); iter != nodeiterEnd; ++iter ) {
1277 std::string metadataID = iter->second->GetName();
1279 std::set<std::string> metadataAtt;
1280 m_metadataConfig.GetAttributeNames(metadataID, metadataAtt);
1281 HanConfigMetadata*
metadata =
new HanConfigMetadata();
1283 for (std::set<std::string>::const_iterator
i = metadataAtt.begin();
i != metadataAtt.end(); ++
i ) {
1284 HanConfigParMap parMap;
1285 parMap.SetName(*
i); parMap.SetValue(m_metadataConfig.GetStringAttribute(metadataID, *
i));
1307 m_config = TFile::Open( configName.c_str(),
"READ" );
1309 std::cerr <<
"HanConfig::Initialize() cannot open file \"" << configName <<
"\"\n";
1313 TMap* refsourcedata =
dynamic_cast<TMap*
>(
m_config->Get(
"refsourcedata"));
1314 if (refsourcedata) {
1317 std::cerr <<
"Can't retrieve reference source info" << std::endl;
1320 TIter nextKey(
m_config->GetListOfKeys() );
1321 TKey* compAlgKey(0);
1322 while( (compAlgKey =
dynamic_cast<TKey*
>( nextKey() )) != 0 ) {
1323 TObject*
obj = compAlgKey->ReadObj();
1324 HanConfigCompAlg* compAlg =
dynamic_cast<HanConfigCompAlg*
>(
obj );
1325 if( compAlg != 0 ) {
1327 new CompositeAlgorithm( *compAlg );
1337 TDirectory* mdDir =
dynamic_cast<TDirectory*
>(
key->ReadObj());
1339 TIter mdIter(mdDir->GetListOfKeys());
1341 while ((mdKey =
dynamic_cast<TKey*
>(mdIter()))) {
1342 HanConfigMetadata* md =
dynamic_cast<HanConfigMetadata*
>(mdKey->ReadObj());
1353 std::cerr <<
"HanConfig::Initialize() cannot find configuration in file \"" << configName <<
"\"\n";
1359 std::cerr <<
"HanConfig::Initialize() cannot find configuration in file \"" << configName <<
"\"\n";
1382 std::string::size_type
i =
path.find_first_of(
'/');
1383 if(
i != std::string::npos ) {
1384 std::string dName(
path, 0,
i );
1385 std::string pName(
path,
i+1, std::string::npos );
1387 TDirectory* subDir(0);
1388 key =
dir->FindKey( dName.c_str() );
1390 subDir =
dynamic_cast<TDirectory*
>(
key->ReadObj() );
1412 std::string::size_type
i =
path.find_last_of(
'/');
1413 if(
i != std::string::npos ) {
1414 std::string subPath(
path, 0,
i );
1415 DirMap_t::const_iterator j =
directories.find( subPath );
1417 TDirectory*
dir = j->second;
1422 std::string dirName;
1423 std::string::size_type
k = subPath.find_last_of(
'/');
1424 dirName = (
k != std::string::npos) ? std::string( subPath,
k+1, std::string::npos ) : subPath;
1425 TDirectory*
dir =
nullptr;
1426 if (!parDir->FindKey(dirName.c_str())) {
1427 dir = parDir->mkdir( dirName.c_str() );
1430 std::cout <<
"Failed to make directory " << dirName.c_str() << std::endl;
1432 DirMap_t::value_type dirVal( subPath,
dir );