31#include "BDSOutputROOTEventHeader.hh"
32#include "BDSOutputROOTEventOptions.hh"
33#include "BDSOutputROOTEventModel.hh"
36#include "BeamAnalysis.hh"
38#include "DataLoader.hh"
39#include "EventAnalysis.hh"
40#include "HeaderAnalysis.hh"
41#include "ModelAnalysis.hh"
42#include "OptionsAnalysis.hh"
43#include "RBDSException.hh"
44#include "RebdsimTypes.hh"
45#include "RunAnalysis.hh"
47int main(
int argc,
char *argv[])
50 if (argc < 2 || argc > 4)
52 std::cout <<
"usage: rebdsim <analysisConfig> (<dataFile>) (<outputFile>)" << std::endl;
53 std::cout <<
" <datafile> (optional) - root file to operate on" << std::endl;
54 std::cout <<
" <outputfile> (optional) - output file name for analysis" << std::endl;
55 std::cout <<
" if no <datafile> and <outputfile> are specified, those from <analysisConfig> are used." << std::endl;
59 std::string configFilePath = std::string(argv[1]);
60 std::string configFileExtension = configFilePath.substr(configFilePath.find_last_of(
'.') + 1) ;
61 if (configFileExtension !=
"txt")
63 std::cerr <<
"Unrecognised extension for file: " << configFilePath <<
". Extension: " << configFileExtension << std::endl;
64 std::cerr <<
"Make sure the config file is plain text with the .txt extension!" << std::endl;
68 std::cout <<
"rebdsim> configuration file name : " << configFilePath << std::endl;
70 std::string inputFilePath =
"";
71 std::string outputFileName =
"";
74 {inputFilePath = std::string(argv[2]);}
76 {outputFileName = std::string(argv[3]);}
88 bool debug = config->
Debug();
100 unsigned long long int nEventsRequested = 0;
101 unsigned long long int nEventsInFileTotal = 0;
102 unsigned long long int nEventsInFileSkippedTotal = 0;
103 unsigned int distrFileLoopNTimes = 0;
105 nEventsInFileSkippedTotal,
107 distrFileLoopNTimes);
139 std::vector<Analysis*> analyses = {beaAnalysis,
145 for (
auto &analysis: analyses)
149 TFile* outputFile =
new TFile(config->
OutputFileName().c_str(),
"RECREATE");
161 TTree* headerTree =
new TTree(
"Header",
"REBDSIM Header");
162 headerTree->Branch(
"Header.",
"BDSOutputROOTEventHeader", headerOut);
164 headerTree->Write(
"", TObject::kOverwrite);
166 for (
auto& analysis : analyses)
167 {analysis->Write(outputFile);}
171 TTree* treeTest = modelTree->GetTree();
174 auto newTree = modelTree->CloneTree();
177 newTree->SetName(
"ModelTree");
178 newTree->Write(
"", TObject::kOverwrite);
183 std::cout <<
"Result written to: " << config->
OutputFileName() << std::endl;
186 for (
auto analysis : analyses)
190 {std::cerr << error.
what() << std::endl; exit(1);}
191 catch (
const std::exception& error)
192 {std::cerr << error.what() << std::endl; exit(1);}
virtual void Execute()
Method which calls all other methods in order.
Analysis of the options tree.
Configuration and configuration parser class.
std::string InputFilePath() const
Accessor.
bool PerEntryEvent() const
bool AllBranchesToBeActivated() const
bool GetOptionBool(const std::string &key) const
General accessor for option.
double PrintModuloFraction() const
Accessor.
static Config * Instance(const std::string &fileName="", const std::string &inputFilePath="", const std::string &outputFileName="", const std::string &defaultOutputFileSuffix="_ana")
Singleton accessor.
bool PerEntryModel() const
bool PerEntryOption() const
bool PrintOut() const
Accessor.
double GetOptionNumber(const std::string &key) const
General accessor for option.
bool Debug() const
Accessor.
bool EmittanceOnTheFly() const
Accessor.
bool PerEntryBeam() const
std::string OutputFileName() const
Accessor.
bool ProcessSamplers() const
Accessor.
const RBDS::VectorString & BranchesToBeActivated(const std::string &treeName) const
Loader for a ROOT file using classes used to generate the file.
std::vector< std::string > GetFileNames()
Accessor.
Event * GetEvent()
Accessor.
Beam * GetBeam()
Accessor.
Header * GetHeader()
Accessor.
TChain * GetBeamTree()
Accessor.
TChain * GetOptionsTree()
Accessor.
TChain * GetRunTree()
Accessor.
TChain * GetModelTree()
Accessor.
Options * GetOptions()
Accessor.
TChain * GetEventTree()
Accessor.
Model * GetModel()
Accessor.
TChain * GetHeaderTree()
Accessor.
Analysis of the model tree.
Analysis of the options tree.
General exception with possible name of object and message.
const char * what() const noexcept override
Override message in std::exception.