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