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 
12 //____________________________________________________
13 
14 
16 void 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);
118  if (!fOutputDirectory.EndsWith("/")) fOutputDirectory += "/";
119  filename.Prepend(fOutputDirectory);
120  Info("DeclareTree", "Ouverture du fichier de stockage %s", filename.Data());
121  file = new TFile(filename, option);
122 
123  tree = new TTree(tree_name, tree_title);
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();
298  if (HasToFill()) DeclareTree(option);
299  nuc = 0;
300  nevt = 0;
301 
302  ReadFile();
303 
304  if (HasToFill())
305  GetTree()->ResetBranchAddress(GetTree()->GetBranch(branch_name.Data()));
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 
351 void 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 KVUnownedList();
386  linked_info->SetName("Simulation info");
387 }
388 
389 
390 
391 
393 
395 {
396  return linked_objects;
397 }
398 
399 
400 
402 
404 {
405  GetLinkedObjects()->Add(obj);
406 }
407 
408 
409 
411 
413 {
414 
415  TList* list = GetTree()->GetUserInfo();
417  for (Int_t ii = 0; ii < nentries; ii += 1) {
418  list->Add(linked_objects->RemoveAt(0));
419  }
420 
421 }
422 
423 
424 
426 
428 {
430  linked_objects->SetName("List of objects");
431 }
432 
433 
434 /*
435 
436 fichier correspondant au format de lecture:
437 
438 0 2
439 10
440 1 1 5.810748 2.580167 -2.821796
441 1 1 9.990623 2.013791 3.080918
442 1 1 12.384371 1.813083 1.459004
443 1 1 7.553329 1.807012 1.629090
444 0 1 1.493379 2.652475 2.525657
445 0 1 0.971787 2.151803 0.616233
446 0 1 1.889498 0.789652 -1.659597
447 1 1 5.860981 1.636198 2.878590
448 1 1 4.296264 2.359454 2.377290
449 50 109 1.424833 0.958413 -0.798826
450 9
451 1 1 7.719303 0.954321 0.703780
452 1 1 13.956905 0.957730 1.756477
453 1 1 6.952527 1.496332 0.294119
454 1 1 7.750355 2.158870 -2.119215
455 1 1 5.972726 2.073538 1.496040
456 1 1 6.617680 1.352951 3.015066
457 1 1 7.526133 1.842921 3.073465
458 0 1 0.435096 1.950363 2.852936
459 49 110 0.426353 1.688514 -1.100454
460 10 3
461 9
462 0 1 2.385526 2.187467 -2.383691
463 2 4 13.103434 1.147666 2.958037
464 1 1 7.084269 1.675831 0.720834
465 0 1 0.742568 1.607419 0.278490
466 1 1 9.079510 2.765702 -0.297527
467 1 1 9.300734 0.170849 -0.891740
468 1 1 8.797631 1.098980 -0.344032
469 1 1 4.680343 1.923954 -3.007086
470 49 107 0.133186 2.320088 -0.156727
471 8
472 1 1 7.249172 1.496348 -0.976620
473 2 4 17.685099 0.551523 -2.905849
474 2 4 27.911638 1.766578 0.524513
475 1 1 8.419456 1.628637 -1.882687
476 0 1 0.680420 0.786916 0.688403
477 1 1 4.465025 1.745583 -1.592567
478 1 1 4.812778 2.287951 -3.126746
479 48 105 0.364456 2.255794 2.579171
480 9
481 1 1 12.462525 1.826489 1.113706
482 1 1 7.000116 2.608909 1.919405
483 0 1 2.846559 2.288652 -1.294329
484 0 1 1.650262 0.578845 -0.605950
485 1 1 6.264917 2.046585 1.862553
486 1 1 5.637622 0.790498 -2.418233
487 0 1 1.533256 0.051853 -0.220994
488 2 4 13.625276 0.567988 0.888917
489 50 107 0.708753 2.151470 -1.940892
490 
491 */
492 
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
void Error(const char *method, const char *msgfmt,...) const override
Definition: KVBase.cpp:1666
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:788
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
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
void Clear(Option_t *opt="") override
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()
KVString root_file_name
Definition: KVSimReader.h:63
Int_t nevt
Definition: KVSimReader.h:62
KVSeqCollection * GetLinkedObjects()
void WriteObjects()
KVUnownedList * linked_objects
liste d'objets a enregistree avec l'arbre
Definition: KVSimReader.h:72
KVUnownedList * linked_info
Liste d'info (TNamed) enregistree dans l arbre.
Definition: KVSimReader.h:71
void DeclareTree(Option_t *option)
KVString tree_name
Definition: KVSimReader.h:63
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")
void CleanAll()
Definition: KVSimReader.cpp:87
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()
Definition: KVSimReader.h:127
Int_t fFileIndex
Definition: KVSimReader.h:66
void AddObject(TObject *obj)
void CreateObjectList()
void WriteInfo()
virtual void ConvertEventsInFile(KVString filename)
Method called by constructors with KVString filename argument.
Definition: KVSimReader.cpp:57
void CreateInfoList()
KVSimReader()
Default constructor.
Definition: KVSimReader.cpp:46
KVSimEvent * evt
Definition: KVSimReader.h:59
virtual ~KVSimReader()
Destructor.
Definition: KVSimReader.cpp:72
TTree * GetTree()
Definition: KVSimReader.h:119
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
Extended TList class which does not own its objects by default.
Definition: KVUnownedList.h:20
void SetName(const char *name)
virtual Int_t GetEntries() const
void Add(TObject *obj) override
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)