00001
00002 #define EVENTCNVSVC_CPP
00003
00004
00005
00006 #include <iostream>
00007 #include "GaudiKernel/SvcFactory.h"
00008 #include "GaudiKernel/CnvFactory.h"
00009 #include "GaudiKernel/AddrFactory.h"
00010 #include "GaudiKernel/HashTable.h"
00011 #include "GaudiKernel/MsgStream.h"
00012 #include "GaudiKernel/ICnvManager.h"
00013 #include "GaudiKernel/ISvcLocator.h"
00014 #include "GaudiKernel/IDataProviderSvc.h"
00015 #include "GaudiKernel/RegistryEntry.h"
00016 #include "BaseCnv.h"
00017
00018 #include "GaudiKernel/AddrFactory.h"
00019
00020 #include "Address.h"
00021 #include "EventCnvSvc.h"
00022
00023
00024 static const InterfaceID IID_IBaseCnv(902, 1 , 0);
00025
00026
00027 static const char* rcsid = "$Id: EventCnvSvc.cpp,v 1.3 2001/04/19 01:32:29 igable Exp $";
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 static SvcFactory<EventCnvSvc> s_factory;
00042 const ISvcFactory& EventCnvSvcFactory = s_factory;
00043
00044
00045
00046
00047 extern const IAddrFactory& DummyAddressFactory;
00048 extern const IID& IID_ISicbEventCnvSvc;
00049 extern const ICnvFactory& EventCnvFactory;
00050
00051
00053 StatusCode EventCnvSvc::initialize() {
00054 StatusCode status = ConversionSvc::initialize();
00055 if ( status.isSuccess() ) {
00056 ISvcLocator* svclocator = serviceLocator();
00057
00058
00059
00060 IDataProviderSvc *pIDP = 0;
00061
00062 status = serviceLocator()->getService("EventDataSvc", IID_IDataProviderSvc, (IInterface*&)pIDP);
00063 if ( status.isSuccess() ) {
00064 status = setStore ( pIDP );
00065 }
00066 else {
00067 return status;
00068 }
00069
00070 ICnvManager::CnvIterator i, stop;
00071 for ( i = cnvManager()->cnvBegin(), stop = cnvManager()->cnvEnd(); i != stop; i++ ) {
00072 if ( repSvcType() == (*i)->repSvcType() ) {
00073 StatusCode iret = addConverter( *(*i) );
00074 if ( !iret.isSuccess() ) {
00075 status = iret;
00076 }
00077 }
00078 }
00079
00080
00081 for (LeafMap::iterator k = m_leaves.begin(); k != m_leaves.end(); k++ ) {
00082 std::string path = (*k).first;
00083 for (LeafMap::iterator j = m_leaves.begin(); j != m_leaves.end(); j++ ) {
00084 std::string pp = (*j).first.substr(0, (*j).first.rfind("/"));
00085 if ( path == pp && path != (*j).first ) {
00086 (*k).second->push_back((*j).second);
00087 }
00088 }
00089 }
00090
00091 }
00092
00093 return status;
00094 }
00095
00097 StatusCode EventCnvSvc::finalize() {
00098 StatusCode status = ConversionSvc::finalize();
00099 for (LeafMap::iterator k = m_leaves.begin(); k != m_leaves.end(); k++ ) {
00100 delete (*k).second;
00101 }
00102 m_leaves.erase(m_leaves.begin(), m_leaves.end());
00103 return status;
00104 }
00105
00106 StatusCode EventCnvSvc::declareObject(const IEventCnvSvc::Leaf& leaf) {
00107 Leaf* ll = new Leaf(leaf);
00108 std::pair<LeafMap::iterator, bool> p = m_leaves.insert(LeafMap::value_type( leaf.path, ll) );
00109 if( p.second ) {
00110 return StatusCode::SUCCESS;
00111 }
00112 delete ll;
00113 return StatusCode::FAILURE;
00114 }
00115
00117 StatusCode EventCnvSvc::updateServiceState(IOpaqueAddress* pAddress) {
00118
00119
00120
00121 MsgStream log(messageService(), name());
00122
00123
00124 Address* addr = dynamic_cast<Address*>(pAddress);
00125 if ( 0 != addr ) {
00126 const std::string& new_fid = addr->dbName();
00127 int new_recid = addr->sicbInfo()->entryID();
00128
00129 IDataDirectory* dir = addr->directory();
00130 if ( 0 != dir ) {
00131 RegistryEntry* ent = dynamic_cast<RegistryEntry*>(dir);
00132 if ( 0 != ent && 0 == ent->object() ) {
00133 std::string path = dir->fullpath();
00134 LeafMap::iterator itm = m_leaves.find(path);
00135 if ( itm != m_leaves.end() ) {
00136 IEventCnvSvc::Leaf* leaf = (*itm).second;
00137 if ( 0 != leaf ) {
00138
00139 for ( Leaf::iterator il = leaf->begin(); il != leaf->end(); il++ ) {
00140 RegistryEntry* newEntry = new RegistryEntry((*il)->path, 0);
00141 newEntry->setAddress(new Address((*il)->clid, new_fid, new_recid, (*il)->bank));
00142 ent->add( newEntry );
00143 }
00144 }
00145 }
00146 }
00147 }
00148 return StatusCode::SUCCESS;
00149 }
00150 return StatusCode::FAILURE;
00151 }
00152
00154 StatusCode EventCnvSvc::queryInterface(const IID& riid, void** ppvInterface) {
00155 if ( IID_IBaseCnv == riid ) {
00156 *ppvInterface = (IEventCnvSvc*)this;
00157 }
00158 else {
00159
00160 return ConversionSvc::queryInterface(riid, ppvInterface);
00161 }
00162 addRef();
00163 return StatusCode::SUCCESS;
00164 }
00165
00166
00168 EventCnvSvc::EventCnvSvc(const std::string& name, ISvcLocator* svc)
00169 : ConversionSvc(name, svc, SICB_StorageType)
00170 {
00171
00172 setAddressFactory(&DummyAddressFactory);
00173 }
00174
00175
00177 EventCnvSvc::~EventCnvSvc()
00178 {
00179 }