42 #include <boost/progress.hpp>
47 #include "reportingUtils.hpp"
48 #include "fileUtils.hpp"
54 using namespace boost;
63 const long int maxNmbEvents,
64 const string& ampLeafName,
65 const long int treeCacheSize,
69 printInfo <<
"opening input file '" << inFileName <<
"'" << endl;
70 ifstream inFile(inFileName.c_str());
71 if (not inFile or not inFile.good()) {
72 printErr <<
"cannot open amplitude file '" << inFileName <<
"'." << endl;
78 const string ampTreeName = fileNameFromPath(inFileName);
79 printInfo <<
"writing to tree '" << ampTreeName <<
"'" << endl;
80 outTree.SetName (ampTreeName.c_str());
81 outTree.SetTitle(ampTreeName.c_str());
82 const int splitLevel = 99;
83 const int bufSize = 256000;
84 outTree.Branch(ampLeafName.c_str(), &TreeLeaf, bufSize, splitLevel);
87 printInfo <<
"writing amplitudes..." << endl;
88 long int countEvents = 0;
89 streampos fileLength = fileSize(inFile);
90 streampos lastPos = inFile.tellg();
93 while (inFile.read((
char*)&,
sizeof(complex<double>))) {
97 progressIndicator += inFile.tellg() - lastPos;
98 lastPos = inFile.tellg();
99 if ((maxNmbEvents > 0) and (countEvents >= maxNmbEvents))
103 printInfo <<
"optimizing tree" << endl;
105 outTree.OptimizeBaskets(treeCacheSize, 1,
"d");
108 printInfo <<
"wrote amplitudes for " << countEvents <<
" events to tree "
109 <<
"'" << outTree.GetName() <<
"'" << endl;
116 const std::string& outFileName,
117 const long int maxNmbEvents,
118 const std::string& ampLeafName,
122 printInfo <<
"creating output file '" << outFileName <<
"'" << endl;
123 ofstream outFile(outFileName.c_str());
125 printWarn <<
"cannot create amplitude file '" << outFileName <<
"'." << endl;
131 inTree.SetBranchAddress(ampLeafName.c_str(), &TreeLeaf);
134 printInfo <<
"writing amplitudes..." << endl;
136 const long int nmbEventsTree = inTree.GetEntries();
137 const long int nmbEvents = ((maxNmbEvents > 0) ? min(maxNmbEvents, nmbEventsTree)
140 for (
long int eventIndex = 0; eventIndex < nmbEvents; ++eventIndex) {
143 if (inTree.LoadTree(eventIndex) < 0)
145 inTree.GetEntry(eventIndex);
149 printWarn <<
"amplitude leaf for event " << eventIndex <<
" is empty. skipping." << endl;
154 printWarn <<
"amplitude leaf for event " << eventIndex
156 <<
" writing only first amplitude."<< endl;
158 complex<double> amp = ampTreeLeaf->
amp();
159 outFile.write((
char*)(&),
sizeof(complex<double>));
163 printInfo <<
"wrote amplitudes for " << nmbEvents <<
" events to output file "
164 <<
"'" << outFileName <<
"'" << endl;