File indexing completed on 2025-08-06 08:14:12
0001 #ifndef noiGetter__h
0002 #define noiGetter__h
0003 struct noiGetter{
0004 map<string, vector<TObject*>> got {};
0005 map <string, TFile*> files {};
0006 int n_objects {0};
0007 noiGetter(){};
0008
0009 TFile* get_file(string f_name) {
0010 if (f_name.find(".root") == string::npos) f_name += ".root";
0011 TFile *f = ( files.count(f_name) ? files[f_name] : new TFile(f_name.c_str(), "read") );
0012 if (!f->IsOpen()) {
0013 cout << " Fatal error, cannot open file: " << f_name << endl;
0014 exit (1);
0015 }
0016 return f;
0017 };
0018
0019 TObject* operator()(string f_name, string object_name) {
0020 TFile *s_current = gDirectory->GetFile();
0021 TFile *f = get_file(f_name);
0022 TObject* obj;
0023 f->GetObject(object_name.c_str(), obj);
0024 if (obj == nullptr) {
0025 cout << " !fatal: failed to get object " << object_name
0026 << " from file " << f_name << endl;
0027 exit(2);
0028 }
0029 ++n_objects;
0030
0031 if (got.count(object_name) != 0) got[object_name].push_back(obj);
0032 else got[object_name].push_back({obj});
0033
0034 if (s_current!=nullptr) s_current->cd();
0035 return obj;
0036 };
0037
0038 };
0039 #endif