KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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
12//____________________________________________________
13
14
15
16void KVSimReader::init()
17{
18
19 kmode = kTRUE;
20 tree = 0;
21 evt = 0;
22 nuc = 0 ;
23 nevt = 0;
24 fMultiFiles = kFALSE;
25 fFileIndex = 1;
26 fOutputDirectory = "./";
27
28 tree_name = "SIMULATION_NAME";
29 tree_title = "SIMULATION";
30 root_file_name = "Output.root";
31 //ascii_file_name = "";
32 branch_name = "Simulated_evts";
33
34 nv = new KVNameValueList();
35
36 CreateObjectList();
37 CreateInfoList();
38
39}
40
41
42
45
47{
48 // Default constructor
49 init();
50}
51
52
53
56
58{
59 // Method called by constructors with KVString filename argument
60 if (!OpenFileToRead(filename)) return;
61
62 Run();
63
64 CloseFile();
65}
66
67
68
71
73{
74 // Destructor
75 CleanAll();
76
77 delete nv;
78 delete linked_objects;
79 delete linked_info;
80
81}
82
83
84
86
88{
89
90 nv->Clear();
91 GetSimuInfo()->Clear();
93
94}
95
96
97
105
107{
108 // Use root_file_name as basename for file
109 // If multiple files are being read, they will be named
110 // [root_file_name].1
111 // [root_file_name].2
112 // [root_file_name].etc
113 // Files are written in fOutputDirectory (default: "./")
114
117 if (fMultiFiles) filename += Form(".%d", fFileIndex);
119 filename.Prepend(fOutputDirectory);
120 Info("DeclareTree", "Ouverture du fichier de stockage %s", filename.Data());
121 file = new TFile(filename, option);
122
125}
126
127
128
130
132{
133
134 Info("ReadFile", "To be defined in child class");
135
136 /*
137 while (f_in.good()){
138 if (ReadHeader()){
139 for (Int_t nn=0;nn<nv->GetIntValue("stat"));nn+=1)
140 if (!ReadEvent()) break;
141 else if (HasToFill()) FillTree();
142 else {}
143 }
144
145 }
146
147 */
148}
149
150
151
153
155{
156
157 Info("ReadHeader", "To be defined in child class");
158 /*
159 Int_t res = ReadLineAndCheck(2," ");
160 switch (res){
161 case 0:
162 Info("ReadHeader","case 0 line est vide");
163 return kFALSE;
164 case 1:
165 nv->SetValue("J",GetDoubleReadPar(0));
166 nv->SetValue("stat",GetDoubleReadPar(1));
167
168 Info("ReadHeader","case 1 moment angulaire %1.0lf stat %1.0lf",nv->GetIntValue("J"),nv->GetIntValue("stat"));
169 return kTRUE;
170 default:
171 Info("ReadHeader","case 2 nombre de par lus %d differents de celui attendu %d",toks->GetEntries(),2);
172 //Info("ReadHeader","line %s",line.Data());
173 return kFALSE;
174 }
175 */
176 return kTRUE;
177}
178
179
180
182
184{
185
186 Info("ReadEvent", "To be defined in child class");
187 /*
188 evt->Clear();
189 Int_t mult=0;
190 Int_t res = ReadLineAndCheck(1," ");
191 switch (res){
192 case 0:
193 Info("ReadEvent","case 0 line est vide");
194 return kFALSE;
195
196 case 1:
197 evt->SetNumber(nevt);
198 mult = GetIntReadPar(0);
199 evt->GetParameters()->SetValue("ll",kSIM_var1);
200
201 for (Int_t mm=0; mm<mult; mm+=1){
202 nuc = (KVSimNucleus* )evt->AddParticle();
203 ReadNucleus();
204 }
205
206 nevt+=1;
207 return kTRUE;
208
209 default:
210 Info("ReadEvent","case 2 nombre de par lus %d differents de celui attendu %d",toks->GetEntries(),1);
211 //Info("ReadHeader","line %s",line.Data());
212 return kFALSE;
213 }
214 */
215 return kTRUE;
216
217}
218
219
220
222
224{
225
226 Info("ReadNucleus", "To be defined in child class");
227 /*
228 Int_t res = ReadLineAndCheck(5," ");
229 switch (res){
230 case 0:
231 Info("ReadNucleus","case 0 line est vide");
232 return kFALSE;
233
234 case 1:
235
236 nuc->SetZ( GetIntReadPar(0) );
237 nuc->SetA( GetIntReadPar(1) );
238 nuc->SetKE( GetDoubleReadPar(2) );
239 nuc->SetTheta( GetDoubleReadPar(3) * TMath::RadToDeg() );
240 nuc->SetPhi( GetDoubleReadPar(4) * TMath::RadToDeg() );
241
242 return kTRUE;
243
244 default:
245
246 Info("ReadNucleus","case 2 nombre de par lus %d differents de celui attendu %d",toks->GetEntries(),5);
247 //Info("ReadHeader","line %s",line.Data());
248 return kFALSE;
249 }
250 */
251 return kTRUE;
252}
253
254
255
258
260{
261 // Read events, convert and save in ROOT file
263 SaveTree();
264}
265
266
267
271
273{
274 // Static method
275 // Returns an instance of a child class specific to given model.
276
277 TPluginHandler* ph = LoadPlugin("KVSimReader", model_uri);
278 if (!ph) {
279 ::Error("KVSimReader::MakeSimReader", "No plugin defined with name %s", model_uri);
280 return nullptr;
281 }
282 return (KVSimReader*)ph->ExecPlugin(0);
283}
284
285
286
288
290{
291
292 AddInfo("ascii file read", GetFileName().Data());
293
294 TStopwatch chrono;
295 chrono.Start();
296
297 evt = new KVSimEvent();
299 nuc = 0;
300 nevt = 0;
301
302 ReadFile();
303
304 if (HasToFill())
306
307 delete evt;
308 chrono.Stop();
309
310 //Info("Run","%d evts lus en %lf seconds",GetNumberOfEvents(),chrono.RealTime());
311
312 KVString snevt;
313 snevt.Form("%d", nevt);
314 AddInfo("number of events read", snevt.Data());
315 AddInfo("date", GetDate().Data());
316 AddInfo("user", gSystem->GetUserInfo()->fUser.Data());
317
318}
319
320
321
323
325{
326
327 WriteObjects();
328 WriteInfo();
329
330 GetTree()->Write();
331 CleanAll();
332 file->Close();
333
334}
335
336
337
340
342{
343 //
344 return linked_info;
345}
346
347
348
350
351void KVSimReader::AddInfo(const Char_t* name, const Char_t* val)
352{
353 GetSimuInfo()->Add(new TNamed(name, val));
354}
355
356
357
359
361{
362
363 GetSimuInfo()->Add(named);
364}
365
366
367
369
371{
372 TList* list = GetTree()->GetUserInfo();
374 for (Int_t ii = 0; ii < nentries; ii += 1) {
375 list->Add(linked_info->RemoveAt(0));
376 }
377}
378
379
380
382
384{
385 linked_info = new KVList();
387 linked_info->SetName("Simulation info");
388}
389
390
391
392
394
399
400
401
403
405{
406 GetLinkedObjects()->Add(obj);
407}
408
409
410
412
414{
415
416 TList* list = GetTree()->GetUserInfo();
418 for (Int_t ii = 0; ii < nentries; ii += 1) {
419 list->Add(linked_objects->RemoveAt(0));
420 }
421
422}
423
424
425
427
429{
431 linked_objects->SetName("List of objects");
432}
433
434
435/*
436
437fichier correspondant au format de lecture:
438
4390 2
44010
4411 1 5.810748 2.580167 -2.821796
4421 1 9.990623 2.013791 3.080918
4431 1 12.384371 1.813083 1.459004
4441 1 7.553329 1.807012 1.629090
4450 1 1.493379 2.652475 2.525657
4460 1 0.971787 2.151803 0.616233
4470 1 1.889498 0.789652 -1.659597
4481 1 5.860981 1.636198 2.878590
4491 1 4.296264 2.359454 2.377290
45050 109 1.424833 0.958413 -0.798826
4519
4521 1 7.719303 0.954321 0.703780
4531 1 13.956905 0.957730 1.756477
4541 1 6.952527 1.496332 0.294119
4551 1 7.750355 2.158870 -2.119215
4561 1 5.972726 2.073538 1.496040
4571 1 6.617680 1.352951 3.015066
4581 1 7.526133 1.842921 3.073465
4590 1 0.435096 1.950363 2.852936
46049 110 0.426353 1.688514 -1.100454
46110 3
4629
4630 1 2.385526 2.187467 -2.383691
4642 4 13.103434 1.147666 2.958037
4651 1 7.084269 1.675831 0.720834
4660 1 0.742568 1.607419 0.278490
4671 1 9.079510 2.765702 -0.297527
4681 1 9.300734 0.170849 -0.891740
4691 1 8.797631 1.098980 -0.344032
4701 1 4.680343 1.923954 -3.007086
47149 107 0.133186 2.320088 -0.156727
4728
4731 1 7.249172 1.496348 -0.976620
4742 4 17.685099 0.551523 -2.905849
4752 4 27.911638 1.766578 0.524513
4761 1 8.419456 1.628637 -1.882687
4770 1 0.680420 0.786916 0.688403
4781 1 4.465025 1.745583 -1.592567
4791 1 4.812778 2.287951 -3.126746
48048 105 0.364456 2.255794 2.579171
4819
4821 1 12.462525 1.826489 1.113706
4831 1 7.000116 2.608909 1.919405
4840 1 2.846559 2.288652 -1.294329
4850 1 1.650262 0.578845 -0.605950
4861 1 6.264917 2.046585 1.862553
4871 1 5.637622 0.790498 -2.418233
4880 1 1.533256 0.051853 -0.220994
4892 4 13.625276 0.567988 0.888917
49050 107 0.708753 2.151470 -1.940892
491
492*/
493
int Int_t
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
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
char name[80]
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:793
static void MakeEventBranch(TTree *tree, const TString &branchname, T &event, Int_t bufsize=10000000)
Definition KVEvent.h:210
KVString GetFileName()
Bool_t OpenFileToRead(const KVString &filename)
Extended TList class which owns its objects by default.
Definition KVList.h:28
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
virtual void Clear(Option_t *opt="")
virtual void SetOwner(Bool_t enable=kTRUE)
virtual void Clear(Option_t *option="")
virtual void Add(TObject *obj)
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
virtual Bool_t ReadHeader()
KVString root_file_name
Definition KVSimReader.h:63
void WriteObjects()
void DeclareTree(Option_t *option)
KVString tree_name
Definition KVSimReader.h:63
KVList * linked_info
Liste d'info (TNamed) enregistree dans l arbre.
Definition KVSimReader.h:71
TTree * GetTree()
KVString tree_title
Definition KVSimReader.h:63
virtual Bool_t ReadNucleus()
virtual Bool_t ReadEvent()
TString fOutputDirectory
where to save converted events
Definition KVSimReader.h:67
void Run(Option_t *option="recreate")
KVList * linked_objects
liste d'objets a enregistree avec l'arbre
Definition KVSimReader.h:72
KVList * GetLinkedObjects()
void CleanAll()
KVString branch_name
Definition KVSimReader.h:63
KVSimNucleus * nuc
Definition KVSimReader.h:60
static KVSimReader * MakeSimReader(const char *model_uri)
Bool_t fMultiFiles
Definition KVSimReader.h:65
virtual Bool_t HasToFill()
Int_t fFileIndex
Definition KVSimReader.h:66
void AddObject(TObject *obj)
void CreateObjectList()
virtual void ConvertEventsInFile(KVString filename)
Method called by constructors with KVString filename argument.
void CreateInfoList()
KVList * GetSimuInfo()
KVSimReader()
Default constructor.
KVSimEvent * evt
Definition KVSimReader.h:59
virtual ~KVSimReader()
Destructor.
virtual KVString GetDate()
Definition KVSimReader.h:97
KVNameValueList * nv
Definition KVSimReader.h:74
void AddInfo(const Char_t *name, const Char_t *val)
virtual void ReadFile()
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
void SetName(const char *name)
virtual Int_t GetEntries() const
void Add(TObject *obj) override
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
virtual TObject * RemoveAt(Int_t idx)
void Start(Bool_t reset=kTRUE)
void Stop()
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
void Form(const char *fmt,...)
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()
str tree_name
TString fUser
ClassImp(TPyArg)