3#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 14, 0)
6 : fPpg(static_cast<
TPPG*>(input->FindObject(
"TPPG"))), fRunInfo(static_cast<
TRunInfo*>(input->FindObject(
"TRunInfo"))), fUserSettings(static_cast<
TUserSettings*>(input->FindObject(
"UserSettings")))
13 std::ostringstream str;
15 throw std::runtime_error(str.str());
18 for(
int i = 0; input->FindObject(Form(
"calFile%d", i)) !=
nullptr; ++i) {
19 const char* fileName =
static_cast<TNamed*
>(input->FindObject(Form(
"calFile%d", i)))->GetTitle();
20 if(fileName[0] == 0) {
21 std::cout <<
"Error, empty file name!" << std::endl;
26 for(
int i = 0; input->FindObject(Form(
"valFile%d", i)) !=
nullptr; ++i) {
27 const char* fileName =
static_cast<TNamed*
>(input->FindObject(Form(
"valFile%d", i)))->GetTitle();
28 if(fileName[0] == 0) {
29 std::cout <<
"Error, empty file name!" << std::endl;
34 for(
int i = 0; input->FindObject(Form(
"cutFile%d", i)) !=
nullptr; ++i) {
35 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;
36 const char* fileName =
static_cast<TNamed*
>(input->FindObject(Form(
"cutFile%d", i)))->GetTitle();
37 if(fileName[0] == 0) {
38 std::cout <<
"Error, empty file name!" << std::endl;
42 auto* file =
new TFile(fileName);
43 if(file !=
nullptr && file->IsOpen()) {
44 TIter iter(file->GetListOfKeys());
46 while((key =
static_cast<TKey*
>(iter.Next())) !=
nullptr) {
47 if(strcmp(key->GetClassName(),
"TCutG") != 0) {
50 auto* tmpCut =
static_cast<TCutG*
>(key->ReadObj());
51 if(tmpCut !=
nullptr) {
52 fCuts[tmpCut->GetName()] = tmpCut;
56 std::cout <<
"Error, failed to open file " << fileName <<
"!" << std::endl;
60 for(
auto& cut :
fCuts) {
61 std::cout << cut.first <<
" = " << cut.second << std::endl;
65 std::cout <<
"No g-values!" << std::endl;
74 TH1::AddDirectory(
false);
75 for(
auto i : ROOT::TSeqU(nSlots)) {
76 fLists.emplace_back(std::make_shared<std::map<std::string, TList>>());
85 for(
auto& it :
fH1[i]) {
87 if(it.first.find_last_of(
'/') == std::string::npos) {
88 (*
fLists[i])[
""].Add(it.second);
91 auto lastSlash = it.first.find_last_of(
'/');
92 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
95 for(
auto& it :
fH2[i]) {
97 if(it.first.find_last_of(
'/') == std::string::npos) {
98 (*
fLists[i])[
""].Add(it.second);
101 auto lastSlash = it.first.find_last_of(
'/');
102 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
105 for(
auto& it :
fH3[i]) {
107 if(it.first.find_last_of(
'/') == std::string::npos) {
108 (*
fLists[i])[
""].Add(it.second);
111 auto lastSlash = it.first.find_last_of(
'/');
112 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
115 for(
auto& it :
fSym[i]) {
117 if(it.first.find_last_of(
'/') == std::string::npos) {
118 (*
fLists[i])[
""].Add(it.second);
121 auto lastSlash = it.first.find_last_of(
'/');
122 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
125 for(
auto& it :
fCube[i]) {
127 if(it.first.find_last_of(
'/') == std::string::npos) {
128 (*
fLists[i])[
""].Add(it.second);
131 auto lastSlash = it.first.find_last_of(
'/');
132 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
135 for(
auto& it :
fTree[i]) {
137 (*
fLists[i])[
""].Add(it.second);
141 if(it.first.find_last_of(
'/') == std::string::npos) {
142 (*
fLists[i])[
""].Add(it.second);
145 auto lastSlash = it.first.find_last_of(
'/');
146 (*
fLists[i])[it.first.substr(0, lastSlash)].Add(it.second);
151 TH1::AddDirectory(
true);
161 std::map<TTree*, TList*> treeList;
163 for(
auto slot : ROOT::TSeqU(1,
fLists.size())) {
166 for(
const auto& list : *res) {
168 for(
const auto&& obj : list.second) {
170 if((*
fLists[slot]).at(list.first).FindObject(obj->GetName()) !=
nullptr) {
172 if(obj->InheritsFrom(TH1::Class())) {
174 static_cast<TH1*
>(obj)->Add(
static_cast<TH1*
>((*
fLists[slot]).at(list.first).FindObject(obj->GetName())));
175 }
else if(obj->InheritsFrom(TTree::Class())) {
177 auto* tree =
static_cast<TTree*
>(obj);
179 treeList.emplace(tree,
new TList);
180 treeList.at(tree)->Add((*
fLists[slot]).at(list.first).FindObject(obj->GetName()));
181 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;
183 std::cerr <<
"Object '" << obj->GetName() <<
"' is not a histogram (" << obj->ClassName() <<
"), don't know what to do with it!" << std::endl;
187 if(obj->InheritsFrom(TH1::Class()) || obj->InheritsFrom(TTree::Class())) {
188 std::cerr <<
"Failed to find object '" << obj->GetName() <<
"' in " << slot <<
". list" << std::endl;
195 for(
auto& tree : treeList) {
196 tree.second->Add(tree.first);
197 Long64_t entries = 0;
199 for(
const auto&& obj : *tree.second) {
200 std::cout << ++i <<
". " << tree.first->GetName() <<
" tree: " <<
static_cast<TTree*
>(obj)->GetEntries() <<
" entries" << std::endl;
201 entries +=
static_cast<TTree*
>(obj)->GetEntries();
203 std::cout <<
"total of " << entries <<
" entries" << std::endl;
204 auto* newTree = TTree::MergeTrees(tree.second);
205 std::cout <<
"Got new tree with " << newTree->GetEntries() <<
" => " << entries - newTree->GetEntries() <<
" less than total" << std::endl;
206 (*res).at(
"").Remove(tree.first);
207 (*res).at(
"").Add(newTree);
219 for(
auto& list : *
fLists[slot]) {
221 for(
const auto&& obj : list.second) {
222 TBufferFile buf(TBuffer::kWrite, 10000);
223 obj->IsA()->WriteBuffer(buf, obj);
225 std::ostringstream str;
226 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;
227 std::cout << str.str();
231 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