4 #include "KVSimReader.h"
5 #include "TDirectory.h"
6 #include "TStopwatch.h"
16 linked_info.SetName(
"Simulation info");
17 linked_objects.SetName(
"List of objects");
29 KVError::Error(
this,
"ReadFileHeader",
"Error reading the file header");
97 void KVSimReader::InitializeOutputFileAndTree()
111 auto filename = GetCurrentRootFileName();
112 if (!fOutputDirectory.EndsWith(
"/")) fOutputDirectory +=
"/";
113 filename.Prepend(fOutputDirectory);
114 file =
new TFile(filename,
"recreate");
115 KVError::Info(
this,
"InitializeOutputFileAndTree",
"Opened output file: %s", filename.Data());
117 tree =
new TTree(tree_name, tree_title);
126 void KVSimReader::ReadEventsInFile()
130 total_nevents=total_nevents_current_output_file=0;
139 if(NeedNewOutputFile())
142 InitializeOutputFileAndTree();
143 total_nevents_current_output_file=0;
145 ++total_nevents_current_output_file;
147 if(OutputFileIsFull())
249 TString KVSimReader::GetCurrentRootFileName()
252 filename = root_file_name;
253 if (fMultiFiles) filename += Form(
".%d", fFileIndex);
254 if(max_number_events_per_output_file)
255 filename += Form(
".%d", current_output_file_index++);
269 if(!NeedNewOutputFile())
282 TPluginHandler* ph =
LoadPlugin(
"KVSimReader", model_uri);
284 ::Error(
"KVSimReader::MakeSimReader",
"No plugin defined with name %s", model_uri);
294 void KVSimReader::Run()
302 InitializeOutputFileAndTree();
308 AddInfo({
"date", GetDate()});
309 AddInfo({
"user", gSystem->GetUserInfo()->fUser});
317 void KVSimReader::SaveTree()
322 KVError::Info(
this,
"SaveTree",
"Writing %d events in file : %s", total_nevents_current_output_file, file->GetName());
365 void KVSimReader::WriteInfo()
367 TList* list = GetTree()->GetUserInfo();
368 Int_t nentries = linked_info.GetEntries();
369 for (Int_t ii = 0; ii < nentries; ii += 1) {
381 return &linked_objects;
391 void KVSimReader::AddObject(TObject* obj)
396 GetLinkedObjects()->
Add(obj);
403 void KVSimReader::WriteObjects()
406 TList* list = GetTree()->GetUserInfo();
407 Int_t nentries = linked_objects.GetEntries();
408 for (Int_t ii = 0; ii < nentries; ii += 1)
410 list->
Add(linked_objects.
At(ii));
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
static void MakeEventBranch(TTree *tree, const TString &branchname, T &event, Int_t bufsize=10000000)
void Clear(Option_t *opt="") override
Bool_t OpenFileToRead(const KVString &filename)
A generic named parameter storing values of different types.
KaliVeda extensions to ROOT collection classes.
void Add(TObject *obj) override
TObject * At(Int_t idx) const override
Container class for simulated nuclei, KVSimNucleus.
Nucleus in a simulated event.
Base class to convert output from different simulation codes into TTrees containing KVSimEvent event ...
virtual Bool_t ReadEventHeader(KVSimEvent *)
virtual Bool_t ReadNucleus(KVSimNucleus *)
virtual Bool_t ReadFileHeader()
static KVSimReader * MakeSimReader(const char *model_uri)
Returns an instance of a child class specific to given model.
virtual void NotifyChangeOfOutputFile()
void ConvertEventsInFile(KVString filename)
virtual Bool_t ReadEvent(KVSimEvent *evt)=0
void ConvertAndSaveEventsInFile(KVString filename)
Read events, convert and save in ROOT file(s)
virtual bool NeedToIterateReadEvent()
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Error(UserClass p, const char *location, const char *va_(fmt),...)
void Info(UserClass p, const char *location, const char *va_(fmt),...)