BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataCnvSvc.cxx
Go to the documentation of this file.
1#include "GaudiKernel/GenericAddress.h"
2#include "GaudiKernel/IOpaqueAddress.h"
3#include "GaudiKernel/IRegistry.h"
4#include "GaudiKernel/SmartDataPtr.h"
5
6#include "EventModel/EventModel.h"
7#include "RawDataCnv/ClassID_temp.h"
8#include <iostream>
9
30#include "RawDataCnvSvc.h"
31
33// DECLARE_COMPONENT_WITH_ID( RawDataCnvSvc, "PackedRawDataCnvSvc" );
34
35RawDataCnvSvc::RawDataCnvSvc( const std::string& name, ISvcLocator* svc )
36 : base_class( name, svc, PACKEDRAWEVENT_StorageType ) {
37 declareProperty( "RawDataOutputSvc", m_ioSvcName );
38 declareProperty( "Status", m_status = 0xFFFFFFFF ); // fucd
39}
40
42 StatusCode iret;
43 StatusCode sc = ConversionSvc::initialize();
44
45 if ( sc.isFailure() )
46 {
47 error() << "Unable to initialize ConversionSvc" << endmsg;
48 return sc;
49 }
50
51 IDataProviderSvc* pIDP = 0;
52 // Set event data service
53 sc = service( "EventDataSvc", pIDP, true );
54 if ( !sc.isSuccess() )
55 {
56 error() << "Unable to get EventDataSvc" << endmsg;
57 return sc;
58 }
59
60 sc = setDataProvider( pIDP );
61 if ( !sc.isSuccess() )
62 {
63 error() << "Unable to set DataProvider" << endmsg;
64 return sc;
65 }
66
67 // Add converters to the service
68 sc = addConverters();
69 if ( !sc.isSuccess() )
70 {
71 error() << "Unable to add converters to the service" << endmsg;
72 return sc;
73 }
74
75 // Now we have to configure the map of leaves
76 // Which should contain the association of converters with
77 // paths on the TDS
78 for ( LeafMap::iterator k = m_leaves.begin(); k != m_leaves.end(); k++ )
79 {
80 std::string path = ( *k ).first;
81 for ( LeafMap::iterator j = m_leaves.begin(); j != m_leaves.end(); j++ )
82 {
83 std::string pp = ( *j ).first.substr( 0, ( *j ).first.rfind( "/" ) );
84 if ( path == pp && path != ( *j ).first ) { ( *k ).second->push_back( ( *j ).second ); }
85 }
86 }
87
88 sc = service( m_ioSvcName, m_ioSvc );
89 if ( sc != StatusCode::SUCCESS )
90 {
91 warning() << "Cant get RawDataOutputSvc " << endmsg;
92 // return sc;
93 }
94
95 return StatusCode::SUCCESS;
96}
97
98/// Add converters to the service
100 MsgStream log( msgSvc(), name() );
101 // log << MSG::INFO << name() << " PackedRawDataCnvSvc::addConverters" << endmsg;
103 IRawDataCnvSvc::Leaf( EventModel::EventH, RawDataCnv::classID(), "PASS", 0 ) );
104 // log << MSG::INFO << "EventModel::EventH " << RawDataCnv::classID() << endmsg;
106 "PASS", 0 ) );
107 // log << MSG::INFO << "EventModel::EventHeader " << RawDataEvtHeaderCnv::classID() <<
108 // endmsg;
112 RawDataMcParticleCnv::classID(), "PASS", 0 ) );
114 RawDataMdcMcHitCnv::classID(), "PASS", 0 ) );
116 RawDataTofMcHitCnv::classID(), "PASS", 0 ) );
118 RawDataEmcMcHitCnv::classID(), "PASS", 0 ) );
120 RawDataMucMcHitCnv::classID(), "PASS", 0 ) );
124 RawDataMdcDigiCnv::classID(), "PASS", 0 ) );
126 RawDataTofDigiCnv::classID(), "PASS", 0 ) );
128 RawDataLumiDigiCnv::classID(), "PASS", 0 ) );
130 RawDataEmcDigiCnv::classID(), "PASS", 0 ) );
132 RawDataMucDigiCnv::classID(), "PASS", 0 ) );
136 RawDataTrigGTDCnv::classID(), "PASS", 0 ) );
140 "PASS", 0 ) );
142 RawDataZddEventCnv::classID(), "PASS", 0 ) );
143
144 return StatusCode::SUCCESS;
145}
146
147StatusCode RawDataCnvSvc::connectOutput( const std::string& /* t */ ) {
148
149 MsgStream log( msgSvc(), name() );
150
151 log << MSG::DEBUG << " In connectOutput " << endmsg;
152
153 // Get DataObj from TDS
154 SmartDataPtr<Event::EventHeader> evt( dataProvider(), EventModel::EventHeader );
155 if ( !evt )
156 {
157 log << MSG::ERROR << "Did not retrieve event" << endmsg;
158 return StatusCode::FAILURE;
159 }
160 unsigned int eventNo = evt->eventNumber();
161 unsigned int runNo = evt->runNumber();
162
163 m_rawEvent = new WriteRawEvent( 0x790000, // source_id
164 eventNo, // global_id
165 runNo, // run_no
166 eventNo, // lel1_id
167 0, // lel1_type
168 0, // lel2_info
169 ef_info // ef_info
170 );
171 // const unsigned int status = 0; // place holder for status
172 if ( m_status != 0xFFFFFFFF ) m_rawEvent->status( 1, &m_status );
173 else m_rawEvent->status( 0, NULL ); // fucd
174
175 return StatusCode::SUCCESS;
176}
177
178StatusCode RawDataCnvSvc::commitOutput( const std::string& /* t*/, bool /*b*/ ) {
179 MsgStream log( msgSvc(), name() );
180
181 log << MSG::DEBUG << "In flushOutput" << endmsg;
182
183 if ( !m_ioSvc )
184 {
185 log << MSG::ERROR << "RawDataCnvSvc not configure for output" << endmsg;
186 return StatusCode::FAILURE;
187 }
188
189 log << MSG::DEBUG << "commitOutput: Size of Event (words) =" << m_rawEvent->size_word()
190 << endmsg;
191
192 if ( !m_ioSvc->putEvent( m_rawEvent ) )
193 {
194 log << MSG::ERROR << "commitOutput failed to send output" << endmsg;
195 return StatusCode::FAILURE;
196 }
197
198 // delete ...
199 const eformat::write::SubDetectorFragment* sd = m_rawEvent->first_child();
200 while ( sd != 0 )
201 {
202 const eformat::write::ROSFragment* ros = sd->first_child();
203 while ( ros != 0 )
204 {
205 const eformat::write::ROBFragment* rob = ros->first_child();
206 while ( rob != 0 )
207 {
208 const eformat::write::ROBFragment* rob_tmp = rob;
209 rob = rob->next();
210 delete rob_tmp;
211 }
212 const eformat::write::ROSFragment* ros_tmp = ros;
213 ros = ros->next();
214 delete ros_tmp;
215 }
216 const eformat::write::SubDetectorFragment* sd_tmp = sd;
217 sd = sd->next();
218 delete sd_tmp;
219 }
220 delete m_rawEvent;
221
222 return StatusCode::SUCCESS;
223}
224
225IConverter* RawDataCnvSvc::createConverter( long typ, const CLID& wanted,
226 const ICnvFactory* fac ) {
227 if ( wanted == RawDataCnv::classID() ) return new RawDataCnv( Gaudi::svcLocator() );
228 if ( wanted == RawDataDigiCnv::classID() ) return new RawDataDigiCnv( Gaudi::svcLocator() );
229 if ( wanted == RawDataEmcDigiCnv::classID() )
230 return new RawDataEmcDigiCnv( Gaudi::svcLocator() );
231 if ( wanted == RawDataEmcMcHitCnv::classID() )
232 return new RawDataEmcMcHitCnv( Gaudi::svcLocator() );
233 if ( wanted == RawDataEvtHeaderCnv::classID() )
234 return new RawDataEvtHeaderCnv( Gaudi::svcLocator() );
235 if ( wanted == RawDataHltCnv::classID() ) return new RawDataHltCnv( Gaudi::svcLocator() );
236 if ( wanted == RawDataHltRawCnv::classID() )
237 return new RawDataHltRawCnv( Gaudi::svcLocator() );
238 if ( wanted == RawDataLumiDigiCnv::classID() )
239 return new RawDataLumiDigiCnv( Gaudi::svcLocator() );
240 if ( wanted == RawDataMcCnv::classID() ) return new RawDataMcCnv( Gaudi::svcLocator() );
241 if ( wanted == RawDataMcParticleCnv::classID() )
242 return new RawDataMcParticleCnv( Gaudi::svcLocator() );
243 if ( wanted == RawDataMdcDigiCnv::classID() )
244 return new RawDataMdcDigiCnv( Gaudi::svcLocator() );
245 if ( wanted == RawDataMdcMcHitCnv::classID() )
246 return new RawDataMdcMcHitCnv( Gaudi::svcLocator() );
247 if ( wanted == RawDataMucDigiCnv::classID() )
248 return new RawDataMucDigiCnv( Gaudi::svcLocator() );
249 if ( wanted == RawDataMucMcHitCnv::classID() )
250 return new RawDataMucMcHitCnv( Gaudi::svcLocator() );
251 if ( wanted == RawDataTofDigiCnv::classID() )
252 return new RawDataTofDigiCnv( Gaudi::svcLocator() );
253 if ( wanted == RawDataTofMcHitCnv::classID() )
254 return new RawDataTofMcHitCnv( Gaudi::svcLocator() );
255 if ( wanted == RawDataTrigCnv::classID() ) return new RawDataTrigCnv( Gaudi::svcLocator() );
256 if ( wanted == RawDataTrigGTDCnv::classID() )
257 return new RawDataTrigGTDCnv( Gaudi::svcLocator() );
258 if ( wanted == RawDataZddEventCnv::classID() )
259 return new RawDataZddEventCnv( Gaudi::svcLocator() );
260 return ConversionSvc::createConverter( typ, wanted, fac );
261}
262
264 StatusCode status = ConversionSvc::finalize();
265 for ( LeafMap::iterator k = m_leaves.begin(); k != m_leaves.end(); k++ )
266 { delete ( *k ).second; }
267 m_leaves.erase( m_leaves.begin(), m_leaves.end() );
268 return status;
269}
270
272 // Purpose and Method: Callback from each of the individual converters that allows
273 // association of TDS path and converter.
274 Leaf* ll = new Leaf( leaf );
275 std::pair<LeafMap::iterator, bool> p =
276 m_leaves.insert( LeafMap::value_type( leaf.path, ll ) );
277 if ( p.second ) { return StatusCode::SUCCESS; }
278 delete ll;
279 return StatusCode::FAILURE;
280}
281
282StatusCode RawDataCnvSvc::updateServiceState( IOpaqueAddress* pAddress ) {
283
284 // not sure about the use of recid or bank...
285 MsgStream log( msgSvc(), name() );
286 StatusCode status = Status::INVALID_ADDRESS;
287 IRegistry* ent = pAddress->registry();
288
289 if ( 0 != ent )
290 {
291 SmartIF<IDataManagerSvc> iaddrReg( dataProvider() );
292 // if ( 0 != iaddrReg ) {
293 status = StatusCode::SUCCESS;
294 std::string path = ent->identifier();
295
296 LeafMap::iterator itm = m_leaves.find( path );
297 if ( itm != m_leaves.end() )
298 {
299 IRawDataCnvSvc::Leaf* leaf = ( *itm ).second;
300 if ( 0 != leaf )
301 {
302 // ipar[0] = leaf->userParameter;
303 for ( Leaf::iterator il = leaf->begin(); il != leaf->end(); il++ )
304 {
305 IOpaqueAddress* newAddr = 0;
306 unsigned long ipars[2] = { 0, 0 }; //{(*il)->userParameter, new_rid};
307 const std::string spars[2] = { "", "" }; //{par[0], (*il)->bank};
308
309 StatusCode ir = createAddress( repSvcType(), ( *il )->clid, spars, ipars, newAddr );
310 if ( ir.isSuccess() )
311 {
312 ir = iaddrReg->registerAddress( ( *il )->path, newAddr );
313 if ( !ir.isSuccess() )
314 {
315 newAddr->release();
316 status = ir;
317 }
318 }
319 }
320 }
321 }
322 }
323 else { status = IInterface::Status::NO_INTERFACE; }
324
325 return status;
326}
327
328StatusCode RawDataCnvSvc::createAddress( long storageType, const CLID& clid,
329 const std::string*, const unsigned long*,
330 IOpaqueAddress*& refpAddress ) {
331 MsgStream log( msgSvc(), name() );
332
333 if ( storageType != repSvcType() )
334 {
335 log << MSG::ERROR << "bad storage type" << storageType << endmsg;
336 return StatusCode::FAILURE;
337 }
338
339 refpAddress = new GenericAddress( storageType, clid, "", "", 0 );
340
341 return StatusCode::SUCCESS;
342}
343
344StatusCode RawDataCnvSvc::createAddress( long storageType, const CLID& clid,
345 const std::string&, IOpaqueAddress*& refpAddress ) {
346 return createAddress( storageType, clid, nullptr, nullptr, refpAddress );
347}
int runNo
Definition DQA_TO_DB.cxx:13
eformat::write::FullEventFragment WriteRawEvent
int eventNo
DECLARE_COMPONENT(RawDataCnvSvc)
IMessageSvc * msgSvc()
StatusCode updateServiceState(IOpaqueAddress *pAddress)
RawDataCnvSvc(const std::string &name, ISvcLocator *svc)
StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
Override inherited queryInterface due to enhanced interface.
StatusCode initialize()
StatusCode finalize()
StatusCode addConverters()
Add converters to the service.
IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
StatusCode connectOutput(const std::string &t)
StatusCode declareObject(const IRawDataCnvSvc::Leaf &leaf)
Associates a path on TDS with a particular converter.
StatusCode commitOutput(const std::string &t, bool b)
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()
static const CLID & classID()