ATLAS Offline Software
readfile.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "rootincludes.h"
6 #include <map>
7 #include <string>
8 #include <cassert>
9 
10 typedef std::map<std::string,TH1*> KeyToHistMap;
11 
12 //____________________________________________________________________
14  const std::string& posinfile,const std::string& histpostfix )
15 {
16  TIter nextkey( dir->GetListOfKeys() );
17  TKey *key;
18  while ((key = (TKey*)nextkey())) {
19  TObject *obj = key->ReadObj();
20  TDirectory * subdir = dynamic_cast<TDirectory*>(obj);
21  if (subdir) {
22  appendHistsFromTDirRecursively(subdir,hists,posinfile+std::string(subdir->GetName())+'/',histpostfix);
23  continue;
24  }
25  TH1 * h = dynamic_cast<TH1*>(obj);
26  if (h) {
27  assert(hists.find(posinfile+h->GetName())==hists.end());
28  TH1* hclone = dynamic_cast<TH1*>(h->Clone((h->GetName()+histpostfix).c_str()));
29  assert(hclone);
30  hists[posinfile+h->GetName()] = hclone;
31  }
32  }
33 }
34 
35 //____________________________________________________________________
37 {
38  //NB: Do NOT delete the file before returning. Due to the workings
39  //of ROOT, this results in the read histograms to become invalid!!
40  TFile *file = TFile::Open(filename.c_str());
41  if (!file||!file->IsOpen()) {
42  //delete file;
43  return false;
44  }
45  std::string posinfile="/";
46  //NB: filename might contain directories. Should we replace all '/'?
48  // delete file;
49  return true;
50 }
KeyToHistMap
std::map< std::string, TH1 * > KeyToHistMap
Definition: readfile.h:10
appendHistsFromTDirRecursively
void appendHistsFromTDirRecursively(TDirectory *dir, KeyToHistMap &hists, const std::string &posinfile, const std::string &histpostfix)
Definition: readfile.h:13
file
TFile * file
Definition: tile_monitor.h:29
MakeTH3DFromTH2Ds.hists
hists
Definition: MakeTH3DFromTH2Ds.py:72
beamspotman.dir
string dir
Definition: beamspotman.py:623
rootincludes.h
h
TH1
Definition: rootspy.cxx:268
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
getAllHistsInRootFile
bool getAllHistsInRootFile(const std::string &filename, KeyToHistMap &hists)
Definition: readfile.h:36
python.LumiCalcRecover.subdir
subdir
Definition: LumiCalcRecover.py:25
python.PyAthena.obj
obj
Definition: PyAthena.py:135
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37