/
BuildTree.cxx
105 lines (88 loc) · 3.15 KB
/
BuildTree.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
\file
Defines the main BuildTree function.
\author Thomas Burton
\date 2011-06-24
\copyright 2011 Brookhaven National Lab
*/
#include <string>
#include <TString.h>
#include <TSystem.h>
#include "eicsmear/erhic/Forester.h"
#include "eicsmear/erhic/File.h"
/**
This is an example function to generate ROOT files.
It can be used "out of the box".
If more control over the output is desired, then the settings of the
Forester can be tweaked to do so.
*/
Long64_t
BuildTree(const std::string& inputFileName,
const std::string& outputDirName,
const Long64_t maxEvent,
const std::string& logFileName) {
// Set the maximum size of the tree on disk.
// Once this size is reached a new file is opened for continued writing.
// Set 10 Gb. Us LL to force long integer.
TTree::SetMaxTreeSize(10LL * 1024LL * 1024LL * 1024LL);
// Get the input file name, stripping any leading directory path via
// use of the BaseName() method from TSystem.
TString outName = gSystem->BaseName(inputFileName.c_str());
// Remove zip extension, if there is one.
if ( outName.EndsWith(".gz", TString::kIgnoreCase) ||
outName.EndsWith(".zip", TString::kIgnoreCase) )
outName.Replace(outName.Last('.'), outName.Length(), "");
// Remove the remaining extension, if there is one.
if (outName.Last('.') > -1) {
outName.Replace(outName.Last('.'), outName.Length(), "");
} // if
// If we are analysing a subset of events, include the number of events in
// the file name before the extension.
if (maxEvent > 0) {
outName.Append(".");
outName += maxEvent;
outName.Append("event");
} // if
outName.Append(".root");
TString outDir(outputDirName);
if (!outDir.EndsWith("/")) outDir.Append('/');
outName.Prepend(outDir);
// Configure an object of class Forester, which handles processing the text
// file into a tree.
erhic::Forester forester;
forester.SetInputFileName(inputFileName);
forester.SetOutputFileName(std::string(outName.Data())); //
forester.SetMaxNEvents(maxEvent);
forester.SetMessageInterval(10000);
forester.SetBeVerbose(true);
forester.SetBranchName("event");
Long64_t result = forester.Plant(); // Plant that tree!
if (result != 0) {
std::cerr << "Tree building failed" << std::endl;
return result;
} // if
// Search the log file for information.
// Use the provided log file name if there is one, otherwise attempt
// automated procedure to locate it.
std::string logFile(logFileName);
if (logFile.empty()) {
logFile =
erhic::LogReaderFactory::GetInstance().Locate(inputFileName.c_str());
} // if
// Use the FileType created by Forester when running to generate a
// LogReader to process the log file, assuming a FileType was created and
// the log file was located.
if (forester.GetFileType() && !logFile.empty()) {
TFile rootFile(outName, "UPDATE");
erhic::LogReader* reader =
forester.GetFileType()->CreateLogReader();
if (reader) {
bool wasRead = (reader ? reader->Extract(logFile) : false);
if (wasRead) {
reader->Save();
} // if
delete reader;
} // if
} // if
return result;
}