-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrending.C
69 lines (56 loc) · 1.99 KB
/
Trending.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
69
/**
* File : Trending.C
* Author : Anton Riedel <[email protected]>
* Date : 12.08.2021
* Last Modified Date: 27.10.2021
* Last Modified By : Anton Riedel <[email protected]>
*/
#include "GridHelperMacros.H"
#include <boost/algorithm/string.hpp>
Int_t Trending(const char *DataFiles, Int_t NumberOfRuns, const char *Trend) {
// file holding list of all merged files
std::ifstream Filenames(DataFiles);
// variables used in loop over all file names
std::string Filename;
TFile *File;
TDirectoryFile *ResultDir;
TList *Task;
Int_t Run = 1;
std::string runname;
Int_t start, end;
TH1 *tmp;
TH1D *hist = new TH1D(Trend, "Trending", NumberOfRuns, 0, NumberOfRuns);
hist->SetMinimum(1e-6);
// loop over filename
for (std::string line; getline(Filenames, Filename);) {
// get run number from path
// path will have the form
// $OUTPUT_DIR_REL/RUNNUMBER/MERGED.root
// extract the string within /.../
// std::cout << Filename << std::endl;
start = Filename.find("/");
end = Filename.find("/", start + 1);
runname = Filename.substr(start + 1, end - start - 1);
// std::cout << runname << std::endl;
File = TFile::Open(Filename.c_str(), "READ");
ResultDir = dynamic_cast<TDirectoryFile *>(
File->Get(std::getenv("OUTPUT_TDIRECTORY_FILE")));
// hack to get the first task
// only support for one task so far
for (auto T : *(ResultDir->GetListOfKeys())) {
Task = dynamic_cast<TList *>(ResultDir->Get(T->GetName()));
tmp = dynamic_cast<TH1 *>(IterateList(Task, std::string(Trend)));
break;
}
hist->SetBinContent(Run, tmp->GetBinContent(1));
hist->SetBinError(Run, tmp->GetBinError(1));
hist->GetXaxis()->SetBinLabel(Run, runname.c_str());
File->Close();
std::cout << Run << "/" << NumberOfRuns << std::endl;
Run++;
}
TFile *out = new TFile(std::getenv("LOCAL_OUTPUT_TRENDING_FILE"), "UPDATE");
hist->Write();
out->Close();
return 0;
}