30#include "BDSOutputROOTEventHeader.hh"
31#include "BDSOutputROOTEventOptions.hh"
32#include "BDSOutputROOTEventModel.hh"
35#include "BeamAnalysis.hh"
37#include "DataLoader.hh"
38#include "EventAnalysis.hh"
39#include "HeaderAnalysis.hh"
40#include "ModelAnalysis.hh"
41#include "OptionsAnalysis.hh"
42#include "RBDSException.hh"
43#include "RebdsimTypes.hh"
44#include "RunAnalysis.hh"
46int main(
int argc,
char *argv[])
49 if (argc < 2 || argc > 4)
51 std::cout <<
"usage: rebdsim <analysisConfig> (<dataFile>) (<outputFile>)" << std::endl;
52 std::cout <<
" <datafile> (optional) - root file to operate on" << std::endl;
53 std::cout <<
" <outputfile> (optional) - output file name for analysis" << std::endl;
54 std::cout <<
" if no <datafile> and <outputfile> are specified, those from <analysisConfig> are used." << std::endl;
58 std::string configFilePath = std::string(argv[1]);
59 std::string configFileExtension = configFilePath.substr(configFilePath.find_last_of(
'.') + 1) ;
60 if (configFileExtension !=
"txt")
62 std::cerr <<
"Unrecognised extension for file: " << configFilePath <<
". Extension: " << configFileExtension << std::endl;
63 std::cerr <<
"Make sure the config file is plain text with the .txt extension!" << std::endl;
67 std::cout <<
"rebdsim> configuration file name : " << configFilePath << std::endl;
69 std::string inputFilePath =
"";
70 std::string outputFileName =
"";
73 {inputFilePath = std::string(argv[2]);}
75 {outputFileName = std::string(argv[3]);}
87 bool debug = config->
Debug();
96 dl->GetAllSphericalSamplerNames());
102 unsigned long long int nEventsRequested = 0;
103 unsigned long long int nEventsInFileTotal = 0;
104 unsigned long long int nEventsInFileSkippedTotal = 0;
105 unsigned int distrFileLoopNTimes = 0;
107 nEventsInFileSkippedTotal,
109 distrFileLoopNTimes);
141 std::vector<Analysis*> analyses = {beaAnalysis,
147 for (
auto &analysis: analyses)
151 TFile* outputFile =
new TFile(config->
OutputFileName().c_str(),
"RECREATE");
163 TTree* headerTree =
new TTree(
"Header",
"REBDSIM Header");
164 headerTree->Branch(
"Header.",
"BDSOutputROOTEventHeader", headerOut);
166 headerTree->Write(
"", TObject::kOverwrite);
168 for (
auto& analysis : analyses)
169 {analysis->Write(outputFile);}
173 TTree* treeTest = modelTree->GetTree();
176 auto newTree = modelTree->CloneTree();
179 newTree->SetName(
"ModelTree");
180 newTree->Write(
"", TObject::kOverwrite);
185 std::cout <<
"Result written to: " << config->
OutputFileName() << std::endl;
188 for (
auto analysis : analyses)
192 {std::cerr << error.
what() << std::endl; exit(1);}
193 catch (
const std::exception& error)
194 {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
Accessor.
bool GetOptionBool(const std::string &key) const
General accessor for option.
double PrintModuloFraction() const
Accessor.
void FixCylindricalAndSphericalSamplerVariablesInSets(const std::set< std::string > &allCNames, const std::set< std::string > &allSNames)
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.