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 virtual void Run(
long long nEvents = -1);
59 virtual void Finish();
61 void AddTask(
Task* task) { tasks_.emplace_back(task); }
68 template<
class BranchPtr>
70 if (out_tree_ ==
nullptr) {
71 throw std::runtime_error(
"No output tree. Probably, TaskManager::Init() was not called or output file/tree names are not set.");
75 ptr =
new BranchPtr(config.GetId());
76 }
else if (ptr->GetId() != config.GetId()) {
77 std::cout <<
"WARNING! ptr->GetId() != config.GetId()!" << std::endl;
78 ptr =
new BranchPtr(config.GetId());
81 if (write_mode_ == eBranchWriteMode::kCreateNewTree) {
82 chain_->GetConfiguration()->AddBranchConfig(config);
85 out_tree_->Branch((config.GetName() +
".").c_str(), &ptr);
89 switch (branch->GetBranchType()) {
90 case DetType::kParticle: {
94 case DetType::kTrack: {
95 AddBranch(branch->GetDataRaw<TrackDetector*>(), branch->GetConfig());
99 AddBranch(branch->GetDataRaw<HitDetector*>(), branch->GetConfig());
102 case DetType::kModule: {
103 AddBranch(branch->GetDataRaw<ModuleDetector*>(), branch->GetConfig());
106 case DetType::kEventHeader: {
107 AddBranch(branch->GetDataRaw<EventHeader*>(), branch->GetConfig());
120 assert(!br1.empty() && !br2.empty() && !match);
121 if (out_tree_ ==
nullptr) {
122 throw std::runtime_error(
"No output tree. Probably, TaskManager::Init() was not called or output file/tree names are not set.");
132 out_tree_->Branch((
configuration_->GetMatchName(br1, br2) +
".").c_str(), &match);
135 ANALYSISTREE_ATTR_NODISCARD
const Configuration* GetConfig()
const {
return chain_->GetConfiguration(); }
136 ANALYSISTREE_ATTR_NODISCARD
const DataHeader* GetDataHeader()
const {
return chain_->GetDataHeader(); }
137 ANALYSISTREE_ATTR_NODISCARD Chain* GetChain()
const {
return chain_; }
139 ANALYSISTREE_ATTR_NODISCARD
const Configuration* GetOutConfig()
const {
return configuration_; }
140 ANALYSISTREE_ATTR_NODISCARD
const DataHeader* GetOutDataHeader()
const {
return data_header_; }
142 void SetOutputDataHeader(DataHeader* dh) {
144 chain_->SetDataHeader(dh);
146 void FillOutput() { out_tree_->Fill(); }
150 std::vector<Task*>& Tasks() {
return tasks_; }
152 void SetOutputName(std::string file, std::string tree =
"aTree") {
153 out_file_name_ = std::move(file);
154 out_tree_name_ = std::move(tree);
155 fill_out_tree_ =
true;
158 void SetWriteMode(eBranchWriteMode mode) { write_mode_ = mode; }
159 void SetBranchesExclude(std::vector<std::string> brex) { branches_exclude_ = std::move(brex); }
160 void SetVerbosityPeriod(
int value) { verbosity_period_ = value; }
161 void SetIsWriteHashInfo(
bool is =
true) { is_write_hash_info_ = is; }
162 void SetIsUpdateEntryInExec(
bool is =
true) { is_update_entry_in_exec_ = is; }
164 void ClearTasks() { tasks_.clear(); }
167 TaskManager() =
default;
168 static TaskManager* manager_;
172 static void WriteCommitInfo();
173 static void PrintCommitInfo();
176 Chain* chain_{
nullptr};
177 std::vector<Task*> tasks_{};
180 TFile* out_file_{
nullptr};
181 TTree* out_tree_{
nullptr};
184 std::string out_tree_name_{
"aTree"};
185 std::string out_file_name_{
"analysis_tree.root"};
186 std::vector<std::string> branches_exclude_{};
188 int verbosity_period_{-1};
191 eBranchWriteMode write_mode_{eBranchWriteMode::kCreateNewTree};
192 bool is_init_{
false};
193 bool fill_out_tree_{
false};
194 bool is_update_entry_in_exec_{
true};
195 bool read_in_tree_{
false};
196 bool is_owns_tasks_{
true};
197 bool is_write_hash_info_{
true};
199 ClassDef(TaskManager, 0);
void SetOwnsTasks(bool owns_flag=true)
If TaskManager owns its tasks, they will be deleted on TaskManager' destruction.
Definition TaskManager.hpp:45