37 TaskManager(TaskManager& other) =
delete;
38 void operator=(
const TaskManager&) =
delete;
39 virtual ~TaskManager();
45 void SetOwnsTasks(
bool owns_flag =
true) { is_owns_tasks_ = owns_flag; }
52 virtual void Init(
const std::vector<std::string>& filelists,
const std::vector<std::string>& in_trees);
58 void Run(
long long nEventFrom,
long long nEvents);
59 void Run(
long long nEvents = -1);
60 virtual void Finish();
62 void AddTask(
Task* task) { tasks_.emplace_back(task); }
69 template<
class BranchPtr>
71 if (out_tree_ ==
nullptr) {
72 throw std::runtime_error(
"No output tree. Probably, TaskManager::Init() was not called or output file/tree names are not set.");
76 ptr =
new BranchPtr(config.GetId());
77 }
else if (ptr->GetId() != config.GetId()) {
78 std::cout <<
"WARNING! ptr->GetId() != config.GetId()!" << std::endl;
79 ptr =
new BranchPtr(config.GetId());
82 if (write_mode_ == eBranchWriteMode::kCreateNewTree) {
83 chain_->GetConfiguration()->AddBranchConfig(config);
86 out_tree_->Branch((config.GetName() +
".").c_str(), &ptr);
90 switch (branch->GetBranchType()) {
91 case DetType::kParticle: {
92 AddBranch(branch->GetDataRaw<Particles*>(), branch->GetConfig());
95 case DetType::kTrack: {
96 AddBranch(branch->GetDataRaw<TrackDetector*>(), branch->GetConfig());
100 AddBranch(branch->GetDataRaw<HitDetector*>(), branch->GetConfig());
103 case DetType::kModule: {
104 AddBranch(branch->GetDataRaw<ModuleDetector*>(), branch->GetConfig());
107 case DetType::kEventHeader: {
108 AddBranch(branch->GetDataRaw<EventHeader*>(), branch->GetConfig());
111 case DetType::kGeneric: {
112 AddBranch(branch->GetDataRaw<GenericDetector*>(), branch->GetConfig());
125 assert(!br1.empty() && !br2.empty() && !match);
126 if (out_tree_ ==
nullptr) {
127 throw std::runtime_error(
"No output tree. Probably, TaskManager::Init() was not called or output file/tree names are not set.");
134 out_tree_->Branch((
configuration_->GetMatchName(br1, br2) +
".").c_str(), &match);
137 ANALYSISTREE_ATTR_NODISCARD
const Configuration* GetConfig()
const {
return chain_->GetConfiguration(); }
138 ANALYSISTREE_ATTR_NODISCARD
const DataHeader* GetDataHeader()
const {
return chain_->GetDataHeader(); }
139 ANALYSISTREE_ATTR_NODISCARD Chain* GetChain()
const {
return chain_; }
141 ANALYSISTREE_ATTR_NODISCARD
const Configuration* GetOutConfig()
const {
return configuration_; }
142 ANALYSISTREE_ATTR_NODISCARD
const DataHeader* GetOutDataHeader()
const {
return data_header_; }
144 void SetOutputDataHeader(DataHeader* dh) {
146 chain_->SetDataHeader(dh);
148 void FillOutput() { out_tree_->Fill(); }
152 std::vector<Task*>& Tasks() {
return tasks_; }
154 void SetOutputName(std::string file, std::string tree =
"aTree") {
155 out_file_name_ = std::move(file);
156 out_tree_name_ = std::move(tree);
157 fill_out_tree_ =
true;
160 void SetWriteMode(eBranchWriteMode mode) { write_mode_ = mode; }
161 void SetBranchesExclude(std::vector<std::string> brex) { branches_exclude_ = std::move(brex); }
162 void SetVerbosityPeriod(
int value) { verbosity_period_ = value; }
163 void SetVerbosityFrequency(
int value) { verbosity_frequency_ = value; }
164 void SetIsWriteHashInfo(
bool is =
true) { is_write_hash_info_ = is; }
165 void SetIsUpdateEntryInExec(
bool is =
true) { is_update_entry_in_exec_ = is; }
167 void ClearTasks() { tasks_.clear(); }
170 TaskManager() =
default;
171 static TaskManager* manager_;
175 static void WriteCommitInfo();
176 static void PrintCommitInfo();
179 Chain* chain_{
nullptr};
180 std::vector<Task*> tasks_{};
183 TFile* out_file_{
nullptr};
184 TTree* out_tree_{
nullptr};
187 std::string out_tree_name_{
"aTree"};
188 std::string out_file_name_{
"analysis_tree.root"};
189 std::vector<std::string> branches_exclude_{};
191 int verbosity_period_{-1};
192 int verbosity_frequency_{-1};
195 eBranchWriteMode write_mode_{eBranchWriteMode::kCreateNewTree};
196 bool is_init_{
false};
197 bool fill_out_tree_{
false};
198 bool is_update_entry_in_exec_{
true};
199 bool read_in_tree_{
false};
200 bool is_owns_tasks_{
true};
201 bool is_write_hash_info_{
true};
203 ClassDef(TaskManager, 0);