-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReTerminate.C
68 lines (54 loc) · 2.22 KB
/
ReTerminate.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* File : ReTerminate.C
* Author : Anton Riedel <[email protected]>
* Date : 14.05.2021
* Last Modified Date: 27.01.2022
* Last Modified By : Anton Riedel <[email protected]>
*/
#include <boost/algorithm/string.hpp>
#include <nlohmann/json.hpp>
Int_t ReTerminate(const char *mergedFileName) {
std::fstream ConfigFile("config.json");
nlohmann::json Jconfig = nlohmann::json::parse(ConfigFile);
// open merged file
TFile *mergedFile = new TFile(mergedFileName, "READ");
// mergedFile->ls();
// create new file so we do not overwrite the original
std::string reterminatedFileName(mergedFileName);
boost::replace_all(reterminatedFileName, "Merged", "ReTerminated");
TFile *updatedFile = new TFile(reterminatedFileName.c_str(), "RECREATE");
// initalize task
AliAnalysisTaskAR *Task = new AliAnalysisTaskAR("ReTerminate");
// get TDirectoryFile holding all outputs
TDirectoryFile *tdirFile = dynamic_cast<TDirectoryFile *>(mergedFile->Get(
Jconfig["task"]["OutputTDirectory"].get<std::string>().c_str()));
/* create new TDirectoryFile to hold the updated outputs, give it the same
* name and title as the old one, cloning not working? */
TDirectoryFile *newTdirFile =
new TDirectoryFile(tdirFile->GetName(), tdirFile->GetTitle());
// change directory to new TDirectoryFile so we write the updated lists to it
newTdirFile->cd();
// loop over all output lists
TList *TaskList;
for (auto KeyTask : *(tdirFile->GetListOfKeys())) {
// get the output list of a task
TaskList = dynamic_cast<TList *>(tdirFile->Get(KeyTask->GetName()));
std::cout << "Working on Task: " << KeyTask->GetName() << " ... ";
// TaskList->ls();
// initialize the task with the list
Task->GetPointers(TaskList);
// RETERMINATE
Task->Terminate(nullptr);
// write the reterminated list back to the new TDirectoryFile
TaskList->Write(TaskList->GetName(),
TObject::kSingleKey + TObject::kOverwrite);
std::cout << "Done" << std::endl;
}
// write all reterminated objects back to file
updatedFile->cd();
newTdirFile->Write(newTdirFile->GetName());
// close files
updatedFile->Close();
mergedFile->Close();
return 0;
}