Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EDepSim::KinemPassThrough Class Reference

#include <EDepSimKinemPassThrough.hh>

Public Types

typedef std::map< const TTree *, int > TreeToInt
 for relating input tree pointers to the input file. More...
 

Public Member Functions

 ~KinemPassThrough ()
 
bool AddInputTree (const TTree *inputTreePtr, const char *inputFileName, const char *generatorName)
 
bool AddEntry (const TTree *inputTreePtr, const int origEntry)
 
int LastEntryNumber ()
 

Static Public Member Functions

static EDepSim::KinemPassThroughGetInstance ()
 

Private Member Functions

 KinemPassThrough ()
 Private constructor. More...
 
void CreateInternalTrees ()
 
void CleanUp ()
 Clean up all of the allocated pointers. More...
 
void Init ()
 Set default values for all fields. More...
 
std::string SetInputFileName (std::string name)
 Set the name of the input file being read. More...
 

Private Attributes

TTree * fPersistentTree
 Persistent tree that stores entries from multiple temp trees. More...
 
TChain * fInputTreeChain
 TChain to store input trees. More...
 
std::string fFirstTreeName
 Store the first tree name. More...
 
TreeToInt fInputTreeMap
 for relating input tree pointers to the input file. More...
 
TreeToInt fFirstEntryMap
 for relating input tree to first entry in TChain. More...
 
std::vector< std::stringfFileList
 Used to store list of files before they are written to tree. More...
 
TTree * fInputKinemTree
 Tree relating all events in the persistent tree to an input file. More...
 
int fInputFileNumber
 
int fOrigEntryNumber
 
TTree * fInputFilesTree
 Tree containing list of input files. More...
 
char fInputFileName [1024]
 Used to fill input file list tree with input file name. More...
 
char fInputFileGenerator [128]
 Used to fill the name of the generator for this file. More...
 
char fInputFileTreeName [128]
 Used to fill the name of the tree for this file. More...
 
double fInputFilePOT
 Used to fill input file list tree "filePOT" field. More...
 
int fInputFileEntries
 

Static Private Attributes

static EDepSim::KinemPassThroughfKinemPassThrough = NULL
 Static pointer to singleton instance. More...
 

Detailed Description

Definition at line 54 of file EDepSimKinemPassThrough.hh.

Member Typedef Documentation

typedef std::map<const TTree *, int> EDepSim::KinemPassThrough::TreeToInt

for relating input tree pointers to the input file.

Definition at line 57 of file EDepSimKinemPassThrough.hh.

Constructor & Destructor Documentation

EDepSim::KinemPassThrough::~KinemPassThrough ( )

Definition at line 42 of file EDepSimKinemPassThrough.cc.

42  {
43  CleanUp();
44 }
void CleanUp()
Clean up all of the allocated pointers.
EDepSim::KinemPassThrough::KinemPassThrough ( )
private

Private constructor.

Definition at line 46 of file EDepSimKinemPassThrough.cc.

46  {
47  Init();
48  EDepSimNamedDebug("PassThru",
49  "Have called the EDepSim::KinemPassThrough constructor.");
50 }
#define EDepSimNamedDebug(trace, outStream)
Definition: EDepSimLog.hh:634
void Init()
Set default values for all fields.

Member Function Documentation

bool EDepSim::KinemPassThrough::AddEntry ( const TTree *  inputTreePtr,
const int  origEntry 
)

Copy the i'th entry from segment of the TChain corresponding to the input tree pointed at (in detsim) by inputTreePtr.

Definition at line 199 of file EDepSimKinemPassThrough.cc.

199  {
200  if (!fPersistentTree) {
201  EDepSimNamedDebug("PassThru", "Cannot copy entry from tree "
202  "since fPersistentTree is NULL.");
203  return false;
204  }
205 
207 
208  // Search the input tree maps for a TTree pointer that matches the
209  // inputTree.
210  TreeToInt::iterator treeid_iter = fInputTreeMap.find(inputTree);
211  TreeToInt::iterator firstentry_iter = fFirstEntryMap.find(inputTree);
212  if (treeid_iter == fInputTreeMap.end()
213  || firstentry_iter == fFirstEntryMap.end()) {
214  EDepSimError("Cannot copy entry from tree not in list of input trees.");
215  return false;
216  }
217 
218  fInputFileNumber = treeid_iter->second;
219  int first_event_in_chain = firstentry_iter->second;
220 
221  // Now fill temp tree with i'th entry from first_event_in_chain of TChain
222  // of input trees.
223  if (fInputTreeChain->GetEntry(origEntry+first_event_in_chain)) {
224  fOrigEntryNumber = origEntry;
225  fPersistentTree->Fill();
226  fInputKinemTree->Fill(); // Also store book keeping info.
227 
228  EDepSimNamedTrace("PassThru",
229  "Copied entry " << origEntry
230  << " from " << fFirstTreeName
231  << " tree in file "
233 
234  return true;
235  }
236 
237  EDepSimError("Cannot copy entry " << origEntry+first_event_in_chain
238  << " from TChained Tree. Make sure entry is in input tree!");
239  return false;
240 }
TTree * fInputKinemTree
Tree relating all events in the persistent tree to an input file.
intermediate_table::iterator iterator
std::string fFirstTreeName
Store the first tree name.
TChain * fInputTreeChain
TChain to store input trees.
TreeToInt fFirstEntryMap
for relating input tree to first entry in TChain.
#define EDepSimNamedDebug(trace, outStream)
Definition: EDepSimLog.hh:634
std::vector< std::string > fFileList
Used to store list of files before they are written to tree.
#define EDepSimNamedTrace(trace, outStream)
Definition: EDepSimLog.hh:672
TreeToInt fInputTreeMap
for relating input tree pointers to the input file.
#define EDepSimError(outStream)
Definition: EDepSimLog.hh:503
TTree * fPersistentTree
Persistent tree that stores entries from multiple temp trees.
bool EDepSim::KinemPassThrough::AddInputTree ( const TTree *  inputTreePtr,
const char *  inputFileName,
const char *  generatorName 
)

Add an input tree to the TChain of input trees that rootracker entries will be copied from. A map between the tree pointer that detsim is using and the correct segment of the TChain is also made.

Definition at line 61 of file EDepSimKinemPassThrough.cc.

63  {
64  EDepSimNamedDebug("PassThru",
65  "Adding a generator mc-truth input"
66  " tree to the list of input trees that can be used.");
67 
69 
71  EDepSimError("Pass-through trees not created.");
72  return false;
73  }
74 
75  if (inputTreePtr == NULL) {
76  EDepSimError("NULL input tree pointer. TTree not saved.");
77  return false;
78  }
79 
80  std::string inputTreeName(inputTreePtr->GetName());
81  // check that all input trees have the same name. In future may add
82  // functionality so that maintain two persistent trees simultaneously
83  if (!fInputTreeChain) {
84  fFirstTreeName = inputTreeName;
85  fInputTreeChain = new TChain(fFirstTreeName.c_str());
86  }
87 
88  if (fFirstTreeName != inputTreeName) {
89  EDepSimError("Input tree name not compatible: "
90  " All pass-through trees must have same name.");
91  return false;
92  }
93 
94  // check if its already been added
95  if (fInputTreeMap.find(inputTreePtr) != fInputTreeMap.end()) {
96  EDepSimError("Input tree already in chain.");
97  return false;
98  }
99 
100  // Add input tree to TChain
101  fInputTreeChain->Add(inputFileName);
102 
103  // Clone tree if this has not been done already. We check if fPersistent
104  // tree is NULL rather than looking to see if fInputTreeChain has a list
105  // of clones (as for a TChain this always returns false).
106  if (fPersistentTree == NULL) {
107  EDepSimNamedDebug("PassThru", "Clone the input TTree");
108  fPersistentTree = (TTree*) fInputTreeChain->CloneTree(0);
109  }
110 
111  // Add the input file to the file list so it can be saved in the output
112  // tree. This is used for error reporting and debugging.
113  fFileList.push_back(SetInputFileName(inputFileName));
114 
115  // fill in input tree maps
116  fInputTreeMap[inputTreePtr] = fFileList.size() - 1;
117  fFirstEntryMap[inputTreePtr] = (fInputTreeChain->GetEntries()
118  - inputTreePtr->GetEntries());
119 
120  // Copy the input file name and make sure it's 0 terminated.
121  std::strncpy(fInputFileName, fFileList.back().c_str(),
122  sizeof(fInputFileName));
123  fInputFileName[sizeof(fInputFileName)-1] = 0;
124  // Copy the generator name and make sure it's 0 terminated.
125  std::strncpy(fInputFileGenerator, generatorName,
126  sizeof(fInputFileGenerator));
127  // Copy the generator name and make sure it's 0 terminated.
128  std::strncpy(fInputFileTreeName, inputTreeName.c_str(),
129  sizeof(fInputFileTreeName));
130  fInputFileTreeName[sizeof(fInputFileTreeName)-1] = 0;
131  fInputFilePOT = inputTreePtr->GetWeight();
132  fInputFileEntries = inputTreePtr->GetEntries();
133  fInputFilesTree->Fill();
134 
135  EDepSimNamedDebug("PassThru",
136  "Have added a " << fFirstTreeName
137  << " tree from the input file "<< inputFileName);
138 
139  // Now can start copying events
140  return true;
141 }
char fInputFileTreeName[128]
Used to fill the name of the tree for this file.
TTree * fInputKinemTree
Tree relating all events in the persistent tree to an input file.
std::string fFirstTreeName
Store the first tree name.
TChain * fInputTreeChain
TChain to store input trees.
TreeToInt fFirstEntryMap
for relating input tree to first entry in TChain.
#define EDepSimNamedDebug(trace, outStream)
Definition: EDepSimLog.hh:634
std::vector< std::string > fFileList
Used to store list of files before they are written to tree.
std::string string
Definition: nybbler.cc:12
double fInputFilePOT
Used to fill input file list tree "filePOT" field.
std::string SetInputFileName(std::string name)
Set the name of the input file being read.
char fInputFileName[1024]
Used to fill input file list tree with input file name.
TreeToInt fInputTreeMap
for relating input tree pointers to the input file.
TTree * fInputFilesTree
Tree containing list of input files.
char fInputFileGenerator[128]
Used to fill the name of the generator for this file.
#define EDepSimError(outStream)
Definition: EDepSimLog.hh:503
TTree * fPersistentTree
Persistent tree that stores entries from multiple temp trees.
void EDepSim::KinemPassThrough::CleanUp ( )
private

Clean up all of the allocated pointers.

Definition at line 262 of file EDepSimKinemPassThrough.cc.

262  {
263  // Delete the output trees so that they can not be written twice (which
264  // they would be as detsim calls TFile::Write() which writes anything in
265  // memory to the TFile.
266 
267  if (fPersistentTree) {delete fPersistentTree;}
268  if (fInputFilesTree) {delete fInputFilesTree;}
269  if (fInputKinemTree) {delete fInputKinemTree;}
270  if (fInputTreeChain) {delete fInputTreeChain;}
271 
272  Init();
273 
274  return;
275 }
TTree * fInputKinemTree
Tree relating all events in the persistent tree to an input file.
TChain * fInputTreeChain
TChain to store input trees.
TTree * fInputFilesTree
Tree containing list of input files.
void Init()
Set default values for all fields.
TTree * fPersistentTree
Persistent tree that stores entries from multiple temp trees.
void EDepSim::KinemPassThrough::CreateInternalTrees ( )
private

Create the bookkeeping and file list trees. This also creates the directory.

Definition at line 143 of file EDepSimKinemPassThrough.cc.

143  {
144  TFile* output = NULL;;
145  TIter files(gROOT->GetListOfFiles());
146  TObject* object;
147  while ((object = files.Next())) {
148  TFile* file = dynamic_cast<TFile*>(object);
149  if (!file) continue;
150  if (!file->IsOpen()) continue;
151  std::string fileOption(file->GetOption());
152  if (fileOption.find("CREATE") != std::string::npos) {
153  output = file;
154  continue;
155  }
156  }
157 
158  if (!output) {
159  return;
160  }
161 
162  output->cd();
163 
164  // Check if the directory exists (and possibly create it).
165  if (!output->Get(PASSTHRUDIR)) {
166  output->mkdir(PASSTHRUDIR,"DETSIM Pass-Through Information");
167  }
168 
169  // Make sure we are in the pass-thru directory.
170  output->cd(PASSTHRUDIR);
171 
172  // Create the book keeping three that connects a particular entry to the
173  // entry in the original file.
174  if (fInputKinemTree == NULL) {
175  EDepSimNamedDebug("PassThru", "Create InputKinem TTree");
176  // This adds the tree to the current output file.
177  fInputKinemTree = new TTree("InputKinem",
178  "Map kinematics with input files");
179  fInputKinemTree->Branch("inputFileNum" , &fInputFileNumber);
180  fInputKinemTree->Branch("inputEntryNum", &fOrigEntryNumber);
181  }
182 
183  if (fInputFilesTree == NULL) {
184  EDepSimNamedDebug("PassThru","Create inputFileList TTree");
185  // This adds the tree to the current output file.
186  fInputFilesTree = new TTree("InputFiles","Input file information");
187  fInputFilesTree->Branch("fileName", &fInputFileName,
188  "fileName/C");
189  fInputFilesTree->Branch("generatorName", &fInputFileGenerator,
190  "generatorName/C");
191  fInputFilesTree->Branch("treeName", &fInputFileTreeName,
192  "treeName/C");
193  fInputFilesTree->Branch("filePOT", &fInputFilePOT);
194  fInputFilesTree->Branch("fileEntries", &fInputFileEntries);
195  }
196 }
char fInputFileTreeName[128]
Used to fill the name of the tree for this file.
TTree * fInputKinemTree
Tree relating all events in the persistent tree to an input file.
#define EDepSimNamedDebug(trace, outStream)
Definition: EDepSimLog.hh:634
std::string string
Definition: nybbler.cc:12
double fInputFilePOT
Used to fill input file list tree "filePOT" field.
#define PASSTHRUDIR
list files
Definition: languages.py:9
char fInputFileName[1024]
Used to fill input file list tree with input file name.
TTree * fInputFilesTree
Tree containing list of input files.
char fInputFileGenerator[128]
Used to fill the name of the generator for this file.
EDepSim::KinemPassThrough * EDepSim::KinemPassThrough::GetInstance ( )
static

Returns (or initialises if first time) the instance of the singleton.

Definition at line 52 of file EDepSimKinemPassThrough.cc.

52  {
53  EDepSimNamedTrace("PassThru",
54  "Get pointer to EDepSim::KinemPassThrough instance.");
57  if (!fKinemPassThrough) std::abort();
58  return fKinemPassThrough;
59 }
static EDepSim::KinemPassThrough * fKinemPassThrough
Static pointer to singleton instance.
#define EDepSimNamedTrace(trace, outStream)
Definition: EDepSimLog.hh:672
void EDepSim::KinemPassThrough::Init ( void  )
private

Set default values for all fields.

Definition at line 277 of file EDepSimKinemPassThrough.cc.

277  {
278  fPersistentTree = NULL;
279  fInputFilesTree = NULL;
280  fInputKinemTree = NULL;
281  fInputTreeChain = NULL;
282  fFirstTreeName.clear();
283  fFileList.clear();
284  fInputFileNumber = -1;
285  fOrigEntryNumber = -1;
286  fInputFileName[0] = 0;
287  fInputFileGenerator[0] = 0;
288  fInputFileTreeName[0] = 0;
289  return;
290 }
char fInputFileTreeName[128]
Used to fill the name of the tree for this file.
TTree * fInputKinemTree
Tree relating all events in the persistent tree to an input file.
std::string fFirstTreeName
Store the first tree name.
TChain * fInputTreeChain
TChain to store input trees.
std::vector< std::string > fFileList
Used to store list of files before they are written to tree.
char fInputFileName[1024]
Used to fill input file list tree with input file name.
TTree * fInputFilesTree
Tree containing list of input files.
char fInputFileGenerator[128]
Used to fill the name of the generator for this file.
TTree * fPersistentTree
Persistent tree that stores entries from multiple temp trees.
int EDepSim::KinemPassThrough::LastEntryNumber ( )

Return the position (entry number) that the most recent entry to be copied to the pass-through tree will have.

Definition at line 242 of file EDepSimKinemPassThrough.cc.

242  {
243  // The most recent entry number is the sum of the entry number in
244  // the current tree plus the number of entries already stored in
245  // persistent tree.
246  if (!fPersistentTree) {
247  EDepSimError("No entries in fPersistent tree.");
248  return -1;
249  }
250  return fPersistentTree->GetEntries() - 1;
251 }
#define EDepSimError(outStream)
Definition: EDepSimLog.hh:503
TTree * fPersistentTree
Persistent tree that stores entries from multiple temp trees.
std::string EDepSim::KinemPassThrough::SetInputFileName ( std::string  name)
private

Set the name of the input file being read.

Definition at line 253 of file EDepSimKinemPassThrough.cc.

253  {
254  // Remove the path from the input file name.
255  std::string::size_type start_pos = name.rfind("/");
256  if (start_pos == std::string::npos) start_pos = 0; else ++start_pos;
257  std::string baseName(name,start_pos);
258 
259  return baseName;
260 }
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
static QCString baseName
Definition: scanner.cpp:10890

Member Data Documentation

std::vector<std::string> EDepSim::KinemPassThrough::fFileList
private

Used to store list of files before they are written to tree.

Definition at line 116 of file EDepSimKinemPassThrough.hh.

TreeToInt EDepSim::KinemPassThrough::fFirstEntryMap
private

for relating input tree to first entry in TChain.

Definition at line 113 of file EDepSimKinemPassThrough.hh.

std::string EDepSim::KinemPassThrough::fFirstTreeName
private

Store the first tree name.

Definition at line 107 of file EDepSimKinemPassThrough.hh.

int EDepSim::KinemPassThrough::fInputFileEntries
private

Used to fill input file list tree "nEntriesTot" field. This is the total number of entries in the input tree.

Definition at line 148 of file EDepSimKinemPassThrough.hh.

char EDepSim::KinemPassThrough::fInputFileGenerator[128]
private

Used to fill the name of the generator for this file.

Definition at line 138 of file EDepSimKinemPassThrough.hh.

char EDepSim::KinemPassThrough::fInputFileName[1024]
private

Used to fill input file list tree with input file name.

Definition at line 135 of file EDepSimKinemPassThrough.hh.

int EDepSim::KinemPassThrough::fInputFileNumber
private

Used to fill the bookkeeping tree "inputFileNum" field. This is the entry number of the input file in the input file tree.

Definition at line 124 of file EDepSimKinemPassThrough.hh.

double EDepSim::KinemPassThrough::fInputFilePOT
private

Used to fill input file list tree "filePOT" field.

Definition at line 144 of file EDepSimKinemPassThrough.hh.

TTree* EDepSim::KinemPassThrough::fInputFilesTree
private

Tree containing list of input files.

Definition at line 132 of file EDepSimKinemPassThrough.hh.

char EDepSim::KinemPassThrough::fInputFileTreeName[128]
private

Used to fill the name of the tree for this file.

Definition at line 141 of file EDepSimKinemPassThrough.hh.

TTree* EDepSim::KinemPassThrough::fInputKinemTree
private

Tree relating all events in the persistent tree to an input file.

Definition at line 120 of file EDepSimKinemPassThrough.hh.

TChain* EDepSim::KinemPassThrough::fInputTreeChain
private

TChain to store input trees.

Definition at line 104 of file EDepSimKinemPassThrough.hh.

TreeToInt EDepSim::KinemPassThrough::fInputTreeMap
private

for relating input tree pointers to the input file.

Definition at line 110 of file EDepSimKinemPassThrough.hh.

EDepSim::KinemPassThrough * EDepSim::KinemPassThrough::fKinemPassThrough = NULL
staticprivate

Static pointer to singleton instance.

Definition at line 85 of file EDepSimKinemPassThrough.hh.

int EDepSim::KinemPassThrough::fOrigEntryNumber
private

Used to fill the bookkeeping tree "origEntryNum" field. This is the entry number of the event in the original tree.

Definition at line 128 of file EDepSimKinemPassThrough.hh.

TTree* EDepSim::KinemPassThrough::fPersistentTree
private

Persistent tree that stores entries from multiple temp trees.

Definition at line 101 of file EDepSimKinemPassThrough.hh.


The documentation for this class was generated from the following files: