Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-29 07:05:50

0001 /**
0002  \file
0003  Defines the main BuildTree function.
0004 
0005  \author    Thomas Burton
0006  \date      2011-06-24
0007  \copyright 2011 Brookhaven National Lab
0008  */
0009 
0010 #include <string>
0011 
0012 #include <TString.h>
0013 #include <TSystem.h>
0014 
0015 #include "eicsmear/erhic/Forester.h"
0016 #include "eicsmear/erhic/File.h"
0017 
0018 /**
0019  This is an example function to generate ROOT files.
0020  It can be used "out of the box".
0021  If more control over the output is desired, then the settings of the
0022  Forester can be tweaked to do so.
0023  */
0024 Long64_t
0025 BuildTree(const std::string& inputFileName,
0026           const std::string& outputDirName,
0027           const Long64_t maxEvent,
0028           const std::string& logFileName) {
0029   // Set the maximum size of the tree on disk.
0030   // Once this size is reached a new file is opened for continued writing.
0031   // Set 10 Gb. Us LL to force long integer.
0032   TTree::SetMaxTreeSize(10LL * 1024LL * 1024LL * 1024LL);
0033 
0034   // Get the input file name, stripping any leading directory path via
0035   // use of the BaseName() method from TSystem.
0036   TString outName = gSystem->BaseName(inputFileName.c_str());
0037 
0038   // Remove zip extension, if there is one.
0039   if ( outName.EndsWith(".gz", TString::kIgnoreCase) ||
0040        outName.EndsWith(".zip", TString::kIgnoreCase) )
0041     outName.Replace(outName.Last('.'), outName.Length(), "");
0042     
0043   // Remove the remaining extension, if there is one.
0044   if (outName.Last('.') > -1) {
0045     outName.Replace(outName.Last('.'), outName.Length(), "");
0046   }  // if
0047 
0048   // If we are analysing a subset of events, include the number of events in
0049   // the file name before the extension.
0050   if (maxEvent > 0) {
0051     outName.Append(".");
0052     outName += maxEvent;
0053     outName.Append("event");
0054   }  // if
0055 
0056   outName.Append(".root");
0057 
0058   TString outDir(outputDirName);
0059   if (!outDir.EndsWith("/")) outDir.Append('/');
0060   outName.Prepend(outDir);
0061 
0062 
0063   // Configure an object of class Forester, which handles processing the text
0064   // file into a tree.
0065   erhic::Forester forester;
0066   forester.SetInputFileName(inputFileName);
0067   forester.SetOutputFileName(std::string(outName.Data()));  //
0068   forester.SetMaxNEvents(maxEvent);
0069   forester.SetMessageInterval(10000);
0070   forester.SetBeVerbose(true);
0071   forester.SetBranchName("event");
0072 
0073   Long64_t result = forester.Plant();  // Plant that tree!
0074   if (result != 0) {
0075     std::cerr << "Tree building failed" << std::endl;
0076     return result;
0077   }  // if
0078 
0079   // Search the log file for information.
0080   // Use the provided log file name if there is one, otherwise attempt
0081   // automated procedure to locate it.
0082   std::string logFile(logFileName);
0083   if (logFile.empty()) {
0084     logFile =
0085     erhic::LogReaderFactory::GetInstance().Locate(inputFileName.c_str());
0086   }  // if
0087 
0088   // Use the FileType created by Forester when running to generate a
0089   // LogReader to process the log file, assuming a FileType was created and
0090   // the log file was located.
0091   if (forester.GetFileType() && !logFile.empty()) {
0092     TFile rootFile(outName, "UPDATE");
0093     erhic::LogReader* reader =
0094     forester.GetFileType()->CreateLogReader();
0095     if (reader) {
0096       bool wasRead = (reader ? reader->Extract(logFile) : false);
0097       if (wasRead) {
0098         reader->Save();
0099       }  // if
0100       delete reader;
0101     }  // if
0102   }  // if
0103 
0104   return result;
0105 }