20#include "BDSException.hh"
21#include "BDSOutputLoaderSampler.hh"
22#include "BDSOutputROOTEventOptions.hh"
23#include "BDSOutputROOTEventSampler.hh"
24#include "BDSUtilities.hh"
28#include "RtypesCore.h"
34BDSOutputLoaderSampler::BDSOutputLoaderSampler(
const G4String& filePath,
35 const G4String& samplerName):
37 doublePrecision(false),
39 localSamplerFloat(nullptr),
40 localSamplerDouble(nullptr)
42 G4String samplerNameLocal = samplerName;
44 {samplerNameLocal +=
".";}
46 TBranch* search = eventTree->GetBranch(samplerNameLocal);
48 {
throw BDSException(__METHOD_NAME__,
"no such sampler name \"" + samplerName +
"\"");}
52 doublePrecision = localOptions->outputDoublePrecision;
53 if (localOptions->outputDoublePrecision)
54 {eventTree->SetBranchAddress(samplerNameLocal, &localSamplerDouble);}
56 {eventTree->SetBranchAddress(samplerNameLocal, &localSamplerFloat);}
57 nEvents = (G4long)eventTree->GetEntries();
60BDSOutputLoaderSampler::~BDSOutputLoaderSampler()
62 delete localSamplerFloat;
63 delete localSamplerDouble;
68 localSamplerFloat->
Flush();
70 return localSamplerFloat;
75 localSamplerDouble->
Flush();
77 return localSamplerDouble;
80void BDSOutputLoaderSampler::Common(G4long eventNumber)
82 if (eventNumber > nEvents)
84 G4String msg =
"requested event number " + std::to_string(eventNumber);
85 msg +=
" is beyond number of entries in the file (" + std::to_string(nEvents) +
")";
93 if (eventNumber > eventTree->GetEntries())
95 G4cout << __METHOD_NAME__ <<
"event index beyond number stored in file - no seed state loaded" << G4endl;
98 eventTree->GetEntry((Long64_t)eventNumber);
General exception with possible name of object and message.
Loader of ROOT Event output for recreating events.
virtual void Flush()
Clean Sampler.
G4bool EndsWith(const std::string &expression, const std::string &suffix)
Return true if a string "expression" ends with "suffix".