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