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;
66 if(cut.second !=
nullptr) { cut.second->Print(); }
70 std::cout <<
"No g-values!" << std::endl;
79 TH1::AddDirectory(
false);
80 for(
auto i : ROOT::TSeqU(nSlots)) {
81 fLists.emplace_back(std::make_shared<std::map<std::string, TList>>());
90 for(
auto& it :
fH1[i]) {
92 if(it.first.find_last_of(
'/') == std::string::npos) {
93 (*
fLists[i])[
""].Add(it.second);
96 auto lastSlash = it.first.find_last_of(
'/');
97 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
100 for(
auto& it :
fH2[i]) {
102 if(it.first.find_last_of(
'/') == std::string::npos) {
103 (*
fLists[i])[
""].Add(it.second);
106 auto lastSlash = it.first.find_last_of(
'/');
107 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
110 for(
auto& it :
fH3[i]) {
112 if(it.first.find_last_of(
'/') == std::string::npos) {
113 (*
fLists[i])[
""].Add(it.second);
116 auto lastSlash = it.first.find_last_of(
'/');
117 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
120 for(
auto& it :
fSym[i]) {
122 if(it.first.find_last_of(
'/') == std::string::npos) {
123 (*
fLists[i])[
""].Add(it.second);
126 auto lastSlash = it.first.find_last_of(
'/');
127 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
130 for(
auto& it :
fCube[i]) {
132 if(it.first.find_last_of(
'/') == std::string::npos) {
133 (*
fLists[i])[
""].Add(it.second);
136 auto lastSlash = it.first.find_last_of(
'/');
137 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
140 for(
auto& it :
fTree[i]) {
142 (*
fLists[i])[
""].Add(it.second);
146 if(it.first.find_last_of(
'/') == std::string::npos) {
147 (*
fLists[i])[
""].Add(it.second);
150 auto lastSlash = it.first.find_last_of(
'/');
151 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
156 TH1::AddDirectory(
true);
166 std::map<TTree*, TList*> treeList;
168 for(
auto slot : ROOT::TSeqU(1,
fLists.size())) {
171 for(
const auto& list : *res) {
173 for(
const auto&& obj : list.second) {
175 if((*
fLists[slot]).at(list.first).FindObject(obj->GetName()) !=
nullptr) {
177 if(obj->InheritsFrom(TH1::Class())) {
179 static_cast<TH1*
>(obj)->Add(
static_cast<TH1*
>((*
fLists[slot]).at(list.first).FindObject(obj->GetName())));
180 }
else if(obj->InheritsFrom(TTree::Class())) {
182 auto* tree =
static_cast<TTree*
>(obj);
184 treeList.emplace(tree,
new TList);
185 treeList.at(tree)->Add((*
fLists[slot]).at(list.first).FindObject(obj->GetName()));
186 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;
188 std::cerr <<
"Object '" << obj->GetName() <<
"' is not a histogram (" << obj->ClassName() <<
"), don't know what to do with it!" << std::endl;
192 if(obj->InheritsFrom(TH1::Class()) || obj->InheritsFrom(TTree::Class())) {
193 std::cerr <<
"Failed to find object '" << obj->GetName() <<
"' in " << slot <<
". list" << std::endl;
200 for(
auto& tree : treeList) {
201 tree.second->Add(tree.first);
202 Long64_t entries = 0;
204 for(
const auto&& obj : *tree.second) {
205 std::cout << ++i <<
". " << tree.first->GetName() <<
" tree: " <<
static_cast<TTree*
>(obj)->GetEntries() <<
" entries" << std::endl;
206 entries +=
static_cast<TTree*
>(obj)->GetEntries();
208 std::cout <<
"total of " << entries <<
" entries" << std::endl;
209 auto* newTree = TTree::MergeTrees(tree.second);
210 std::cout <<
"Got new tree with " << newTree->GetEntries() <<
" => " << entries - newTree->GetEntries() <<
" less than total" << std::endl;
211 (*res).at(
"").Remove(tree.first);
212 (*res).at(
"").Add(newTree);
224 for(
auto& list : *
fLists[slot]) {
226 for(
const auto&& obj : list.second) {
227 TBufferFile buf(TBuffer::kWrite, 10000);
228 obj->IsA()->WriteBuffer(buf, obj);
230 std::ostringstream str;
231 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;
232 std::cout << str.str();
236 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