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(
const std::string & infileName,
const std::string & outfileName,
const 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(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(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");
172 BuildMonitors( std::string configName, HanInputRootFile& input, HanOutput& output )
174 bool isInitialized =
Initialize( configName );
175 if( !isInitialized ) {
181 output.setConfig(
this );
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 ));
228 ConfigVisitor confvisitor(
m_config, &output );
238 bool isInitialized =
Initialize( configName );
239 if( !isInitialized ) {
247 TDirectory* basedir(0);
249 std::string pathForSearch =
path +
"/dummyName";
257 TSeqCollection* mdList =
newTList(
"HanMetadata_");
258 HanConfigMetadata* md(0);
259 while ((md =
dynamic_cast<HanConfigMetadata*
>(mdIter()))) {
260 mdList->Add( md->GetList(basedir,*outputMap) );
263 top_level_list->Add( mdList );
264 outputList->Add( top_level_list );
282 if (!
a.get())
return 0;
283 std::string refName(
a->GetAlgRefName() );
284 if( refName !=
"" ) {
288 TObject*
ref =
key->ReadObj();
298 SplitReference(std::string
refPath,
const std::string& refName )
301 static std::map<std::string, std::string> mappingCache;
304 std::vector<std::string> refFileDirList;
308 std::vector<std::string> refFileList;
309 for (
const auto&
dir : refFileDirList ) {
310 refFileList.push_back(boost::algorithm::trim_copy(
dir+refName));
316 const auto& cachehit = mappingCache.find(tfilestring);
317 if (cachehit != mappingCache.end()) {
318 return cachehit->second;
321 if (
const auto*
f = TFile::Open(tfilestring.c_str())) {
322 mappingCache[tfilestring] =
f->GetName();
324 std::cerr <<
"Unable to open any reference files in " << tfilestring <<
", reference will not be included" << std::endl;
325 mappingCache[tfilestring] =
"";
327 return mappingCache[tfilestring];
330 const HanConfigAssessor*
343 const HanConfigAssessor&
a =
parent->GetAssessor(
name);
345 return new HanConfigAssessor(
a);
352 RegexVisitor
rv(regexlist);
362 : m_outfile(outfile_)
363 , m_directories(directories_)
364 , m_refsourcedata(refsourcedata_)
374 std::string
name =
node->GetAttribute(
"name");
378 std::string refInfo =
node->GetAttribute(
"info");
380 std::cerr <<
"INFO: Reference " <<
name <<
" is defined without an \"info\" attribute. Consider adding one"
386 std::cerr <<
"WARNING: HanConfig::RefVisitor::Visit(): Reference not found: \"" <<
name <<
"\"\n";
399 obj->Write(newHistoName.c_str());
401 TObjString* fnameostr =
new TObjString(
fileName.c_str());
405 m_refsourcedata->Add(fnameostr->Clone(), refInfo !=
"" ?
new TObjString(refInfo.c_str())
406 :
new TObjString(
"Reference"));
412 RefWriter( DatabaseConfig& databaseConfig_,
const bool bulk)
413 : m_databaseConfig(databaseConfig_),
426 database += (m_bulk ?
"-physics-UPD4" :
"-express-UPD1");
430 if(jsonPayload.find(
reference) != jsonPayload.end()) {
433 node->SetAttribute(
it.key(),
it.value(),
false);
436 std::cerr <<
"Unable to find reference definition in database: " <<
reference <<
'\n';
443 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
445 TMap* refsourcedata_ )
447 , m_algConfig(algConfig_)
448 , m_thrConfig(thrConfig_)
449 , m_refConfig(refConfig_)
450 , m_outfile(outfile_)
451 , m_directories(directories_)
452 , m_refsourcedata(refsourcedata_)
456 std::shared_ptr<TFile>
460 auto it = m_filecache.find(
fname);
461 if (
it !=
end(m_filecache)) {
464 if (m_badPaths.find(
fname) != m_badPaths.end()) {
465 return std::shared_ptr<TFile>(
nullptr);
467 std::shared_ptr<TFile> thisptr(TFile::Open(
fname.c_str()));
469 return ( m_filecache[
fname] = std::move(thisptr) );
471 m_badPaths.insert(
fname);
487 DisableMustClean dmc;
490 if (m_keycache.find(
fname) != m_keycache.end()) {
493 m_keycache[
fname].reserve(100000);
499 float AttribToFloat(
const MiniConfigTreeNode*
node,
const std::string& attrib,
500 const std::string& warningString,
bool local=
false)
502 std::istringstream valstream;
504 valstream.str(
node->GetAttributeLocal(attrib));
506 valstream.str(
node->GetAttribute(attrib));
511 std::cerr << warningString << std::endl;
521 const std::string& assessorName )
524 std::set<std::string> algAtt;
525 m_algConfig.GetAttributeNames( algID, algAtt );
526 std::set<std::string>::const_iterator algAttEnd = algAtt.end();
527 for( std::set<std::string>::const_iterator
i = algAtt.begin();
i != algAttEnd; ++
i ) {
528 std::string trail(
"");
529 std::string::size_type
pos = (*i).find(
'|');
530 if (
pos != std::string::npos) {
531 trail = (*i).substr(
pos + 1, std::string::npos);
535 std::string
algName( m_algConfig.GetStringAttribute(algID,
"name") );
538 else if( *
i ==
"libname" ) {
539 std::string algLibName( m_algConfig.GetStringAttribute(algID,
"libname") );
540 dqpar->SetAlgLibName( std::move(algLibName) );
542 else if( *
i ==
"thresholds" || trail ==
"thresholds" ) {
543 std::string thrID( m_algConfig.GetStringAttribute(algID,*
i) );
544 std::set<std::string> thrAtt;
545 m_thrConfig.GetAttributeNames( thrID, thrAtt );
546 std::set<std::string>::const_iterator thrAttEnd = thrAtt.end();
547 for( std::set<std::string>::const_iterator
t = thrAtt.begin();
t != thrAttEnd; ++
t ) {
548 std::string thrAttName = *
t;
549 std::string thrAttVal = m_thrConfig.GetStringAttribute( thrID, thrAttName );
550 std::string limName = thrAttVal + std::string(
"/") + thrAttName;
551 HanConfigAlgLimit algLim;
552 if (
pos != std::string::npos) {
553 algLim.SetName( (*i).substr(0,
pos) + std::string(
"|") + *
t );
555 algLim.SetName( *
t );
557 algLim.SetGreen( m_thrConfig.GetFloatAttribute(limName,
"warning") );
558 algLim.SetRed( m_thrConfig.GetFloatAttribute(std::move(limName),
"error") );
559 dqpar->AddAlgLimit( algLim );
562 else if( *
i ==
"reference" ) {
566 std::string tmpRefID=m_algConfig.GetStringAttribute(algID,
"reference");
571 std::stringstream newRefString;
573 for(
size_t t=0;
t<condPairs.size();
t++){
574 bool refsuccess(
false);
575 std::string refID=condPairs.at(
t).second;
576 std::string cond=condPairs.at(
t).first;
577 std::vector<std::string> refIDVec;
579 std::vector<std::vector<std::pair<std::string, std::shared_ptr<TObject>>>>
objects;
580 std::string newRefId(
"");
581 bool isMultiRef(
false);
582 std::vector<std::string> sourceMatches;
583 if (refID[0] ==
'[') {
584 std::string cleanedRefID = refID;
585 boost::algorithm::trim_if(cleanedRefID, boost::is_any_of(
"[] "));
587 boost::split(refIDVec, cleanedRefID, boost::is_any_of(
","));
591 refIDVec.push_back(refID);
596 std::string algRefName( m_refConfig.GetStringAttribute(refID,
"name") );
597 std::string algRefInfo( m_refConfig.GetStringAttribute(refID,
"info") );
598 std::string algRefFile( m_refConfig.GetStringAttribute(refID,
"file") );
599 if (algRefName !=
"same_name" && !isMultiRef) {
602 if(newRefId.empty()){
603 std::string algRefPath( m_refConfig.GetStringAttribute(refID,
"path") );
604 std::cerr<<
"Warning New reference id is empty for refId=\""
605 <<refID<<
"\", cond=\""<<cond<<
"\", assessorName=\""
606 <<assessorName<<
"\", algRefName=\""
607 <<algRefName<<
"\""<<std::endl;
608 std::cerr <<
"AlgRefPath=" << algRefPath <<
" AlgRefInfo=" << algRefInfo << std::endl;
614 objects.resize(refIDVec.size());
615 std::string absAlgRefName, algRefPath, algRefInfo;
616 for (
size_t iRefID = 0; iRefID < refIDVec.size(); ++iRefID) {
617 const auto& thisRefID = refIDVec[iRefID];
618 algRefName = m_refConfig.GetStringAttribute(thisRefID,
"name");
619 algRefPath = m_refConfig.GetStringAttribute(thisRefID,
"path");
620 algRefInfo = m_refConfig.GetStringAttribute(thisRefID,
"info");
621 algRefFile = m_refConfig.GetStringAttribute(thisRefID,
"file");
622 if (algRefInfo ==
"") {
623 std::cerr <<
"INFO: Reference " << thisRefID <<
" is defined without an \"info\" attribute. Consider adding one"
627 if( algRefPath !=
"" ) {
628 absAlgRefName += algRefPath;
629 absAlgRefName +=
"/";
631 if( algRefName ==
"same_name" ) {
632 algRefName = assessorName;
633 absAlgRefName += algRefName;
634 algRefFile = SplitReference( m_refConfig.GetStringAttribute(thisRefID,
"location"), algRefFile);
636 if( algRefFile !=
"" ) {
637 std::shared_ptr<TFile>
infile = GetROOTFile(algRefFile);
639 std::cerr <<
"HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile <<
" not found" << std::endl;
642 std::vector<std::string> localMatches;
643 if (
dqpar->GetIsRegex()) {
644 if (! sourceMatches.empty()) {
645 std::cerr <<
"same_name appears twice in a reference request???" << std::endl;
648 std::string regexPattern = boost::regex_replace(absAlgRefName,
boost::regex(
"\\(\\?P=([^)]*)\\)"),
"\\\\k<\\1>", boost::format_all);
649 boost::regex re(boost::replace_all_copy(regexPattern,
"(?P",
"(?"));
650 EnsureKeyCache(algRefFile);
651 for (
const auto& iKey: m_keycache[algRefFile]) {
652 if (boost::regex_match(iKey,
re)) {
653 sourceMatches.push_back(iKey);
656 objects[iRefID].emplace_back(iKey,
key->ReadObj());
667 std::shared_ptr<TObject>
q(
key->ReadObj());
668 objects[iRefID].emplace_back(absAlgRefName,
q);
672 absAlgRefName += algRefName;
673 algRefFile = SplitReference( m_refConfig.GetStringAttribute(thisRefID,
"location"), algRefFile);
675 if( algRefFile !=
"" ) {
676 std::shared_ptr<TFile>
infile = GetROOTFile(algRefFile);
678 std::cerr <<
"HanConfig::AssessmentVistorBase::GetAlgorithmConfiguration: Reference file " << algRefFile <<
" not found" << std::endl;
685 std::cerr <<
"Couldn't find reference " << absAlgRefName << std::endl;
689 std::shared_ptr<TObject>
q(
key->ReadObj());
690 TNamed* qn =
dynamic_cast<TNamed*
>(
q.get());
691 if (isMultiRef && qn) {
692 std::string multirefname = thisRefID;
693 if (algRefInfo !=
"") {
694 multirefname = algRefInfo;
695 }
else if (algRefFile !=
"") {
696 multirefname = algRefFile;
698 qn->SetName(multirefname.c_str());
700 objects[iRefID].emplace_back(absAlgRefName,
q);
702 std::cerr <<
"No file specified for " << absAlgRefName <<
" ?" << std::endl;
707 std::shared_ptr<TObject> toWriteOut;
708 std::string algRefUniqueName;
709 std::string algRefSourceInfo = (algRefInfo !=
"" ? algRefInfo.c_str() :
"Reference");
715 TMap* tmapobj =
new TMap();
716 tmapobj->SetOwnerKeyValue();
717 for (
const auto& thisPair:
objects[0]) {
718 std::unique_ptr<TObject> cobj(thisPair.second->Clone());
719 TNamed* hobj =
dynamic_cast<TNamed*
>(cobj.get());
721 hobj->SetName(refID.c_str());
723 algRefUniqueName = algRefFile+
":/"+thisPair.first;
725 if(newRefId.empty()){
728 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
729 new TObjString(algRefFile.c_str()));
730 cobj->Write(newRefId.c_str(), 1);
733 std::string maprefstring(thisPair.first);
734 if (algRefPath !=
"") {
735 boost::replace_first(maprefstring, algRefPath +
"/",
"");
737 tmapobj->Add(
new TObjString(maprefstring.c_str()),
738 new TObjString(newRefId.c_str()));
740 toWriteOut.reset(tmapobj);
741 algRefUniqueName = algRefFile+
"_regex:/"+
dqpar->GetUniqueName();
744 algRefUniqueName = algRefFile+
":/"+absAlgRefName;
747 toWriteOut =
objects[0][0].second;
751 algRefUniqueName=cond+
"_multiple:/"+absAlgRefName;
752 algRefSourceInfo=
"Multiple references";
754 if (
dqpar->GetIsRegex()) {
757 TObjArray* toarray =
new TObjArray();
758 toarray->SetOwner(
true);
759 for (
size_t iRef = 0; iRef <
objects.size(); ++iRef) {
765 toWriteOut.reset(toarray);
770 if (refsuccess && toWriteOut) {
773 if(newRefId.empty()){
778 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
779 new TObjString(algRefFile.c_str()));
781 if (! m_refsourcedata->FindObject(algRefFile.c_str())) {
782 m_refsourcedata->Add(
new TObjString(algRefFile.c_str()),
783 new TObjString(algRefSourceInfo.c_str()));
787 m_refsourcedata->Add(
new TObjString(newRefId.c_str()),
788 new TObjString(algRefSourceInfo.c_str()));
792 toWriteOut->Write(newRefId.c_str(), 1);
796 if (!newRefId.empty()) {
798 newRefString<<cond<<
":"<<newRefId<<
";";
800 newRefString<<newRefId;
804 dqpar->SetAlgRefName((newRefString.str()));
807 std::string
stringValue = m_algConfig.GetStringAttribute( algID, *
i );
812 HanConfigParMap algPar;
813 algPar.SetName( *
i );
815 dqpar->AddAlgStrPar( algPar );
817 HanConfigAlgPar algPar;
818 algPar.SetName( *
i );
819 algPar.SetValue( numberValue );
820 dqpar->AddAlgPar( algPar );
828 RegionVisitor( HanConfigGroup* root_,
const MiniConfig& algConfig_,
829 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
831 : AssessmentVisitorBase( root_, algConfig_, thrConfig_, refConfig_, 0, directories_,
nullptr )
840 const MiniConfigTreeNode*
parent =
node->GetParent();
844 const MiniConfigTreeNode* grandparent =
parent->GetParent();
845 auto alloc = std::make_unique<HanConfigGroup>();
846 HanConfigGroup* reg = (grandparent==0) ? m_root : alloc.get();
850 reg->SetName(
node->GetName() );
851 reg->SetPathName(
node->GetPathName() );
853 std::string algID(
node->GetAttribute(
"algorithm") );
855 GetAlgorithmConfiguration( reg, algID );
857 std::cerr <<
"Warning: no summary algorithm specified for " <<
node->GetPathName() << std::endl
858 <<
"This is probably not what you want" << std::endl;
861 if (
node->GetAttributeLocal(
"weight") !=
"") {
862 std::ostringstream
err;
863 err <<
"Weight is not a floating point attribute for " <<
node->GetPathName() <<
"; setting to 0";
864 reg->SetWeight(AttribToFloat(
node,
"weight",
err.str(),
true));
867 if( grandparent != 0 ) {
869 HanConfigGroup* parentReg = m_root->GetNode(
path );
870 parentReg = (parentReg==0) ? m_root : parentReg;
871 if( parentReg != 0 ) {
872 parentReg->AddGroup( *reg );
879 : m_regexes(regexes_)
883 boost::shared_ptr<dqm_core::Node>
885 Visit(
const HanConfigAssessor*
node, boost::shared_ptr<dqm_core::Region> )
888 if (
dynamic_cast<const HanConfigGroup*
>(
node) != NULL) {
889 return boost::shared_ptr<dqm_core::Parameter>();
891 if (
node->GetIsRegex()) {
892 m_regexes.insert(
node->GetName());
894 return boost::shared_ptr<dqm_core::Parameter>();
899 const MiniConfig& thrConfig_,
const MiniConfig& refConfig_,
901 TMap* refsourcedata_ )
902 : AssessmentVisitorBase( root_, algConfig_, thrConfig_, refConfig_, outfile_, directories_, refsourcedata_ )
910 std::set<std::string> histAtt;
911 node->GetAttributeNames( histAtt );
912 std::set<std::string> defined;
913 std::string regID(
"");
914 std::string algID(
"");
915 std::set<std::string>::const_iterator histAttEnd = histAtt.end();
916 for( std::set<std::string>::const_iterator
h = histAtt.begin();
h != histAttEnd; ++
h ) {
917 const MiniConfigTreeNode* histNode =
node->GetDaughter( *
h );
921 algID = histNode->GetAttribute(
"algorithm");
922 regID = histNode->GetAttribute(
"output");
925 std::cerr <<
"No \"algorithm\" defined for " << histNode->GetPathName() <<
"\n";
932 std::string strNodeName(histNode->GetName());
933 std::string strHistName, strFullHistName;
934 std::string::size_type atsign = strNodeName.find(
'@');
935 if (atsign == std::string::npos) {
936 strHistName = std::move(strNodeName);
937 strFullHistName = histNode->GetPathName();
939 strHistName = strNodeName.substr(0, atsign);
940 strFullHistName = histNode->GetPathName();
941 strFullHistName.resize(strFullHistName.find(
'@'));
944 if( strHistName ==
"all_in_dir" )
947 if( defined.find(histNode->GetPathName()) != defined.end() )
950 HanConfigAssessor
dqpar;
951 dqpar.SetName( histNode->GetPathName() );
953 dqpar.SetIsRegex(TestMiniNodeIsRegex(histNode));
955 if (histNode->GetAttribute(
"weight") !=
"") {
956 std::ostringstream
err;
957 err <<
"Weight attribute not a floating point type for " << histNode->GetPathName() <<
"; setting to zero";
958 dqpar.SetWeight(AttribToFloat(histNode,
"weight",
962 GetAlgorithmConfiguration( &
dqpar, algID, strFullHistName );
964 std::set<std::string> histAtt2;
965 histNode->GetAttributeNames( histAtt2 );
966 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
967 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
968 if (
node->GetDaughter( *h2 )
969 || *h2 ==
"algorithm" || *h2 ==
"output" || *h2 ==
"reference"
970 || *h2 ==
"weight" || *h2 ==
"regex") {
973 HanConfigParMap parMap;
974 parMap.SetName(*h2); parMap.SetValue(histNode->GetAttribute(*h2));
975 dqpar.AddAnnotation(parMap);
979 HanConfigParMap parMap;
980 parMap.SetName(
"inputname"); parMap.SetValue( strFullHistName );
981 dqpar.AddAnnotation(parMap);
983 HanConfigGroup* dqreg = m_root->GetNode( regID );
984 dqreg = (dqreg==0) ? m_root : dqreg;
986 dqreg->AddAssessor(
dqpar );
988 defined.insert( strFullHistName );
991 for( std::set<std::string>::const_iterator
h = histAtt.begin();
h != histAttEnd; ++
h ) {
992 const MiniConfigTreeNode* histNode =
node->GetDaughter( *
h );
996 algID = histNode->GetAttribute(
"algorithm");
997 regID = histNode->GetAttribute(
"output");
1000 std::cerr <<
"No \"algorithm\" defined for " << histNode->GetPathName() <<
"\n";
1005 regID =
"top_level";
1007 std::string strNodeName(histNode->GetName());
1008 std::string strHistName, strFullHistName, extension;
1009 std::string::size_type atsign = strNodeName.find(
'@');
1010 if (atsign == std::string::npos) {
1011 strHistName = std::move(strNodeName);
1012 strFullHistName = histNode->GetPathName();
1015 strHistName = strNodeName.substr(0, atsign);
1016 extension = strNodeName.substr(atsign, std::string::npos);
1017 strFullHistName = histNode->GetPathName();
1018 strFullHistName.resize(strFullHistName.find(
'@'));
1021 if( strHistName ==
"all_in_dir" ) {
1023 std::string regexflag(histNode->GetAttribute(
"regex"));
1024 if (histNode->GetAttribute(
"regex") !=
"") {
1025 std::cerr <<
"WARNING: all_in_dir and regex are incompatible; ignoring regex flag for " << histNode->GetPathName()
1026 <<
"/all_in_dir" << std::endl;
1029 std::string refID( histNode->GetAttribute(
"reference") );
1031 std::cerr <<
"WARNING: No \"reference\" defined for " << histNode->GetPathName() <<
"\n";
1034 std::string refFile( m_refConfig.GetStringAttribute(refID,
"file") );
1035 if( refFile ==
"" ) {
1036 std::cerr <<
"WARNING: No \"file\" defined for " << histNode->GetPathName() <<
"\n";
1040 std::string
refPath( m_refConfig.GetStringAttribute(refID,
"path") );
1042 std::string objPath(
"");
1043 std::string absObjPath(
"");
1045 refFile = SplitReference( m_refConfig.GetStringAttribute(std::move(refID),
"location"), refFile);
1046 std::shared_ptr<TFile>
infile( GetROOTFile(refFile) );
1047 TDirectory* basedir(0);
1055 std::string refPathForSearch =
refPath;
1056 refPathForSearch +=
"/dummyName";
1058 if( basedir == 0 ) {
1059 std::cerr <<
"INFO: Cannot find path \"" <<
refPath <<
"\" in reference file\n";
1067 std::string allPathName( histNode->GetPathName() );
1068 std::string::size_type
i = allPathName.find_last_of(
'/');
1069 if(
i != std::string::npos ) {
1070 objPath = std::string( allPathName, 0,
i );
1072 absObjPath += std::string( allPathName, 0,
i );
1078 std::cerr <<
"INFO: Cannot find path \"" << absObjPath <<
"\" in reference file\n";
1082 TIter
next(
dir->GetListOfKeys() );
1083 std::string objName;
1084 std::string absObjName;
1087 std::set<std::string> localdefined;
1088 while( (
key =
dynamic_cast<TKey*
>(
next())) != 0 ) {
1089 TObject* tmpobj =
key->ReadObj();
1090 TH1* tmph =
dynamic_cast<TH1*
>(tmpobj);
1091 TGraph* tmpg =
dynamic_cast<TGraph*
>(tmpobj);
1092 TEfficiency* tmpe =
dynamic_cast<TEfficiency*
>(tmpobj);
1093 if( tmph == 0 && tmpg == 0 && tmpe == 0 )
1097 objName += std::string( tmpobj->GetName() );
1098 absObjName = absObjPath;
1099 absObjName += std::string( tmpobj->GetName() );
1102 if( defined.find(objName) != defined.end() ||
1103 localdefined.find(objName) != localdefined.end() )
1110 HanConfigAssessor
dqpar;
1111 dqpar.SetName( objName + extension );
1112 GetAlgorithmConfiguration( &
dqpar, algID, objName );
1114 if (histNode->GetAttribute(
"weight") !=
"") {
1115 std::ostringstream
err;
1116 err <<
"Weight attribute not a floating point type for " << objName <<
"; setting to zero";
1117 dqpar.SetWeight(AttribToFloat(histNode,
"weight",
1121 std::set<std::string> histAtt2;
1122 histNode->GetAttributeNames( histAtt2 );
1123 std::set<std::string>::const_iterator histAttEnd2 = histAtt2.end();
1124 for( std::set<std::string>::const_iterator h2 = histAtt2.begin(); h2 != histAttEnd2; ++h2 ) {
1125 if (
node->GetDaughter( *h2 )
1126 || *h2 ==
"algorithm" || *h2 ==
"output" || *h2 ==
"reference"
1127 || *h2 ==
"weight" || *h2 ==
"regex") {
1130 HanConfigParMap parMap;
1131 parMap.SetName(*h2); parMap.SetValue(histNode->GetAttribute(*h2));
1132 dqpar.AddAnnotation(parMap);
1136 HanConfigParMap parMap;
1137 parMap.SetName(
"inputname"); parMap.SetValue( objName );
1138 dqpar.AddAnnotation(parMap);
1140 HanConfigGroup* dqreg = m_root->GetNode( regID );
1141 dqreg = (dqreg==0) ? m_root : dqreg;
1143 dqreg->AddAssessor(
dqpar );
1145 localdefined.insert( objName );
1162 boost::shared_ptr<dqm_core::Node>
1164 Visit(
const HanConfigAssessor*
node, boost::shared_ptr<dqm_core::Region> dqParent )
1166 const HanConfigGroup* gnode =
dynamic_cast<const HanConfigGroup*
>(
node );
1168 std::string algLibName(
node->GetAlgLibName() );
1169 if( algLibName !=
"" ) {
1173 catch ( dqm_core::Exception& ex ) {
1179 dqm_core::RegionConfig regc(
algName,
node->GetWeight() );
1180 std::string regName( gnode->GetPathName() );
1181 boost::shared_ptr<dqm_core::Region> reg(dqParent->addRegion( regName, regc ));
1182 m_output->addListener(regName, dqParent.get());
1186 std::string inputData(
node->GetHistPath() );
1187 HanAlgorithmConfig* algConfig =
new HanAlgorithmConfig( *
node,
m_file );
1188 dqm_core::ParameterConfig parc( inputData,
algName,
node->GetWeight(),
1189 std::shared_ptr<HanAlgorithmConfig>(algConfig),
node->GetIsRegex() );
1190 boost::shared_ptr<dqm_core::Node>
par(dqParent->addParameter(
node->GetName(), parc ));
1191 m_output->addListener(
node->GetName(), dqParent.get());
1197 CompAlgVisitor(TFile* outfile_,
const MiniConfig& compAlgConfig_)
1198 : m_outfile(outfile_)
1199 , m_compAlgConfig(compAlgConfig_)
1209 std::map<std::string,MiniConfigTreeNode*> daughters =
node->GetDaughters();
1210 std::map<std::string,MiniConfigTreeNode*>::const_iterator nodeiterEnd = daughters.end();
1211 for( std::map<std::string,MiniConfigTreeNode*>::const_iterator iter = daughters.begin(); iter != nodeiterEnd; ++iter ) {
1212 std::string compAlgID = iter->second->GetName();
1213 std::string compAlgKey = iter->first;
1215 HanConfigCompAlg* compAlg =
new HanConfigCompAlg();
1216 std::set<std::string> compAlgAtt;
1217 m_compAlgConfig.GetAttributeNames(compAlgID, compAlgAtt);
1218 std::set<std::string>::const_iterator compAlgAttEnd = compAlgAtt.end();
1220 compAlg->SetName(compAlgID);
1221 for( std::set<std::string>::const_iterator
i = compAlgAtt.begin();
i != compAlgAttEnd; ++
i ) {
1222 if( *
i ==
"subalgs" ) {
1223 std::string subAlgs( m_compAlgConfig.GetStringAttribute(compAlgID,
"subalgs") );
1224 std::string::size_type
pos = subAlgs.find(
',');
1225 for(
int size=subAlgs.size(), sizeOld=-8;
1227 subAlgs.erase(0,
pos+1),
pos = subAlgs.find(
','),sizeOld=
size,
size=subAlgs.size()) {
1229 compAlg->AddAlg( subAlgs.substr(0,
pos));
1232 else if( *
i ==
"libnames" ) {
1233 std::string
libs( m_compAlgConfig.GetStringAttribute(compAlgID,
"libnames") );
1234 std::string::size_type
pos =
libs.find(
',');
1235 for(
int size=
libs.size(), sizeOld=-8;
1239 compAlg->AddLib(
libs.substr(0,
pos));
1249 : m_outfile(outfile_)
1250 , m_metadataConfig(metadataConfig_)
1260 if (m_outfile->Get(
"HanMetadata")) {
1261 m_outfile->cd(
"HanMetadata");
1264 TDirectory* mdir = m_outfile->mkdir(
"HanMetadata");
1273 std::map<std::string,MiniConfigTreeNode*> daughters =
node->GetDaughters();
1274 std::map<std::string,MiniConfigTreeNode*>::const_iterator nodeiterEnd = daughters.end();
1275 for( std::map<std::string,MiniConfigTreeNode*>::const_iterator iter = daughters.begin(); iter != nodeiterEnd; ++iter ) {
1276 std::string metadataID = iter->second->GetName();
1278 std::set<std::string> metadataAtt;
1279 m_metadataConfig.GetAttributeNames(metadataID, metadataAtt);
1280 HanConfigMetadata*
metadata =
new HanConfigMetadata();
1282 for (std::set<std::string>::const_iterator
i = metadataAtt.begin();
i != metadataAtt.end(); ++
i ) {
1283 HanConfigParMap parMap;
1284 parMap.SetName(*
i); parMap.SetValue(m_metadataConfig.GetStringAttribute(metadataID, *
i));
1306 m_config = TFile::Open( configName.c_str(),
"READ" );
1308 std::cerr <<
"HanConfig::Initialize() cannot open file \"" << configName <<
"\"\n";
1312 TMap* refsourcedata =
dynamic_cast<TMap*
>(
m_config->Get(
"refsourcedata"));
1313 if (refsourcedata) {
1316 std::cerr <<
"Can't retrieve reference source info" << std::endl;
1319 TIter nextKey(
m_config->GetListOfKeys() );
1320 TKey* compAlgKey(0);
1321 while( (compAlgKey =
dynamic_cast<TKey*
>( nextKey() )) != 0 ) {
1322 TObject*
obj = compAlgKey->ReadObj();
1323 HanConfigCompAlg* compAlg =
dynamic_cast<HanConfigCompAlg*
>(
obj );
1324 if( compAlg != 0 ) {
1326 new CompositeAlgorithm( *compAlg );
1336 TDirectory* mdDir =
dynamic_cast<TDirectory*
>(
key->ReadObj());
1338 TIter mdIter(mdDir->GetListOfKeys());
1340 while ((mdKey =
dynamic_cast<TKey*
>(mdIter()))) {
1341 HanConfigMetadata* md =
dynamic_cast<HanConfigMetadata*
>(mdKey->ReadObj());
1352 std::cerr <<
"HanConfig::Initialize() cannot find configuration in file \"" << configName <<
"\"\n";
1358 std::cerr <<
"HanConfig::Initialize() cannot find configuration in file \"" << configName <<
"\"\n";
1381 std::string::size_type
i =
path.find_first_of(
'/');
1382 if(
i != std::string::npos ) {
1383 std::string dName(
path, 0,
i );
1384 std::string pName(
path,
i+1, std::string::npos );
1386 TDirectory* subDir(0);
1387 key =
dir->FindKey( dName.c_str() );
1389 subDir =
dynamic_cast<TDirectory*
>(
key->ReadObj() );
1411 std::string::size_type
i =
path.find_last_of(
'/');
1412 if(
i != std::string::npos ) {
1413 std::string subPath(
path, 0,
i );
1414 DirMap_t::const_iterator j =
directories.find( subPath );
1416 TDirectory*
dir = j->second;
1422 std::string::size_type
k = subPath.find_last_of(
'/');
1423 dirName = (
k != std::string::npos) ? std::string( subPath,
k+1, std::string::npos ) : subPath;
1424 TDirectory*
dir =
nullptr;
1425 if (!parDir->FindKey(
dirName.c_str())) {
1429 std::cout <<
"Failed to make directory " <<
dirName.c_str() << std::endl;
1431 DirMap_t::value_type dirVal( subPath,
dir );