Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

EventCnvSvc.cpp

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GlastSvc/src/EventSelector/EventCnvSvc.cpp,v 1.3 2001/04/19 01:32:29 igable Exp $
00002 #define EVENTCNVSVC_CPP
00003 
00004 
00005 // Include files
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 //extern const IID& IID_ISicbEventCnvSvc;
00024 static const InterfaceID IID_IBaseCnv(902, 1 , 0); 
00025 //extern IID& IID_IBaseCnv;
00026 // RCS Id for identification of object version
00027 static const char* rcsid = "$Id: EventCnvSvc.cpp,v 1.3 2001/04/19 01:32:29 igable Exp $";
00028 
00029 
00030 //------------------------------------------------------------------------------
00031 //
00032 // Implementation of class :  EventCnvSvc
00033 //
00034 // modified SicbEventCnvSvc
00035 //
00036 //------------------------------------------------------------------------------
00037 
00038 
00039 // Instantiation of a static factory class used by clients to create
00040 // instances of this service
00041 static SvcFactory<EventCnvSvc> s_factory;
00042 const ISvcFactory& EventCnvSvcFactory = s_factory;
00043 
00044 
00045 // External factories
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     // Add known converters to the service: 
00059     //======================================================================
00060     IDataProviderSvc *pIDP = 0;
00061     // Set event data service
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     // Now we have to configure the map of leaves
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     // not sure about the use of recid or bank...
00120 
00121   MsgStream log(messageService(), name());
00122 
00123   // convert to an address of an Event
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(); // HMA???
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               //addr->setUserParameter(leaf->userParameter);
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     // Interface is not directly availible: try out a base class
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   // Set address factory for my type
00172   setAddressFactory(&DummyAddressFactory);
00173 }
00174 
00175 
00177 EventCnvSvc::~EventCnvSvc()                         
00178 {
00179 }

Generated at Wed Nov 21 12:21:12 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000