KaliVeda
Toolkit for HIC analysis
KVSimReader.cpp
1 //Created by KVClassFactory on Wed Jun 30 17:45:01 2010
2 //Author: bonnet
3 
4 #include "KVSimReader.h"
5 #include "TDirectory.h"
6 #include "TStopwatch.h"
7 
9 
10 
11 
14  : evt{new KVSimEvent}
15 {
16  linked_info.SetName("Simulation info");
17  linked_objects.SetName("List of objects");
18 }
19 
20 
21 
23 
25 {
26  if (!OpenFileToRead(filename)) return;
27  Run();
28  CloseFile();
29 }
30 
31 
32 
34 
36 {
37  nv.Clear();
38  GetSimuInfo()->Clear();
40 }
41 
42 
43 
55 
57 {
58  // Use root_file_name as basename for file
59  //
60  // If multiple files are being read, they will be named
61  //~~~
62  // [root_file_name].1
63  // [root_file_name].2
64  // [root_file_name].etc
65  //~~~
66  //
67  // Files are written in fOutputDirectory (default: "./")
68 
70  filename = root_file_name;
71  if (fMultiFiles) filename += Form(".%d", fFileIndex);
72  if (!fOutputDirectory.EndsWith("/")) fOutputDirectory += "/";
73  filename.Prepend(fOutputDirectory);
74  KVError::Info(this, "DeclareTree", "Opened output file: %s", filename.Data());
75  file = new TFile(filename, option);
76 
77  tree = new TTree(tree_name, tree_title);
78  KVEvent::MakeEventBranch(tree, branch_name, evt);
79 }
80 
81 
82 
84 
86 {
87  AbstractMethod("ReadFile");
88 }
89 
90 
91 
93 
95 {
96 
97  AbstractMethod("ReadHeader");
98  return kTRUE;
99 }
100 
101 
102 
104 
106 {
107  AbstractMethod("ReadEvent");
108  return kTRUE;
109 }
110 
111 
112 
114 
116 {
117  AbstractMethod("ReadNucleus");
118  return kTRUE;
119 }
120 
121 
122 
125 
127 {
128  // Read events, convert and save in ROOT file
130  SaveTree();
131 }
132 
133 
134 
137 
139 {
140  // Returns an instance of a child class specific to given model.
141 
142  TPluginHandler* ph = LoadPlugin("KVSimReader", model_uri);
143  if (!ph) {
144  ::Error("KVSimReader::MakeSimReader", "No plugin defined with name %s", model_uri);
145  return nullptr;
146  }
147  return (KVSimReader*)ph->ExecPlugin(0);
148 }
149 
150 
151 
153 
155 {
156 
157  AddInfo({"ascii file read", GetFileName()});
158 
159  TStopwatch chrono;
160  chrono.Start();
161 
162  if (HasToFill()) DeclareTree(option);
163  nuc = nullptr;
164  nevt = 0;
165 
166  ReadFile();
167 
168  if (HasToFill())
169  GetTree()->ResetBranchAddress(GetTree()->GetBranch(branch_name.Data()));
170 
171  chrono.Stop();
172 
173  //Info("Run","%d evts lus en %lf seconds",GetNumberOfEvents(),chrono.RealTime());
174 
175  AddInfo({"number of events read", nevt});
176  AddInfo({"date", GetDate()});
177  AddInfo({"user", gSystem->GetUserInfo()->fUser});
178 
179 }
180 
181 
182 
184 
186 {
187  WriteObjects();
188  WriteInfo();
189 
190  GetTree()->Write();
191  CleanAll();
192  file->Close();
193 }
194 
195 
196 
198 
200 {
201  return &linked_info;
202 }
203 
204 
205 
212 
213 void KVSimReader::AddInfo(const KVNamedParameter& info)
214 {
215  // Add information on simulation using KVNamedParameter, can be int, double or string:
216  //~~~{.cpp}
217  // AddInfo({"model", "AMD"});
218  // AddInfo({"sigma_NN_screen_factor", 0.85});
219  // AddInfo({"N_part_test", 150});
220 
221  linked_info.Add(new KVNamedParameter(info));
222 }
223 
224 
225 
227 
229 {
230  TList* list = GetTree()->GetUserInfo();
231  Int_t nentries = linked_info.GetEntries();
232  for (Int_t ii = 0; ii < nentries; ii += 1) {
233  list->Add(linked_info.RemoveAt(0));
234  }
235 }
236 
237 
238 
240 
242 {
243  return &linked_objects;
244 }
245 
246 
247 
249 
251 {
252  GetLinkedObjects()->Add(obj);
253 }
254 
255 
256 
258 
260 {
261 
262  TList* list = GetTree()->GetUserInfo();
263  Int_t nentries = linked_objects.GetEntries();
264  for (Int_t ii = 0; ii < nentries; ii += 1) {
265  list->Add(linked_objects.RemoveAt(0));
266  }
267 
268 }
269 
270 
int Int_t
bool Bool_t
constexpr Bool_t kTRUE
const char Option_t
Option_t Option_t option
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
int nentries
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:795
static void MakeEventBranch(TTree *tree, const TString &branchname, T &event, Int_t bufsize=10000000)
Definition: KVEvent.h:211
KVString GetFileName()
Definition: KVFileReader.h:190
void CloseFile()
Definition: KVFileReader.h:237
Bool_t OpenFileToRead(const KVString &filename)
Definition: KVFileReader.h:210
void Clear(Option_t *opt="") override
A generic named parameter storing values of different types.
KaliVeda extensions to ROOT collection classes.
void Add(TObject *obj) override
void Clear(Option_t *option="") override
Container class for simulated nuclei, KVSimNucleus.
Definition: KVSimEvent.h:22
Base class to read output files for simulation and create tree using KVSimEvent class.
Definition: KVSimReader.h:51
KVSeqCollection * GetSimuInfo()
virtual Bool_t ReadHeader()
Definition: KVSimReader.cpp:94
void WriteObjects()
void DeclareTree(Option_t *option)
Definition: KVSimReader.cpp:56
virtual Bool_t ReadNucleus()
virtual Bool_t ReadEvent()
void AddInfo(const KVNamedParameter &)
void Run(Option_t *option="recreate")
KVSeqCollection * GetLinkedObjects()
void CleanAll()
Definition: KVSimReader.cpp:35
static KVSimReader * MakeSimReader(const char *model_uri)
Returns an instance of a child class specific to given model.
Bool_t HasToFill()
Definition: KVSimReader.h:122
void AddObject(TObject *obj)
void WriteInfo()
virtual void ConvertEventsInFile(KVString filename)
Definition: KVSimReader.cpp:24
TTree * GetTree()
Definition: KVSimReader.h:114
virtual KVString GetDate()
Definition: KVSimReader.h:92
virtual void ReadFile()
Definition: KVSimReader.cpp:85
virtual void ConvertAndSaveEventsInFile(KVString filename)
Read events, convert and save in ROOT file.
virtual void SaveTree()
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
virtual Int_t GetEntries() const
void Add(TObject *obj) override
virtual void SetName(const char *name)
void AbstractMethod(const char *method) const
virtual void Error(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
virtual TObject * RemoveAt(Int_t idx)
void Start(Bool_t reset=kTRUE)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
virtual UserGroup_t * GetUserInfo(const char *user=nullptr)
virtual void ResetBranchAddress(TBranch *)
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
virtual TList * GetUserInfo()
void Info(UserClass p, const char *location, const char *va_(fmt),...)
Definition: KVError.h:134
ClassImp(TPyArg)