FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
read_digis.C
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 void read_digis()
9 {
10 
11  TStopwatch timer;
12  timer.Start();
13 
14  TString dir = getenv("VMCWORKDIR");
15  TString tutdir = dir + "/simulation/Tutorial2";
16 
17  TString inFile = "./tutorial2_pions.mc_p2.000_t0_n10.root";
18  TString parFile = "./tutorial2_pions.params_p2.000_t0_n10.root";
19  TString outFile = "./digis.mc.root";
20 
21  cout << "******************************" << endl;
22  cout << "InFile: " << inFile << endl;
23  cout << "ParamFile: " << parFile << endl;
24  cout << "OutFile: " << outFile << endl;
25  cout << "******************************" << endl;
26 
27  FairRunAna* fRun = new FairRunAna();
28  FairFileSource* fFileSource = new FairFileSource(inFile);
29  fRun->SetSource(fFileSource);
30  fRun->SetSink(new FairRootFileSink(outFile));
31 
32  // Init Simulation Parameters from Root File
33  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
35  io1->open(parFile.Data(), "UPDATE");
36 
37  // Fallback solution if paramters are not found in database (ROOT file)
38  FairParAsciiFileIo* parInput2 = new FairParAsciiFileIo();
39  TString tutDetDigiFile = gSystem->Getenv("VMCWORKDIR");
40  tutDetDigiFile += "/simulation/Tutorial2/parameters/tutdet.digi.par";
41  parInput2->open(tutDetDigiFile.Data(), "in");
42 
43  // The parameter container is initialized from first input since it
44  // is available from the ROOT parameter file. The second input is the
45  // fallback when a parameter container is not found in the first
46  // input. If you want to overwrite a paramter container already
47  // existing in the "database" (ROOT file) you have to change the
48  // order of the inputs. In this case the ASCII file has to be the
49  // first input.
50  rtdb->setFirstInput(io1);
51  rtdb->setSecondInput(parInput2);
52 
53  // It is needed to request the parameter container before the run is
54  // initialized. Otherwise the runtime database does not know that the
55  // parameter container is needed and creates one with the default
56  // constructor of the parameter container which is an empty one.
57  // Normally the request is done in the function SetParContainers of the task.
58  // You can check what happens if no parameter conatiner is requested
59  // by disabling the next line.
60  rtdb->getContainer("FairTutorialDet2DigiPar");
61  rtdb->print();
62 
63  fRun->Init();
64 
65  rtdb->getContainer("FairTutorialDet2DigiPar")->print();
66 
67  // First short version to print the parameters
68  // If you want to confirm that the parameters are really there you can
69  // print them by disabling the following line
70  // static_cast<FairTutorialDet2DigiPar*>(rtdb->getContainer("FairTutorialDet2DigiPar"))->printparams();
71 
72  rtdb->saveOutput();
73 
74  // -- Print out the random seed from the simulation ----------------------
75  FairBaseParSet* BasePar = (FairBaseParSet*)rtdb->getContainer("FairBaseParSet");
76  cout << "RndSeed used in simulation was " << BasePar->GetRndSeed() << endl;
77 
78  // -----------------------------------------------------------------------
79 
80  // Second version to print the parameters
81  // which also shows how to change and save them again
82 
83  FairTutorialDet2DigiPar* DigiPar = (FairTutorialDet2DigiPar*)rtdb->getContainer("FairTutorialDet2DigiPar");
84 
85  DigiPar->setChanged();
86  DigiPar->setInputVersion(fRun->GetRunId(), 1);
87  // If you want to confirm that the parameters are really there you can
88  // print them by disabling the following line
89  DigiPar->printParams();
90 
91  rtdb->print();
92  rtdb->saveOutput();
93 
94  fRun->Run();
95 
96  // ----- Finish -------------------------------------------------------
97 
98  cout << endl << endl;
99 
100  // Extract the maximal used memory an add is as Dart measurement
101  // This line is filtered by CTest and the value send to CDash
102  FairSystemInfo sysInfo;
103  Float_t maxMemory = sysInfo.GetMaxMemory();
104  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
105  cout << maxMemory;
106  cout << "</DartMeasurement>" << endl;
107 
108  timer.Stop();
109  Double_t rtime = timer.RealTime();
110  Double_t ctime = timer.CpuTime();
111 
112  Float_t cpuUsage = ctime / rtime;
113  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
114  cout << cpuUsage;
115  cout << "</DartMeasurement>" << endl;
116 
117  cout << endl << endl;
118  cout << "Output file is " << outFile << endl;
119  cout << "Parameter file is " << parFile << endl;
120  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
121  cout << "Macro finished successfully." << endl;
122 }
list of container factories
Definition: FairRuntimeDb.h:24
Bool_t open(const Text_t *fname, const Text_t *status="in")
void Init()
Definition: FairRunAna.cxx:127
void read_digis()
Definition: read_digis.C:8
void setChanged(Bool_t flag=kTRUE)
Definition: FairParSet.h:72
virtual void print()
Definition: FairParSet.cxx:94
Bool_t setSecondInput(FairParIo *)
void print(void)
void Run(Int_t NStart=0, Int_t NStop=0)
Definition: FairRunAna.cxx:275
void SetSink(FairSink *tempSink)
Definition: FairRun.h:84
FairParSet * getContainer(const Text_t *)
UInt_t GetRndSeed()
Float_t GetMaxMemory()
virtual void printParams()
void setInputVersion(Int_t v=-1, Int_t i=0)
Definition: FairParSet.h:51
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
Bool_t open(const Text_t *fname, Option_t *option="READ", const Text_t *ftitle="", Int_t compress=1)
virtual void SetSource(FairSource *tempSource)
Definition: FairRunAna.h:70
Bool_t setFirstInput(FairParIo *)
Int_t GetRunId()
Definition: FairRun.h:97
void saveOutput(void)