00001 00002 #include "SimpleOuputModule.h" 00003 #include "RootIOSvc/IRootIOSvc.h" 00004 00005 #include "GaudiKernel/RegistryEntry.h" 00006 #include "GaudiKernel/IConversionSvc.h" 00007 00008 using namespace std; 00009 00010 SimpleOuputModule::SimpleOuputModule(const std::string& name, 00011 ISvcLocator* pSvcLocator) 00012 : GaudiAlgorithm(name,pSvcLocator) 00013 , m_rio(0) 00014 , m_cnv(0) 00015 { 00016 } 00017 00018 SimpleOuputModule::~SimpleOuputModule() 00019 { 00020 } 00021 00022 StatusCode SimpleOuputModule::initialize() 00023 { 00024 StatusCode sc = this->GaudiAlgorithm::initialize(); 00025 if (sc.isFailure()) return sc; 00026 00027 sc = serviceLocator()->getService("RootIOCnvSvc", 00028 IID_IConversionSvc, 00029 *pp_cast<IInterface>(&m_cnv)); 00030 if (sc.isFailure()) { 00031 error() << "Failed to get IConversionSvc RootIOCnvSvc" << endreq; 00032 return sc; 00033 } 00034 00035 sc = m_cnv->queryInterface(IRootIOSvc::interfaceID(),(void**)&m_rio); 00036 if (sc.isFailure()) { 00037 error() << "Failed to get IRootIOSvc interface from RootIOCnvSvc" << endreq; 00038 return sc; 00039 } 00040 00041 return sc; 00042 } 00043 00044 StatusCode SimpleOuputModule::execute() 00045 { 00046 DataObject *d = get<DataObject>("/Event"); 00047 StatusCode sc = this->createReps(d); 00048 if (sc.isFailure()) { 00049 error() << "Failed in calling createReps" << endreq; 00050 return sc; 00051 } 00052 00053 sc = this->fillRepRefs(d); 00054 if (sc.isFailure()) { 00055 error() << "Failed in calling fillRepRefs" << endreq; 00056 } 00057 return sc; 00058 } 00059 00060 StatusCode SimpleOuputModule::createReps(DataObject* dobj) 00061 { 00062 IRegistry* dr = dobj->registry(); 00063 using namespace DataSvcHelpers; 00064 RegistryEntry* dre = dynamic_cast<RegistryEntry*>(dr); 00065 if (!dre) { 00066 error() << "Failed in createReps to get RegistryEntry for " 00067 << dr->identifier() << endreq; 00068 return StatusCode::FAILURE; 00069 } 00070 00071 RegistryEntry::Iterator it = dre->begin(), done = dre->end(); 00072 for (; it != done; ++it) { 00073 string id = (*it)->identifier(); 00074 00075 DataObject* child = get<DataObject>(id); 00076 if (!child) { 00077 error() << "Failed in createReps to get object for " 00078 << id << endreq; 00079 return StatusCode::FAILURE; 00080 } 00081 00082 IOpaqueAddress* addr = 0; 00083 StatusCode sc = m_cnv->createRep(child,addr); 00084 if (sc.isFailure()) { 00085 warning() << "Failed to createRep for " << id << ", skipping" << endreq; 00086 continue; 00087 } 00088 IRegistry* reg = child->registry(); 00089 reg->setAddress(addr); 00090 00091 sc = this->createReps(child); 00092 if (sc.isFailure()) return sc; 00093 } 00094 return StatusCode::SUCCESS; 00095 } 00096 00097 StatusCode SimpleOuputModule::fillRepRefs(DataObject* dobj) 00098 { 00099 IRegistry* dr = dobj->registry(); 00100 using namespace DataSvcHelpers; 00101 RegistryEntry* dre = dynamic_cast<RegistryEntry*>(dr); 00102 if (!dre) { 00103 error() << "Failed in fillReps to get RegistryEntry for " 00104 << dr->identifier() << endreq; 00105 return StatusCode::FAILURE; 00106 } 00107 00108 RegistryEntry::Iterator it = dre->begin(), done = dre->end(); 00109 for (; it != done; ++it) { 00110 string id = (*it)->identifier(); 00111 00112 DataObject* child = get<DataObject>(id); 00113 if (!child) { 00114 error() << "Failed to in fillReps get object for " 00115 << id << endreq; 00116 return StatusCode::FAILURE; 00117 } 00118 00119 IRegistry* reg = child->registry(); 00120 StatusCode sc = m_cnv->fillRepRefs(reg->address(), child); 00121 if (sc.isFailure()) { 00122 warning() << "Failed to fillRepRefs with " 00123 << id << ", skipping" << endreq; 00124 continue; 00125 } 00126 00127 sc = this->fillRepRefs(child); 00128 if (sc.isFailure()) return sc; 00129 } 00130 return StatusCode::SUCCESS; 00131 } 00132 00133 StatusCode SimpleOuputModule::finalize() 00134 { 00135 00136 return this->GaudiAlgorithm::finalize(); 00137 } 00138