eic-smear  1.0.3
A collection of ROOT classes for Monte Carlo events and a fast-smearing code simulating detector effects for the Electron-Ion Collider task force
BuildTree.cxx
Go to the documentation of this file.
1 
10 #include <string>
11 
12 #include <TString.h>
13 #include <TSystem.h>
14 
16 #include "eicsmear/erhic/File.h"
17 
24 Long64_t
25 BuildTree(const TString& inputFileName,
26  const TString& outputDirName,
27  const Long64_t maxEvent,
28  const std::string& logFileName) {
29  // Set the maximum size of the tree on disk.
30  // Once this size is reached a new file is opened for continued writing.
31  // Set 10 Gb. Us LL to force long integer.
32  TTree::SetMaxTreeSize(10LL * 1024LL * 1024LL * 1024LL);
33 
34  // Get the input file name, stripping any leading directory path via
35  // use of the BaseName() method from TSystem.
36  TString outName = gSystem->BaseName(inputFileName);
37 
38  // Remove the existing extension, if there is one.
39  if (outName.Last('.') > -1) {
40  outName.Replace(outName.Last('.'), outName.Length(), "");
41  } // if
42 
43  // If we are analysing a subset of events, include the number of events in
44  // the file name before the extension.
45  if (maxEvent > 0) {
46  outName.Append(".");
47  outName += maxEvent;
48  outName.Append("event");
49  } // if
50 
51  outName.Append(".root");
52 
53  TString outDir(outputDirName);
54  if (!outDir.EndsWith("/")) outDir.Append('/');
55  outName.Prepend(outDir);
56 
57  // Configure an object of class Forester, which handles processing the text
58  // file into a tree.
59  erhic::Forester forester;
60  forester.SetInputFileName(std::string(inputFileName));
61  forester.SetOutputFileName(std::string(outName));
62  forester.SetMaxNEvents(maxEvent);
63  forester.SetMessageInterval(10000);
64  forester.SetBeVerbose(true);
65  forester.SetBranchName("event");
66 
67  Long64_t result = forester.Plant(); // Plant that tree!
68  if (result != 0) {
69  std::cerr << "Tree building failed" << std::endl;
70  return result;
71  } // if
72 
73  // Search the log file for information.
74  // Use the provided log file name if there is one, otherwise attempt
75  // automated procedure to locate it.
76  std::string logFile(logFileName);
77  if (logFile.empty()) {
78  logFile =
79  erhic::LogReaderFactory::GetInstance().Locate(inputFileName.Data());
80  } // if
81 
82  // Use the FileType created by Forester when running to generate a
83  // LogReader to process the log file, assuming a FileType was created and
84  // the log file was located.
85  if (forester.GetFileType() && !logFile.empty()) {
86  TFile rootFile(outName, "UPDATE");
87  erhic::LogReader* reader =
88  forester.GetFileType()->CreateLogReader();
89  if (reader) {
90  bool wasRead = (reader ? reader->Extract(logFile) : false);
91  if (wasRead) {
92  reader->Save();
93  } // if
94  delete reader;
95  } // if
96  } // if
97 
98  return result;
99 }
Long64_t BuildTree(const TString &inputFileName, const TString &outputDirName, const Long64_t maxEvent, const std::string &logFileName)
Definition: BuildTree.cxx:25
virtual LogReader * CreateLogReader() const =0
void SetMessageInterval(Long64_t=10000)
Definition: Forester.h:332
void SetBranchName(const std::string &="event")
Definition: Forester.h:304
std::string Locate(const std::string &mcFile) const
Definition: File.cxx:427
Long64_t Plant()
Definition: Forester.cxx:67
const erhic::FileType * GetFileType() const
Definition: Forester.h:352
static LogReaderFactory & GetInstance()
Definition: File.cxx:360
virtual bool Extract(const std::string &file)=0
void SetInputFileName(const std::string &)
Definition: Forester.h:292
void SetMaxNEvents(Long64_t=0)
Definition: Forester.h:324
void SetOutputFileName(const std::string &)
Definition: Forester.h:296
void SetBeVerbose(bool=false)
Definition: Forester.h:344
virtual Int_t Save() const =0