1 #include "SimpleLoopBase.hxx" 2 #include "Parameters.hxx" 7 const int NENTRIES_TREESAVE_SIMPLE=5000;
10 SimpleLoopBase::SimpleLoopBase(
int argc,
char *argv[]){
12 std::string programName = argv[0];
13 std::string paramFile =
"";
20 bool logMemory =
false;
23 int c = getopt(argc, argv,
"cvmn:o:p:s:");
40 std::istringstream tmp(optarg);
53 std::istringstream tmp(optarg);
65 std::cerr <<
"ERROR: No output file" << std::endl << std::endl;
71 std::cerr <<
"ERROR: No input file" << std::endl << std::endl;
73 }
else if (argc != optind + 1) {
74 std::cerr <<
"ERROR: Only one input file may be specified. To process multiple ROOT files, " << std::endl
75 <<
" list them in a text file, and specify that text file as the input." << std::endl << std::endl;
82 if (paramFile !=
"") {
120 if (!OutputManager::Initialize())
return false;
147 OutputManager::InitializeEntry();
160 _entry_count += entry1-entry0;
163 if (_entry_count%1000==0 || _entry_count == _entry_nmax)
164 std::cout <<
"entry: " << _entry_count <<
" of " << _entry_nmax <<
" (" << (100*_entry_count/_entry_nmax) <<
"%) --> " <<
_entry << std::endl;
167 if (!spillOK)
return false;
192 if (
_entry%NENTRIES_TREESAVE_SIMPLE == 0){
193 std::vector< TTree* >::iterator it;
195 (*it)->AutoSave(
"SaveSelf");
215 Header* headerp = &_input.header();
216 GetTree(OutputManager::header)->Branch(
"POTInfo",
"Header",&headerp,32000,0);
217 GetTree(OutputManager::header)->Fill();
220 std::vector< TTree* >::iterator it;
222 (*it)->AutoSave(
"SaveSelf");
226 OutputManager::Finalize();
255 std::cout <<
"SimpleLoopBase::Loop(). input tree has " << nentries <<
" entries. You cannot start from entry " << imin << std::endl;
260 if (nmax==0 || imin+nmax>nentries) _entry_nmax = nentries-imin;
261 else _entry_nmax = nmax;
264 _entry_imax = _entry_imin+_entry_nmax;
266 if (input().InputIsFlatTree())
267 std::cout <<
"SimpleLoopBase::Loop(). input tree has " << nentries <<
" entries for " << input().header().
GetPOT() <<
" good POT" << std::endl;
269 std::cout <<
"SimpleLoopBase::Loop(). input tree has " << nentries <<
" entries (POT counted on the fly)" << std::endl;
270 std::cout <<
"SimpleLoopBase::Loop(). loop over " << _entry_nmax <<
" entries from entry number "<< _entry_imin << std::endl;
274 gettimeofday(&tim, NULL);
275 double t0=tim.tv_sec+(tim.tv_usec/1000000.0);
280 while (
_entry<_entry_imax) {
287 gettimeofday(&tim, NULL);
288 double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
290 std::cout <<
"--------- time profile --------------" << std::endl;
291 std::cout << _entry_nmax <<
" entries processed in " << t1-t0 <<
" seconds" << std::endl;
303 SetFillSingleTree(OutputManager::config);
306 AddVar(OutputManager::config, SimpleLoopBase::CMTPATH,
"CMTPATH",
"C",
"the CMTPATH used to produce the output file");
307 FillVar(SimpleLoopBase::CMTPATH, (std::string)getenv(
"CMTPATH") );
310 AddVar(OutputManager::config, SimpleLoopBase::HOSTNAME,
"HOSTNAME",
"C",
"the machine used to produce the output file");
311 if (getenv(
"HOSTNAME"))
312 FillVar(SimpleLoopBase::HOSTNAME, (std::string)getenv(
"HOSTNAME") );
314 FillVar(SimpleLoopBase::HOSTNAME,
"unknown" );
317 AddVar(OutputManager::config, SimpleLoopBase::INPUTFILE,
"InputFile",
"C",
"the input file used to produce the output file");
321 AddVar(OutputManager::config, SimpleLoopBase::OriginalFile,
"OriginalFile",
"C",
"the original file used to produce the output file");
324 TChain* chain =
new TChain(
"config");
326 char OriginalFile[200]=
"unknown";
327 if (chain->FindLeaf(
"OriginalFile")){
328 chain->SetBranchAddress(
"OriginalFile", OriginalFile);
329 Long64_t centry = chain->LoadTree(0);
330 Int_t nb = chain->GetEntry(0);
334 FillVar(SimpleLoopBase::OriginalFile, OriginalFile );
344 ND::versioning().WriteClonesArray(*
GetTree(OutputManager::config));
361 GetTree(OutputManager::config)->Fill();
362 GetTree(OutputManager::config)->AutoSave(
"SaveSelf");
368 std::cout <<
"usage: " << programName <<
" [options] [input-file]" << std::endl;
369 std::cout << std::endl;
370 std::cout <<
"Options:" << std::endl;
371 std::cout <<
" -c Run in cosmics mode, putting all tracks in one 'bunch'" << std::endl;
372 std::cout <<
" -n <cnt> Only read <cnt> events" << std::endl;
373 std::cout <<
" -o <file> Set the name of an output file (mandatory)" << std::endl;
374 std::cout <<
" -s <cnt> Skip <cnt> events" << std::endl;
375 std::cout <<
" -p <file> Set the name of a parameter override file" << std::endl;
376 std::cout <<
" -v Don't Check version compatibility between nd280AnalysisTools and oaAnalysis file" << std::endl;
377 std::cout <<
" -m Log memory usage (written to histograms in output file)" << std::endl;
384 Loop(_entry_nmax,_entry_imin);
void AddVar(Int_t index, const std::string &name, const std::string &type, const std::string &doc, double ini=-9999)
Add a single variable to all trees.
void Loop(int nmax=0, int imin=0)
void AddTreeWithName(Int_t tree_index, const std::string &tree_name, TTree *tree=NULL)
Add a tree provided its index and name.
virtual void DefineOutputTree()
Define the tree that should be written to the output file.
CorrectionManager _corrections
Correction manager.
MemoryUsage _memory
Memory logging.
std::string _inputFileName
Input file name, as specified by the user.
virtual bool InitializeSpill()
void ApplyCorrections(AnaSpillC &spill)
Apply all corrections.
Long64_t _entry
The current entry in the file.
void PrintUsage(const std::string &programName)
Print the program's usage statement.
virtual void FinalizeSpill()
Finalize each spill, including cleaning up data read from the input file.
void ReadParamOverrideFile(TString filename)
virtual bool Initialize()
void FillVar(Int_t index, Float_t var)
Fill a single variable.
void DumpCorrections()
Dump all corrections.
std::vector< TTree *> & GetTrees()
Returns the map of trees.
void CloseOutputFile()
close the output file
DocStringManager _docStrings
DocStrings manager.
bool OpenOutputFile(const std::string &file)
open the output file
bool _versionCheck
Check version compatibility between nd280AnalysisTools compilation and oaAnalysis file...
void Enable(bool enable=true)
TTree * GetTree()
Returns the a tree set as current.
void FillConfigTree()
Fill the "config" tree, which includes details of the analysis cuts etc.
void Write()
Write histograms of the memory usage to the output file.
std::string _inputFileType
std::string _outputFileName
The output file name, as specified by the user.
void SetReadParamOverrideFilePointPassed()
Set whether the point in which the overwride parameters file is read is passed or not...
void ReadCorrections(const std::string &file, bool input=false)
Readthe corrections from a file.