EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BuildTree.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BuildTree.cxx
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 std::string& inputFileName,
26  const std::string& 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.c_str());
37 
38  // Remove zip extension, if there is one.
39  if ( outName.EndsWith(".gz", TString::kIgnoreCase) ||
40  outName.EndsWith(".zip", TString::kIgnoreCase) )
41  outName.Replace(outName.Last('.'), outName.Length(), "");
42 
43  // Remove the remaining extension, if there is one.
44  if (outName.Last('.') > -1) {
45  outName.Replace(outName.Last('.'), outName.Length(), "");
46  } // if
47 
48  // If we are analysing a subset of events, include the number of events in
49  // the file name before the extension.
50  if (maxEvent > 0) {
51  outName.Append(".");
52  outName += maxEvent;
53  outName.Append("event");
54  } // if
55 
56  outName.Append(".root");
57 
58  TString outDir(outputDirName);
59  if (!outDir.EndsWith("/")) outDir.Append('/');
60  outName.Prepend(outDir);
61 
62 
63  // Configure an object of class Forester, which handles processing the text
64  // file into a tree.
65  erhic::Forester forester;
66  forester.SetInputFileName(inputFileName);
67  forester.SetOutputFileName(std::string(outName.Data())); //
68  forester.SetMaxNEvents(maxEvent);
69  forester.SetMessageInterval(10000);
70  forester.SetBeVerbose(true);
71  forester.SetBranchName("event");
72 
73  Long64_t result = forester.Plant(); // Plant that tree!
74  if (result != 0) {
75  std::cerr << "Tree building failed" << std::endl;
76  return result;
77  } // if
78 
79  // Search the log file for information.
80  // Use the provided log file name if there is one, otherwise attempt
81  // automated procedure to locate it.
82  std::string logFile(logFileName);
83  if (logFile.empty()) {
84  logFile =
85  erhic::LogReaderFactory::GetInstance().Locate(inputFileName.c_str());
86  } // if
87 
88  // Use the FileType created by Forester when running to generate a
89  // LogReader to process the log file, assuming a FileType was created and
90  // the log file was located.
91  if (forester.GetFileType() && !logFile.empty()) {
92  TFile rootFile(outName, "UPDATE");
94  forester.GetFileType()->CreateLogReader();
95  if (reader) {
96  bool wasRead = (reader ? reader->Extract(logFile) : false);
97  if (wasRead) {
98  reader->Save();
99  } // if
100  delete reader;
101  } // if
102  } // if
103 
104  return result;
105 }