00001 #include "RootIOSvc/RootIOBaseCnv.h"
00002 #include "RootIOSvc/RootIOAddress.h"
00003
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/DataObject.h"
00006
00007 RootIOBaseCnv::RootIOBaseCnv(const CLID& clid, ISvcLocator* svc)
00008 : Converter(ROOT_StorageType,clid,svc)
00009 , m_rioSvc(0)
00010 {
00011 }
00012
00013 RootIOBaseCnv::~RootIOBaseCnv()
00014 {
00015 }
00016
00017 StatusCode RootIOBaseCnv::initialize()
00018 {
00019 StatusCode sc = Converter::initialize();
00020 if (sc.isFailure()) return sc;
00021
00022 MsgStream log(msgSvc(), "RootIOBaseCnv");
00023
00024 IService* isvc=0;
00025 sc = serviceLocator()->service("RootIOCnvSvc", isvc, false);
00026 if (sc.isFailure()) {
00027 log << MSG::ERROR << "Conversion service RootIOCnvSvc"
00028 << " could not be retrieved" << endreq;
00029 return sc;
00030 }
00031 isvc->addRef();
00032
00033 sc = isvc->queryInterface(IRootIOSvc::interfaceID(), (void**)&m_rioSvc);
00034 if (sc.isFailure()) {
00035 log << MSG::ERROR << "Conversion service RootIOCnvSvc"
00036 << " does not implement IRootIOCnvSvc" << endreq;
00037 return sc;
00038 }
00039
00040 sc = isvc->queryInterface(IConversionSvc::interfaceID(),(void**)&m_cnvSvc);
00041 if (sc.isFailure()) {
00042 log << MSG::ERROR
00043 << "RootIOCnvSvc does not implement IConversionSvc" << endreq;
00044 return sc;
00045 }
00046
00047 return sc;
00048 }
00049
00050
00051 StatusCode RootIOBaseCnv::createObj(IOpaqueAddress* addr, DataObject*& dat)
00052 {
00053 MsgStream log(msgSvc(), "RootIOBaseCnv::createObj");
00054 log << MSG::DEBUG << "createObj " << objType() << endreq;
00055
00056 RootInputAddress* ria = dynamic_cast<RootInputAddress*>(addr);
00057 if (!ria) {
00058 log << MSG::ERROR << "was not given a RootInputAddress" << endreq;
00059 return StatusCode::FAILURE;
00060 }
00061
00062 RootInputStream* ris = ria->stream();
00063 if (!ris) {
00064 log << MSG::ERROR << "RootInputAddress did not have stream" << endreq;
00065 return StatusCode::FAILURE;
00066 }
00067
00068
00069 if (!ria->readIsDone()) {
00070 bool okay = false;
00071 int fileNumber = ria->fileNumber();
00072
00073
00074 if (fileNumber == -1) {
00075 log << MSG::DEBUG << "setEntry(" << ria->entry() <<")"<< endreq;
00076 okay = ris->setEntry(ria->entry(),false);
00077 }
00078 else {
00079 log << MSG::DEBUG << "setFileEntry(" << fileNumber
00080 <<","<< ria->entry() <<")"<< endreq;
00081 okay = ris->setFileEntry(fileNumber,ria->entry(),false);
00082 if (!okay) {
00083 log << MSG::ERROR << "failed to set " << objType()
00084 << " entry to " << ria->entry() << " fileNumber=" << fileNumber
00085 << endreq;
00086 return StatusCode::FAILURE;
00087 }
00088 }
00089
00090
00091 okay = ris->read();
00092 if (!okay) {
00093 log << MSG::ERROR << "failed to read " << objType()
00094 << " entry " << ria->entry()
00095 << endreq;
00096 return StatusCode::FAILURE;
00097 }
00098 ria->readDone();
00099 }
00100
00101 m_ris = ris;
00102 return PerObjectToTranObject(dat);
00103 }
00104
00105 StatusCode RootIOBaseCnv::createRep(DataObject* obj,
00106 IOpaqueAddress*& addr)
00107 {
00108
00109
00110
00111 MsgStream log(msgSvc(), "RootIOBaseCnv");
00112 log << MSG::DEBUG << "createRep " << objType() << endreq;
00113
00114
00115 RootOutputAddress *roa = 0;
00116 StatusCode sc = m_rioSvc->createAddress(obj,roa);
00117 addr = roa;
00118
00119
00120 sc = TranObjectToPerObject(*obj,*roa);
00121 if (sc.isFailure()) {
00122 log << MSG::ERROR << "Could not transform object" << endreq;
00123 return sc;
00124 }
00125
00126 return StatusCode::SUCCESS;
00127 }
00128
00129 StatusCode RootIOBaseCnv::fillRepRefs(IOpaqueAddress* ,DataObject* )
00130 {
00131 MsgStream log(msgSvc(), "RootIOBaseCnv");
00132 log << MSG::DEBUG << "fillRepRefs " << objType() << endreq;
00133
00134 return StatusCode::SUCCESS;
00135 }
00136
00137 StatusCode RootIOBaseCnv::fillObjRefs(IOpaqueAddress* ,DataObject* )
00138 {
00139 return StatusCode::SUCCESS;
00140 }
00141
00142 StatusCode RootIOBaseCnv::finalize()
00143 {
00144 return StatusCode::SUCCESS;
00145 }
00146
00147
00148 int RootIOBaseCnv::commit(const RootOutputAddress& roa)
00149 {
00150 RootOutputStream* ros = m_rioSvc->outputStream(roa);
00151 if (!ros) return StatusCode::FAILURE;
00152
00153 int entries = ros->fileEntries();
00154 bool okay = ros->write();
00155 if (okay) return entries;
00156 return -1;
00157 }
00158
00159
00160 RootIOBaseCnv* RootIOBaseCnv::otherConverter(int clID)
00161 {
00162 MsgStream log(msgSvc(), "RootIOBaseCnv::otherConverter");
00163
00164 IConversionSvc* cnvSvc = this->conversionSvc();
00165 if (!cnvSvc) {
00166 log << MSG::WARNING
00167 << "Failed to get conversion service" << endreq;
00168 return 0;
00169 }
00170 IConverter* cnv = cnvSvc->converter(clID);
00171 if (!cnv) {
00172 log << MSG::WARNING
00173 << "Failed to get converter for class ID #" << clID << endreq;
00174 return 0;
00175 }
00176
00177 RootIOBaseCnv* base = dynamic_cast<RootIOBaseCnv*>(cnv);
00178 if (!base) {
00179 log << MSG::WARNING
00180 << "Failed to dynamic_cast converter to RootIOBaseCnv" << endreq;
00181 }
00182 return base;
00183 }
00184
00185