FairRoot/PandaRoot
PndMasterRunAna.cxx
Go to the documentation of this file.
1 #include "PndMasterRunAna.h"
2 
3 #include "PndMasterDigiTask.h"
5 #include "PndMasterRecoTask.h"
8 #include "PndMasterPidTask.h"
10 #include "PndFileNameCreator.h"
11 #include "PndEventCounterTask.h"
12 
13 #include "FairFileSource.h"
14 #include "FairFileHeader.h"
15 #include "FairParRootFileIo.h"
16 #include "FairParAsciiFileIo.h"
17 #include "FairRuntimeDb.h"
18 #include "FairSystemInfo.h"
19 #include "FairLogger.h"
20 #include "FairGeane.h"
21 #include "TGeoManager.h"
22 #include "TROOT.h"
23 
24 #include <iostream>
25 
26 using std::cout;
27 using std::endl;
28 
29 // ----- Default constructor -------------------------------------------
31  FairRunAna(), fInput(), fParamRootFile(), fParamAsciiFile(),
32  fOptions(), fEventCounterRate(100), fNoGeane(kTRUE),
33  fGenerateRunInfo(kFALSE), fUseFairLinks(kTRUE), fTimer()
34 {
35  fTimer.Start();
36 }
37 // ----- Default destructor -------------------------------------------
39 {
40  if (gROOT->GetVersionInt() >= 60602 && gGeoManager!=NULL) {
41  gGeoManager->GetListOfVolumes()->Delete();
42  gGeoManager->GetListOfShapes()->Delete();
43  delete gGeoManager;
44  }
45 }
46 
47 // ----- Setup ---------------------------------------------------------
49 {
50  TString inputName = outprefix;
51 
52  // If no prefix is given, we create one from fInput and force lower-case
53  if (inputName=="")
54  {
55  inputName = fInput;
56  inputName.ToLower();
57  }
58 
59  if (inputName.EndsWith(".dec")) inputName.Remove(inputName.Length()-4,4);
60  inputName.ReplaceAll(":","_");
61 
62  PndFileNameCreator creator(inputName.Data());
63 
64  FairFileSource *fileSource;
65  if (fFriendFiles.size() == 0) {
66  fileSource = new FairFileSource(creator.GetSimFileName().data());
67  fFriendFiles.push_back(creator.GetSimFileName().data());
68  }
69  else {
70  fileSource = new FairFileSource(creator.GetCustomFileName(fFriendFiles[0].Data()));
71  fFriendFiles[0] = creator.GetCustomFileName(fFriendFiles[0].Data());
72  }
73 
74  for (unsigned int files = 1; files < fFriendFiles.size(); files++) {
75  fileSource->AddFriend(creator.GetCustomFileName(fFriendFiles[files].Data()));
76  fFriendFiles[files] = creator.GetCustomFileName(fFriendFiles[files].Data());
77  }
78 
79  SetSource(fileSource);
80 
81  // This set the output file name
82  SetOutputFile(creator.GetCustomFileName(fOutFile.Data()).data());
83  // This set the string for the output file name, used by Finish()
84  SetOutput(creator.GetCustomFileName(fOutFile.Data()));
85  SetParamRootFile(creator.GetParFileName().data());
86  SetGenerateRunInfo(fGenerateRunInfo);
88  // ----- Parameter database --------------------------------------------
89  TString allDigiFile = gSystem->Getenv("VMCWORKDIR");
90  allDigiFile += "/macro/params/";
91  allDigiFile += fParamAsciiFile;
92 
93  FairRuntimeDb* rtdb = GetRuntimeDb();
94  FairParRootFileIo* parInput1 = new FairParRootFileIo();
95  parInput1->open(fParamRootFile.Data());
96 
97  FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo();
98  parIo1->open(allDigiFile.Data(),"in");
99 
100  rtdb->setFirstInput(parInput1);
101  rtdb->setSecondInput(parIo1);
102 
103  // ----- Event Counter --------------------------------
104  AddTask(new PndEventCounterTask("Event Counter", 0, fEventCounterRate));
105 
106  return kTRUE;
107 }
108 
109 // ----- AddDigiTasks ---------------------------------------------------
111 {
113  if (!pers) digi->SetPersistency(kFALSE);
114  digi->SetPersistency(pers);
115  AddTask(digi);
116 }
117 
118 // ----- AddDigiTasks ---------------------------------------------------
120 {
122  if (!pers) digi->SetPersistency(kFALSE);
123  digi->SetPersistency(pers);
124  AddTask(digi);
125 }
126 
127 // ----- AddRecoTasks ---------------------------------------------------
129 {
130  // ----- Geane ---------------------------------------
131  if(fNoGeane) {
132  AddTask(new FairGeane());
133  fNoGeane=false;
134  }
136  if (!pers) reco->SetPersistency(kFALSE);
137  reco->SetPersistency(pers);
138  AddTask(reco);
139 }
140 
141 // ----- AddLocalRecoTasks ---------------------------------------------------
143 {
144  // ----- Geane ---------------------------------------
145  if(fNoGeane) {
146  AddTask(new FairGeane());
147  fNoGeane=false;
148  }
150  if (!pers) reco->SetPersistency(kFALSE);
151  reco->SetPersistency(pers);
152  AddTask(reco);
153 }
154 
155 // ----- AddRecoTasks ---------------------------------------------------
157 {
158  // ----- Geane ---------------------------------------
159  if(fNoGeane) {
160  AddTask(new FairGeane());
161  fNoGeane=false;
162  }
164  if (!pers) recoIdeal->SetPersistency(kFALSE);
165  recoIdeal->SetPersistency(pers);
166  AddTask(recoIdeal);
167 }
168 
169 // ----- AddPidTasks ----------------------------------------------------
171 {
172  if(fNoGeane) {
173  AddTask(new FairGeane());
174  fNoGeane=false;
175  }
176  if (fOptions.Contains("multikalman"))
177  {
179  if (!pers) pid->SetPersistency(kFALSE);
180  pid->SetPersistency(pers);
181  AddTask(pid);
182  } else {
184  if (!pers) pid->SetPersistency(kFALSE);
185  pid->SetPersistency(pers);
186  AddTask(pid);
187  }
188 }
189 
191 {
192  cout<<"Tasks that ran just now:"<<endl;
193  TFile* outfile=fRootManager->GetOutFile();
194  bool wasopen=outfile->IsOpen ();
195  if (!wasopen)
196  {
197  cout<<"file is "<< ((wasopen) ? "" : "not " ) <<"open" <<endl;
198  outfile=new TFile(outfile->GetName(),"UPDATE");
199  }
200  FairFileHeader* outheader=(FairFileHeader*)outfile->Get("FileHeader");
201  for(const auto&& os : *(outheader->GetListOfTasks()) ) cout<<" - "<<((TObjString*)os)->GetString().Data()<<endl;
202 }
203 
204 // ----- Finish ---------------------------------------------------------
206 {
207  cout << endl;
208 
209  TFile* outfile=fRootManager->GetOutFile();
210  bool wasopen=outfile->IsOpen ();
211  if (!wasopen)
212  {
213  cout<<"file is "<< ((wasopen) ? "" : "not " ) <<"open" <<endl;
214  outfile=new TFile(outfile->GetName(),"UPDATE");
215  }
216  outfile->cd();
217 
218  cout<<"PndMasterRunAna::Finish():";
220 
221  TObjString outoptions(fOptions);
222  outoptions.Write("PndOptions",kOverwrite);
223 
224  outfile->Write();
225  if(!wasopen) outfile->Close();
226 
227  //safety delete for newer ROOT
228  if (gROOT->GetVersionInt() >= 60602) {
229  gGeoManager->GetListOfVolumes()->Delete();
230  gGeoManager->GetListOfShapes()->Delete();
231  delete gGeoManager;
232  }
233 
234  // Extract the maximal used memory an add is as Dart measurement
235  // This line is filtered by CTest and the value send to CDash
236  FairSystemInfo sysInfo;
237  Float_t maxMemory=sysInfo.GetMaxMemory();
238  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
239  cout << maxMemory;
240  cout << "</DartMeasurement>" << endl;
241 
242  fTimer.Stop();
243  Double_t rtime = fTimer.RealTime();
244  Double_t ctime = fTimer.CpuTime();
245 
246  Float_t cpuUsage=ctime/rtime;
247  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
248  cout << cpuUsage;
249  cout << "</DartMeasurement>" << endl;
250 
251  cout << endl;
252  cout << "Output file is\t\t" << fOutFile << endl;
253  for (auto files : fFriendFiles) {
254  cout << "Friend file is\t\t" << files << endl;
255  }
256 
257 
258  cout << "Parameter ROOT file is\t" << fParamRootFile << endl;
259  cout << "Parameter ASCII file is\t" << fParamAsciiFile << endl;
260  cout << "Real time " << rtime << " s, CPU time " << ctime
261  << "s" << endl;
262  cout << "CPU usage " << cpuUsage*100. << "%" << endl;
263  cout << "Max Memory " << maxMemory << " MB" << endl;
264 
265  cout << "Macro finished successfully." << endl;
266 
267 
268 }
269 
TString fOutFile
Name of the output file.
TString fParamRootFile
Name of the parameter root file.
Int_t fEventCounterRate
After how many events the counter will print.
TClonesArray * digi
TStopwatch fTimer
Timer.
void AddLocalRecoTasks(Bool_t pers=kTRUE)
Add local reconstruction tasks.
The default pid tasks.
void AddDigiOnlyTasks(Bool_t pers=kTRUE)
Add digitization tasks without reconstruction.
Class for the master reconstruction chain.
TString fInput
Name of the input for the simulation.
Bool_t Setup(TString outprefix="")
Initial setup.
int pid()
std::map< int, TString > files
Definition: simubg.C:28
TGeoManager * gGeoManager
virtual void SetPersistency(Bool_t pers=kTRUE)
Set the persistency of all the tasks.
TString allDigiFile
Definition: hit_muo.C:36
TString fOptions
Options parsed to the reconstruction.
void AddRecoTasks(Bool_t pers=kTRUE)
Add reconstruction tasks.
Bool_t fNoGeane
Protect GEANE from being loaded twice.
The default local reconstruction tasks.
virtual void SetPersistency(Bool_t pers=kTRUE)
Set the persistency of all the tasks.
Bool_t fGenerateRunInfo
Switches on/off the generation of Run info.
A simple class which adds the corresponding file extensions to a given base class.
Double_t
virtual void SetPersistency(Bool_t pers=kTRUE)
Set the persistency of all the tasks.
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
The default digitization tasks.
virtual void SetPersistency(Bool_t pers=kTRUE)
Set the persistency of all the tasks.
The default reconstruction tasks.
The default pid tasks.
fRun AddTask(drcdigi)
void AddPidTasks(Bool_t pers=kTRUE)
Add pid tasks.
Bool_t fUseFairLinks
Switches on/off the usage of FairLinks.
FairParRootFileIo * parInput1
Definition: hit_dirc.C:67
void AddRecoIdealTasks(Bool_t pers=kTRUE)
Add ideal pattern reconstruction tasks.
Double_t ctime
Definition: hit_dirc.C:114
FairParAsciiFileIo * parIo1
Definition: bump_emc.C:53
void SetParamRootFile(TString par)
Setter of the parameter root file.
virtual void SetPersistency(Bool_t pers=kTRUE)
Set the persistency of all the tasks This function has to be implemented for each master task...
PndMasterRunAna()
Default constructor.
fRun SetOutputFile(outFile)
virtual ~PndMasterRunAna()
Default destructor.
PndMvdCreateDefaultApvMap * creator
void AddDigiTasks(Bool_t pers=kTRUE)
Add digitization and local reconstruction tasks.
TString fParamAsciiFile
Name of the parameter ascii file.
int reco()
void Finish()
Final diagnostics.
std::vector< TString > fFriendFiles
Name of friend files.
ClassImp(PndAnaContFact)
void SetOutput(TString par)
Tag of the output file of the macro.
fRun SetUseFairLinks(kTRUE)
Double_t rtime
Definition: hit_dirc.C:113
The default reconstruction tasks.
The default digitization tasks.
TString outfile
virtual void SetPersistency(Bool_t pers=kTRUE)
Set the persistency of all the tasks.