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