3#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 14, 0)
7#include "TBufferFile.h"
10 : fPpg(static_cast<
TPPG*>(input->FindObject(
"TPPG"))), fRunInfo(static_cast<
TRunInfo*>(input->FindObject(
"TRunInfo"))), fUserSettings(static_cast<
TUserSettings*>(input->FindObject(
"UserSettings")))
17 std::ostringstream str;
19 throw std::runtime_error(str.str());
22 for(
int i = 0; input->FindObject(Form(
"calFile%d", i)) !=
nullptr; ++i) {
23 const char* fileName =
static_cast<TNamed*
>(input->FindObject(Form(
"calFile%d", i)))->GetTitle();
24 if(fileName[0] == 0) {
25 std::cout <<
"Error, empty file name!" << std::endl;
30 for(
int i = 0; input->FindObject(Form(
"valFile%d", i)) !=
nullptr; ++i) {
31 const char* fileName =
static_cast<TNamed*
>(input->FindObject(Form(
"valFile%d", i)))->GetTitle();
32 if(fileName[0] == 0) {
33 std::cout <<
"Error, empty file name!" << std::endl;
38 for(
int i = 0; input->FindObject(Form(
"cutFile%d", i)) !=
nullptr; ++i) {
39 std::cout <<
"trying to open " << Form(
"cutFile%d", i) << std::flush <<
" = " << input->FindObject(Form(
"cutFile%d", i)) << std::flush <<
" with title " <<
static_cast<TNamed*
>(input->FindObject(Form(
"cutFile%d", i)))->GetTitle() << std::endl;
40 const char* fileName =
static_cast<TNamed*
>(input->FindObject(Form(
"cutFile%d", i)))->GetTitle();
41 if(fileName[0] == 0) {
42 std::cout <<
"Error, empty file name!" << std::endl;
46 auto* file =
new TFile(fileName);
47 if(file !=
nullptr && file->IsOpen()) {
48 TIter iter(file->GetListOfKeys());
50 while((key =
static_cast<TKey*
>(iter.Next())) !=
nullptr) {
51 if(strcmp(key->GetClassName(),
"TCutG") != 0) {
54 auto* tmpCut =
static_cast<TCutG*
>(key->ReadObj());
55 if(tmpCut !=
nullptr) {
56 fCuts[tmpCut->GetName()] = tmpCut;
60 std::cout <<
"Error, failed to open file " << fileName <<
"!" << std::endl;
64 for(
auto& cut :
fCuts) {
65 std::cout << cut.first <<
" = " << cut.second << std::endl;
69 std::cout <<
"No g-values!" << std::endl;
78 TH1::AddDirectory(
false);
79 for(
auto i : ROOT::TSeqU(nSlots)) {
80 fLists.emplace_back(std::make_shared<std::map<std::string, TList>>());
89 for(
auto& it :
fH1[i]) {
91 if(it.first.find_last_of(
'/') == std::string::npos) {
92 (*
fLists[i])[
""].Add(it.second);
95 auto lastSlash = it.first.find_last_of(
'/');
96 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
99 for(
auto& it :
fH2[i]) {
101 if(it.first.find_last_of(
'/') == std::string::npos) {
102 (*
fLists[i])[
""].Add(it.second);
105 auto lastSlash = it.first.find_last_of(
'/');
106 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
109 for(
auto& it :
fH3[i]) {
111 if(it.first.find_last_of(
'/') == std::string::npos) {
112 (*
fLists[i])[
""].Add(it.second);
115 auto lastSlash = it.first.find_last_of(
'/');
116 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
119 for(
auto& it :
fSym[i]) {
121 if(it.first.find_last_of(
'/') == std::string::npos) {
122 (*
fLists[i])[
""].Add(it.second);
125 auto lastSlash = it.first.find_last_of(
'/');
126 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
129 for(
auto& it :
fCube[i]) {
131 if(it.first.find_last_of(
'/') == std::string::npos) {
132 (*
fLists[i])[
""].Add(it.second);
135 auto lastSlash = it.first.find_last_of(
'/');
136 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
139 for(
auto& it :
fTree[i]) {
141 (*
fLists[i])[
""].Add(it.second);
145 if(it.first.find_last_of(
'/') == std::string::npos) {
146 (*
fLists[i])[
""].Add(it.second);
149 auto lastSlash = it.first.find_last_of(
'/');
150 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
155 TH1::AddDirectory(
true);
165 std::map<TTree*, TList*> treeList;
167 for(
auto slot : ROOT::TSeqU(1,
fLists.size())) {
170 for(
const auto& list : *res) {
172 for(
const auto&& obj : list.second) {
174 if((*
fLists[slot]).at(list.first).FindObject(obj->GetName()) !=
nullptr) {
176 if(obj->InheritsFrom(TH1::Class())) {
178 static_cast<TH1*
>(obj)->Add(
static_cast<TH1*
>((*
fLists[slot]).at(list.first).FindObject(obj->GetName())));
179 }
else if(obj->InheritsFrom(TTree::Class())) {
181 auto* tree =
static_cast<TTree*
>(obj);
183 treeList.emplace(tree,
new TList);
184 treeList.at(tree)->Add((*
fLists[slot]).at(list.first).FindObject(obj->GetName()));
185 std::cout << slot <<
": adding " << treeList.at(tree)->GetSize() <<
". " << tree->GetName() <<
" tree with " <<
static_cast<TTree*
>((*
fLists[slot]).at(list.first).FindObject(obj->GetName()))->GetEntries() <<
" entries" << std::endl;
187 std::cerr <<
"Object '" << obj->GetName() <<
"' is not a histogram (" << obj->ClassName() <<
"), don't know what to do with it!" << std::endl;
191 if(obj->InheritsFrom(TH1::Class()) || obj->InheritsFrom(TTree::Class())) {
192 std::cerr <<
"Failed to find object '" << obj->GetName() <<
"' in " << slot <<
". list" << std::endl;
199 for(
auto& tree : treeList) {
200 tree.second->Add(tree.first);
201 Long64_t entries = 0;
203 for(
const auto&& obj : *tree.second) {
204 std::cout << ++i <<
". " << tree.first->GetName() <<
" tree: " <<
static_cast<TTree*
>(obj)->GetEntries() <<
" entries" << std::endl;
205 entries +=
static_cast<TTree*
>(obj)->GetEntries();
207 std::cout <<
"total of " << entries <<
" entries" << std::endl;
208 auto* newTree = TTree::MergeTrees(tree.second);
209 std::cout <<
"Got new tree with " << newTree->GetEntries() <<
" => " << entries - newTree->GetEntries() <<
" less than total" << std::endl;
210 (*res).at(
"").Remove(tree.first);
211 (*res).at(
"").Add(newTree);
223 for(
auto& list : *
fLists[slot]) {
225 for(
const auto&& obj : list.second) {
226 TBufferFile buf(TBuffer::kWrite, 10000);
227 obj->IsA()->WriteBuffer(buf, obj);
229 std::ostringstream str;
230 str <<
DRED << slot <<
". slot: " << obj->ClassName() <<
" '" << obj->GetName() <<
"' too large to " << usage <<
": " << buf.Length() <<
" bytes = " << buf.Length() / 1024. / 1024. / 1024. <<
" GB, removing it!" <<
RESET_COLOR << std::endl;
231 std::cout << str.str();
235 list.second.Remove(obj);
static int ReadValFile(const char *filename="", Option_t *opt="replace")
static Int_t ReadCalFile(std::ifstream &infile)
std::vector< TGRSIMap< std::string, TTree * > > fTree
std::map< std::string, TCutG * > fCuts
std::vector< TGRSIMap< std::string, GCube * > > fCube
std::vector< TGRSIMap< std::string, GHSym * > > fSym
std::vector< TGRSIMap< std::string, TH2 * > > fH2
void CheckSizes(unsigned int slot, const char *usage)
std::vector< TGRSIMap< std::string, TObject * > > fObject
std::vector< TGRSIMap< std::string, TH1 * > > fH1
virtual void CreateHistograms(unsigned int)
Virtual helper function that the user uses to create their histograms.
virtual void EndOfSort(std::shared_ptr< std::map< std::string, TList > > &)
This method gets called at the end of Finalize()
std::vector< std::shared_ptr< std::map< std::string, TList > > > fLists
TGRSIHelper(TList *input)
static constexpr int fSizeLimit
! 1 GiB size limit for objects in ROOT
std::vector< TGRSIMap< std::string, TH3 * > > fH3
static TGRSIOptions * Get(int argc=0, char **argv=nullptr)
Do not use!
static TAnalysisOptions * AnalysisOptions()
int GetMaxWorkers() const