7 #include <TDirectory.h>
8 #include <TEfficiency.h>
15 #include <TObjArray.h>
16 #include <TObjString.h>
21 #include <boost/algorithm/string.hpp>
29 #include "dqm_core/OutputListener.h"
30 #include "dqm_core/Parameter.h"
31 #include "dqm_core/Region.h"
32 #include "dqm_core/Result.h"
33 #include "dqm_core/exceptions.h"
49 if (TH1*
h =
dynamic_cast<TH1*
>(
obj))
51 h->SetName(
name.c_str());
54 else if (TObjArray*
a =
dynamic_cast<TObjArray*
>(
obj))
56 a->SetName(
name.c_str());
59 else if (TGraph*
g =
dynamic_cast<TGraph*
>(
obj))
61 g->SetName(
name.c_str());
64 else if (TEfficiency*
e =
dynamic_cast<TEfficiency*
>(
obj))
66 e->SetName(
name.c_str());
71 TClass*
kl =
obj->IsA();
72 TMethod* klm =
kl->GetMethod(
"SetName",
"\"Reference\"");
75 std::cerr <<
"Error: attempt to change object name to " <<
name <<
" failed as its name is not settable"
80 std::cout <<
"Manually doing cast for " <<
name <<
" of class " <<
kl->GetName() << std::endl;
81 obj->Execute(
"SetName", (
"\"" +
name +
"\"").c_str());
96 : m_fileName(rootFileName),
97 m_file(TFile::Open(rootFileName.c_str(),
"RECREATE")),
98 m_retainUnpubData(false),
106 std::cerr <<
"File not writable: " << rootFileName <<
"\n";
112 DQResultMap_t::const_iterator rend =
m_dqResults.end();
113 for (DQResultMap_t::const_iterator
i =
m_dqResults.begin();
i != rend; ++
i)
124 if (region == 0)
return;
129 if (
i->second != region)
131 std::cerr <<
"Attempt to add " <<
name <<
" twice; ignoring" << std::endl;
139 DQParMap_t::value_type dqParVal(
name, region);
142 DQRegMap_t::value_type dqRegVal(region,
name);
171 dqm_core::OutputListener* plistener =
parent;
181 DQParSet_t::const_iterator regexEnd =
m_regexlist.end();
184 TSeqCollection* resultList = (*m_outputMap)[*
regex];
187 std::cerr <<
"Can't find original list for regex???" << std::endl;
191 tmpRegex.insert(DQOutputMap_t::value_type(*
regex, resultList));
192 (*m_outputMap).erase(*
regex);
200 dynamic_cast<TSeqCollection*
>((*m_outputMap)[
parentName])->Remove(resultList);
206 DQResultMap_t::const_iterator rEnd =
m_dqResults.end();
207 for (DQResultMap_t::const_iterator
r =
m_dqResults.begin();
r != rEnd; ++
r)
209 const std::string
name(
r->first);
222 TSeqCollection* resultList = (*m_outputMap)[
name];
224 std::string storename(
name);
226 if (resultList == NULL)
229 bool isRegex =
false;
233 std::string::size_type regexlen =
regex->length();
234 if (*
regex +
"_" ==
name.substr(0, regexlen + 1))
238 std::string::size_type atsign =
regex->rfind(
'@');
239 if (atsign != std::string::npos)
241 extra =
regex->substr(atsign, std::string::npos);
243 storename =
name.substr(regexlen + 1, std::string::npos);
251 std::cerr <<
"WARNING: setInput() has not been set; cannot publish regex results" << std::endl;
254 resultList =
dynamic_cast<TSeqCollection*
>(tmpRegex[
parname]->Clone());
255 (*m_outputMap)[storename +
extra] = resultList;
258 bool use_full_name =
false;
264 std::string store_using_path;
268 store_using_path.assign(hcpm->
GetValue());
270 boost::algorithm::to_lower(store_using_path);
271 if (store_using_path ==
"1" || store_using_path ==
"yes" || store_using_path ==
"true")
273 use_full_name =
true;
279 resultList->SetName((boost::algorithm::replace_all_copy(storename,
"/",
"_") +
extra +
"_").c_str());
283 resultList->SetName((storename +
extra +
"_").c_str());
285 dynamic_cast<TSeqCollection*
>((*m_outputMap)[
parentName])->Add(resultList);
291 (strncmp(
className,
"TProfile", 8) == 0) || (strncmp(
className,
"TEfficiency", 11) == 0))
293 TNamed* transobj =
dynamic_cast<TNamed*
>(
key->ReadObj());
294 if (transobj != NULL)
299 hhl->SetName((boost::algorithm::replace_all_copy(storename,
"/",
"_") +
extra).c_str());
303 hhl->SetName((std::string(transobj->GetName()) +
extra).c_str());
307 resultList->Add(hhl);
311 std::cerr <<
"TNamed* cast failed for " << storename << std::endl;
317 std::cout <<
"key is NULL" << std::endl;
322 std::cerr <<
"WARNING: Unable to find mapping for " <<
name << std::endl;
330 resultList =
dynamic_cast<TSeqCollection*
>(resultList->FindObject(
"Results"));
333 if (resultList ==
nullptr)
335 std::cerr <<
"Warning: no result list found associated with '" <<
name <<
"'\n";
340 resultList->Add(
newTObjArray(
"Status",
new TObjString(StatusToStr(
result.status_).c_str()), 1));
343 std::map<std::string, double>::const_iterator iter =
result.tags_.begin();
344 for (; iter !=
result.tags_.end(); ++iter)
346 std::ostringstream tagval;
347 tagval << std::setprecision(4) << iter->second;
348 resultList->Add(
newTObjArray(iter->first.c_str(),
new TObjString(tagval.str().c_str()), 1));
352 TObject* resultobj =
result.getObject();
355 TObject* resultobjclone = resultobj->Clone();
358 resultList->Add(resultobjclone);
362 std::cerr <<
"Discarding result object " <<
result.getObject()->GetName() << std::endl;
363 delete resultobjclone;
374 resultList->Add(
ref);
378 std::cerr <<
"Discarding reference object " <<
ref->GetName() << std::endl;
389 static bool include_hist(TObject*
obj) {
392 if ((strncmp(
obj->ClassName(),
"TH", 2) == 0) || (strncmp(
obj->ClassName(),
"TGraph", 6) == 0) ||
393 (strncmp(
obj->ClassName(),
"TProfile", 8) == 0) || (strncmp(
obj->ClassName(),
"TEfficiency", 11) == 0))
398 TSeqCollection* tmpList{};
399 tmpList =
dynamic_cast<TSeqCollection*
>(
obj);
402 TIter nextElem(tmpList);
404 while ((tmpobj = nextElem()) != 0)
406 result = include_hist(tmpobj);
416 static void WriteListToDirectory(
417 TDirectory*
dir, TSeqCollection*
list, TFile*
file,
int level,
int HanOutput_FileVersion)
419 TIter nextElem(
list);
421 TSeqCollection* tmpList{};
423 while ((
obj = nextElem()) != 0)
425 bool delete_when_done =
false;
426 HanHistogramLink* hhl =
dynamic_cast<HanHistogramLink*
>(
obj);
429 obj = hhl->getObject();
431 delete_when_done =
true;
434 std::cerr <<
"HanOutput.cxx, WriteListToDirectory : setNameGeneral failed\n";
439 if (strncmp(
obj->GetName(),
"Reference", 9) == 0 || strncmp(
obj->GetName(),
"ResultObject", 12) == 0)
442 if (delete_when_done)
delete obj;
445 tmpList =
dynamic_cast<TSeqCollection*
>(
obj);
449 std::vector<std::string>
dirs;
454 if (
dirs.back().empty())
dirs.pop_back();
458 if (HanOutput_FileVersion == 2)
460 TString listname = tmpList->GetName();
461 if (listname ==
"Config" || listname ==
"Results")
465 TIter nextElemConfRes(tmpList);
466 TObject* objInResultConfig;
467 while ((objInResultConfig = nextElemConfRes()) != 0)
469 if (include_hist(objInResultConfig))
472 TSeqCollection* tmpList_ResConf{};
473 tmpList_ResConf =
dynamic_cast<TSeqCollection*
>(objInResultConfig);
474 if ((tmpList_ResConf != 0) && (strncmp(tmpList_ResConf->GetName(),
"TObjArray", 9) == 0))
477 TIter nextEleminTObjArray(tmpList_ResConf);
478 TObject* objInTObjArray;
479 while ((objInTObjArray = nextEleminTObjArray()) != 0){
480 dir->WriteTObject(objInTObjArray);
482 tmpList->Remove(objInResultConfig);
486 dir->WriteTObject(objInResultConfig);
491 nlohmann::ordered_json j =
to_JSON(tmpList);
494 std::string
string = j.dump(4);
496 char* cstr =
new char[
string.length() + 1];
497 std::strcpy(cstr,
string.c_str());
499 TObjString string_to_tfile;
500 string_to_tfile.SetString(cstr);
502 string_to_tfile.Write(listname);
508 TDirectory* daughter;
509 if (!
dir->FindKey(
str.c_str()))
511 daughter =
dir->mkdir(
str.c_str());
515 std::cout <<
"Failed to make " <<
str <<
" from " << tmpList->GetName() << std::endl;
518 WriteListToDirectory(daughter, tmpList,
file,
level - 1, HanOutput_FileVersion);
525 else if ((strncmp(
obj->ClassName(),
"TH", 2) == 0) || (strncmp(
obj->ClassName(),
"TGraph", 6) == 0) ||
526 (strncmp(
obj->ClassName(),
"TProfile", 8) == 0) || (strncmp(
obj->ClassName(),
"TEfficiency", 11) == 0))
528 dir->GetMotherDir()->WriteTObject(
obj);
535 if (delete_when_done)
delete obj;
539 nlohmann::ordered_json
to_JSON(TSeqCollection* tseq)
541 using json = nlohmann::ordered_json;
544 TIter nextElem(tseq);
546 while ((
obj = nextElem()) != 0)
550 if ((strncmp(
obj->ClassName(),
"TH", 2) == 0) || (strncmp(
obj->ClassName(),
"TGraph", 6) == 0) ||
551 (strncmp(
obj->ClassName(),
"TProfile", 8) == 0) || (strncmp(
obj->ClassName(),
"TEfficiency", 11) == 0) ||
552 (strncmp(
obj->GetName(),
"Reference", 9) == 0))
557 TSeqCollection* tmpList =
dynamic_cast<TSeqCollection*
>(
obj);
562 std::string key_name_string(
obj->GetName());
563 j.emplace(key_name_string,
to_JSON(tmpList));
576 m_file->SetBit(TFile::kDevNull);
578 WriteListToDirectory(
583 m_file->cd(
"HanMetadata_");
584 TDirectory* version_dir =
gDirectory->mkdir(
"File");
586 TDirectory* version_subdir =
gDirectory->mkdir(
"Version_name");
587 version_subdir->cd();
588 TObjString file_version;
589 file_version.Write(
"V.2.3");
605 DQRegMap_t::const_iterator dqRegIter =
m_dqRegs.begin();
606 DQRegMap_t::const_iterator dqRegEnd =
m_dqRegs.end();
607 for (; dqRegIter != dqRegEnd; ++dqRegIter)
609 std::string regname = dqRegIter->first->getName();
613 DQParSet_t::const_iterator regexItr =
m_regexlist.begin();
614 DQParSet_t::const_iterator regexEnd =
m_regexlist.end();
615 for (; regexItr != regexEnd; ++regexItr)
625 for (; unpubIter != unpubEnd; ++unpubIter)
627 const std::string&
name = *unpubIter;
641 : m_result(
new TTree(
"result",
"Assessment Result")), m_status(
new char[s_charArrSize])
651 copyString(m_status, StatusToStr(
result.status_));
660 const char*
f = from.c_str();
661 while (++
i < s_charArrSize && (*
to++ = *
f++) != 0)
663 if (
i == s_charArrSize)
671 return (
a->getName() <
b->getName());
691 case dqm_core::Result::Yellow:
695 case dqm_core::Result::Disabled: