13#include <TCollection.h>
14#include <TDirectory.h>
21#include <TSeqCollection.h>
27#include "Package2HTML.h"
32 fHTMLCounter(0), fMainPackageArray(NULL), fCutContainerArray(NULL), fMetaDataPack(NULL), fFilename(filename) {
33 fFile =
new TFile(filename);
34 if (fFile->IsZombie()) {
38 fMetaDataPack = (
Package*) fFile->Get(
"HalInfo/RunInfo");
40 Int_t SoftVer = Hal::Std::VersionId(str->
GetValue());
41 if (SoftVer <= 201612) {
42 Cout::PrintInfo(
"This file version might be not compatible wtih current version, use "
43 "macro/path/fix_files.C to fix it",
44 Hal::EInfo::kWarning);
46 TDirectory* PhysDir = (TDirectory*) fFile->Get(
"HalPhysics");
47 fPhysKeys = PhysDir->GetListOfKeys();
49 fMainPackageArray =
new TObjArray();
50 fCutContainerArray =
new TObjArray();
51 fMainPackageArray->SetOwner(kTRUE);
52 fCutContainerArray->SetOwner(kFALSE);
55 for (
int i = 0; i < fPhysKeys->GetEntries(); i++) {
56 TString name = ((TKey*) (fPhysKeys->At(0)))->GetName();
57 if (name != packname) {
58 fPhysKeys->RemoveAt(i);
60 fMainPackageArray->AddLast(
dynamic_cast<Package*
>(PhysDir->Get(name)));
61 if (FindCutContainer(0) == kFALSE) {
Cout::PrintInfo(
"Cut container not found !", Hal::EInfo::kWarning); }
65 for (
int i = 0; i < fPhysKeys->GetEntries(); i++) {
66 TString name = ((TKey*) (fPhysKeys->At(i)))->GetName();
67 TObject* pack_candidate = PhysDir->Get(name);
68 if (!pack_candidate->InheritsFrom(
"Hal::Package")) {
69 fPhysKeys->RemoveAt(i);
70 delete pack_candidate;
72 fMainPackageArray->AddLast(pack_candidate);
75 fMaxPackID = fPhysKeys->GetEntries();
76 for (
int i = 0; i < fMaxPackID; i++) {
77 if (FindCutContainer(i) == kFALSE) {
Cout::PrintInfo(
"Cut container not found !", Hal::EInfo::kWarning); }
80 fMainPackageArray->Compress();
84 fHTMLCounter(0), fMainPackageArray(NULL), fCutContainerArray(NULL), fMetaDataPack(NULL), fFilename(filename) {
85 fFile =
new TFile(filename);
86 if (fFile->IsZombie()) { exit(0); }
87 fMetaDataPack = (
Package*) fFile->Get(
"HalInfo/RunInfo");
89 Int_t SoftVer = Hal::Std::VersionId(str->
GetValue());
90 if (SoftVer <= 201612) {
91 Cout::PrintInfo(
"This file version might be not compatible wtih current version, use "
92 "macro/path/fix_files.C to fix it",
93 Hal::EInfo::kWarning);
95 TDirectory* PhysDir = (TDirectory*) fFile->Get(
"HalPhysics");
96 fPhysKeys = (TList*) PhysDir->GetListOfKeys()->Clone();
98 fMainPackageArray =
new TObjArray();
99 fCutContainerArray =
new TObjArray();
100 fMainPackageArray->SetOwner(kTRUE);
101 fCutContainerArray->SetOwner(kFALSE);
104 if (
id > fPhysKeys->GetEntries()) {
105 Cout::PrintInfo(Form(
"Package with id = %i not found !",
id), Hal::EInfo::kWarning);
108 TString name = ((TKey*) (fPhysKeys->At(
id)))->GetName();
109 fMainPackageArray->AddLast(
dynamic_cast<Package*
>(PhysDir->Get(name)));
110 if (FindCutContainer(0) == kFALSE) {
Cout::PrintInfo(
"Cut container not found !", Hal::EInfo::kWarning); }
112 for (
int i = 0; i < fPhysKeys->GetEntries(); i++) {
113 TString name = ((TKey*) (fPhysKeys->At(i)))->GetName();
114 TObject* pack_candidate = PhysDir->Get(name);
115 if (!pack_candidate->InheritsFrom(
"Hal::Package")) {
116 fPhysKeys->RemoveAt(i--);
117 delete pack_candidate;
119 fMainPackageArray->AddLast(pack_candidate);
122 fMaxPackID = fPhysKeys->GetEntries();
123 for (
int i = 0; i < fMaxPackID; i++) {
124 if (FindCutContainer(i) == kFALSE) {
Cout::PrintInfo(
"Cut container not found !", Hal::EInfo::kWarning); }
127 fMainPackageArray->Compress();
134 void AnaFile::PrintMonitorCutList(TList* list)
const {
136 TString no, type, unitx, unity, unitz;
137 for (
int i = 0; i < list->GetEntries(); i++) {
138 Package* mon = (Package*) list->At(i);
139 TString size = mon->GetComment();
140 no = Hal::Std::RoundToString(i);
142 unitx = unity = unitz =
"-";
143 ParameterString* xN = ((ParameterString*) mon->GetObjectByName(
"AxisX", 0, kTRUE));
144 if (xN) unitx = xN->GetValue();
145 xN = ((ParameterString*) mon->GetObjectByName(
"AxisY", 0, kTRUE));
146 if (xN) unity = xN->GetValue();
147 xN = ((ParameterString*) mon->GetObjectByName(
"AxisZ", 0, kTRUE));
148 if (xN) unitz = xN->GetValue();
155 Package* AnaFile::GetCutCollection(Hal::ECutUpdate update, Int_t no)
const {
157 TString listName = Form(
"%sCutCollectionList", Hal::Std::UpdateEnumToString(update).Data());
158 list = ((TList*) GetCutContainer()->GetObjectByName(listName));
159 return (
Package*) list->At(no);
175 case Hal::ECutUpdate::kEvent: label =
"Event_collections_No";
break;
176 case Hal::ECutUpdate::kTrack: label =
"Track_collections_No";
break;
177 case Hal::ECutUpdate::kTwoTrack: label =
"TwoTrack_collections_No";
break;
178 case Hal::ECutUpdate::kTwoTrackBackground: label =
"TwoTrack_collections_background_No";
break;
179 default:
return 0;
break;
181 if (GetCutContainer()->Exist(label, 0)) {
return ((
ParameterInt*) GetCutContainer()->GetObjectByName(label))->GetValue(); }
186 Package* pack = GetCutCollection(update, collection);
188 if (lista == NULL)
return NULL;
194 Package* pack = GetCutCollection(update, collection);
196 if (lista == NULL)
return NULL;
203 for (
int i = 0; i < fMainPackageArray->GetEntriesFast(); i++) {
204 TString name = ((TKey*) fPhysKeys->At(i))->GetName();
205 TObject* obj = fMainPackageArray->UncheckedAt(i);
206 if (obj->InheritsFrom(
"Hal::Package") && name == packname) {
return (
Package*) obj; }
208 Cout::FailSucced(Form(
"Package %s not found !", packname.Data()),
"WARNING", kRed);
213 Bool_t not_switched = kTRUE;
214 for (
int i = 0; i < fPhysKeys->GetEntries(); i++) {
215 TKey* key = (TKey*) fPhysKeys->At(i);
216 TString key_name = key->GetName();
217 if (key_name.EqualTo(name)) {
219 not_switched = kFALSE;
223 Cout::PrintInfo(Form(
"%s not found in HalPhysics", name.Data()), Hal::EInfo::kLowWarning);
230 if (no < 0)
return kFALSE;
231 if (no >= fMaxPackID)
return kFALSE;
236 Bool_t AnaFile::FindCutContainer(Int_t pack_no) {
237 Package* mainpack =
static_cast<Package*
>(fMainPackageArray->UncheckedAt(pack_no));
238 for (
int i = 0; i < mainpack->
GetEntries(); i++) {
240 TString classname = obj->ClassName();
241 if (classname ==
"Hal::Package") {
243 TString pack_class_name(pack->
GetName(), strlen(pack->
GetName()));
244 if (pack_class_name.EqualTo(
"Hal::CutContainer")) {
245 fCutContainerArray->AddAtAndExpand(pack, pack_no);
255 AnaFile::~AnaFile() {
256 delete fMetaDataPack;
257 delete fMainPackageArray;
258 delete fCutContainerArray;
266 TFile* file =
new TFile(filename);
267 TDirectory* tdir = (TDirectory*) file->Get(
"HalPhysics");
268 TList* list = tdir->GetListOfKeys();
269 for (
int i = 0; i < list->GetEntries(); i++) {
270 TString name = ((TKey*) (list->At(i)))->GetName();
271 TObject*
object = tdir->Get(name);
273 if (object->InheritsFrom(
"Hal::Package")) {
276 Cout::PrintInfo(Form(
"%s found in HalPhysics but don't inherit from HalPackage", name.Data()), Hal::EInfo::kLowWarning);
283 Package* pack = GetCutCollection(update, collection);
284 TString option = opt;
285 if (option ==
"fast")
286 option =
"PassedFast";
288 option =
"PassedSlow";
294 Package* pack = GetCutCollection(update, collection);
295 TString option = opt;
296 if (option ==
"fast")
297 option =
"FailedFast";
299 option =
"FailedSlow";
305 Package* pack = GetCutCollection(update, collection);
306 TString option = opt;
307 if (option ==
"fast") {
309 if (list)
return list->GetEntries();
310 }
else if (option ==
"slow") {
312 if (list)
return list->GetEntries();
317 if (listf) total += listf->GetEntries();
318 if (list) total += list->GetEntries();
325 Package* pack = GetCutCollection(update, collection);
326 TString option = opt;
327 Int_t d1, d2, d3, d4;
328 d1 = d2 = d3 = d4 = 0;
330 if (list == NULL)
return 0;
331 for (
int iCut = 0; iCut < list->GetEntries(); iCut++) {
342 if (option ==
"1d")
return d1;
343 if (option ==
"2d")
return d2;
344 if (option ==
"3d")
return d3;
352 ((TList*) GetCutContainer()->GetObjectByName(Form(
"%sCutCollectionList", Hal::Std::UpdateEnumToString(update).Data())));
353 label = Form(
"%s Cuts", Hal::Std::UpdateEnumToString(update).Data());
354 if (list == NULL)
return;
356 for (
int i = 0; i < list->GetEntries(); i++) {
357 Cout::Text(Form(
"%s Cut col: %i", label.Data(), i),
"M", kCyan);
358 PrintCutsInPackage((
Package*) list->At(i));
361 Cout::Text(Form(
"%s Cut col: %i", label.Data(), col),
"M", kCyan);
362 PrintCutsInPackage((
Package*) list->At(col));
366 void AnaFile::PrintCutsInPackage(
Package* pack)
const {
373 TString PassedFast = Hal::Std::RoundToString(passedFast->
GetValue());
374 TString PassedSlow = Hal::Std::RoundToString(passedSlow->
GetValue());
375 TString FailedFast = Hal::Std::RoundToString(failedFast->
GetValue());
376 TString FailedSlow = Hal::Std::RoundToString(failedSlow->
GetValue());
382 for (
int i = 0; i < fast_cuts->GetEntries(); i++)
383 PrintCut((Package*) fast_cuts->At(i));
385 for (
int i = 0; i < slow_cuts->GetEntries(); i++)
386 PrintCut((Package*) slow_cuts->At(i));
389 void AnaFile::PrintCut(Package* cut)
const {
390 TString name = cut->GetName();
391 Double_t passed = (Double_t)(((ParameterULong64*) cut->GetObjectByName(
"Passed")))->GetValue();
392 Double_t failed = (Double_t)(((ParameterULong64*) cut->GetObjectByName(
"Failed")))->GetValue();
393 Int_t cut_size = (((ParameterInt*) cut->GetObjectByName(
"CutSize")))->GetValue();
394 passed = passed / (passed + failed) * 100.0;
396 TString unit_name = ((ParameterString*) cut->GetObjectByName(
"UnitName_0i"))->GetValue();
397 TString min = Hal::Std::RoundToString(((ParameterDouble*) cut->GetObjectByName(
"MinCut_0"))->GetValue(), 3);
398 TString max = Hal::Std::RoundToString(((ParameterDouble*) cut->GetObjectByName(
"MaxCut_0"))->GetValue(), 3);
399 Cout::Database({name, Form(
"%4.2f", passed), unit_name, min, max});
402 TString min, max, unit;
404 for (
int i = 0; i < cut_size; i++) {
405 min = Form(
"MinCut_%i", i);
406 max = Form(
"MaxCut_%i", i);
407 unit = Form(
"UnitName_%i", i);
408 unit = ((ParameterString*) cut->GetObjectByName(unit))->GetValue();
409 min = Hal::Std::RoundToString(((ParameterDouble*) cut->GetObjectByName(min))->GetValue(), 3);
410 max = Hal::Std::RoundToString(((ParameterDouble*) cut->GetObjectByName(max))->GetValue(), 3);
423 ((TList*) GetCutContainer()->GetObjectByName(Form(
"%sCutCollectionList", Hal::Std::UpdateEnumToString(update).Data())));
424 label = Form(
"%s Cuts", Hal::Std::UpdateEnumToString(update).Data());
425 if (list == NULL)
return NULL;
427 if (cutCollection == NULL)
return NULL;
428 TString option = opt;
429 TList* list_fast = (TList*) cutCollection->
GetObjectByName(
"FastCutList");
431 if (option ==
"all") {
432 if (cutNo > list_fast->GetEntries()) {
433 return (
Package*) list_slow->At(cutNo - list_fast->GetEntries());
435 return (
Package*) list_fast->At(cutNo);
437 }
else if (option ==
"slow") {
438 return (
Package*) list_slow->At(cutNo);
440 return (
Package*) list_fast->At(cutNo);
444 Package* AnaFile::GetMainPackage()
const {
return static_cast<Package*
>(fMainPackageArray->UncheckedAt(fCurrentPackID)); }
446 Package* AnaFile::GetCutContainer()
const {
return static_cast<Package*
>(fCutContainerArray->UncheckedAt(fCurrentPackID)); }
Int_t GetMainObjectsNo() const
void ExportHTML(TString dirname="extr_html", Int_t task_id=-1) const
TObject * GetMainObject(Int_t i=0) const
AnaFile(TString filename, TString packname)
TH1 * GetHistogramPassed(Hal::ECutUpdate update, Int_t collection, Int_t no) const
Package * GetPackage(TString name) const
Package * GetMetaData() const
ULong64_t GetPassedNo(Hal::ECutUpdate update, Int_t collection, Option_t *opt="slow") const
void PrintCuts(Hal::ECutUpdate update=Hal::ECutUpdate::kNo, Int_t col=-1) const
Int_t GetCutsNo(Hal::ECutUpdate update, Int_t collection, TString opt="all") const
Int_t GetCollectionsNo(Hal::ECutUpdate update) const
Int_t GetCuMonitorsNo(Hal::ECutUpdate update, Int_t collection, TString opt="all") const
static void GetPackageList(TString filename)
TH1 * GetHistogramFailed(Hal::ECutUpdate update, Int_t collection, Int_t no) const
Bool_t SwitchPackage(TString name)
Package * GetCutPackage(Hal::ECutUpdate update, Int_t collection, Int_t cutNo, Option_t *type="all") const
ULong64_t GetFailedNo(Hal::ECutUpdate update, Int_t collection, Option_t *opt=" slow") const
static void Text(TString text, TString option="L", Color_t color=-1)
static void PrintInfo(TString text, Hal::EInfo status)
static void Database(Int_t no...)
static void FailSucced(TString value, TString flag, Color_t color)
TObject * GetObject(Int_t i) const
TObject * GetObjectByName(TString name, Int_t index=0, Bool_t quited=kFALSE) const
const char * GetName() const
ULong64_t GetValue() const