Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ConversionSvc.cpp
Go to the documentation of this file.
1 // $Id: ConversionSvc.cpp,v 1.22 2007/09/24 08:58:21 hmd Exp $
2 #define GAUDIKERNEL_CONVERSIONSVC_CPP
3 
8 #include "GaudiKernel/System.h"
13 
14 using ROOT::Reflex::PluginService;
15 
25 };
26 
28  bool ignore_add,
29  bool ignore_obj,
30  bool update,
31  IOpaqueAddress*& pAddress,
32  DataObject*& pObject) {
33  if ( 0 != pAddress || ignore_add ) {
34  if ( 0 != pObject || ignore_obj ) {
35  const CLID& obj_class =
36  (0 != pObject && !ignore_obj) ? pObject->clID()
37  : (0 != pAddress && !ignore_add)
38  ? pAddress->clID()
39  : CLID_NULL;
40  IConverter* cnv = converter(obj_class);
41  if ( !cnv && pObject ) {
42  //Give it a try to autoload the class (dictionary) for which the converter is needed
43  loadConverter( pObject);
44  cnv = converter(obj_class);
45  }
46 
47  StatusCode status(StatusCode::FAILURE,true);
48  if ( 0 != cnv ) {
49  switch(typ) {
50  case CREATE_OBJ:
51  pObject = 0;
52  status = cnv->createObj(pAddress, pObject);
53  break;
54  case FILL_OBJ_REFS:
55  status = cnv->fillObjRefs(pAddress, pObject);
56  break;
57  case UPDATE_OBJ:
58  status = cnv->updateObj(pAddress, pObject);
59  break;
60  case UPDATE_OBJ_REFS:
61  status = cnv->updateObjRefs(pAddress, pObject);
62  break;
63  case CREATE_REP:
64  pAddress = 0;
65  status = cnv->createRep(pObject, pAddress);
66  break;
67  case FILL_REP_REFS:
68  status = cnv->fillRepRefs(pAddress, pObject);
69  break;
70  case UPDATE_REP:
71  status = cnv->updateRep(pAddress, pObject);
72  break;
73  case UPDATE_REP_REFS:
74  status = cnv->updateRepRefs(pAddress, pObject);
75  break;
76  default:
77  status = StatusCode::FAILURE;
78  break;
79  }
80  if ( status.isSuccess() && update ) {
81  status = updateServiceState(pAddress);
82  }
83  return status;
84  }
85  status.ignore();
86  MsgStream log(msgSvc(), name());
87  log << MSG::INFO << "No converter for object ";
88  if ( pObject != 0 ) {
89  log << System::typeinfoName(typeid(*pObject));
90  }
91  log << " CLID= " << obj_class << endmsg;
92  return NO_CONVERTER;
93  }
94  return INVALID_OBJECT;
95  }
96  return INVALID_ADDRESS;
97 }
98 
100 
101 }
102 
104  return StatusCode::SUCCESS;
105 }
106 
109  return makeCall(CREATE_OBJ, false, true, false, pAddress, refpObj);
110 }
111 
114  return makeCall(FILL_OBJ_REFS, false, true, true, pAddress, pObj);
115 }
116 
119  return makeCall(UPDATE_OBJ, false, true, false, pAddress, pObj);
120 }
121 
124  return makeCall(UPDATE_OBJ_REFS, false, true, true, pAddress, pObj);
125 }
126 
129  return makeCall(CREATE_REP, true, false, false, refpAddress, pObj);
130 }
131 
134  return makeCall(FILL_REP_REFS, true, false, false, pAddress, pObj);
135 }
136 
139  return makeCall(UPDATE_REP, true, false, false, pAddress, pObj);
140 }
141 
144  return makeCall(UPDATE_REP_REFS, true, false, false, pAddress, pObj);
145 }
146 
149  IConverter* cnv = 0;
151  if ( i != m_workers->end() ) {
152  cnv = (*i).converter();
153  }
154  if ( 0 == cnv ) {
155  StatusCode status = addConverter(clid);
156  if ( status.isSuccess() ) {
157  i = std::find_if(m_workers->begin(),m_workers->end(),CnvTest(clid));
158  if ( i != m_workers->end() ) {
159  cnv = (*i).converter();
160  }
161  }
162  }
163  return cnv;
164 }
165 
168  if ( !pDataSvc ) return StatusCode::SUCCESS; //Atlas does not use DataSvc
169  if ( m_dataSvc ) m_dataSvc->release();
170  m_dataSvc = pDataSvc;
171  m_dataSvc->addRef();
174  for(Workers::iterator i=start; i != stop; i++ ) {
175  IConverter* cnv = (*i).converter();
176  if ( 0 != cnv ) {
177  if (cnv->setDataProvider(m_dataSvc).isFailure()) {
178  MsgStream log(msgSvc(), name());
179  log << MSG::ERROR << "setting Data Provider" << endmsg;
180  }
181  }
182  }
183  return StatusCode::SUCCESS;
184 }
185 
188  return m_dataSvc;
189 }
190 
193  m_addressCreator = creator;
196  for(Workers::iterator i=start; i != stop; i++ ) {
197  IConverter* cnv = (*i).converter();
198  if ( 0 != cnv ) {
200  MsgStream log(msgSvc(), name());
201  log << MSG::ERROR << "setting Address Creator" << endmsg;
202  }
203  }
204  }
205  return StatusCode::SUCCESS;
206 }
207 
210  return m_addressCreator;
211 }
212 
215  return StatusCode::FAILURE;
216 }
217 
220  return m_cnvSvc;
221 }
222 
225  // First look for the more specific converter
226  long typ = repSvcType();
227  IConverter* pConverter = createConverter(typ, clid, 0);
228  if ( 0 != pConverter ) {
229  StatusCode status = configureConverter( typ, clid, pConverter );
230  if ( status.isSuccess() ) {
231  status = initializeConverter( typ, clid, pConverter );
232  if ( status.isSuccess() ) {
233  status = activateConverter( typ, clid, pConverter );
234  if ( status.isSuccess() ) {
235  long conv_typ = pConverter->repSvcType();
236  const CLID& conv_clid = pConverter->objType();
237  typ = (typ<0xFF) ? typ : typ&0xFFFFFF00;
238  conv_typ = (conv_typ<0xFF) ? conv_typ : conv_typ&0xFFFFFF00;
239  if ( conv_typ == typ && conv_clid == clid ) {
240  return addConverter(pConverter);
241  }
242  }
243  }
244  }
245  pConverter->release();
246  }
247  return NO_CONVERTER;
248 }
249 
252  if ( 0 != pConverter ) {
253  const CLID& clid = pConverter->objType();
254  removeConverter(clid).ignore();
255  m_workers->push_back(WorkerEntry(clid, pConverter));
256  pConverter->addRef();
257  return StatusCode::SUCCESS;
258  }
259  return NO_CONVERTER;
260 }
261 
264  CnvTest test(clid);
267  for(Workers::iterator i=start; i != stop; i++ ) {
268  if ( test( *i ) ) {
269  (*i).converter()->finalize().ignore();
270  (*i).converter()->release();
271  }
272  }
273  Workers::iterator j = std::remove_if(start, stop, test);
274  if ( j != stop ) {
275  m_workers->erase(j, stop);
276  return StatusCode::SUCCESS;
277  }
278  return NO_CONVERTER;
279 }
280 
283  StatusCode status = Service::initialize();
284  return status;
285 }
286 
289  // Release all workers.
290  MsgStream log(msgSvc(), name());
291  for ( Workers::iterator i = m_workers->begin(); i != m_workers->end(); i++ ) {
292  if ( (*i).converter()->finalize().isFailure() ) {
293  log << MSG::ERROR << "finalizing worker" << endmsg;
294  }
295  (*i).converter()->release();
296  }
298  // release interfaces
299  m_addressCreator = 0;
300  m_dataSvc = 0;
301  m_cnvSvc = 0;
302  return Service::finalize();
303 }
304 
305 
308  const CLID& clid,
309  const ICnvFactory* /*fac*/) {
310  IConverter* pConverter;
311  pConverter = PluginService::CreateWithId<IConverter*>(ConverterID(typ,clid),serviceLocator().get());
312  if ( 0 == pConverter ) {
313  typ = (typ<0xFF) ? typ : typ&0xFFFFFF00;
314  pConverter = PluginService::CreateWithId<IConverter*>(ConverterID(typ,clid),serviceLocator().get());
315  }
316  return pConverter;
317 }
318 
321  const CLID& /* clid */,
322  IConverter* pConverter) {
323  if ( 0 != pConverter ) {
324  pConverter->setConversionSvc(this).ignore();
326  pConverter->setDataProvider(m_dataSvc).ignore();
327  return StatusCode::SUCCESS;
328  }
329  return NO_CONVERTER;
330 }
331 
334  const CLID& /* clid */,
335  IConverter* pConverter) {
336  if ( pConverter ) {
337  return pConverter->initialize();
338  }
339  return NO_CONVERTER;
340 }
341 
344  const CLID& /* clid */,
345  IConverter* pConverter) {
346  if ( 0 != pConverter ) {
347  return StatusCode::SUCCESS;
348  }
349  return NO_CONVERTER;
350 }
351 
353 const CLID& ConversionSvc::objType() const {
354  return CLID_NULL;
355 }
356 
359  return m_type;
360 }
361 
364  const std::string& /* openMode */) {
365  return connectOutput(outputFile);
366 }
367 
370  return StatusCode::SUCCESS;
371 }
372 
375  return StatusCode::SUCCESS;
376 }
377 
380  const CLID& /* clid */,
381  const std::string* /* par */,
382  const unsigned long* /* ip */,
383  IOpaqueAddress*& refpAddress) {
384  refpAddress = 0;
385  return StatusCode::FAILURE;
386 }
387 
390  std::string& refAddress)
391 {
392  refAddress = "";
393  return StatusCode::FAILURE;
394 }
395 
398  const CLID& /* clid */,
399  const std::string& /* refAddress */,
400  IOpaqueAddress*& refpAddress)
401 {
402  refpAddress = 0;
403  return StatusCode::FAILURE;
404 }
405 
408  : base_class(name, svc)
409 {
410  m_type = type;
411  m_dataSvc = 0;
412  m_cnvSvc = this;
413  m_workers = new Workers();
414  setAddressCreator(this).ignore();
415 }
416 
419  // Release all workers.
420  for ( Workers::iterator i = m_workers->begin(); i != m_workers->end(); i++ ) {
421  (*i).converter()->release();
422  }
424  delete m_workers;
425 }

Generated at Wed Nov 28 2012 12:17:15 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004