Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
EventRunCut.cxx
1/*
2 * EventRunCut.cxx
3 *
4 * Created on: 30 sie 2022
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "EventRunCut.h"
11
12#include "Cout.h"
13#include "Cut.h"
14#include "ExpEvent.h"
15#include "Package.h"
16#include "Parameter.h"
17#include "Std.h"
18#include "XMLNode.h"
19
20#include <fstream>
21#include <iostream>
22#include <vector>
23
24#include <RtypesCore.h>
25#include <TString.h>
26
27namespace Hal {
28 EventRunCut::EventRunCut() : fMode(EMode::kBad) { SetUnitName("RunId [AU]"); }
29
30 Bool_t EventRunCut::Init(Int_t format_id) {
31 std::vector<int> runs;
32 if (fListFile.Length() == 0 && fRuns.size() == 0) {
33 Cout::PrintInfo(Form("Lack of run list in %s", this->ClassName()), EInfo::kWarning);
34 return kFALSE;
35 }
36
37 if (fListFile.EndsWith(".xml")) {
38 XMLFile xml(fListFile);
39 XMLNode* root = xml.GetRootNode();
40 if (fLabel.Length() > 0) {
41 root = root->GetChild(fLabel);
42 if (root == nullptr) {
43 Cout::PrintInfo(Form("Lack of runs %s in file %s", fLabel.Data(), fListFile.Data()), EInfo::kWarning);
44 return kFALSE;
45 }
46 }
47 TString name = "bad_runs";
48 if (fMode == EMode::kGood) { name = "good_runs"; }
49
50 XMLNode* xmlRuns = root->GetChild(name);
51 if (xmlRuns == nullptr) {
52 Cout::PrintInfo(Form("Lack of run list in file %s", fListFile.Data()), EInfo::kWarning);
53 return kFALSE;
54 }
55 for (int i = 0; i < xmlRuns->GetNChildren(); i++) {
56 TString val = xmlRuns->GetChild(i)->GetValue();
57 runs.push_back(val.Atoi());
58 }
59
60 } else {
61 /* flat list */
62 std::ifstream file;
63 file.open(fListFile);
64 int temp;
65 while (!file.eof()) {
66 file >> temp;
67 runs.push_back(temp);
68 }
69 file.close();
70 }
71 for (auto i : runs) {
72 fRuns.push_back(i);
73 }
74 return EventExpCut::Init(format_id);
75 }
76
77 Bool_t EventRunCut::Pass(Event* event) {
78 Int_t runId = ((ExpEvent*) event)->GetRunId();
79 switch (fMode) {
80 case EMode::kGood: {
81 for (auto run : fRuns) {
82 if (run == runId) return ForcedUpdate(kTRUE);
83 }
84 return ForcedUpdate(kFALSE);
85 } break;
86 case EMode::kBad: {
87 for (auto run : fRuns) {
88 if (run == runId) return ForcedUpdate(kFALSE);
89 }
90 return ForcedUpdate(kTRUE);
91 } break;
92 }
93 return ForcedUpdate(kFALSE);
94 }
95
96 void EventRunCut::Print(Option_t* /*opt*/) const {
97 std::cout << ClassName() << std::endl;
98 if (fMode == EMode::kBad) {
99 std::cout << "MODE: BAD" << std::endl;
100 } else {
101 std::cout << "MODE: GOOD" << std::endl;
102 }
103 std::cout << "RUN ID LIST" << std::endl;
104 int count = 0;
105 for (auto i : fRuns) {
106 std::cout << ++count << "\t" << i << std::endl;
107 }
108 }
109 void EventRunCut::SetRunList(std::initializer_list<int> list) {
110 for (auto i : list) {
111 fRuns.push_back(i);
112 }
113 }
114
115 Package* EventRunCut::Report() const {
116 Package* pack = EventExpCut::Report();
117 switch (fMode) {
118 case EMode::kBad: {
119 pack->AddObject(new ParameterString("Mode", "Reject bad runs", '='));
120 } break;
121 case EMode::kGood: {
122 pack->AddObject(new ParameterString("Mode", "Accept good runs", '='));
123 } break;
124 }
125 TList* triggers = new TList();
126 for (auto i : fRuns) {
127 pack->AddObject(new TObjString(Form("%i", i)));
128 }
129 pack->AddObject(triggers);
130 return pack;
131 }
132} // namespace Hal
void AddObject(TObject *object)
Definition Package.cxx:209
XMLNode * GetRootNode() const
Definition XMLNode.h:180
Int_t GetNChildren() const
Definition XMLNode.h:104
XMLNode * GetChild(TString name, Int_t count=0) const
Definition XMLNode.cxx:93
TString GetValue() const
Definition XMLNode.h:120