CbmRoot
CbmMCDataManager.cxx
Go to the documentation of this file.
1 #include "CbmMCDataManager.h"
2 
3 #include "CbmMCDataArray.h" // for CbmMCDataArray
4 #include "CbmMCDataObject.h" // for CbmMCDataObject
5 
6 #include <FairLogger.h>
7 #include <FairRootManager.h> // for FairRootManager
8 #include <FairTask.h> // for FairTask, InitStatus, kFATAL, kSUCCESS
9 
10 #include <utility> // for pair
11 
12 using namespace std;
13 
14 // --- Default constructor
16  : CbmMCDataManager("MCDataManager", 0)
17 // : FairTask("MCDataManager", 0), fLegacy(0), fFileList(), fActive(), fActiveObj(), fFriends()
18 {
19  fFileList.clear();
20  fActive.clear();
21  fActiveObj.clear();
22  fFriends.clear();
23 }
24 
25 
26 // --- Standard constructor
27 CbmMCDataManager::CbmMCDataManager(const char* name, Int_t legacy)
28  : FairTask(name, 0)
29  , fLegacy(legacy)
30  , fFileList()
31  , fActive()
32  , fActiveObj()
33  , fFriends() {
34  fFileList.clear();
35  fActive.clear();
36  fActiveObj.clear();
37  fFriends.clear();
38 }
39 
40 
41 // --- Destructor
43  map<TString, CbmMCDataArray*>::const_iterator p;
44  for (p = fActive.begin(); p != fActive.end(); ++p)
45  delete p->second;
46  fActive.clear();
47 
48  map<TString, CbmMCDataObject*>::const_iterator o;
49  for (o = fActiveObj.begin(); o != fActiveObj.end(); ++o)
50  delete o->second;
51  fActiveObj.clear();
52 }
53 
54 
55 // --- Add an additional input file
56 Int_t CbmMCDataManager::AddFile(const char* name) {
57  Int_t n = fFileList.size();
58  fFileList.resize(n + 1);
59  fFileList[n].clear();
60  fFileList[n].push_back(name);
61  return n;
62 }
63 
64 
65 // --- Add a file to a given input chain
66 Int_t CbmMCDataManager::AddFileToChain(const char* name, Int_t number) {
67  Int_t i;
68  Int_t n = fFileList.size();
69 
70  if (number < 0) return -1111;
71  if (number >= n) {
72  fFileList.resize(number + 1);
73  for (i = n; i <= number; i++)
74  fFileList[i].clear();
75  }
76  fFileList[number].push_back(name);
77 
78  return fFileList[number].size();
79 }
80 
81 
82 // --- End of event action
84  map<TString, CbmMCDataArray*>::const_iterator p;
85  map<TString, CbmMCDataObject*>::const_iterator o;
86 
87  for (p = fActive.begin(); p != fActive.end(); ++p)
88  p->second->FinishEvent();
89  for (o = fActiveObj.begin(); o != fActiveObj.end(); ++o)
90  o->second->FinishEvent();
91 }
92 
93 
94 // --- Initialisation
95 InitStatus CbmMCDataManager::Init() {
96  FairRootManager* fManager = FairRootManager::Instance();
97  if (!fManager) return kFATAL;
98 
99  fManager->Register("MCDataManager", "Stack", (TNamed*) this, kFALSE);
100 
101  return kSUCCESS;
102 }
103 
104 
105 // --- Instantiate a data branch
107  CbmMCDataArray* arr = nullptr;
108  TString nm = brname;
109  map<Int_t, Int_t>::const_iterator p;
110 
111  if (fActive.find(nm) != fActive.end()) {
112  LOG(info) << "InitBranch: " << nm << " " << fActive[nm];
113  return fActive[nm];
114  }
115  if (fLegacy == 0) {
116  arr = new CbmMCDataArray(brname, fFileList);
117  fActive[nm] = arr;
118  for (p = fFriends.begin(); p != fFriends.end(); ++p) {
119  arr->AddFriend(p->first, p->second);
120  }
121  } //? Standard mode
122  else {
123  if (FairRootManager::Instance()->GetObject(brname) != nullptr) {
124  arr = new CbmMCDataArray(brname);
125  fActive[nm] = arr;
126  LOG(info) << "InitBranch: " << nm << " " << arr;
127  } //? Branch found
128  else {
129  LOG(info) << "InitBranch: " << nm << " could not be initialised.";
130  } //? Branch not found in FairRootManager
131  } //? Legacy mode
132 
133  return arr;
134 }
135 
136 // --- Instantiate a data branch containing TObject
138  CbmMCDataObject* arr;
139  TString nm = brname;
140  map<Int_t, Int_t>::const_iterator p;
141 
142  if (fActiveObj.find(nm) != fActiveObj.end()) {
143  LOG(info) << "InitBranch: " << nm << " " << fActiveObj[nm];
144  return fActiveObj[nm];
145  }
146  if (fLegacy == 0) {
147  arr = new CbmMCDataObject(brname, fFileList);
148  for (p = fFriends.begin(); p != fFriends.end(); ++p) {
149  arr->AddFriend(p->first, p->second);
150  }
151  } else
152  arr = new CbmMCDataObject(brname);
153 
154  fActiveObj[nm] = arr;
155  LOG(info) << "InitBranch: " << nm << " " << arr;
156  return arr;
157 }
158 
CbmMCDataManager::fFriends
std::map< Int_t, Int_t > fFriends
Definition: CbmMCDataManager.h:103
CbmMCDataManager::GetObject
CbmMCDataObject * GetObject(const char *name)
Definition: CbmMCDataManager.cxx:137
CbmMCDataManager.h
CbmMCDataObject::AddFriend
void AddFriend(Int_t chainNum1, Int_t chainNum2)
Definition: CbmMCDataObject.cxx:54
CbmMCDataManager::CbmMCDataManager
CbmMCDataManager()
Definition: CbmMCDataManager.cxx:15
CbmMCDataManager::fActiveObj
std::map< TString, CbmMCDataObject * > fActiveObj
Definition: CbmMCDataManager.h:101
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmMCDataManager::InitBranch
CbmMCDataArray * InitBranch(const char *name)
Definition: CbmMCDataManager.cxx:106
CbmMCDataArray::AddFriend
void AddFriend(Int_t chainNum1, Int_t chainNum2)
Definition: CbmMCDataArray.cxx:56
CbmMCDataArray.h
CbmMCDataArray
Access to a MC data branch for time-based analysis.
Definition: CbmMCDataArray.h:35
CbmMCDataObject.h
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMCDataManager::Init
virtual InitStatus Init()
Definition: CbmMCDataManager.cxx:95
CbmMCDataManager::AddFileToChain
Int_t AddFileToChain(const char *fileName, Int_t chainNumber)
Definition: CbmMCDataManager.cxx:66
CbmMCDataManager
Task class creating and managing CbmMCDataArray objects.
Definition: CbmMCDataManager.h:27
CbmMCDataManager::fActive
std::map< TString, CbmMCDataArray * > fActive
Array of filename chains.
Definition: CbmMCDataManager.h:99
CbmMCDataManager::~CbmMCDataManager
~CbmMCDataManager()
Definition: CbmMCDataManager.cxx:42
CbmMCDataObject
Access to a MC data branch for time-based analysis.
Definition: CbmMCDataObject.h:34
CbmMCDataManager::fLegacy
Int_t fLegacy
If true, use FairRootManager in event-by-event mode.
Definition: CbmMCDataManager.h:93
CbmMCDataManager::FinishEvent
virtual void FinishEvent()
Definition: CbmMCDataManager.cxx:83
CbmMCDataManager::fFileList
std::vector< std::list< TString > > fFileList
Definition: CbmMCDataManager.h:96
CbmMCDataManager::AddFile
Int_t AddFile(const char *fileName)
Definition: CbmMCDataManager.cxx:56