Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
noiGetter.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file noiGetter.h
1 #ifndef noiGetter__h
2 #define noiGetter__h
3 struct noiGetter{
4  map<string, vector<TObject*>> got {};
5  map <string, TFile*> files {};
6  int n_objects {0};
7  noiGetter(){};
8 
9  TFile* get_file(string f_name) {
10  if (f_name.find(".root") == string::npos) f_name += ".root";
11  TFile *f = ( files.count(f_name) ? files[f_name] : new TFile(f_name.c_str(), "read") );
12  if (!f->IsOpen()) {
13  cout << " Fatal error, cannot open file: " << f_name << endl;
14  exit (1);
15  }
16  return f;
17  };
18 
19  TObject* operator()(string f_name, string object_name) {
20  TFile *s_current = gDirectory->GetFile();
21  TFile *f = get_file(f_name);
22  TObject* obj;
23  f->GetObject(object_name.c_str(), obj);
24  if (obj == nullptr) {
25  cout << " !fatal: failed to get object " << object_name
26  << " from file " << f_name << endl;
27  exit(2);
28  }
29  ++n_objects;
30  /* obj->SetName(unique_name()); */
31  if (got.count(object_name) != 0) got[object_name].push_back(obj);
32  else got[object_name].push_back({obj});
33 
34  if (s_current!=nullptr) s_current->cd();
35  return obj;
36  };
37 
38 };
39 #endif