39 TaskManager(TaskManager& other) =
delete;
40 void operator=(
const TaskManager&) =
delete;
41 virtual ~TaskManager();
47 void SetOwnsTasks(
bool owns_flag =
true) { is_owns_tasks_ = owns_flag; }
54 virtual void Init(
const std::vector<std::string>& filelists,
const std::vector<std::string>& in_trees);
60 void Run(
long long nEventFrom,
long long nEvents);
61 void Run(
long long nEvents = -1);
62 virtual void Finish();
64 void AddTask(
Task* task) { tasks_.emplace_back(task); }
71 template<
class BranchPtr>
73 if (out_tree_ ==
nullptr) {
74 throw std::runtime_error(
"No output tree. Probably, TaskManager::Init() was not called or output file/tree names are not set.");
78 ptr =
new BranchPtr(config.GetId());
79 }
else if (ptr->GetId() != config.GetId()) {
80 std::cout <<
"WARNING! ptr->GetId() != config.GetId()!" << std::endl;
81 ptr =
new BranchPtr(config.GetId());
84 if (write_mode_ == eBranchWriteMode::kCreateNewTree) {
85 chain_->GetConfiguration()->AddBranchConfig(config);
88 out_tree_->Branch((config.GetName() +
".").c_str(), &ptr);
92 switch (branch->GetBranchType()) {
93 case DetType::kParticle: {
94 AddBranch(branch->GetDataRaw<Particles*>(), branch->GetConfig());
97 case DetType::kTrack: {
98 AddBranch(branch->GetDataRaw<TrackDetector*>(), branch->GetConfig());
101 case DetType::kHit: {
102 AddBranch(branch->GetDataRaw<HitDetector*>(), branch->GetConfig());
105 case DetType::kModule: {
106 AddBranch(branch->GetDataRaw<ModuleDetector*>(), branch->GetConfig());
109 case DetType::kEventHeader: {
110 AddBranch(branch->GetDataRaw<EventHeader*>(), branch->GetConfig());
113 case DetType::kGeneric: {
114 AddBranch(branch->GetDataRaw<GenericDetector*>(), branch->GetConfig());
127 assert(!br1.empty() && !br2.empty() && !match);
128 if (out_tree_ ==
nullptr) {
129 throw std::runtime_error(
"No output tree. Probably, TaskManager::Init() was not called or output file/tree names are not set.");
136 out_tree_->Branch((
configuration_->GetMatchName(br1, br2) +
".").c_str(), &match);
139 ANALYSISTREE_ATTR_NODISCARD
const Configuration* GetConfig()
const {
return chain_->GetConfiguration(); }
140 ANALYSISTREE_ATTR_NODISCARD
const DataHeader* GetDataHeader()
const {
return chain_->GetDataHeader(); }
141 ANALYSISTREE_ATTR_NODISCARD Chain* GetChain()
const {
return chain_; }
143 ANALYSISTREE_ATTR_NODISCARD
const Configuration* GetOutConfig()
const {
return configuration_; }
144 ANALYSISTREE_ATTR_NODISCARD
const DataHeader* GetOutDataHeader()
const {
return data_header_; }
146 void SetOutputDataHeader(DataHeader* dh) {
148 chain_->SetDataHeader(dh);
150 void FillOutput() { out_tree_->Fill(); }
154 std::vector<Task*>& Tasks() {
return tasks_; }
156 void SetOutputName(std::string file, std::string tree =
"aTree") {
157 out_file_name_ = std::move(file);
158 out_tree_name_ = std::move(tree);
159 fill_out_tree_ =
true;
162 void SetWriteMode(eBranchWriteMode mode) { write_mode_ = mode; }
163 void SetBranchesExclude(std::vector<std::string> brex) { branches_exclude_ = std::move(brex); }
164 void SetVerbosityPeriod(
int value) { verbosity_period_ = value; }
165 void SetVerbosityFrequency(
int value) { verbosity_frequency_ = value; }
166 void SetIsWriteHashInfo(
bool is =
true) { is_write_hash_info_ = is; }
167 void SetIsUpdateEntryInExec(
bool is =
true) { is_update_entry_in_exec_ = is; }
181 is_set_auto_flush_ =
true;
184 void ClearTasks() { tasks_.clear(); }
187 TaskManager() =
default;
188 static TaskManager* manager_;
192 static void WriteCommitInfo();
193 static void PrintCommitInfo();
196 Chain* chain_{
nullptr};
197 std::vector<Task*> tasks_{};
200 TFile* out_file_{
nullptr};
201 TTree* out_tree_{
nullptr};
204 std::string out_tree_name_{
"aTree"};
205 std::string out_file_name_{
"analysis_tree.root"};
206 std::vector<std::string> branches_exclude_{};
208 int verbosity_period_{-1};
209 int verbosity_frequency_{-1};
211 int compression_settings_{ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault};
212 Long64_t auto_flush_{0};
213 bool is_set_auto_flush_{
false};
216 eBranchWriteMode write_mode_{eBranchWriteMode::kCreateNewTree};
217 bool is_init_{
false};
218 bool fill_out_tree_{
false};
219 bool is_update_entry_in_exec_{
true};
220 bool read_in_tree_{
false};
221 bool is_owns_tasks_{
true};
222 bool is_write_hash_info_{
true};
224 ClassDef(TaskManager, 0);