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"
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;
329 resultList =
dynamic_cast<TSeqCollection*
>(resultList->FindObject(
"Results"));
333 std::cerr <<
"Warning: no result list found associated with '" <<
name <<
"'\n";
336 resultList->Add(
newTObjArray(
"Status",
new TObjString(StatusToStr(
result.status_).c_str()), 1));
339 std::map<std::string, double>::const_iterator iter =
result.tags_.begin();
340 for (; iter !=
result.tags_.end(); ++iter)
342 std::ostringstream tagval;
343 tagval << std::setprecision(4) << iter->second;
344 resultList->Add(
newTObjArray(iter->first.c_str(),
new TObjString(tagval.str().c_str()), 1));
348 TObject* resultobj =
result.getObject();
351 TObject* resultobjclone = resultobj->Clone();
354 resultList->Add(resultobjclone);
358 std::cerr <<
"Discarding result object " <<
result.getObject()->GetName() << std::endl;
359 delete resultobjclone;
370 resultList->Add(
ref);
374 std::cerr <<
"Discarding reference object " <<
ref->GetName() << std::endl;
385 static bool include_hist(TObject*
obj) {
388 if ((strncmp(
obj->ClassName(),
"TH", 2) == 0) || (strncmp(
obj->ClassName(),
"TGraph", 6) == 0) ||
389 (strncmp(
obj->ClassName(),
"TProfile", 8) == 0) || (strncmp(
obj->ClassName(),
"TEfficiency", 11) == 0))
394 TSeqCollection* tmpList{};
395 tmpList =
dynamic_cast<TSeqCollection*
>(
obj);
398 TIter nextElem(tmpList);
400 while ((tmpobj = nextElem()) != 0)
402 result = include_hist(tmpobj);
412 static void WriteListToDirectory(
413 TDirectory*
dir, TSeqCollection*
list, TFile*
file,
int level,
int HanOutput_FileVersion)
415 TIter nextElem(
list);
417 TSeqCollection* tmpList{};
419 while ((
obj = nextElem()) != 0)
421 bool delete_when_done =
false;
422 HanHistogramLink* hhl =
dynamic_cast<HanHistogramLink*
>(
obj);
425 obj = hhl->getObject();
427 delete_when_done =
true;
430 std::cerr <<
"HanOutput.cxx, WriteListToDirectory : setNameGeneral failed\n";
435 if (strncmp(
obj->GetName(),
"Reference", 9) == 0 || strncmp(
obj->GetName(),
"ResultObject", 12) == 0)
438 if (delete_when_done)
delete obj;
441 tmpList =
dynamic_cast<TSeqCollection*
>(
obj);
445 std::vector<std::string>
dirs;
450 if (
dirs.back().empty())
dirs.pop_back();
454 if (HanOutput_FileVersion == 2)
456 TString listname = tmpList->GetName();
457 if (listname ==
"Config" || listname ==
"Results")
461 TIter nextElemConfRes(tmpList);
462 TObject* objInResultConfig;
463 while ((objInResultConfig = nextElemConfRes()) != 0)
465 if (include_hist(objInResultConfig))
468 TSeqCollection* tmpList_ResConf{};
469 tmpList_ResConf =
dynamic_cast<TSeqCollection*
>(objInResultConfig);
470 if ((tmpList_ResConf != 0) && (strncmp(tmpList_ResConf->GetName(),
"TObjArray", 9) == 0))
473 TIter nextEleminTObjArray(tmpList_ResConf);
474 TObject* objInTObjArray;
475 while ((objInTObjArray = nextEleminTObjArray()) != 0){
476 dir->WriteTObject(objInTObjArray);
478 tmpList->Remove(objInResultConfig);
482 dir->WriteTObject(objInResultConfig);
487 nlohmann::ordered_json j =
to_JSON(tmpList);
490 std::string
string = j.dump(4);
492 char* cstr =
new char[
string.length() + 1];
493 std::strcpy(cstr,
string.c_str());
495 TObjString string_to_tfile;
496 string_to_tfile.SetString(cstr);
498 string_to_tfile.Write(listname);
504 TDirectory* daughter;
505 if (!
dir->FindKey(
str.c_str()))
507 daughter =
dir->mkdir(
str.c_str());
511 std::cout <<
"Failed to make " <<
str <<
" from " << tmpList->GetName() << std::endl;
514 WriteListToDirectory(daughter, tmpList,
file,
level - 1, HanOutput_FileVersion);
521 else if ((strncmp(
obj->ClassName(),
"TH", 2) == 0) || (strncmp(
obj->ClassName(),
"TGraph", 6) == 0) ||
522 (strncmp(
obj->ClassName(),
"TProfile", 8) == 0) || (strncmp(
obj->ClassName(),
"TEfficiency", 11) == 0))
524 dir->GetMotherDir()->WriteTObject(
obj);
531 if (delete_when_done)
delete obj;
535 nlohmann::ordered_json
to_JSON(TSeqCollection* tseq)
537 using json = nlohmann::ordered_json;
540 TIter nextElem(tseq);
542 while ((
obj = nextElem()) != 0)
546 if ((strncmp(
obj->ClassName(),
"TH", 2) == 0) || (strncmp(
obj->ClassName(),
"TGraph", 6) == 0) ||
547 (strncmp(
obj->ClassName(),
"TProfile", 8) == 0) || (strncmp(
obj->ClassName(),
"TEfficiency", 11) == 0) ||
548 (strncmp(
obj->GetName(),
"Reference", 9) == 0))
553 TSeqCollection* tmpList =
dynamic_cast<TSeqCollection*
>(
obj);
558 std::string key_name_string(
obj->GetName());
559 j.emplace(key_name_string,
to_JSON(tmpList));
572 m_file->SetBit(TFile::kDevNull);
574 WriteListToDirectory(
579 m_file->cd(
"HanMetadata_");
580 TDirectory* version_dir =
gDirectory->mkdir(
"File");
582 TDirectory* version_subdir =
gDirectory->mkdir(
"Version_name");
583 version_subdir->cd();
584 TObjString file_version;
585 file_version.Write(
"V.2.3");
601 DQRegMap_t::const_iterator dqRegIter =
m_dqRegs.begin();
602 DQRegMap_t::const_iterator dqRegEnd =
m_dqRegs.end();
603 for (; dqRegIter != dqRegEnd; ++dqRegIter)
605 std::string regname = dqRegIter->first->getName();
609 DQParSet_t::const_iterator regexItr =
m_regexlist.begin();
610 DQParSet_t::const_iterator regexEnd =
m_regexlist.end();
611 for (; regexItr != regexEnd; ++regexItr)
621 for (; unpubIter != unpubEnd; ++unpubIter)
623 const std::string&
name = *unpubIter;
637 : m_result(
new TTree(
"result",
"Assessment Result")), m_status(
new char[s_charArrSize])
647 copyString(m_status, StatusToStr(
result.status_));
656 const char*
f = from.c_str();
657 while (++
i < s_charArrSize && (*
to++ = *
f++) != 0)
659 if (
i == s_charArrSize)
667 return (
a->getName() <
b->getName());
687 case dqm_core::Result::Yellow:
691 case dqm_core::Result::Disabled: