CGEM BOSS 6.6.5.i
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>
11#ifndef OnlineMode
14#endif
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 = false);
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:
215 m_re->addReTofDigi(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 delete m_re;
245 m_re = NULL;
246 }
247 catch (eformat::Issue& ex) {
248 std::cerr << std::endl << "Uncaught eformat issue: " << ex.what() << std::endl;
249 }
250 catch (ers::Issue& ex) {
251 std::cerr << std::endl << "Uncaught ERS issue: " << ex.what() << std::endl;
252 }
253 catch (std::exception& ex) {
254 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
255 }
256 catch (...) {
257 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
258 }
259#endif
260
261 return m_re;
262}
263
264
265/** Get a pointer to the current event.
266 */
268{
269 // Return a pointer to the raw event.
270 //std::cout << "RawDataCnv -> Return a pointer to the raw event." << std::endl;
271 //std::cout << "It is the first time to call the currentEvent()" << std::endl;
272 return m_re;
273}
274
276{
277 //std::cout << "setCurrentEvent(RAWEVENT* m_onlinere)" << std::endl;
278 return (m_re = m_onlinere);
279}
PthrReaderBufPool< DimRpcReader, 4 > NetDataReader
virtual const uint32_t * nextEvent()=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 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:76
void setTime(uint32_t time)
Definition RAWEVENT.h:48
void setEventNo(uint32_t event_no)
Definition RAWEVENT.h:47
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()
RawDataInputSvc(const std::string &name, ISvcLocator *svcloc)
virtual RAWEVENT * nextEvent()
virtual void print() const
FullEventFragment & assign(const TPointer &it)
void event_filter_info(TPointer &it) const
virtual uint32_t children(TPointer *p, size_t max) const
Definition Header.h:293
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:105