00001 #include <utility>
00002 #include <iostream>
00003 #include "GaudiKernel/SvcFactory.h"
00004
00005 #include "GaudiKernel/ISvcLocator.h"
00006 #include "GaudiKernel/RegistryEntry.h"
00007
00008 #include "RawDataIO/RawReadoutHeaderCnv.h"
00009 #include "RawDataIO/RawDataObjectCnv.h"
00010 #include "RawDataAddress.h"
00011
00012 #include "RawEventHeaderCnv.h"
00013 #include "RawDataConSvc.h"
00014
00015 using namespace std;
00016
00017 extern const long RAWDATA_StorageType;
00018
00019 RawDataConSvc::RawDataConSvc(const string& name, ISvcLocator* svc)
00020 : ConversionSvc(name, svc, RAWDATA_StorageType)
00021 , m_log(msgSvc(), name)
00022 {
00023 m_log << MSG::DEBUG << "constructor" << endreq;
00024 }
00025
00026 StatusCode RawDataConSvc::initialize()
00027 {
00028 m_log << MSG::DEBUG << "initialize()" << endreq;
00029 StatusCode iret;
00030 StatusCode status = ConversionSvc::initialize();
00031 if (status.isSuccess()) {
00032 IDataProviderSvc *pIDP = 0;
00033 status = service("EventDataSvc", pIDP, true);
00034 if (status.isSuccess()) {
00035 status = setDataProvider(pIDP);
00036 } else return status;
00037
00038 status = addConverters();
00039 if (!status.isSuccess()) {
00040 m_log << MSG::ERROR << "Unable to add converters to the service" << endreq;
00041 return status;
00042 }
00043
00044
00045
00046
00047 for (map<string, Leaf*>::iterator k = m_leaves.begin(); k != m_leaves.end(); k++) {
00048 string path = (*k).first;
00049 m_log << MSG::DEBUG << path <<endreq;
00050 for (map<string, Leaf*>::iterator j = m_leaves.begin(); j != m_leaves.end(); j++) {
00051 string pp = (*j).first.substr(0, (*j).first.rfind("/"));
00052 m_log << MSG::DEBUG << pp <<endreq;
00053 if (path == pp && path != (*j).first)(*k).second->push_back((*j).second);
00054 }
00055 }
00056 }
00057 return status;
00058 }
00059
00060 StatusCode RawDataConSvc::finalize()
00061 {
00062 m_log << MSG::DEBUG << "finalize()" << endreq;
00063 StatusCode status = ConversionSvc::finalize();
00064 for (map<string, Leaf*>::iterator k = m_leaves.begin(); k != m_leaves.end(); k++) {
00065 delete(*k).second;
00066 }
00067 m_leaves.erase(m_leaves.begin(), m_leaves.end());
00068
00069 if (status.isFailure()) {
00070 m_log << MSG::ERROR << "Unable to finalize service " << endreq;
00071 return status;
00072 }
00073 return StatusCode::SUCCESS;
00074 }
00075
00076
00077 StatusCode RawDataConSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
00078 {
00079 m_log << MSG::DEBUG << "queryInterface()" << endreq;
00080 if (IID_IRawDataConSvc.versionMatch(riid)) {
00081 *ppvInterface = (IRawDataConSvc*)this;
00082 } else {
00083
00084 return ConversionSvc::queryInterface(riid, ppvInterface);
00085 }
00086 addRef();
00087 return StatusCode::SUCCESS;
00088 }
00089
00090 StatusCode RawDataConSvc::declareObject(const IRawDataConSvc::Leaf& leaf)
00091 {
00092 m_log << MSG::DEBUG << "declareObject() " << leaf.path << endreq;
00093
00094
00095 Leaf* ll = new Leaf(leaf);
00096 pair<map<string, Leaf*>::iterator, bool> p = m_leaves.insert(map<string, Leaf*>::value_type(leaf.path, ll));
00097 if (p.second) return StatusCode::SUCCESS;
00098 else return StatusCode::FAILURE;
00099 delete ll;
00100 }
00101
00102 StatusCode RawDataConSvc::createAddress(long storageType,
00103 const CLID& clid,
00104 const string*,
00105 const unsigned long*,
00106 IOpaqueAddress*& refpAddr)
00107 {
00108 m_log << MSG::DEBUG << "createAddress(storageType=" << storageType << ", CLID=" << clid << ", IOpaqueAddress*=" << refpAddr << ")" << endreq;
00109 if (storageType != repSvcType()) {
00110 m_log << MSG::ERROR << "bad storage type" << storageType << endreq;
00111 return StatusCode::FAILURE;
00112 }
00113
00114 refpAddr = new RawDataAddress(clid, "", "");
00115
00116 return StatusCode::SUCCESS;
00117 }
00118
00119 StatusCode RawDataConSvc::createAddress(long storageType,
00120 const CLID& clid,
00121 const string&,
00122 IOpaqueAddress*& refpAddr)
00123 {
00124 return createAddress(storageType, clid, NULL, NULL, refpAddr);
00125 }
00126
00127 StatusCode RawDataConSvc::addConverters()
00128 {
00129 m_log << MSG::DEBUG << "addConverters(): RawReadoutHeaderCnv" << endreq;
00130 declareObject(IRawDataConSvc::Leaf("/Event", RawDataObjectCnv::classID()));
00131 declareObject(IRawDataConSvc::Leaf("/Event/Readout", RawDataObjectCnv::classID()));
00132 declareObject(IRawDataConSvc::Leaf("/Event/Readout/ReadoutHeader", RawReadoutHeaderCnv::classID()));
00133 declareObject(IRawDataConSvc::Leaf("/Event/Raw", RawDataObjectCnv::classID()));
00134 declareObject(IRawDataConSvc::Leaf("/Event/Raw/RawEventHeader", RawEventHeaderCnv::classID()));
00135 return StatusCode::SUCCESS;
00136 }
00137
00138
00139 StatusCode RawDataConSvc::updateServiceState(IOpaqueAddress* pAddress)
00140 {
00141
00142 m_log << MSG::DEBUG << "updateServiceState(" << pAddress << ")" << endreq;
00143 StatusCode status = INVALID_ADDRESS;
00144 IRegistry* ent = pAddress->registry();
00145 if (0 != ent) {
00146 SmartIF<IDataManagerSvc> iaddrReg(IID_IDataManagerSvc, dataProvider());
00147 status = StatusCode::SUCCESS;
00148 std::string path = ent->identifier();
00149 m_log << MSG::DEBUG << "... for path: " << path << endreq;
00150 map<string, Leaf*>::iterator itm = m_leaves.find(path);
00151 if (itm != m_leaves.end()) {
00152 IRawDataConSvc::Leaf* leaf = (*itm).second;
00153 if (0 != leaf) {
00154 for (Leaf::iterator il = leaf->begin(); il != leaf->end(); il++) {
00155 IOpaqueAddress* newAddr = 0;
00156 unsigned long ipars[2] = {0, 0};
00157 const std::string spars[2] = {"", ""};
00158 StatusCode ir = createAddress(repSvcType(),
00159 (*il)->clid,
00160 spars,
00161 ipars,
00162 newAddr);
00163 if (ir.isSuccess()) {
00164 ir = iaddrReg->registerAddress((*il)->path, newAddr);
00165 if (!ir.isSuccess()) {
00166 newAddr->release();
00167 status = ir;
00168 }
00169 }
00170 }
00171 }
00172 }
00173 } else {
00174 status = NO_INTERFACE;
00175 }
00176 return status;
00177 }
00178
00179