All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ConversionSvc.cpp
Go to the documentation of this file.
1 #define GAUDIKERNEL_CONVERSIONSVC_CPP
2 
6 #include "GaudiKernel/System.h"
11 #include "GaudiKernel/Converter.h"
12 
22 };
23 
25  bool ignore_add,
26  bool ignore_obj,
27  bool update,
28  IOpaqueAddress*& pAddress,
29  DataObject*& pObject) {
30  if ( 0 != pAddress || ignore_add ) {
31  if ( 0 != pObject || ignore_obj ) {
32  const CLID& obj_class =
33  (0 != pObject && !ignore_obj) ? pObject->clID()
34  : (0 != pAddress && !ignore_add)
35  ? pAddress->clID()
36  : CLID_NULL;
37  IConverter* cnv = converter(obj_class);
38  if ( !cnv && pObject ) {
39  //Give it a try to autoload the class (dictionary) for which the converter is needed
40  loadConverter( pObject);
41  cnv = converter(obj_class);
42  }
43 
44  StatusCode status(StatusCode::FAILURE,true);
45  if ( 0 != cnv ) {
46  switch(typ) {
47  case CREATE_OBJ:
48  pObject = 0;
49  status = cnv->createObj(pAddress, pObject);
50  break;
51  case FILL_OBJ_REFS:
52  status = cnv->fillObjRefs(pAddress, pObject);
53  break;
54  case UPDATE_OBJ:
55  status = cnv->updateObj(pAddress, pObject);
56  break;
57  case UPDATE_OBJ_REFS:
58  status = cnv->updateObjRefs(pAddress, pObject);
59  break;
60  case CREATE_REP:
61  pAddress = 0;
62  status = cnv->createRep(pObject, pAddress);
63  break;
64  case FILL_REP_REFS:
65  status = cnv->fillRepRefs(pAddress, pObject);
66  break;
67  case UPDATE_REP:
68  status = cnv->updateRep(pAddress, pObject);
69  break;
70  case UPDATE_REP_REFS:
71  status = cnv->updateRepRefs(pAddress, pObject);
72  break;
73  default:
74  status = StatusCode::FAILURE;
75  break;
76  }
77  if ( status.isSuccess() && update ) {
78  status = updateServiceState(pAddress);
79  }
80  return status;
81  }
82  status.ignore();
83  MsgStream log(msgSvc(), name());
84  log << MSG::INFO << "No converter for object ";
85  if ( pObject != 0 ) {
86  log << System::typeinfoName(typeid(*pObject));
87  }
88  log << " CLID= " << obj_class << endmsg;
89  return NO_CONVERTER;
90  }
91  return INVALID_OBJECT;
92  }
93  return INVALID_ADDRESS;
94 }
95 
97 
98 }
99 
101  return StatusCode::SUCCESS;
102 }
103 
106  return makeCall(CREATE_OBJ, false, true, false, pAddress, refpObj);
107 }
108 
111  return makeCall(FILL_OBJ_REFS, false, true, true, pAddress, pObj);
112 }
113 
116  return makeCall(UPDATE_OBJ, false, true, false, pAddress, pObj);
117 }
118 
121  return makeCall(UPDATE_OBJ_REFS, false, true, true, pAddress, pObj);
122 }
123 
126  return makeCall(CREATE_REP, true, false, false, refpAddress, pObj);
127 }
128 
131  return makeCall(FILL_REP_REFS, true, false, false, pAddress, pObj);
132 }
133 
136  return makeCall(UPDATE_REP, true, false, false, pAddress, pObj);
137 }
138 
141  return makeCall(UPDATE_REP_REFS, true, false, false, pAddress, pObj);
142 }
143 
146  IConverter* cnv = 0;
147  Workers::iterator i = std::find_if(m_workers->begin(),m_workers->end(),CnvTest(clid));
148  if ( i != m_workers->end() ) {
149  cnv = (*i).converter();
150  }
151  if ( 0 == cnv ) {
152  StatusCode status = addConverter(clid);
153  if ( status.isSuccess() ) {
154  i = std::find_if(m_workers->begin(),m_workers->end(),CnvTest(clid));
155  if ( i != m_workers->end() ) {
156  cnv = (*i).converter();
157  }
158  }
159  }
160  return cnv;
161 }
162 
165  if ( !pDataSvc ) return StatusCode::SUCCESS; //Atlas does not use DataSvc
166  if ( m_dataSvc ) m_dataSvc->release();
167  m_dataSvc = pDataSvc;
168  m_dataSvc->addRef();
169  Workers::iterator stop = m_workers->end();
170  Workers::iterator start = m_workers->begin();
171  for(Workers::iterator i=start; i != stop; i++ ) {
172  IConverter* cnv = (*i).converter();
173  if ( 0 != cnv ) {
174  if (cnv->setDataProvider(m_dataSvc).isFailure()) {
175  MsgStream log(msgSvc(), name());
176  log << MSG::ERROR << "setting Data Provider" << endmsg;
177  }
178  }
179  }
180  return StatusCode::SUCCESS;
181 }
182 
185  return m_dataSvc;
186 }
187 
190  m_addressCreator = creator;
191  Workers::iterator stop = m_workers->end();
192  Workers::iterator start = m_workers->begin();
193  for(Workers::iterator i=start; i != stop; i++ ) {
194  IConverter* cnv = (*i).converter();
195  if ( 0 != cnv ) {
197  MsgStream log(msgSvc(), name());
198  log << MSG::ERROR << "setting Address Creator" << endmsg;
199  }
200  }
201  }
202  return StatusCode::SUCCESS;
203 }
204 
207  return m_addressCreator;
208 }
209 
212  return StatusCode::FAILURE;
213 }
214 
217  return m_cnvSvc;
218 }
219 
222  // First look for the more specific converter
223  long typ = repSvcType();
224  IConverter* pConverter = createConverter(typ, clid, 0);
225  if ( 0 != pConverter ) {
226  StatusCode status = configureConverter( typ, clid, pConverter );
227  if ( status.isSuccess() ) {
228  status = initializeConverter( typ, clid, pConverter );
229  if ( status.isSuccess() ) {
230  status = activateConverter( typ, clid, pConverter );
231  if ( status.isSuccess() ) {
232  long conv_typ = pConverter->repSvcType();
233  const CLID& conv_clid = pConverter->objType();
234  typ = (typ<0xFF) ? typ : typ&0xFFFFFF00;
235  conv_typ = (conv_typ<0xFF) ? conv_typ : conv_typ&0xFFFFFF00;
236  if ( conv_typ == typ && conv_clid == clid ) {
237  return addConverter(pConverter);
238  }
239  }
240  }
241  }
242  pConverter->release();
243  }
244  return NO_CONVERTER;
245 }
246 
249  if ( 0 != pConverter ) {
250  const CLID& clid = pConverter->objType();
251  removeConverter(clid).ignore();
252  m_workers->push_back(WorkerEntry(clid, pConverter));
253  pConverter->addRef();
254  return StatusCode::SUCCESS;
255  }
256  return NO_CONVERTER;
257 }
258 
261  CnvTest test(clid);
262  Workers::iterator stop = m_workers->end();
263  Workers::iterator start = m_workers->begin();
264  for(Workers::iterator i=start; i != stop; i++ ) {
265  if ( test( *i ) ) {
266  (*i).converter()->finalize().ignore();
267  (*i).converter()->release();
268  }
269  }
270  Workers::iterator j = std::remove_if(start, stop, test);
271  if ( j != stop ) {
272  m_workers->erase(j, stop);
273  return StatusCode::SUCCESS;
274  }
275  return NO_CONVERTER;
276 }
277 
280  StatusCode status = Service::initialize();
281  return status;
282 }
283 
286  // Release all workers.
287  MsgStream log(msgSvc(), name());
288  for ( Workers::iterator i = m_workers->begin(); i != m_workers->end(); i++ ) {
289  if ( (*i).converter()->finalize().isFailure() ) {
290  log << MSG::ERROR << "finalizing worker" << endmsg;
291  }
292  (*i).converter()->release();
293  }
294  m_workers->erase(m_workers->begin(), m_workers->end() );
295  // release interfaces
296  m_addressCreator = 0;
297  m_dataSvc = 0;
298  m_cnvSvc = 0;
299  return Service::finalize();
300 }
301 
302 
305  const CLID& clid,
306  const ICnvFactory* /*fac*/) {
307  IConverter* pConverter;
308  pConverter = Converter::Factory::create(ConverterID(typ,clid), serviceLocator().get());
309  if ( 0 == pConverter ) {
310  typ = (typ<0xFF) ? typ : typ&0xFFFFFF00;
311  pConverter = Converter::Factory::create(ConverterID(typ,clid), serviceLocator().get());
312  }
313  return pConverter;
314 }
315 
318  const CLID& /* clid */,
319  IConverter* pConverter) {
320  if ( 0 != pConverter ) {
321  pConverter->setConversionSvc(this).ignore();
323  pConverter->setDataProvider(m_dataSvc).ignore();
324  return StatusCode::SUCCESS;
325  }
326  return NO_CONVERTER;
327 }
328 
331  const CLID& /* clid */,
332  IConverter* pConverter) {
333  if ( pConverter ) {
334  return pConverter->initialize();
335  }
336  return NO_CONVERTER;
337 }
338 
341  const CLID& /* clid */,
342  IConverter* pConverter) {
343  if ( 0 != pConverter ) {
344  return StatusCode::SUCCESS;
345  }
346  return NO_CONVERTER;
347 }
348 
350 const CLID& ConversionSvc::objType() const {
351  return CLID_NULL;
352 }
353 
356  return m_type;
357 }
358 
360 StatusCode ConversionSvc::connectOutput(const std::string& outputFile,
361  const std::string& /* openMode */) {
362  return connectOutput(outputFile);
363 }
364 
366 StatusCode ConversionSvc::connectOutput(const std::string& /* outputFile */) {
367  return StatusCode::SUCCESS;
368 }
369 
371 StatusCode ConversionSvc::commitOutput(const std::string& , bool ) {
372  return StatusCode::SUCCESS;
373 }
374 
377  const CLID& /* clid */,
378  const std::string* /* par */,
379  const unsigned long* /* ip */,
380  IOpaqueAddress*& refpAddress) {
381  refpAddress = 0;
382  return StatusCode::FAILURE;
383 }
384 
387  std::string& refAddress)
388 {
389  refAddress = "";
390  return StatusCode::FAILURE;
391 }
392 
395  const CLID& /* clid */,
396  const std::string& /* refAddress */,
397  IOpaqueAddress*& refpAddress)
398 {
399  refpAddress = 0;
400  return StatusCode::FAILURE;
401 }
402 
404 ConversionSvc::ConversionSvc(const std::string& name, ISvcLocator* svc, long type)
405  : base_class(name, svc),
406  m_cnvSvc(static_cast<IConversionSvc*>(this))
407 {
408  m_type = type;
409  m_dataSvc = 0;
410  m_workers = new Workers();
411  setAddressCreator(this).ignore();
412 }
413 
416  // Release all workers.
417  for ( Workers::iterator i = m_workers->begin(); i != m_workers->end(); i++ ) {
418  (*i).converter()->release();
419  }
420  m_workers->erase(m_workers->begin(), m_workers->end() );
421  delete m_workers;
422 }
virtual const CLID & objType() const =0
Retrieve the class type of objects the converter produces.
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Implementation of IConverter: Convert the transient object to the requested representation.
virtual SmartIF< IConversionSvc > & conversionSvc() const
Implementation of IConverter: Get conversion service the converter is connected to.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual StatusCode configureConverter(long typ, const CLID &clid, IConverter *cnv)
Configure the new converter before initialize is called.
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Resolve the references of the created transient object.
StatusCode makeCall(int typ, bool ignore_add, bool ignore_obj, bool update, IOpaqueAddress *&pAddress, DataObject *&pObject)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
virtual StatusCode commitOutput(const std::string &output, bool do_commit)
Commit pending output.
The data converters are responsible to translate data from one representation into another...
Definition: IConverter.h:57
const CLID & objType() const
Implementation of IConverter: dummy call.
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)=0
Create the transient representation of an object.
Invalid address information.
Definition: IConverter.h:205
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
Definition: Service.cpp:152
Workers * m_workers
List of conversion workers.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298
virtual StatusCode updateRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Update the references of an already converted object.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
ConversionSvc(const std::string &name, ISvcLocator *svc, long type)
Standard Constructor.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Resolve the references of the converted object.
virtual StatusCode addConverter(const CLID &clid)
Add converter object to conversion service.
IAddressCreator interface definition.
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
Definition: ConversionSvc.h:50
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject)
Implementation of IConverter: Update the transient object from the other representation.
virtual StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Update the converted representation of a transient object.
virtual StatusCode connectOutput(const std::string &outputFile, const std::string &openMode)
Connect the output file to the service with open mode.
SmartIF< IAddressCreator > m_addressCreator
Pointer to the address creation service interface.
virtual ~ConversionSvc()
Standard Destructor.
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)=0
Convert the transient object to the requested representation.
Data provider interface definition.
Object to be converted is invalid.
Definition: IConverter.h:207
virtual StatusCode updateRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the references of an already converted object.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
virtual void loadConverter(DataObject *pObject)
Load converter or dictionary needed by the converter.
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject)=0
Update the transient object from the other representation.
virtual StatusCode removeConverter(const CLID &clid)
Remove converter object from conversion service (if present).
virtual StatusCode setConversionSvc(IConversionSvc *pService)=0
Set conversion service the converter is connected to.
virtual StatusCode setConversionSvc(IConversionSvc *svc)
Implementation of IConverter: Set conversion service the converter is connected to.
virtual long repSvcType() const
Retrieve the class type of the data store the converter uses.
string type
Definition: gaudirun.py:126
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:58
virtual StatusCode finalize()
stop the service.
virtual const CLID & clID() const =0
Retrieve class information from link.
virtual long repSvcType() const =0
Retrieve the class type of the data store the converter uses.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the references of an updated transient object.
virtual StatusCode setAddressCreator(IAddressCreator *creator)
Set address creator facility.
CnvSvcAction
virtual StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the converted representation of a transient object.
unsigned int CLID
Class ID definition.
Definition: ClassID.h:9
virtual StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress)
Convert an address to string form.
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)
Implementation of IConverter: Create the transient representation of an object.
virtual StatusCode initialize()=0
Initialize the converter.
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
virtual StatusCode updateServiceState(IOpaqueAddress *pAddress)
Update state of the service.
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to data provider service.
No proper converter is available to the service.
virtual StatusCode setAddressCreator(IAddressCreator *creator)=0
Set address creator facility.
virtual StatusCode initializeConverter(long typ, const CLID &clid, IConverter *cnv)
Initialize the new converter.
def update
Definition: install.py:213
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Resolve the references of the created transient object.
virtual unsigned long release()=0
Release Interface instance.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:74
SmartIF< IConversionSvc > m_cnvSvc
Pointer to the IConversionSvc interface of this.
long m_type
Conversion service type.
Templated class to add the standard messaging functionalities.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
virtual StatusCode setDataProvider(IDataProviderSvc *pService)
Implementation of IConverter: Set Data provider service.
virtual IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new Converter using factory.
virtual SmartIF< IAddressCreator > & addressCreator() const
Retrieve address creator facility.
virtual StatusCode initialize()
Initialize the service.
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
Create a Generic address using explicit arguments to identify a single object.
virtual StatusCode start()
Start (from INITIALIZED to RUNNING).
Definition: Service.cpp:158
Opaque address interface definition.
void ignore() const
Definition: StatusCode.h:107
virtual IConverter * converter(const CLID &wanted)
Retrieve converter from list.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
list i
Definition: ana.py:128
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Resolve the references of the converted object.
virtual StatusCode activateConverter(long typ, const CLID &clid, IConverter *cnv)
Activate the new converter after initialization.
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:199
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::vector< WorkerEntry > Workers
Definition: ConversionSvc.h:75
virtual StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Update the references of an updated transient object.
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:336
virtual SmartIF< IDataProviderSvc > & dataProvider() const
Implementation of IConverter: Get Data provider service.