BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataInputSvc.cxx
Go to the documentation of this file.
1//===================================================================
2// Implementation of RawDataInputSvc
3//
4//===================================================================
5//
6
7// Include files.
8//#include <fcntl.h>
12#ifndef OnlineMode
15#endif
18
19#include "GaudiKernel/MsgStream.h"
20#include "GaudiKernel/Bootstrap.h"
21#include "GaudiKernel/PropertyMgr.h"
22#include "GaudiKernel/IJobOptionsSvc.h"
23
24DECLARE_COMPONENT(RawDataInputSvc)
25// Constructor.
26RawDataInputSvc::RawDataInputSvc(const std::string& name, ISvcLocator* svcloc)
27 :base_class(name,svcloc),
28 m_re(0),
29 m_reader(0),
30 m_sds(0),
31 m_robs(0)
32{
33 // Get a pointer to the Job Options Service
34 IJobOptionsSvc* jobSvc;
35 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
36
37 PropertyMgr m_propMgr;
38 // 0-NormalNetMode, 1-OnlineMode, 2-OfflineMode, 3-DistBossMode
39 m_propMgr.declareProperty("RunMode", m_mode = 2);
40 m_propMgr.declareProperty("KeepRandomTrigEvt", m_keepRdm = true);
41 m_propMgr.declareProperty("InputFiles", m_inputFiles);
42 m_propMgr.declareProperty("Config4Revise", m_conf4Revise);
43
44 jobSvc->setMyProperties("RawDataInputSvc", &m_propMgr);
45}
46
47// Destructor.
49{
50 //MsgStream log(messageService(), name() );
51 //log << MSG::DEBUG << "RawDataInputSvc Destructor called " << endreq;
52}
53
54// Open the first input file and read the first event.
56{
57 //MsgStream log(messageService(), name() );
58 //log << MSG::DEBUG << " in RawDataInputSvc::initialize()" << endreq;
59
60 //StatusCode sc= IRawDataInputSvc::initialize();
61 //if(!sc.isSuccess()) {
62 // log << MSG::ERROR << "failed to initialize IRawDataInputSvc" << endreq;
63 // return sc;
64 //}
65
66#ifndef OnlineMode
67 if ( m_mode > 1 ) {
68 try {
69 if ( m_mode == 2 ) { //OfflineMode
70 if ( m_inputFiles.empty() ) return StatusCode::SUCCESS;
71 m_reader = new RawFileReader(m_inputFiles);
72 }
73 else if ( m_mode == 3 ) { //DistBossMode
74 DistBoss::GetPropertyValue<std::string>("DistBoss", "ServerName", m_evtServer);
75 m_reader = new NetDataReader(m_evtServer+"/RawEvtSvc");
76 }
77 else {
78 throw RawExMessage("RawDataInputSvc: Invalid RunMode!");
79 }
80 }
81 catch (RawFileException& ex) {
82 ex.print();
83 return StatusCode::FAILURE;
84 }
85
86 m_re = new RAWEVENT;
87
88 m_sds = new const uint32_t*[64];
89 m_robs = new const uint32_t*[256];
90 }
91#endif
92
93 std::ifstream cf(m_conf4Revise.c_str());
94 m_json = SniperJSON::load(cf);
95
96 m_revisor = new OfflineRevise(m_json["ETS_FIX"]);
97
98 return StatusCode::SUCCESS;
99}
100
102 // clean up
103 if ( m_re ) {
104 delete m_re;
105 m_re = 0;
106 }
107
108 if ( m_reader ) {
109 delete m_reader;
110 m_reader = 0;
111 }
112
113 delete m_revisor;
114
115 if ( m_sds ) delete m_sds;
116 if ( m_robs ) delete m_robs;
117
118 return StatusCode::SUCCESS;
119}
120
121// Read the next event.
123
124 //MsgStream log(messageService(), name() );
125#ifndef OnlineMode
126 //OfflineMode and DistBossMode
127 m_re->reset();
128
129 try {
130 RawEvent f;
131 const uint32_t* ef = 0;
132 do {
133 f.assign( m_reader->nextEvent());
134 if (!f.check()) {
135 std::cerr << "Found invalid event (traceback):" << std::endl;
136 std::exit(1);
137 }
138 //1.print basic event information
139 // log << MSG::DEBUG<< "run" << f.run_no() << " [Event No. #" << f.global_id()
140 // << "] " << f.fragment_size_word() << " words in "
141 // << f.nchildren() << " subdetectors "
142 // << endreq;
143
144 //fucd: get event filter information
145 f.event_filter_info(ef);
146 if ( !ef ) {
147 //log << MSG::ERROR << "Event Filter Data Failed!!!" << endreq;
148 exit(1);
149 }
150 else {
151 //log << MSG::DEBUG<< "Event Filter Information*********" <<std::hex<<endreq
152 // <<*ef<< " "<<*(ef+1)<<" "<<*(ef+2)<<" "<<*(ef+3)<<std::dec<<endreq;
153 if ( ! m_keepRdm && ((*ef)>>31) != 0 ) {
154 continue;
155 }
156 }
157 break;
158 } while (true);
159
160 m_re->setRunNo(f.run_no());
161 m_re->setEventNo(f.global_id());
162 m_re->setTime(f.time());
163 m_re->addReHltRaw((uint32_t*)ef, 4);
164
165 //set HV status and get all robs
166 uint32_t hv_status = 0;
167 int nrobs = 0;
168 int nsds = f.children(m_sds, 64);
169 for ( int sdi = 0; sdi < nsds; ++sdi ) {
171
172 if ( sd.nspecific() != 0 ) {
173 const uint32_t* specific_header;
174 sd.specific_header(specific_header);
175 uint32_t source_id_number = sd.source_id();
176 source_id_number <<= 8;
177 source_id_number >>= 24;
178 switch( source_id_number ) {
179 case 161:
180 hv_status |= ((8 | ((*specific_header)&0x7)) << 8);
181 break;
182 case 162:
183 hv_status |= ((8 | ((*specific_header)&0x7)) << 4);
184 break;
185 case 164:
186 hv_status |= (8 | ((*specific_header)&0x7));
187 break;
188 default:
189 break;
190 }
191 }
192
193 nrobs += eformat::get_robs(m_sds[sdi], m_robs+nrobs, 256-nrobs);
194 }
195
196 m_re->setFlag1( hv_status );
197
198 //log << MSG::INFO << " nrobs: " << nrobs << endreq;
199 for (int robi = 0; robi < nrobs; robi++) {
200 eformat::ROBFragment<uint32_t*> rob((uint32_t*)m_robs[robi]);
201 //uint32_t detev_type = rob.rod_detev_type();
202 uint32_t* dataptr = NULL;
203 rob.rod_data(dataptr);
204
205 //log << MSG::DEBUG<< "addReHltRaw" << endreq;
206 uint32_t source_id_number = rob.rod_source_id();
207 //std::cout<<"#####source_id_number#####"<<source_id_number<<std::endl;
208 source_id_number <<= 8;
209 source_id_number >>= 24;
210 //std::cout<<"#####(source_id_number<<24)>>29#####"<<source_id_number<<std::endl;
211
212 if ((rob.rod_detev_type() & 0x2) != 0) {
213 if ( source_id_number == 165 ) {
214 m_re->addReEtsDigi(dataptr, rob.rod_ndata()); // ETS
215 }
216 continue; //bad data or ETS
217 }
218
219 //be careful here!!!
220 switch(source_id_number) {
221 case 161:
222 m_re->addReMdcDigi(dataptr, rob.rod_ndata());
223 break;
224 case 163:
225 m_re->addReEmcDigi(dataptr, rob.rod_ndata());
226 break;
227 case 162:
228 m_re->addReTofDigi(dataptr, rob.rod_ndata());
229 break;
230 case 167: //ETF(MRPC)
231 m_re->addReEtfDigi(dataptr, rob.rod_ndata());
232 break;
233 case 164:
234 m_re->addReMucDigi(dataptr, rob.rod_ndata());
235 break;
236 case 165: // trigger !!!
237 //std::cout << "Get Trigger Data -" << std::endl;
238 //for (int i = 0; i < rob.rod_ndata(); i++) {
239 // std::cout << "\t0x" << std::hex << dataptr[i] << std::dec << std::endl;
240 //}
241 m_re->addReTrigGTD(dataptr, rob.rod_ndata());
242 break;
243 case 166:
244 m_re->addReZddDigi(dataptr, rob.rod_ndata());
245 break;
246 case 124: // EventFilter
247 m_re->addReHltRaw(dataptr, rob.rod_ndata());
248 break;
249 case 241: // McParticle
250 m_re->addMcParticle(dataptr, rob.rod_ndata());
251 break;
252 default:
253 //log << MSG::ERROR << "no such subdetector type: " << source_id_number << endreq;
254 break;
255 }
256 }
257 }
258 catch (RawFileException& ex) {
259 ex.print();
260 if ( m_reader->stat()&4 ) { // fstream badbit is set
261 std::cerr << std::endl << "reading ifstream error !!!" << std::endl;
262 exit(1);
263 }
264 delete m_re;
265 m_re = NULL;
266 }
267 catch (eformat::Issue& ex) {
268 std::cerr << std::endl << "Uncaught eformat issue: " << ex.what() << std::endl;
269 }
270 catch (ers::Issue& ex) {
271 std::cerr << std::endl << "Uncaught ERS issue: " << ex.what() << std::endl;
272 }
273 catch (std::exception& ex) {
274 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
275 }
276 catch (...) {
277 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
278 }
279#endif
280
281 return m_re;
282}
283
284
285/** Get a pointer to the current event.
286 */
288{
289 // Return a pointer to the raw event.
290 //std::cout << "RawDataCnv -> Return a pointer to the raw event." << std::endl;
291 //std::cout << "It is the first time to call the currentEvent()" << std::endl;
292 return m_re;
293}
294
296{
297 //std::cout << "setCurrentEvent(RAWEVENT* m_onlinere)" << std::endl;
298 return (m_re = m_onlinere);
299}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
PthrReaderBufPool< DimRpcReader, 4 > NetDataReader
#define NULL
virtual const uint32_t * nextEvent()=0
virtual uint32_t stat()=0
void addReTofDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:59
void setFlag1(uint32_t flag1)
Definition RAWEVENT.h:49
void setRunNo(uint32_t run_no)
Definition RAWEVENT.h:46
void addReEtsDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:77
void addReMdcDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:53
void addReTrigGTD(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:65
void addReMucDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:62
void addReZddDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:68
void addMcParticle(uint32_t *buf, uint32_t size)
Definition RAWEVENT.h:82
void setTime(uint32_t time)
Definition RAWEVENT.h:48
void setEventNo(uint32_t event_no)
Definition RAWEVENT.h:47
void addReEtfDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:74
void addReEmcDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:56
void addReHltRaw(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:71
void reset()
Definition RAWEVENT.cxx:6
virtual bool setCurrentEvent(RAWEVENT *m_onlinere)
virtual StatusCode initialize()
virtual StatusCode finalize()
virtual ~RawDataInputSvc()
virtual RAWEVENT * currentEvent()
virtual RAWEVENT * nextEvent()
virtual void print() const
static SniperJSON load(std::istream &is)
uint32_t source_id() const
Definition Header.h:116
uint32_t nspecific() const
Definition Header.h:164
void specific_header(TPointer &it) const
Definition Header.h:172
void rod_data(TPointer &it) const
uint32_t rod_source_id() const
uint32_t rod_ndata() const
uint32_t rod_detev_type() const
Root Issue class.
StatusCode GetPropertyValue(const std::string &client, const std::string &name, T &value)
size_t get_robs(const uint32_t *fragment, const uint32_t **rob, size_t max_count)
Definition util.cxx:107