FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairRun.cxx
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 // -------------------------------------------------------------------------
9 // ----- FairRun source file -----
10 // ----- Created 06/01/04 by M. Al-Turany -----
11 // -------------------------------------------------------------------------
12 
13 #include "FairRun.h"
14 
15 #include "FairEventHeader.h" // for FairEventHeader
16 #include "FairFileHeader.h" // for FairFileHeader
17 #include "FairLinkManager.h" // for FairLinkManager
18 #include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
19 #include "FairRootFileSink.h" // only temporary, should be removed after the move to FairSink is finished
20 #include "FairRootManager.h" // for FairRootManager
21 #include "FairRuntimeDb.h" // for FairRuntimeDb
22 #include "FairTask.h" // for FairTask
23 
24 #include <TFile.h> // for TFile
25 #include <TList.h> // for TList
26 #include <TObject.h> // for TObject
27 #include <cassert> // for... well, assert
28 
29 TMCThreadLocal FairRun* FairRun::fRunInstance = 0;
30 
32 
33 FairRun::FairRun(Bool_t isMaster)
34  : TNamed()
35  , fNTasks(0)
36  , fRtdb(FairRuntimeDb::instance())
37  , fTask(new FairTask("FairTaskList"))
38  , fRootManager(0)
39  , fSink(0)
40  , fUserOutputFileName()
41  , fRunId(0)
42  , fAna(kFALSE)
43  , fEvtHeader(nullptr)
44  , fFileHeader(new FairFileHeader())
45  , fGenerateRunInfo(kFALSE)
46  , fIsMaster(isMaster)
47  , fMarkFill(kTRUE)
48 {
49  if (fRunInstance) {
50  Fatal("FairRun", "Singleton instance already exists.");
51  return;
52  }
53  fRunInstance = this;
54 
56 
57  new FairLinkManager();
58 }
59 
61 {
62  LOG(debug) << "Enter Destructor of FairRun";
63  delete fTask; // There is another tasklist in MCApplication,
64  // but this should be independent
65  delete fRtdb; // who is responsible for the RuntimeDataBase
66  delete fEvtHeader;
67  LOG(debug) << "Leave Destructor of FairRun";
68 }
69 
71 {
72  fTask->Add(task);
73  StoreTaskNames(task);
74 }
75 
77 {
78  if (task) {
79  fFileHeader->AddTaskClassName(task->ClassName());
80  fNTasks++;
81 
82  const TList* subtasks = task->GetListOfTasks();
83  if (subtasks) {
84  for (const auto subtask : *subtasks) {
85  StoreTaskNames(static_cast<FairTask*>(subtask));
86  }
87  }
88  }
89 }
90 
92 {
93  delete fTask;
94  fTask = task;
95  fNTasks = 0;
96  TList* tasklist = fFileHeader->GetListOfTasks();
97  if (tasklist) {
98  tasklist->Clear();
99  StoreTaskNames(task);
100  }
101 }
102 
103 void FairRun::CreateGeometryFile(const char* geofile) { fRootManager->CreateGeometryFile(geofile); }
104 
105 FairTask* FairRun::GetTask(const char* taskName)
106 {
107  TList* taskList = fTask->GetListOfTasks();
108  TObject* task = taskList->FindObject(taskName);
109  return dynamic_cast<FairTask*>(task);
110 }
111 
113 {
114  if (nullptr == fEvtHeader) {
115  fEvtHeader = new FairEventHeader();
116  }
117  return fEvtHeader;
118 }
119 
121 
123 {
124  LOG(warn) << "Function FairRun::SetWriteRunInfoFile(Bool_t) is depcrecated and will vanish in future versions of "
125  "FairRoot.\n";
126  LOG(warn) << "Please use FairRun::SetGenerateRunInfo(Bool_t) instead.";
127 
128  fGenerateRunInfo = write;
129 }
130 
132 {
133  LOG(warn)
134  << "Function FairRun::GetWriteRunInfoFile() is depcrecated and will vanish in future versions of FairRoot.\n";
135  LOG(warn) << "Please use FairRun::IsRunInfoGenerated() instead.";
136 
137  return fGenerateRunInfo;
138 }
139 
140 void FairRun::SetOutputFile(const char* fname)
141 {
142  LOG(WARNING) << "FairRun::SetOutputFile() deprecated. Use FairRootFileSink.";
143  fSink = new FairRootFileSink(fname);
144  if (fRootManager)
146  fUserOutputFileName = fname;
147 }
148 
150 {
151  LOG(WARNING) << "FairRun::SetOutputFile() deprecated. Use FairRootFileSink.";
152  fSink = new FairRootFileSink(f);
153  if (fRootManager)
155  if (f)
156  fUserOutputFileName = f->GetName();
157 }
158 
159 void FairRun::SetOutputFileName(const TString& name)
160 {
161  LOG(WARNING) << "FairRun::SetOutputFileName() deprecated. Use FairRootFileSink.";
162  fSink = new FairRootFileSink(name);
163  if (fRootManager)
165  fUserOutputFileName = name;
166 }
167 
169 {
170  LOG(WARNING) << "FairRun::GetOutputFile() deprecated. Use separate file to store additional data.";
171  auto sink = GetSink();
172  assert(sink->GetSinkType() == kFILESINK);
173  auto rootFileSink = static_cast<FairRootFileSink*>(sink);
174  return rootFileSink->GetRootFile();
175 }
176 
177 void FairRun::SetUserOutputFileName(const TString& name) { fUserOutputFileName = name; }
178 
180 
181 void FairRun::AlignGeometry() const { fAlignmentHandler.AlignGeometry(); }
182 
183 void FairRun::AddAlignmentMatrices(const std::map<std::string, TGeoHMatrix>& alignmentMatrices, bool invertMatrices)
184 {
185  fAlignmentHandler.AddAlignmentMatrices(alignmentMatrices, invertMatrices);
186 }
187 
void AlignGeometry() const
Definition: FairRun.cxx:181
void CreateGeometryFile(const char *geofile)
Definition: FairRun.cxx:103
list of container factories
Definition: FairRuntimeDb.h:24
virtual void SetOutputFile(const char *fname)
Definition: FairRun.cxx:140
void CreateGeometryFile(const char *geofile)
FairAlignmentHandler fAlignmentHandler
Definition: FairRun.h:215
TFile * GetOutputFile()
Definition: FairRun.cxx:168
void AddTaskClassName(TString taskname)
TString GetUserOutputFileName() const
Definition: FairRun.cxx:179
FairTask * GetTask(const char *taskName)
Definition: FairRun.cxx:105
FairRun(Bool_t isMaster=kTRUE)
Definition: FairRun.cxx:33
Bool_t GetWriteRunInfoFile()
Definition: FairRun.cxx:131
FairRootManager * fRootManager
Definition: FairRun.h:193
static FairRun * Instance()
Definition: FairRun.cxx:31
FairTask * fTask
Definition: FairRun.h:191
void SetWriteRunInfoFile(Bool_t write)
Definition: FairRun.cxx:122
FairEventHeader * GetEventHeader()
Definition: FairRun.cxx:112
static FairRootManager * Instance()
FairSink * GetSink()
Definition: FairRun.h:93
FairEventHeader * fEvtHeader
Definition: FairRun.h:205
ClassImp(FairEventBuilder)
void SetSink(FairSink *tempSink)
void SetOutputFileName(const TString &name)
Definition: FairRun.cxx:159
void SetUseFairLinks(Bool_t val)
Definition: FairRun.cxx:120
static TMCThreadLocal FairRun * fRunInstance
Definition: FairRun.h:187
virtual ~FairRun()
Definition: FairRun.cxx:60
void AddAlignmentMatrices(const std::map< std::string, TGeoHMatrix > &alignmentMatrices, bool invertMatrices=false)
Definition: FairRun.cxx:183
FairFileHeader * fFileHeader
Definition: FairRun.h:207
TList * GetListOfTasks()
virtual void StoreTaskNames(const FairTask *t)
Definition: FairRun.cxx:76
FairSink * fSink
Definition: FairRun.h:195
Bool_t fGenerateRunInfo
Definition: FairRun.h:209
virtual void AddTask(FairTask *t)
Definition: FairRun.cxx:70
TString fUserOutputFileName
Definition: FairRun.h:197
void SetUserOutputFileName(const TString &name)
Definition: FairRun.cxx:177
FairRuntimeDb * fRtdb
Definition: FairRun.h:189
virtual void SetTask(FairTask *t)
Definition: FairRun.cxx:91
void SetUseFairLinks(Bool_t val)