CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataCnvSvc.cxx
Go to the documentation of this file.
1#include "GaudiKernel/SmartDataPtr.h"
2#include "GaudiKernel/SmartIF.h"
3#include "GaudiKernel/SvcFactory.h"
4#include "GaudiKernel/CnvFactory.h"
5#include "GaudiKernel/MsgStream.h"
6
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/IDataProviderSvc.h"
9#include "GaudiKernel/IDataManagerSvc.h"
10#include "GaudiKernel/RegistryEntry.h"
11#include "GaudiKernel/GenericAddress.h"
12
13#include "RawDataCnvBase/RawDataBaseCnv.h"
14#include "RawDataCnvBase/RawDataCnvSvc.h"
15#include "EventModel/EventModel.h"
16#include <iostream>
17
18static const InterfaceID IID_IRawDataCnvSvc("IRawDataCnvSvc", 1 , 0);
19
20// RCS Id for identification of object version
21// static const char* rcsid = "$Id: RawDataCnvSvc.cxx,v 1.12 2011/02/17 01:14:23 maqm Exp $";
22
23RawDataCnvSvc::RawDataCnvSvc(const std::string& name, ISvcLocator* svc, long storageType)
24: ConversionSvc(name, svc, storageType)
25{
26}
27
29 // Purpose and Method: Setup Converter Service.
30 // Associate RawDataCnvSvc with the EventDataSvc
31 // Associate the list of known converters with this RawDataCnvSvc.
32
33 MsgStream log(messageService(), name());
34
35 StatusCode iret;
36 StatusCode status = ConversionSvc::initialize();
37 if ( status.isSuccess() ) {
38
39 IDataProviderSvc *pIDP = 0;
40 // Set event data service
41 status = service("EventDataSvc", pIDP, true);
42 if ( status.isSuccess() ) {
43 status = setDataProvider ( pIDP );
44 }
45 else {
46 return status;
47 }
48
49 // Add converters to the service
50 status = addConverters();
51 if ( !status.isSuccess() ) {
52 log << MSG::ERROR << "Unable to add converters to the service" << endreq;
53 return status;
54 }
55
56 // Now we have to configure the map of leaves
57 // Which should contain the association of converters with
58 // paths on the TDS
59 for (LeafMap::iterator k = m_leaves.begin(); k != m_leaves.end(); k++ ) {
60 std::string path = (*k).first;
61 for (LeafMap::iterator j = m_leaves.begin(); j != m_leaves.end(); j++ ) {
62 std::string pp = (*j).first.substr(0, (*j).first.rfind("/"));
63 if ( path == pp && path != (*j).first ) {
64 (*k).second->push_back((*j).second);
65 }
66 }
67 }
68
69 }
70
71 return status;
72}
73
75 StatusCode status = ConversionSvc::finalize();
76 for (LeafMap::iterator k = m_leaves.begin(); k != m_leaves.end(); k++ ) {
77 delete (*k).second;
78 }
79 m_leaves.erase(m_leaves.begin(), m_leaves.end());
80 return status;
81}
82
84 // Purpose and Method: Callback from each of the individual converters that allows
85 // association of TDS path and converter.
86 Leaf* ll = new Leaf(leaf);
87 std::pair<LeafMap::iterator, bool> p = m_leaves.insert(LeafMap::value_type( leaf.path, ll) );
88 if( p.second ) {
89 return StatusCode::SUCCESS;
90 }
91 delete ll;
92 return StatusCode::FAILURE;
93}
94
95/// Update state of the service
96StatusCode RawDataCnvSvc::updateServiceState(IOpaqueAddress* pAddress) {
97
98 // not sure about the use of recid or bank...
99 MsgStream log(msgSvc(), name());
100
101 StatusCode status = INVALID_ADDRESS;
102 IRegistry* ent = pAddress->registry();
103
104 if ( 0 != ent ) {
105 SmartIF<IDataManagerSvc> iaddrReg( dataProvider());
106 // if ( 0 != iaddrReg ) {
107 status = StatusCode::SUCCESS;
108 std::string path = ent->identifier();
109
110 LeafMap::iterator itm = m_leaves.find(path);
111 if ( itm != m_leaves.end() ) {
112 IRawDataCnvSvc::Leaf* leaf = (*itm).second;
113 if ( 0 != leaf ) {
114 //ipar[0] = leaf->userParameter;
115 for ( Leaf::iterator il = leaf->begin(); il != leaf->end(); il++ ) {
116 IOpaqueAddress* newAddr = 0;
117 unsigned long ipars[2] = {0, 0}; //{(*il)->userParameter, new_rid};
118 const std::string spars[2] = {"", ""}; //{par[0], (*il)->bank};
119 /* fix for Gaidi V16r4 -- Weidong Li 2005.10.25
120 StatusCode ir =
121 addressCreator()->createAddress(storageType,
122 (*il)->clid,
123 spars,
124 ipars,
125 newAddr);
126 */
127 StatusCode ir = createAddress(repSvcType(),
128 (*il)->clid,
129 spars,
130 ipars,
131 newAddr);
132 if ( ir.isSuccess() ) {
133 ir = iaddrReg->registerAddress((*il)->path, newAddr);
134 if ( !ir.isSuccess() ) {
135 newAddr->release();
136 status = ir;
137 }
138 }
139 }
140 }
141 }
142 }
143 else {
144 status = NO_INTERFACE;
145 }
146
147 return status;
148}
149
150StatusCode RawDataCnvSvc::queryInterface(const InterfaceID& riid, void** ppvInterface) {
151 if ( IID_IRawDataCnvSvc == riid ) {
152 *ppvInterface = (IRawDataCnvSvc*)this;
153 }
154 else {
155 // Interface is not directly availible: try out a base class
156 return ConversionSvc::queryInterface(riid, ppvInterface);
157 }
158 addRef();
159 return StatusCode::SUCCESS;
160}
161
162StatusCode RawDataCnvSvc::createAddress(long storageType,
163 const CLID& clid,
164 const std::string*,
165 const unsigned long*,
166 IOpaqueAddress*& refpAddress)
167{
168 MsgStream log( msgSvc(), name() );
169
170 if (storageType != repSvcType() ) {
171 log << MSG::ERROR << "bad storage type" << storageType << endreq;
172 return StatusCode::FAILURE;
173 }
174
175 refpAddress = new GenericAddress(storageType,
176 clid,
177 "",
178 "",
179 0);
180
181 return StatusCode::SUCCESS;
182}
183
184StatusCode RawDataCnvSvc::createAddress(long storageType,
185 const CLID& clid,
186 const std::string&,
187 IOpaqueAddress*& refpAddress)
188{
189 return createAddress(storageType, clid, NULL, NULL, refpAddress);
190}
StatusCode updateServiceState(IOpaqueAddress *pAddress)
Update state of the service.
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
virtual StatusCode initialize()
virtual StatusCode finalize()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Override inherited queryInterface due to enhanced interface.
virtual StatusCode addConverters()=0
virtual StatusCode declareObject(const IRawDataCnvSvc::Leaf &leaf)
Associates a path on TDS with a particular converter.
RawDataCnvSvc(const std::string &name, ISvcLocator *svc, long storageTyp)