ATLAS Offline Software
Typedefs | Functions
readfile.h File Reference
#include "rootincludes.h"
#include <map>
#include <string>
#include <cassert>
Include dependency graph for readfile.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef std::map< std::string, TH1 * > KeyToHistMap
 

Functions

void appendHistsFromTDirRecursively (TDirectory *dir, KeyToHistMap &hists, const std::string &posinfile, const std::string &histpostfix)
 
bool getAllHistsInRootFile (const std::string &filename, KeyToHistMap &hists)
 

Typedef Documentation

◆ KeyToHistMap

typedef std::map<std::string,TH1*> KeyToHistMap

Definition at line 10 of file readfile.h.

Function Documentation

◆ appendHistsFromTDirRecursively()

void appendHistsFromTDirRecursively ( TDirectory *  dir,
KeyToHistMap hists,
const std::string &  posinfile,
const std::string &  histpostfix 
)

Definition at line 13 of file readfile.h.

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 }

◆ getAllHistsInRootFile()

bool getAllHistsInRootFile ( const std::string &  filename,
KeyToHistMap hists 
)

Definition at line 36 of file readfile.h.

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 }
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
h
TH1
Definition: rootspy.cxx:268
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
python.LumiCalcRecover.subdir
subdir
Definition: LumiCalcRecover.py:25
python.PyAthena.obj
obj
Definition: PyAthena.py:135
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37