File indexing completed on 2024-06-29 07:05:50
0001
0002
0003
0004
0005
0006
0007
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
0020
0021
0022
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
0030
0031
0032 TTree::SetMaxTreeSize(10LL * 1024LL * 1024LL * 1024LL);
0033
0034
0035
0036 TString outName = gSystem->BaseName(inputFileName.c_str());
0037
0038
0039 if ( outName.EndsWith(".gz", TString::kIgnoreCase) ||
0040 outName.EndsWith(".zip", TString::kIgnoreCase) )
0041 outName.Replace(outName.Last('.'), outName.Length(), "");
0042
0043
0044 if (outName.Last('.') > -1) {
0045 outName.Replace(outName.Last('.'), outName.Length(), "");
0046 }
0047
0048
0049
0050 if (maxEvent > 0) {
0051 outName.Append(".");
0052 outName += maxEvent;
0053 outName.Append("event");
0054 }
0055
0056 outName.Append(".root");
0057
0058 TString outDir(outputDirName);
0059 if (!outDir.EndsWith("/")) outDir.Append('/');
0060 outName.Prepend(outDir);
0061
0062
0063
0064
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();
0074 if (result != 0) {
0075 std::cerr << "Tree building failed" << std::endl;
0076 return result;
0077 }
0078
0079
0080
0081
0082 std::string logFile(logFileName);
0083 if (logFile.empty()) {
0084 logFile =
0085 erhic::LogReaderFactory::GetInstance().Locate(inputFileName.c_str());
0086 }
0087
0088
0089
0090
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 }
0100 delete reader;
0101 }
0102 }
0103
0104 return result;
0105 }