15 #include <TCollection.h>
16 #include <TDirectory.h>
24 #include <TEfficiency.h>
42 #include "dqm_core/LibraryManager.h"
43 #include "dqm_core/Parameter.h"
44 #include "dqm_core/ParameterConfig.h"
45 #include "dqm_core/Region.h"
46 #include "dqm_core/RegionConfig.h"
47 #include <boost/algorithm/string/case_conv.hpp>
48 #include <boost/algorithm/string/classification.hpp>
49 #include <boost/algorithm/string/split.hpp>
50 #include <boost/algorithm/string/join.hpp>
51 #include <boost/algorithm/string/trim.hpp>
86 bool TestMiniNodeIsRegex(
const MiniConfigTreeNode*
node) {
87 std::string regexflag(
node->GetAttribute(
"regex"));
88 boost::algorithm::to_lower(regexflag);
89 if (regexflag ==
"1" || regexflag ==
"true" || regexflag ==
"yes") {
98 AssembleAndSave( std::string infileName, std::string outfileName, std::string connectionString,
long runNumber,
bool bulk)
100 std::unique_ptr< TFile >
outfile( TFile::Open( outfileName.c_str(),
105 MiniConfig refconfig;
106 refconfig.AddKeyword(
"reference");
107 refconfig.ReadFile(infileName);
109 refsourcedata.SetOwnerKeyValue();
111 refconfig.SendVisitor( refvisitor );
113 DatabaseConfig databaseConfig(std::move(connectionString),
runNumber);
114 RefWriter refwriter(databaseConfig, bulk);
115 refconfig.SendWriter( refwriter );
116 databaseConfig.Disconnect();
119 MiniConfig thrconfig;
120 thrconfig.AddKeyword(
"thresholds");
121 thrconfig.AddAttributeKeyword(
"limits");
122 thrconfig.ReadFile(infileName);
125 MiniConfig algconfig;
126 algconfig.AddKeyword(
"algorithm");
127 algconfig.ReadFile(infileName);
130 MiniConfig regconfig;
131 regconfig.AddKeyword(
"output");
132 regconfig.ReadFile(infileName);
135 MiniConfig histconfig;
136 histconfig.AddKeyword(
"dir");
137 histconfig.AddAttributeKeyword(
"hist");
138 histconfig.SetAttribKeywordPropagateDown(
false);
139 histconfig.ReadFile(infileName);
142 MiniConfig compalgconfig;
143 compalgconfig.AddKeyword(
"compositealgorithm");
144 compalgconfig.ReadFile(infileName);
145 CompAlgVisitor compalgvisitor(
outfile.get(), compalgconfig);
146 compalgconfig.SendVisitor(compalgvisitor);
148 MiniConfig metadataconfig;
149 metadataconfig.AddKeyword(
"metadata");
150 metadataconfig.ReadFile(infileName);
151 MetadataVisitor metadatavisitor(
outfile.get(), metadataconfig);
152 metadataconfig.SendVisitor(metadatavisitor);
156 std::unique_ptr< HanConfigGroup >
root(
new HanConfigGroup() );
158 RegionVisitor regvisitor(
root.get(), algconfig, thrconfig, refconfig,
directories );
159 regconfig.SendVisitor( regvisitor );
161 AssessmentVisitor histvisitor(
root.get(), algconfig, thrconfig, refconfig,
outfile.get(),
163 histconfig.SendVisitor( histvisitor );
165 outfile->WriteTObject(&refsourcedata,
"refsourcedata");
176 bool isInitialized =
Initialize( configName );
177 if( !isInitialized ) {
186 boost::shared_ptr<dqm_core::Region>
190 bool isInitialized =
Initialize( configName );
191 if( !isInitialized ) {
192 return boost::shared_ptr<dqm_core::Region>();
195 TDirectory* topdir =
const_cast<TDirectory*
>(
input.getBasedir());
198 TPython::Bind(topdir,
"path");
199 TPython::Exec(
"from DataQualityInterfaces.han import FixRegion, logLevel");
202 TPython::Exec(
"logLevel('INFO')");
204 TPython::Exec(
"logLevel('DEBUG')");
207 HanConfigGroup* new_top_level = TPython::Eval(
"FixRegion(config, top_level, path)");
213 if( algLibName !=
"" ) {
217 catch ( dqm_core::Exception& ex ) {
221 dqm_core::RegionConfig regc(
algName, 1.0 );
222 boost::shared_ptr<dqm_core::Region>
retval(dqm_core::Region::createRootRegion(
"top_level",
input,
output, regc ));
234 bool isInitialized =
Initialize( configName );
235 if( !isInitialized ) {
243 TDirectory* basedir(0);
245 std::string pathForSearch =
path;
246 pathForSearch +=
"/dummyName";
254 TSeqCollection* mdList =
newTList(
"HanMetadata_");
255 HanConfigMetadata* md(0);
256 while ((md =
dynamic_cast<HanConfigMetadata*
>(mdIter()))) {
257 mdList->Add( md->GetList(basedir,*outputMap) );
260 top_level_list->Add( mdList );
261 outputList->Add( top_level_list );
279 if (!
a.get())
return 0;
280 std::string refName(
a->GetAlgRefName() );
281 if( refName !=
"" ) {
285 TObject*
ref =
key->ReadObj();
295 SplitReference(std::string
refPath,
const std::string& refName )
298 static std::map<std::string, std::string> mappingCache;
301 std::vector<std::string> refFileDirList;
305 std::vector<std::string> refFileList;
306 for (
const auto&
dir : refFileDirList ) {
307 refFileList.push_back(boost::algorithm::trim_copy(
dir+refName));
313 const auto& cachehit = mappingCache.find(tfilestring);
314 if (cachehit != mappingCache.end()) {
315 return cachehit->second;
318 if (
const auto*
f = TFile::Open(tfilestring.c_str())) {
319 mappingCache[tfilestring] =
f->GetName();
321 std::cerr <<
"Unable to open any reference files in " << tfilestring <<
", reference will not be included" << std::endl;
322 mappingCache[tfilestring] =
"";
324 return mappingCache[tfilestring];
327 const HanConfigAssessor*
340 const HanConfigAssessor&
a =
parent->GetAssessor(
name);
342 return new HanConfigAssessor(
a);
349 RegexVisitor
rv(regexlist);
359 : m_outfile(outfile_)
360 , m_directories(directories_)
361 , m_refsourcedata(refsourcedata_)
371 std::string
name =
node->GetAttribute(
"name");
375 std::string refInfo =
node->GetAttribute(
"info");
377 std::cerr <<
"INFO: Reference " <<
name <<
" is defined without an \"info\" attribute. Consider adding one"
383 std::cerr <<
"WARNING: HanConfig::RefVisitor::Visit(): Reference not found: \"" <<
name <<
"\"\n";
396 obj->Write(newHistoName.c_str());
398 TObjString* fnameostr =
new TObjString(
fileName.c_str());
402 m_refsourcedata->Add(fnameostr->Clone(), refInfo !=
"" ?
new TObjString(refInfo.c_str())
403 :
new TObjString(
"Reference"));
409 RefWriter( DatabaseConfig& databaseConfig_,
const bool bulk)
410 : m_databaseConfig(databaseConfig_),
423 database += (m_bulk ?
"-physics-UPD4" :
"-express-UPD1");
427 if(jsonPayload.find(
reference) != jsonPayload.end()) {
430 node->SetAttribute(
it.key(),
it.value(),
false);
433 std::cerr <<
"Unable to find reference definition in database: " <<
reference <<
'\n';
440 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
442 TMap* refsourcedata_ )
444 , m_algConfig(algConfig_)
445 , m_thrConfig(thrConfig_)
446 , m_refConfig(refConfig_)
447 , m_outfile(outfile_)
448 , m_directories(directories_)
449 , m_refsourcedata(refsourcedata_)
453 std::shared_ptr<TFile>
457 auto it = m_filecache.find(
fname);
458 if (
it !=
end(m_filecache)) {
461 if (m_badPaths.find(
fname) != m_badPaths.end()) {
462 return std::shared_ptr<TFile>(
nullptr);
464 std::shared_ptr<TFile> thisptr(TFile::Open(
fname.c_str()));
466 return ( m_filecache[
fname] = thisptr );
468 m_badPaths.insert(
fname);
484 DisableMustClean dmc;
487 if (m_keycache.find(
fname) != m_keycache.end()) {
490 m_keycache[
fname].reserve(100000);
496 float AttribToFloat(
const MiniConfigTreeNode*
node,
const std::string& attrib,
497 const std::string& warningString,
bool local=
false)
499 std::istringstream valstream;
501 valstream.str(
node->GetAttributeLocal(attrib));
503 valstream.str(
node->GetAttribute(attrib));
508 std::cerr << warningString << std::endl;
518 const std::string& assessorName )
521 std::set<std::string> algAtt;
522 m_algConfig.GetAttributeNames( algID, algAtt );
523 std::set<std::string>::const_iterator algAttEnd = algAtt.end();
524 for( std::set<std::string>::const_iterator
i = algAtt.begin();
i != algAttEnd; ++
i ) {
525 std::string trail(
"");
526 std::string::size_type
pos = (*i).find(
'|');
527 if (
pos != std::string::npos) {
528 trail = (*i).substr(
pos + 1, std::string::npos);
532 std::string
algName( m_algConfig.GetStringAttribute(algID,
"name") );
535 else if( *
i ==
"libname" ) {
536 std::string algLibName( m_algConfig.GetStringAttribute(algID,
"libname") );
537 dqpar->SetAlgLibName( algLibName );
539 else if( *
i ==
"thresholds" || trail ==
"thresholds" ) {
540 std::string thrID( m_algConfig.GetStringAttribute(algID,*
i) );
541 std::set<std::string> thrAtt;
542 m_thrConfig.GetAttributeNames( thrID, thrAtt );
543 std::set<std::string>::const_iterator thrAttEnd = thrAtt.end();
544 for( std::set<std::string>::const_iterator
t = thrAtt.begin();
t != thrAttEnd; ++
t ) {
545 std::string thrAttName = *
t;
546 std::string thrAttVal = m_thrConfig.GetStringAttribute( thrID, thrAttName );
547 std::string limName = thrAttVal + std::string(
"/") + thrAttName;
548 HanConfigAlgLimit algLim;
549 if (
pos != std::string::npos) {
550 algLim.SetName( (*i).substr(0,
pos) + std::string(
"|") + *
t );
552 algLim.SetName( *
t );
554 algLim.SetGreen( m_thrConfig.GetFloatAttribute(limName,
"warning") );
555 algLim.SetRed( m_thrConfig.GetFloatAttribute(limName,
"error") );
556 dqpar->AddAlgLimit( algLim );
559 else if( *
i ==
"reference" ) {
563 std::string tmpRefID=m_algConfig.GetStringAttribute(algID,
"reference");
568 std::stringstream newRefString;
570 for(
size_t t=0;
t<condPairs.size();
t++){
571 bool refsuccess(
false);
572 std::string refID=condPairs.at(
t).second;
573 std::string cond=condPairs.at(
t).first;
574 std::vector<std::string> refIDVec;
576 std::vector<std::vector<std::pair<std::string, std::shared_ptr<TObject>>>>
objects;
577 std::string newRefId(
"");
578 bool isMultiRef(
false);
579 std::vector<std::string> sourceMatches;
580 if (refID[0] ==
'[') {
581 std::string cleanedRefID = refID;
582 boost::algorithm::trim_if(cleanedRefID, boost::is_any_of(
"[] "));
584 boost::split(refIDVec, cleanedRefID, boost::is_any_of(
","));
588 refIDVec.push_back(refID);
593 std::string algRefName( m_refConfig.GetStringAttribute(refID,
"name") );
594 std::string algRefInfo( m_refConfig.GetStringAttribute(refID,
"info") );
595 std::string algRefFile( m_refConfig.GetStringAttribute(refID,
"file") );
596 if (algRefName !=
"same_name" && !isMultiRef) {
599 if(newRefId.empty()){
600 std::string algRefPath( m_refConfig.GetStringAttribute(refID,
"path") );
601 std::cerr<<
"Warning New reference id is empty for refId=\""
602 <<refID<<
"\", cond=\""<<cond<<
"\", assessorName=\""
603 <<assessorName<<
"\", algRefName=\""
604 <<algRefName<<
"\""<<std::endl;
605 std::cerr <<
"AlgRefPath=" << algRefPath <<
" AlgRefInfo=" << algRefInfo << std::endl;
611 objects.resize(refIDVec.size());
612 std::string absAlgRefName, algRefPath, algRefInfo;
613 for (
size_t iRefID = 0; iRefID < refIDVec.size(); ++iRefID) {
614 const auto& thisRefID = refIDVec[iRefID];
615 algRefName = m_refConfig.GetStringAttribute(thisRefID,
"name");
616 algRefPath = m_refConfig.GetStringAttribute(thisRefID,
"path");
617 algRefInfo = m_refConfig.GetStringAttribute(thisRefID,
"info");
618 algRefFile = m_refConfig.GetStringAttribute(thisRefID,
"file");
619 if (algRefInfo ==
"") {
620 std::cerr <<
"INFO: Reference " << thisRefID <<
" is defined without an \"info\" attribute. Consider adding one"
624 if( algRefPath !=
"" ) {
625 absAlgRefName += algRefPath;
626 absAlgRefName +=
"/";
628 if( algRefName ==
"same_name" ) {
629 algRefName = assessorName;
630 absAlgRefName += algRefName;
631 algRefFile = SplitReference( m_refConfig.GetStringAttribute(thisRefID,
"location"), algRefFile);
633 if( algRefFile !=
"" ) {
634 std::shared_ptr<TFile>
infile = GetROOTFile(algRefFile);
636 std::cerr <<
"HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile <<
" not found" << std::endl;
639 std::vector<std::string> localMatches;
640 if (
dqpar->GetIsRegex()) {
641 if (! sourceMatches.empty()) {
642 std::cerr <<
"same_name appears twice in a reference request???" << std::endl;
645 std::string regexPattern = boost::regex_replace(absAlgRefName,
boost::regex(
"\\(\\?P=([^)]*)\\)"),
"\\\\k<\\1>", boost::format_all);
646 boost::regex re(boost::replace_all_copy(regexPattern,
"(?P",
"(?"));
647 EnsureKeyCache(algRefFile);
648 for (
const auto& iKey: m_keycache[algRefFile]) {
649 if (boost::regex_match(iKey,
re)) {
650 sourceMatches.push_back(iKey);
653 objects[iRefID].emplace_back(iKey,
key->ReadObj());
664 std::shared_ptr<TObject>
q(
key->ReadObj());
665 objects[iRefID].emplace_back(absAlgRefName,
q);
669 absAlgRefName += algRefName;
670 algRefFile = SplitReference( m_refConfig.GetStringAttribute(thisRefID,
"location"), algRefFile);
672 if( algRefFile !=
"" ) {
673 std::shared_ptr<TFile>
infile = GetROOTFile(algRefFile);
675 std::cerr <<
"HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile <<
" not found" << std::endl;
682 std::cerr <<
"Couldn't find reference " << absAlgRefName << std::endl;
686 std::shared_ptr<TObject>
q(
key->ReadObj());
687 TNamed* qn =
dynamic_cast<TNamed*
>(
q.get());
688 if (isMultiRef && qn) {
689 std::string multirefname = thisRefID;
690 if (algRefInfo !=
"") {
691 multirefname = algRefInfo;
692 }
else if (algRefFile !=
"") {
693 multirefname = algRefFile;
695 qn->SetName(multirefname.c_str());
697 objects[iRefID].emplace_back(absAlgRefName,
q);
699 std::cerr <<
"No file specified for " << absAlgRefName <<
" ?" << std::endl;
704 std::shared_ptr<TObject> toWriteOut;
705 std::string algRefUniqueName;
706 std::string algRefSourceInfo = (algRefInfo !=
"" ? algRefInfo.c_str() :
"Reference");
712 TMap* tmapobj =
new TMap();
713 tmapobj->SetOwnerKeyValue();
714 for (
const auto& thisPair:
objects[0]) {
715 std::unique_ptr<TObject> cobj(thisPair.second->Clone());
716 TNamed* hobj =
dynamic_cast<TNamed*
>(cobj.get());
718 hobj->SetName(refID.c_str());
720 algRefUniqueName = algRefFile+
":/"+thisPair.first;
722 if(newRefId.empty()){
725 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
726 new TObjString(algRefFile.c_str()));
727 cobj->Write(newRefId.c_str(), 1);
730 std::string maprefstring(thisPair.first);
731 if (algRefPath !=
"") {
732 boost::replace_first(maprefstring, algRefPath +
"/",
"");
734 tmapobj->Add(
new TObjString(maprefstring.c_str()),
735 new TObjString(newRefId.c_str()));
737 toWriteOut.reset(tmapobj);
738 algRefUniqueName = algRefFile+
"_regex:/"+
dqpar->GetUniqueName();
741 algRefUniqueName = algRefFile+
":/"+absAlgRefName;
744 toWriteOut =
objects[0][0].second;
748 algRefUniqueName=cond+
"_multiple:/"+absAlgRefName;
749 algRefSourceInfo=
"Multiple references";
751 if (
dqpar->GetIsRegex()) {
754 TObjArray* toarray =
new TObjArray();
755 toarray->SetOwner(
true);
756 for (
size_t iRef = 0; iRef <
objects.size(); ++iRef) {
762 toWriteOut.reset(toarray);
767 if (refsuccess && toWriteOut) {
770 if(newRefId.empty()){
775 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
776 new TObjString(algRefFile.c_str()));
778 if (! m_refsourcedata->FindObject(algRefFile.c_str())) {
779 m_refsourcedata->Add(
new TObjString(algRefFile.c_str()),
780 new TObjString(algRefSourceInfo.c_str()));
784 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
785 new TObjString(algRefSourceInfo.c_str()));
789 toWriteOut->Write(newRefId.c_str(), 1);
793 if (!newRefId.empty()) {
795 newRefString<<cond<<
":"<<newRefId<<
";";
797 newRefString<<newRefId;
801 dqpar->SetAlgRefName((newRefString.str()));
804 std::string
stringValue = m_algConfig.GetStringAttribute( algID, *
i );
809 HanConfigParMap algPar;
810 algPar.SetName( *
i );
812 dqpar->AddAlgStrPar( algPar );
814 HanConfigAlgPar algPar;
815 algPar.SetName( *
i );
816 algPar.SetValue( numberValue );
817 dqpar->AddAlgPar( algPar );
825 RegionVisitor( HanConfigGroup* root_,
const MiniConfig& algConfig_,
826 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
828 : AssessmentVisitorBase( root_, algConfig_, thrConfig_, refConfig_, 0, directories_,
nullptr )
837 const MiniConfigTreeNode*
parent =
node->GetParent();
841 const MiniConfigTreeNode* grandparent =
parent->GetParent();
842 auto alloc = std::make_unique<HanConfigGroup>();
843 HanConfigGroup*
reg = (grandparent==0) ? m_root : alloc.get();
845 std::string regName(
node->GetName() );
846 reg->SetName( regName );
847 reg->SetPathName(
node->GetPathName() );
849 std::string algID(
node->GetAttribute(
"algorithm") );
851 GetAlgorithmConfiguration(
reg, algID );
853 std::cerr <<
"Warning: no summary algorithm specified for " <<
node->GetPathName() << std::endl
854 <<
"This is probably not what you want" << std::endl;
857 if (
node->GetAttributeLocal(
"weight") !=
"") {
858 std::ostringstream
err;
859 err <<
"Weight is not a floating point attribute for " <<
node->GetPathName() <<
"; setting to 0";
860 reg->SetWeight(AttribToFloat(
node,
"weight",
err.str(),
true));
863 if( grandparent != 0 ) {
865 HanConfigGroup* parentReg = m_root->GetNode(
path );
866 parentReg = (parentReg==0) ? m_root : parentReg;
867 if( parentReg != 0 ) {
868 parentReg->AddGroup( *
reg );
875 : m_regexes(regexes_)
879 boost::shared_ptr<dqm_core::Node>
881 Visit(
const HanConfigAssessor*
node, boost::shared_ptr<dqm_core::Region> )
884 if (
dynamic_cast<const HanConfigGroup*
>(
node) != NULL) {
885 return boost::shared_ptr<dqm_core::Parameter>();
887 if (
node->GetIsRegex()) {
888 m_regexes.insert(
node->GetName());
890 return boost::shared_ptr<dqm_core::Parameter>();
895 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
897 TMap* refsourcedata_ )
898 : AssessmentVisitorBase( root_, algConfig_, thrConfig_, refConfig_, outfile_, directories_, refsourcedata_ )
906 std::set<std::string> histAtt;
907 node->GetAttributeNames( histAtt );
908 std::set<std::string> defined;
909 std::string regID(
"");
910 std::string algID(
"");
911 std::set<std::string>::const_iterator histAttEnd = histAtt.end();
912 for( std::set<std::string>::const_iterator
h = histAtt.begin();
h != histAttEnd; ++
h ) {
913 const MiniConfigTreeNode* histNode =
node->GetDaughter( *
h );
917 algID = histNode->GetAttribute(
"algorithm");
918 regID = histNode->GetAttribute(
"output");
921 std::cerr <<
"No \"algorithm\" defined for " << histNode->GetPathName() <<
"\n";
928 std::string strNodeName(histNode->GetName());
929 std::string strHistName, strFullHistName;
930 std::string::size_type atsign = strNodeName.find(
'@');
931 if (atsign == std::string::npos) {
932 strHistName = strNodeName;
933 strFullHistName = histNode->GetPathName();
935 strHistName = strNodeName.substr(0, atsign);
936 strFullHistName = histNode->GetPathName();
937 strFullHistName.resize(strFullHistName.find(
'@'));
940 if( strHistName ==
"all_in_dir" )
943 if( defined.find(histNode->GetPathName()) != defined.end() )
946 HanConfigAssessor
dqpar;
947 dqpar.SetName( histNode->GetPathName() );
949 dqpar.SetIsRegex(TestMiniNodeIsRegex(histNode));
951 if (histNode->GetAttribute(
"weight") !=
"") {
952 std::ostringstream
err;
953 err <<
"Weight attribute not a floating point type for " << histNode->GetPathName() <<
"; setting to zero";
954 dqpar.SetWeight(AttribToFloat(histNode,
"weight",
958 GetAlgorithmConfiguration( &
dqpar, algID, strFullHistName );
960 std::set<std::string> histAtt2;
961 histNode->GetAttributeNames( histAtt2 );
962 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
963 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
964 if (
node->GetDaughter( *h2 )
965 || *h2 ==
"algorithm" || *h2 ==
"output" || *h2 ==
"reference"
966 || *h2 ==
"weight" || *h2 ==
"regex") {
969 HanConfigParMap parMap;
970 parMap.SetName(*h2); parMap.SetValue(histNode->GetAttribute(*h2));
971 dqpar.AddAnnotation(parMap);
975 HanConfigParMap parMap;
976 parMap.SetName(
"inputname"); parMap.SetValue( strFullHistName );
977 dqpar.AddAnnotation(parMap);
979 HanConfigGroup* dqreg = m_root->GetNode( regID );
980 dqreg = (dqreg==0) ? m_root : dqreg;
982 dqreg->AddAssessor(
dqpar );
984 defined.insert( strFullHistName );
987 for( std::set<std::string>::const_iterator
h = histAtt.begin();
h != histAttEnd; ++
h ) {
988 const MiniConfigTreeNode* histNode =
node->GetDaughter( *
h );
992 algID = histNode->GetAttribute(
"algorithm");
993 regID = histNode->GetAttribute(
"output");
996 std::cerr <<
"No \"algorithm\" defined for " << histNode->GetPathName() <<
"\n";
1001 regID =
"top_level";
1003 std::string strNodeName(histNode->GetName());
1004 std::string strHistName, strFullHistName, extension;
1005 std::string::size_type atsign = strNodeName.find(
'@');
1006 if (atsign == std::string::npos) {
1007 strHistName = strNodeName;
1008 strFullHistName = histNode->GetPathName();
1011 strHistName = strNodeName.substr(0, atsign);
1012 extension = strNodeName.substr(atsign, std::string::npos);
1013 strFullHistName = histNode->GetPathName();
1014 strFullHistName.resize(strFullHistName.find(
'@'));
1017 if( strHistName ==
"all_in_dir" ) {
1019 std::string regexflag(histNode->GetAttribute(
"regex"));
1020 if (histNode->GetAttribute(
"regex") !=
"") {
1021 std::cerr <<
"WARNING: all_in_dir and regex are incompatible; ignoring regex flag for " << histNode->GetPathName()
1022 <<
"/all_in_dir" << std::endl;
1025 std::string refID( histNode->GetAttribute(
"reference") );
1027 std::cerr <<
"WARNING: No \"reference\" defined for " << histNode->GetPathName() <<
"\n";
1030 std::string refFile( m_refConfig.GetStringAttribute(refID,
"file") );
1031 if( refFile ==
"" ) {
1032 std::cerr <<
"WARNING: No \"file\" defined for " << histNode->GetPathName() <<
"\n";
1036 std::string
refPath( m_refConfig.GetStringAttribute(refID,
"path") );
1038 std::string objPath(
"");
1039 std::string absObjPath(
"");
1041 refFile = SplitReference( m_refConfig.GetStringAttribute(refID,
"location"), refFile);
1042 std::shared_ptr<TFile>
infile( GetROOTFile(refFile) );
1043 TDirectory* basedir(0);
1051 std::string refPathForSearch =
refPath;
1052 refPathForSearch +=
"/dummyName";
1054 if( basedir == 0 ) {
1055 std::cerr <<
"INFO: Cannot find path \"" <<
refPath <<
"\" in reference file\n";
1063 std::string allPathName( histNode->GetPathName() );
1064 std::string::size_type
i = allPathName.find_last_of(
'/');
1065 if(
i != std::string::npos ) {
1066 objPath = std::string( allPathName, 0,
i );
1068 absObjPath += std::string( allPathName, 0,
i );
1074 std::cerr <<
"INFO: Cannot find path \"" << absObjPath <<
"\" in reference file\n";
1078 TIter
next(
dir->GetListOfKeys() );
1079 std::string objName;
1080 std::string absObjName;
1083 std::set<std::string> localdefined;
1084 while( (
key =
dynamic_cast<TKey*
>(
next())) != 0 ) {
1085 TObject* tmpobj =
key->ReadObj();
1086 TH1* tmph =
dynamic_cast<TH1*
>(tmpobj);
1087 TGraph* tmpg =
dynamic_cast<TGraph*
>(tmpobj);
1088 TEfficiency* tmpe =
dynamic_cast<TEfficiency*
>(tmpobj);
1089 if( tmph == 0 && tmpg == 0 && tmpe == 0 )
1093 objName += std::string( tmpobj->GetName() );
1094 absObjName = absObjPath;
1095 absObjName += std::string( tmpobj->GetName() );
1098 if( defined.find(objName) != defined.end() ||
1099 localdefined.find(objName) != localdefined.end() )
1106 HanConfigAssessor
dqpar;
1107 dqpar.SetName( objName + extension );
1108 GetAlgorithmConfiguration( &
dqpar, algID, objName );
1110 if (histNode->GetAttribute(
"weight") !=
"") {
1111 std::ostringstream
err;
1112 err <<
"Weight attribute not a floating point type for " << objName <<
"; setting to zero";
1113 dqpar.SetWeight(AttribToFloat(histNode,
"weight",
1117 std::set<std::string> histAtt2;
1118 histNode->GetAttributeNames( histAtt2 );
1119 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
1120 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
1121 if (
node->GetDaughter( *h2 )
1122 || *h2 ==
"algorithm" || *h2 ==
"output" || *h2 ==
"reference"
1123 || *h2 ==
"weight" || *h2 ==
"regex") {
1126 HanConfigParMap parMap;
1127 parMap.SetName(*h2); parMap.SetValue(histNode->GetAttribute(*h2));
1128 dqpar.AddAnnotation(parMap);
1132 HanConfigParMap parMap;
1133 parMap.SetName(
"inputname"); parMap.SetValue( objName );
1134 dqpar.AddAnnotation(parMap);
1136 HanConfigGroup* dqreg = m_root->GetNode( regID );
1137 dqreg = (dqreg==0) ? m_root : dqreg;
1139 dqreg->AddAssessor(
dqpar );
1141 localdefined.insert( objName );
1158 boost::shared_ptr<dqm_core::Node>
1160 Visit(
const HanConfigAssessor*
node, boost::shared_ptr<dqm_core::Region> dqParent )
1162 const HanConfigGroup* gnode =
dynamic_cast<const HanConfigGroup*
>(
node );
1164 std::string algLibName(
node->GetAlgLibName() );
1165 if( algLibName !=
"" ) {
1169 catch ( dqm_core::Exception& ex ) {
1175 dqm_core::RegionConfig regc(
algName,
node->GetWeight() );
1176 std::string regName( gnode->GetPathName() );
1177 boost::shared_ptr<dqm_core::Region>
reg(dqParent->addRegion( regName, regc ));
1178 m_output->addListener(regName, dqParent.get());
1182 std::string inputData(
node->GetHistPath() );
1183 HanAlgorithmConfig* algConfig =
new HanAlgorithmConfig( *
node,
m_file );
1184 dqm_core::ParameterConfig parc( inputData,
algName,
node->GetWeight(),
1185 std::shared_ptr<HanAlgorithmConfig>(algConfig),
node->GetIsRegex() );
1186 boost::shared_ptr<dqm_core::Node>
par(dqParent->addParameter(
node->GetName(), parc ));
1187 m_output->addListener(
node->GetName(), dqParent.get());
1193 CompAlgVisitor(TFile* outfile_,
const MiniConfig& compAlgConfig_)
1194 : m_outfile(outfile_)
1195 , m_compAlgConfig(compAlgConfig_)
1205 std::map<std::string,MiniConfigTreeNode*> daughters =
node->GetDaughters();
1206 std::map<std::string,MiniConfigTreeNode*>::const_iterator nodeiterEnd = daughters.end();
1207 for( std::map<std::string,MiniConfigTreeNode*>::const_iterator iter = daughters.begin(); iter != nodeiterEnd; ++iter ) {
1208 std::string compAlgID = iter->second->GetName();
1209 std::string compAlgKey = iter->first;
1211 HanConfigCompAlg* compAlg =
new HanConfigCompAlg();
1212 std::set<std::string> compAlgAtt;
1213 m_compAlgConfig.GetAttributeNames(compAlgID, compAlgAtt);
1214 std::set<std::string>::const_iterator compAlgAttEnd = compAlgAtt.end();
1216 compAlg->SetName(compAlgID);
1217 for( std::set<std::string>::const_iterator
i = compAlgAtt.begin();
i != compAlgAttEnd; ++
i ) {
1218 if( *
i ==
"subalgs" ) {
1219 std::string subAlgs( m_compAlgConfig.GetStringAttribute(compAlgID,
"subalgs") );
1220 std::string::size_type
pos = subAlgs.find(
',');
1221 for(
int size=subAlgs.size(), sizeOld=-8;
1223 subAlgs.erase(0,
pos+1),
pos = subAlgs.find(
','),sizeOld=
size,
size=subAlgs.size()) {
1225 compAlg->AddAlg( subAlgs.substr(0,
pos));
1228 else if( *
i ==
"libnames" ) {
1229 std::string
libs( m_compAlgConfig.GetStringAttribute(compAlgID,
"libnames") );
1230 std::string::size_type
pos =
libs.find(
',');
1231 for(
int size=
libs.size(), sizeOld=-8;
1235 compAlg->AddLib(
libs.substr(0,
pos));
1245 : m_outfile(outfile_)
1246 , m_metadataConfig(metadataConfig_)
1256 if (m_outfile->Get(
"HanMetadata")) {
1257 m_outfile->cd(
"HanMetadata");
1260 TDirectory* mdir = m_outfile->mkdir(
"HanMetadata");
1269 std::map<std::string,MiniConfigTreeNode*> daughters =
node->GetDaughters();
1270 std::map<std::string,MiniConfigTreeNode*>::const_iterator nodeiterEnd = daughters.end();
1271 for( std::map<std::string,MiniConfigTreeNode*>::const_iterator iter = daughters.begin(); iter != nodeiterEnd; ++iter ) {
1272 std::string metadataID = iter->second->GetName();
1274 std::set<std::string> metadataAtt;
1275 m_metadataConfig.GetAttributeNames(metadataID, metadataAtt);
1276 HanConfigMetadata*
metadata =
new HanConfigMetadata();
1278 for (std::set<std::string>::const_iterator
i = metadataAtt.begin();
i != metadataAtt.end(); ++
i ) {
1279 HanConfigParMap parMap;
1280 parMap.SetName(*
i); parMap.SetValue(m_metadataConfig.GetStringAttribute(metadataID, *
i));
1302 m_config = TFile::Open( configName.c_str(),
"READ" );
1304 std::cerr <<
"HanConfig::Initialize() cannot open file \"" << configName <<
"\"\n";
1308 TMap* refsourcedata =
dynamic_cast<TMap*
>(
m_config->Get(
"refsourcedata"));
1309 if (refsourcedata) {
1312 std::cerr <<
"Can't retrieve reference source info" << std::endl;
1315 TIter nextKey(
m_config->GetListOfKeys() );
1316 TKey* compAlgKey(0);
1317 while( (compAlgKey =
dynamic_cast<TKey*
>( nextKey() )) != 0 ) {
1318 TObject*
obj = compAlgKey->ReadObj();
1319 HanConfigCompAlg* compAlg =
dynamic_cast<HanConfigCompAlg*
>(
obj );
1320 if( compAlg != 0 ) {
1322 new CompositeAlgorithm( *compAlg );
1332 TDirectory* mdDir =
dynamic_cast<TDirectory*
>(
key->ReadObj());
1334 TIter mdIter(mdDir->GetListOfKeys());
1336 while ((mdKey =
dynamic_cast<TKey*
>(mdIter()))) {
1337 HanConfigMetadata* md =
dynamic_cast<HanConfigMetadata*
>(mdKey->ReadObj());
1348 std::cerr <<
"HanConfig::Initialize() cannot find configuration in file \"" << configName <<
"\"\n";
1354 std::cerr <<
"HanConfig::Initialize() cannot find configuration in file \"" << configName <<
"\"\n";
1377 std::string::size_type
i =
path.find_first_of(
'/');
1378 if(
i != std::string::npos ) {
1379 std::string dName(
path, 0,
i );
1380 std::string pName(
path,
i+1, std::string::npos );
1382 TDirectory* subDir(0);
1383 key =
dir->FindKey( dName.c_str() );
1385 subDir =
dynamic_cast<TDirectory*
>(
key->ReadObj() );
1407 std::string::size_type
i =
path.find_last_of(
'/');
1408 if(
i != std::string::npos ) {
1409 std::string subPath(
path, 0,
i );
1410 DirMap_t::const_iterator j =
directories.find( subPath );
1412 TDirectory*
dir = j->second;
1417 std::string dirName;
1418 std::string::size_type
k = subPath.find_last_of(
'/');
1419 dirName = (
k != std::string::npos) ? std::string( subPath,
k+1, std::string::npos ) : subPath;
1420 TDirectory*
dir =
nullptr;
1421 if (!parDir->FindKey(dirName.c_str())) {
1422 dir = parDir->mkdir( dirName.c_str() );
1425 std::cout <<
"Failed to make directory " << dirName.c_str() << std::endl;
1427 DirMap_t::value_type dirVal( subPath,
dir );