KaliVeda
Toolkit for HIC analysis
KVSimReader.h
1 
4 #ifndef __KVSIMREADER_H
5 #define __KVSIMREADER_H
6 
7 #include "KVSimEvent.h"
8 #include "KVSimNucleus.h"
9 #include "KVString.h"
10 #include "TTree.h"
11 #include "TFile.h"
12 #include "KVUnownedList.h"
13 #include "TObject.h"
14 #include "TDatime.h"
15 #include "KVFileReader.h"
16 
116 class KVSimReader : public KVFileReader
117 {
118  void init();
119  TTree* tree = nullptr;
120  TFile* file = nullptr;
121  KVSimEvent* evt = nullptr;
122 
123  Int_t total_nevents,total_nevents_current_output_file;
124  KVString tree_name{"SIMULATION_NAME"}, tree_title{"SIMULATION"},
125  branch_name{"Simulated_evts"}, root_file_name{"Output.root"};
126  Bool_t fMultiFiles = false;
127  Int_t fFileIndex = 1;
128  TString fOutputDirectory = "./";
129 
130  KVUnownedList linked_info;
131  KVUnownedList linked_objects;
132 
133  std::optional<int> max_number_events_per_output_file;
134  int current_output_file_index=0;
135 
136  bool OutputFileIsFull() const
137  {
138  return max_number_events_per_output_file
139  && total_nevents_current_output_file==*max_number_events_per_output_file;
140  }
141  bool NeedNewOutputFile() const
142  {
143  return !(file && file->IsOpen());
144  }
145  KVString GetDate()
146  {
147  TDatime now;
148  KVString stime;
149  stime.Form("%d_%02d_%02d_%02d:%02d:%02d",
150  now.GetYear(),
151  now.GetMonth(),
152  now.GetDay(),
153  now.GetHour(),
154  now.GetMinute(),
155  now.GetSecond()
156  );
157  return stime;
158  }
159  void InitializeOutputFileAndTree();
160  void FillTree()
161  {
162  GetTree()->Fill();
163  }
164 
165  void SaveTree();
166  void Run();
167 
168  void WriteObjects();
169  void CreateObjectList();
170 
171  TTree* GetTree()
172  {
173  return tree;
174  }
175  void WriteInfo();
176  void ReadEventsInFile();
177  TString GetCurrentRootFileName();
178 
179  protected:
180  KVSeqCollection* GetLinkedObjects();
181  void AddObject(TObject* obj);
182  KVSeqCollection* GetSimuInfo();
183  void AddInfo(const KVNamedParameter&);
184 
185  public:
186  KVSimReader();
187 
189 
190  int GetEventNumber() const { return total_nevents; }
191 
193  {
197  max_number_events_per_output_file=nev;
198  }
199 
200  void SetMultiFiles(Bool_t on = kTRUE)
201  {
202  fMultiFiles = on;
203  }
205  {
206  fFileIndex = i;
207  }
208  void SetOutputDirectory(const TString& where)
209  {
210  fOutputDirectory = where;
211  }
212 
213  virtual Bool_t ReadFileHeader();
215 
226  virtual Bool_t ReadEvent(KVSimEvent*evt) = 0;
227 
228  virtual Bool_t ReadNucleus(KVSimNucleus*);
229  virtual void NotifyChangeOfOutputFile();
230  virtual bool NeedToIterateReadEvent();
231 
233  {
235  tree_name = n;
236  }
238  {
240  tree_title = n;
241  }
243  {
245  return tree_title ;
246  }
248  {
252  root_file_name = name;
253  if(root_file_name.Index(".root")>0)
254  root_file_name.Remove(root_file_name.Index(".root"));
255  }
257  {
259  branch_name = n;
260  }
261 
262  void ConvertAndSaveEventsInFile(KVString filename);
263 
264  static KVSimReader* MakeSimReader(const char* model_uri);
265 
266  ClassDef(KVSimReader, 0) //Base class to read output files for simulation and create tree using KVEvent type class
267 };
268 
269 #endif
int Int_t
bool Bool_t
#define ClassDef(name, id)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Handle reading columns of numeric data in text files.
Definition: KVFileReader.h:121
A generic named parameter storing values of different types.
KaliVeda extensions to ROOT collection classes.
Container class for simulated nuclei, KVSimNucleus.
Definition: KVSimEvent.h:22
Nucleus in a simulated event.
Definition: KVSimNucleus.h:32
Base class to convert output from different simulation codes into TTrees containing KVSimEvent event ...
Definition: KVSimReader.h:117
void SetROOTFileName(KVString name)
Definition: KVSimReader.h:247
void SetMaxNumEventsPerOutputFile(int nev)
Definition: KVSimReader.h:192
KVString GetTreeTitle() const
Definition: KVSimReader.h:242
void SetOutputDirectory(const TString &where)
Definition: KVSimReader.h:208
virtual Bool_t ReadEventHeader(KVSimEvent *)
void SetTreeTitle(KVString n)
Definition: KVSimReader.h:237
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)
Definition: KVSimReader.cpp:24
void SetBranchName(KVString n)
Definition: KVSimReader.h:256
int GetEventNumber() const
Definition: KVSimReader.h:190
void SetFileIndex(Int_t i)
Definition: KVSimReader.h:204
virtual Bool_t ReadEvent(KVSimEvent *evt)=0
void SetMultiFiles(Bool_t on=kTRUE)
Definition: KVSimReader.h:200
void ConvertAndSaveEventsInFile(KVString filename)
Read events, convert and save in ROOT file(s)
void SetTreeName(KVString n)
Definition: KVSimReader.h:232
virtual bool NeedToIterateReadEvent()
Definition: KVSimReader.cpp:59
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
Extended TList class which does not own its objects by default.
Definition: KVUnownedList.h:20
Int_t GetMonth() const
Int_t GetDay() const
Int_t GetHour() const
Int_t GetSecond() const
Int_t GetYear() const
Int_t GetMinute() const
void Form(const char *fmt,...)
TString & Remove(EStripType s, char c)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual Int_t Fill()
const Int_t n