BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
RootRawEvtReader.cxx
Go to the documentation of this file.
1#include "RootRawEvtReader/RootRawEvtReader.h"
2
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/AlgFactory.h"
5#include "GaudiKernel/Bootstrap.h"
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/SmartDataPtr.h"
8#include "GaudiKernel/IDataProviderSvc.h"
9#include "GaudiKernel/PropertyMgr.h"
10#include "GaudiKernel/DataObject.h"
11#include "GaudiKernel/GenericAddress.h"
12#include "GaudiKernel/ClassID.h"
13
14#include "RawEvent/DigiEvent.h" //TDS object
15#include "EventModel/EventModel.h"
16#include "EventModel/EventHeader.h"
17
18//Digi
19#include "MdcRawEvent/MdcDigi.h"
20#include "EmcRawEvent/EmcDigi.h"
21#include "TofRawEvent/TofDigi.h"
22#include "MucRawEvent/MucDigi.h"
23
24#include "RootEventData/TMdcDigi.h"
25#include "RootEventData/TTofDigi.h"
26#include "RootEventData/TEmcDigi.h"
27#include "RootEventData/TMucDigi.h"
28
29
30#include "TFile.h"
31#include "TTree.h"
32#include "TBranch.h"
33#include "TObjArray.h"
34
35/////////////////////////////////////////////////////////////////////////////
36
37RootRawEvtReader::RootRawEvtReader(const std::string& name, ISvcLocator* pSvcLocator) :
38 Algorithm(name, pSvcLocator)
39{
40
41 declareProperty("MdcDigi",m_mdcDigi=1);
42 declareProperty("TofDigi",m_tofDigi=1);
43 declareProperty("EmcDigi",m_emcDigi=1);
44 declareProperty("MucDigi",m_mucDigi=1);
45 declareProperty("InputFiles",m_inputFiles);
46
47 m_totalEvents=0;
48 m_fileNumber=0;
49 m_tempNumber=-1;
50 m_currentEntries=-1;
51 m_currentEntry=-1;
52}
53
55{
56}
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
60
61 MsgStream log(msgSvc(), name());
62 log << MSG::INFO << "in initialize()" << endreq;
63
64 ISvcLocator* svcLocator = Gaudi::svcLocator();
65 StatusCode sc=svcLocator->service("EventDataSvc", m_evtSvc);
66 if (sc.isFailure())
67 std::cout<<"Could not accesss EventDataSvc!"<<std::endl;
68
69 return StatusCode::SUCCESS;
70}
71
72// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
74
75 MsgStream log(msgSvc(), name());
76 log << MSG::INFO << "in execute()" << endreq;
77
78 DigiEvent* aDigiEvent = new DigiEvent;
79 StatusCode sc = m_evtSvc->registerObject("/Event/Digi",aDigiEvent);
80 if(sc!=StatusCode::SUCCESS) {
81 std::cout<< "Could not register DigiEvent" <<std::endl;
82 }
83
84
85 if(m_tempNumber != m_fileNumber)
86 {
87 m_currentEntry = 0;
88 TFile* m_input = TFile::Open(m_inputFiles[m_fileNumber].c_str(), "READ");
89 std::cout<<"input file: "<<m_inputFiles[m_fileNumber].c_str()<<std::endl;
90 m_tree= (TTree *)m_input->Get("Event");
91 m_tree->SetMakeClass(1);
92 m_currentEntries=(Int_t)m_tree->GetEntries();
93 std::cout<<"m_currentEntries: "<<m_currentEntries<<std::endl;
94
95 m_tempNumber = m_fileNumber;
96 }
97
98 if(m_mdcDigi)
99 readMdc(m_currentEntry);
100
101 if(m_tofDigi)
102 readTof(m_currentEntry);
103
104 if(m_emcDigi)
105 readEmc(m_currentEntry);
106
107 if(m_mucDigi)
108 readMuc(m_currentEntry);
109
110 log << MSG::INFO << "current Entry: "<< m_currentEntry << endreq;
111 //std::cout << "current Entry: "<< m_currentEntry << std::endl;
112 m_currentEntry++;
113
114 if(m_currentEntry==m_currentEntries)
115 {
116 m_fileNumber++;
117 }
118
119 m_totalEvents++;
120 log << MSG::INFO << "total events: "<< m_totalEvents << endreq;
121 //std::cout << "total events: "<< m_totalEvents << std::endl;
122
123 return StatusCode::SUCCESS;
124}
125
126
127// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
128StatusCode RootRawEvtReader::readMdc(int entry)
129{
130 TBranch *branch = m_tree->GetBranch("m_mdcDigiCol");
131
132 TObjArray* mdcDigiCol;
133 branch->SetAddress(&mdcDigiCol);
134 mdcDigiCol=0;
135
136 branch->GetEntry(entry);
137
138 //commonData m_common;
139
140 TIter mdcDigiIter(mdcDigiCol);
141 MdcDigiCol* mdcDigiTdsCol = new MdcDigiCol;
142 TMdcDigi *mdcDigiRoot = 0;
143
144 while ((mdcDigiRoot = (TMdcDigi*)mdcDigiIter.Next())) {
145 unsigned int id = mdcDigiRoot->getIntId();
146 unsigned int time = mdcDigiRoot->getTimeChannel();
147 unsigned int charge = mdcDigiRoot->getChargeChannel();
148 unsigned int overflow = mdcDigiRoot->getOverflow();
149 int trackIndex = mdcDigiRoot->getTrackIndex();
150
151 MdcDigi *mdcDigiTds = new MdcDigi(id);
152 //m_common.m_rootMdcDigiMap[mdcDigiRoot] = mdcDigiTds;
153 mdcDigiTds->setTimeChannel(time);
154 mdcDigiTds->setChargeChannel(charge);
155 mdcDigiTds->setOverflow(overflow);
156 mdcDigiTds->setTrackIndex(trackIndex);
157 mdcDigiTdsCol->push_back(mdcDigiTds);
158 /*std::cout<<"trackID: "<<trackIndex;
159 std::cout<<" charge: "<<charge;
160 std::cout<<" time: "<<time<<std::endl;*/
161 }
162
163 //register MDC digits collection to TDS
164 StatusCode scMdc = m_evtSvc->registerObject("/Event/Digi/MdcDigiCol", mdcDigiTdsCol);
165 if(scMdc!=StatusCode::SUCCESS)
166 std::cout<< "Could not register MDC digi collection" <<std::endl;
167
168
169 return StatusCode::SUCCESS;
170}
171
172StatusCode RootRawEvtReader::readTof(int entry)
173{
174 TBranch *branch = m_tree->GetBranch("m_tofDigiCol");
175
176 TObjArray* tofDigiCol;
177 branch->SetAddress(&tofDigiCol);
178 tofDigiCol=0;
179
180 branch->GetEntry(entry);
181
182 //commonData m_common;
183
184 TIter tofDigiIter(tofDigiCol);
185 TofDigiCol* tofDigiTdsCol = new TofDigiCol;
186 TTofDigi *tofDigiRoot = 0;
187
188 while ((tofDigiRoot = (TTofDigi*)tofDigiIter.Next())) {
189 unsigned int id = tofDigiRoot->getIntId();
190 unsigned int time = tofDigiRoot->getTimeChannel();
191 unsigned int charge = tofDigiRoot->getChargeChannel();
192 unsigned int overflow = tofDigiRoot->getOverflow();
193 int trackIndex = tofDigiRoot->getTrackIndex();
194
195 TofDigi *tofDigiTds = new TofDigi(id);
196 //m_common.m_rootTofDigiMap[tofDigiRoot] = tofDigiTds;
197 tofDigiTds->setTimeChannel(time);
198 tofDigiTds->setChargeChannel(charge);
199 tofDigiTds->setOverflow(overflow);
200 tofDigiTds->setTrackIndex(trackIndex);
201 tofDigiTdsCol->push_back(tofDigiTds);
202 }
203
204 //register TOF digits collection to TDS
205 StatusCode scTof = m_evtSvc->registerObject("/Event/Digi/TofDigiCol", tofDigiTdsCol);
206 if(scTof!=StatusCode::SUCCESS)
207 std::cout<< "Could not register TOF digi collection" <<std::endl;
208
209
210 return StatusCode::SUCCESS;
211}
212
213StatusCode RootRawEvtReader::readEmc(int entry)
214{
215 TBranch *branch = m_tree->GetBranch("m_emcDigiCol");
216
217 TObjArray* emcDigiCol;
218 branch->SetAddress(&emcDigiCol);
219 emcDigiCol=0;
220
221 branch->GetEntry(entry);
222
223 //commonData m_common;
224
225 TIter emcDigiIter(emcDigiCol);
226 EmcDigiCol* emcDigiTdsCol = new EmcDigiCol;
227 TEmcDigi *emcDigiRoot = 0;
228
229 while ((emcDigiRoot = (TEmcDigi*)emcDigiIter.Next())) {
230 unsigned int id = emcDigiRoot->getIntId();
231 unsigned int time = emcDigiRoot->getTimeChannel();
232 unsigned int charge = emcDigiRoot->getChargeChannel();
233 unsigned int measure = emcDigiRoot->getMeasure();
234 int trackIndex = emcDigiRoot->getTrackIndex();
235
236 EmcDigi *emcDigiTds = new EmcDigi(id);
237 //m_common.m_rootEmcDigiMap[emcDigiRoot] = emcDigiTds;
238 emcDigiTds->setTimeChannel(time);
239 emcDigiTds->setChargeChannel(charge);
240 emcDigiTds->setMeasure(measure);
241 emcDigiTds->setTrackIndex(trackIndex);
242 emcDigiTdsCol->push_back(emcDigiTds);
243 }
244
245 //register EMC digits collection to TDS
246 StatusCode scEmc = m_evtSvc->registerObject("/Event/Digi/EmcDigiCol", emcDigiTdsCol);
247 if(scEmc!=StatusCode::SUCCESS)
248 std::cout<< "Could not register EMC digi collection" <<std::endl;
249
250
251 return StatusCode::SUCCESS;
252}
253
254StatusCode RootRawEvtReader::readMuc(int entry)
255{
256 TBranch *branch = m_tree->GetBranch("m_mucDigiCol");
257
258 TObjArray* mucDigiCol;
259 branch->SetAddress(&mucDigiCol);
260 mucDigiCol=0;
261
262 branch->GetEntry(entry);
263
264 //commonData m_common;
265
266 TIter mucDigiIter(mucDigiCol);
267 MucDigiCol* mucDigiTdsCol = new MucDigiCol;
268 TMucDigi *mucDigiRoot = 0;
269
270 while ((mucDigiRoot = (TMucDigi*)mucDigiIter.Next())) {
271 unsigned int id = mucDigiRoot->getIntId();
272 unsigned int time = mucDigiRoot->getTimeChannel();
273 unsigned int charge = mucDigiRoot->getChargeChannel();
274 int trackIndex = mucDigiRoot->getTrackIndex();
275
276 MucDigi *mucDigiTds = new MucDigi(id);
277 //m_common.m_rootMucDigiMap[mucDigiRoot] = mucDigiTds;
278 mucDigiTds->setTimeChannel(time);
279 mucDigiTds->setChargeChannel(charge);
280 mucDigiTds->setTrackIndex(trackIndex);
281 mucDigiTdsCol->push_back(mucDigiTds);
282 }
283
284 //register MUC digits collection to TDS
285 StatusCode scMuc = m_evtSvc->registerObject("/Event/Digi/MucDigiCol", mucDigiTdsCol);
286 if(scMuc!=StatusCode::SUCCESS)
287 std::cout<< "Could not register MUC digi collection" <<std::endl;
288
289
290 return StatusCode::SUCCESS;
291}
292
293
294// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
296
297 MsgStream log(msgSvc(), name());
298 log << MSG::INFO << "in finalize()" << endreq;
299
300 return StatusCode::SUCCESS;
301}
Double_t time
ObjectVector< MdcDigi > MdcDigiCol
ObjectVector< MucDigi > MucDigiCol
ObjectVector< TofDigi > TofDigiCol
void setMeasure(const unsigned int measure)
void setOverflow(const unsigned int overflow)
void setTrackIndex(const int trackIndex)
Definition: RawData.cxx:35
void setChargeChannel(const unsigned int chargeChannel)
Definition: RawData.cxx:30
void setTimeChannel(const unsigned int timeChannel)
Definition: RawData.cxx:25
StatusCode initialize()
StatusCode execute()
StatusCode readTof(int entry)
StatusCode readMuc(int entry)
virtual ~RootRawEvtReader()
StatusCode readEmc(int entry)
RootRawEvtReader(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode readMdc(int entry)
UInt_t getMeasure() const
Definition: TEmcDigi.cxx:37
UInt_t getOverflow() const
Definition: TMdcDigi.cxx:42
UInt_t getIntId() const
Definition: TRawData.cxx:50
int getTrackIndex() const
Definition: TRawData.cxx:45
UInt_t getChargeChannel() const
Definition: TRawData.cxx:60
UInt_t getTimeChannel() const
Definition: TRawData.cxx:55
UInt_t getOverflow() const
Definition: TTofDigi.cxx:42
void setOverflow(const unsigned int overflow)