| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

RootIOTypedCnv< PerType, TranType > Class Template Reference

Base class for RootIO converters. More...

#include <RootIOTypedCnv.h>

Inheritance diagram for RootIOTypedCnv< PerType, TranType >:

[legend]
Collaboration diagram for RootIOTypedCnv< PerType, TranType >:
[legend]
List of all members.

Public Types

 INVALID_ADDRESS
 INVALID_OBJECT
 NO_MEMORY
 BAD_STORAGE_TYPE
 NO_SOURCE_OBJECT
 ICONVERSIONSVC_LAST_ERROR
 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
enum  Status

Public Member Functions

 RootIOTypedCnv (std::string class_name, const CLID &clid, ISvcLocator *svc)
 Constructor.
virtual ~RootIOTypedCnv ()
PerType & getPerInputObject ()
 Access the persistent objects.
PerType & getPerOutputObject ()
const RootIOBaseObjectgetBaseInputObject ()
 Satisify base class requirements.
const RootIOBaseObjectgetBaseOutputObject ()
virtual StatusCode PerToTran (const PerType &pobj, TranType &tobj)=0
 Copy data from persistent class of type PerType to DataObject based class of type TranType.
virtual StatusCode TranToPer (const TranType &tobj, PerType &pobj)=0
 Copy data from DataObject based class of type TranType to RootIOBaseObject based class of type PerType.
virtual StatusCode TranObjectToPerObject (DataObject &dat, const RootOutputAddress &)
 Do the concrete conversion from TDS to ROOT.
virtual StatusCode PerObjectToTranObject (DataObject *&dat)
 Do the concrete conversion from ROOT to TDS.
virtual RootInputStreammakeInputStream (const RootInputAddress &ria)
 Make a new input stream for this object and based on the given address.
virtual RootOutputStreammakeOutputStream (const RootOutputAddress &ria)
 Make a new output stream for this object and based on the given address.
virtual long repSvcType () const
 Class type.
virtual StatusCode initialize ()
 Converter interface.
virtual StatusCode finalize ()
virtual StatusCode createObj (IOpaqueAddress *addr, DataObject *&dat)
 Convert the persistent object to transient.
virtual StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress)
 Convert the transient object to the requested representation.
virtual StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the converted object.
virtual StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the converted object.
int commit (const RootOutputAddress &roa)
 Should be called after createRep() and fillRepRefs(), returns the entry number or -1 on error.
RootIOBaseCnvotherConverter (int clID)
 Look up another converter based on the class ID on which it operates.
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
virtual unsigned long addRef ()
virtual unsigned long release ()
virtual StatusCode setDataProvider (IDataProviderSvc *svc)
virtual IDataProviderSvcdataProvider () const
virtual StatusCode setConversionSvc (IConversionSvc *svc)
virtual IConversionSvcconversionSvc () const
virtual StatusCode setAddressCreator (IAddressCreator *creator)
virtual IAddressCreatoraddressCreator () const
virtual const CLIDobjType () const
virtual long i_repSvcType () const
virtual StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *refpObject)
virtual StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
StatusCode service (const std::string &name, T *&psvc, bool createIf=false) const
StatusCode service (const std::string &type, const std::string &name, T *&psvc) const

Static Public Member Functions

static unsigned char storageType ()
 Storage type and class ID.
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()

Public Attributes

 INVALID_ADDRESS
 INVALID_OBJECT
 NO_MEMORY
 BAD_STORAGE_TYPE
 NO_SOURCE_OBJECT
 ICONVERSIONSVC_LAST_ERROR

Protected Member Functions

ISvcLocatorserviceLocator () const
IMessageSvcmsgSvc () const
IMessageSvcmessageService () const
IDataManagerSvcdataManager () const

Protected Attributes

std::string m_perclassName
PerType * m_perInObj
PerType * m_perOutObj
IRootIOSvcm_rioSvc
 Pointer to the IRootIOSvc interface of RootIOCnvSvc.
IConversionSvcm_cnvSvc
 Pointer to the conversion service interface of RootIOCnvSvc.
RootInputStreamm_ris
 Current RootInputStream, set just before PerObjectToTranObject() is called.

Detailed Description

template<class PerType, class TranType>
class RootIOTypedCnv< PerType, TranType >

Base class for RootIO converters.

This templated class takes care of everything a converter needs to handle except the actual copying of data between transient DataObject and persistent object.

Subclasses must implement PerToTran(...) and TranToPer(...) methods and must call the RootIOTypedCnv(...) constructor.

bv@bnl.gov Mon Jun 30 09:27:23 2008

Definition at line 36 of file RootIOTypedCnv.h.


Constructor & Destructor Documentation

template<class PerType, class TranType>
RootIOTypedCnv< PerType, TranType >::RootIOTypedCnv ( std::string  class_name,
const CLID clid,
ISvcLocator svc 
) [inline]

Constructor.

The class_name is the name PerType class which corresponds to the DataObject based class of type TranType.

Definition at line 45 of file RootIOTypedCnv.h.

00046         : RootIOBaseCnv(clid,svc)
00047         , m_perclassName(class_name)
00048         , m_perInObj(new PerType)
00049         , m_perOutObj(new PerType)
00050     {
00051         m_perOutObj->clID = m_perInObj->clID = TranType::classID(); 
00052     }

template<class PerType, class TranType>
virtual RootIOTypedCnv< PerType, TranType >::~RootIOTypedCnv (  )  [inline, virtual]

Definition at line 54 of file RootIOTypedCnv.h.

00054                               {
00055         MsgStream log(msgSvc(), m_perclassName + "Cnv");
00056         log << MSG::DEBUG << "converter for " 
00057             << m_perclassName << " destructing" << endreq;
00058     }


Member Function Documentation

template<class PerType, class TranType>
PerType& RootIOTypedCnv< PerType, TranType >::getPerInputObject (  )  [inline]

Access the persistent objects.

Definition at line 61 of file RootIOTypedCnv.h.

00061 { return *m_perInObj; }

template<class PerType, class TranType>
PerType& RootIOTypedCnv< PerType, TranType >::getPerOutputObject (  )  [inline]

Definition at line 62 of file RootIOTypedCnv.h.

00062 { return *m_perOutObj; }

template<class PerType, class TranType>
const RootIOBaseObject* RootIOTypedCnv< PerType, TranType >::getBaseInputObject (  )  [inline, virtual]

Satisify base class requirements.

Implements RootIOBaseCnv.

Definition at line 65 of file RootIOTypedCnv.h.

00065 { return m_perInObj; }

template<class PerType, class TranType>
const RootIOBaseObject* RootIOTypedCnv< PerType, TranType >::getBaseOutputObject (  )  [inline, virtual]

Implements RootIOBaseCnv.

Definition at line 66 of file RootIOTypedCnv.h.

00066 { return m_perOutObj; }

template<class PerType, class TranType>
virtual StatusCode RootIOTypedCnv< PerType, TranType >::PerToTran ( const PerType &  pobj,
TranType &  tobj 
) [pure virtual]

Copy data from persistent class of type PerType to DataObject based class of type TranType.

template<class PerType, class TranType>
virtual StatusCode RootIOTypedCnv< PerType, TranType >::TranToPer ( const TranType &  tobj,
PerType &  pobj 
) [pure virtual]

Copy data from DataObject based class of type TranType to RootIOBaseObject based class of type PerType.

template<class PerType, class TranType>
virtual StatusCode RootIOTypedCnv< PerType, TranType >::TranObjectToPerObject ( DataObject dat,
const RootOutputAddress  
) [inline, virtual]

Do the concrete conversion from TDS to ROOT.

Implements RootIOBaseCnv.

Definition at line 80 of file RootIOTypedCnv.h.

00082     {
00083         MsgStream log(msgSvc(), m_perclassName + "Cnv");
00084         TranType* tranobj = dynamic_cast<TranType*>(&dat);
00085         if (!tranobj) {
00086             log << MSG::ERROR
00087                 << "Given a DataObject which does not corespond to "
00088                 << m_perclassName << " at location "
00089                 << dat.registry()->identifier()
00090                 << endreq;
00091             return StatusCode::FAILURE;
00092         }
00093         
00094         // Delegate actual copying to subclass.
00095         return this->TranToPer(*tranobj,*m_perOutObj);
00096     }

template<class PerType, class TranType>
virtual StatusCode RootIOTypedCnv< PerType, TranType >::PerObjectToTranObject ( DataObject *&  dat  )  [inline, virtual]

Do the concrete conversion from ROOT to TDS.

Implements RootIOBaseCnv.

Definition at line 99 of file RootIOTypedCnv.h.

00099                                                                {
00100         MsgStream log(msgSvc(), m_perclassName + "Cnv");
00101         TranType* tranobj = new TranType;
00102         StatusCode sc = this->PerToTran(*m_perInObj,*tranobj);
00103         if (sc.isFailure()) {
00104             delete tranobj;
00105             dat = 0;
00106             return sc;
00107         }
00108         dat = tranobj;
00109 
00110         log << MSG::DEBUG << "Converted " << m_perclassName << endreq;
00111 
00112         return sc;
00113     }

template<class PerType, class TranType>
virtual RootInputStream* RootIOTypedCnv< PerType, TranType >::makeInputStream ( const RootInputAddress ria  )  [inline, virtual]

Make a new input stream for this object and based on the given address.

Implements IRootIOCnv.

Definition at line 116 of file RootIOTypedCnv.h.

00116                                                                           {
00117         RootInputStream* ris = 
00118             new RootInputStream(&m_perInObj, ria.tespath(), ria.branchname());
00119 
00120         MsgStream log(msgSvc(), m_perclassName + "Cnv");
00121         log << MSG::DEBUG
00122             << "Made input stream for " << ria.tespath()
00123             << endreq;
00124         return ris;
00125     }

template<class PerType, class TranType>
virtual RootOutputStream* RootIOTypedCnv< PerType, TranType >::makeOutputStream ( const RootOutputAddress ria  )  [inline, virtual]

Make a new output stream for this object and based on the given address.

Implements IRootIOCnv.

Definition at line 128 of file RootIOTypedCnv.h.

00128                                                                              {
00129         MsgStream log(msgSvc(), m_perclassName + "Cnv");
00130         log << MSG::DEBUG
00131             << "Making output stream with class " << m_perclassName 
00132             << " and tespath " << ria.tespath()
00133             << " and branchname " << ria.branchname()
00134             << endreq;
00135 
00136         return new RootOutputStream((void*)&m_perOutObj,m_perclassName.c_str(),
00137                                     ria.tespath(),ria.branchname());
00138     }

static unsigned char RootIOBaseCnv::storageType (  )  [inline, static, inherited]

Storage type and class ID.

Definition at line 35 of file RootIOBaseCnv.h.

00035                                        {
00036         return ROOT_StorageType; 
00037     }

virtual long RootIOBaseCnv::repSvcType (  )  const [inline, virtual, inherited]

Class type.

Implements Converter.

Definition at line 40 of file RootIOBaseCnv.h.

00040                                     {
00041         return ROOT_StorageType; 
00042     }

StatusCode RootIOBaseCnv::initialize (  )  [virtual, inherited]

Converter interface.

Reimplemented from Converter.

Definition at line 17 of file RootIOBaseCnv.cc.

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 }

StatusCode RootIOBaseCnv::finalize (  )  [virtual, inherited]

Reimplemented from Converter.

Definition at line 142 of file RootIOBaseCnv.cc.

00143 {
00144     return StatusCode::SUCCESS;
00145 }

StatusCode RootIOBaseCnv::createObj ( IOpaqueAddress addr,
DataObject *&  dat 
) [virtual, inherited]

Convert the persistent object to transient.

IMPLEMENTED, sub class should not override.

Reimplemented from Converter.

Definition at line 51 of file RootIOBaseCnv.cc.

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     // Read in persistent object unless already done so.
00069     if (!ria->readIsDone()) {
00070         bool okay = false;
00071         int fileNumber = ria->fileNumber();
00072 
00073         // Set entry but don't read.
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         // Now read
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 }

StatusCode RootIOBaseCnv::createRep ( DataObject pObject,
IOpaqueAddress *&  refpAddress 
) [virtual, inherited]

Convert the transient object to the requested representation.

IMPLEMENTED, sub class should not override

Reimplemented from Converter.

Definition at line 105 of file RootIOBaseCnv.cc.

00107 {
00108 
00109     // Purpose and Method: Convert the transient object to ROOT
00110 
00111     MsgStream log(msgSvc(), "RootIOBaseCnv");
00112     log << MSG::DEBUG << "createRep " << objType() << endreq;
00113 
00114     // get the corresponding address 
00115     RootOutputAddress *roa = 0;
00116     StatusCode sc = m_rioSvc->createAddress(obj,roa);
00117     addr = roa;
00118     
00119     //  do the real conversion in the derived converter
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 }

StatusCode RootIOBaseCnv::fillRepRefs ( IOpaqueAddress pAddress,
DataObject pObject 
) [virtual, inherited]

Resolve the references of the converted object.

UNIMPLEMENTED (empty), subclass may override.

Reimplemented from Converter.

Definition at line 129 of file RootIOBaseCnv.cc.

00130 {
00131     MsgStream log(msgSvc(), "RootIOBaseCnv");
00132     log << MSG::DEBUG << "fillRepRefs " << objType() << endreq;
00133 
00134     return StatusCode::SUCCESS;
00135 }

StatusCode RootIOBaseCnv::fillObjRefs ( IOpaqueAddress pAddress,
DataObject pObject 
) [virtual, inherited]

Resolve the references of the converted object.

UNIMPLEMENTED (empty), subclass may override.

Reimplemented from Converter.

Definition at line 137 of file RootIOBaseCnv.cc.

00138 {
00139     return StatusCode::SUCCESS;
00140 }

int RootIOBaseCnv::commit ( const RootOutputAddress roa  )  [inherited]

Should be called after createRep() and fillRepRefs(), returns the entry number or -1 on error.

Definition at line 148 of file RootIOBaseCnv.cc.

00149 {
00150     RootOutputStream* ros = m_rioSvc->outputStream(roa);
00151     if (!ros) return StatusCode::FAILURE;
00152     //int entries = ros->entries();
00153     int entries = ros->fileEntries();
00154     bool okay = ros->write();
00155     if (okay) return entries;
00156     return -1;
00157 }

RootIOBaseCnv * RootIOBaseCnv::otherConverter ( int  clID  )  [inherited]

Look up another converter based on the class ID on which it operates.

Definition at line 160 of file RootIOBaseCnv.cc.

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 }

static const InterfaceID& IRootIOCnv::interfaceID (  )  [inline, static, inherited]

Reimplemented from IInterface.

Definition at line 19 of file IRootIOCnv.h.

00019 { return IID_IRootIOCnv; }


Member Data Documentation

template<class PerType, class TranType>
std::string RootIOTypedCnv< PerType, TranType >::m_perclassName [protected]

Definition at line 39 of file RootIOTypedCnv.h.

template<class PerType, class TranType>
PerType* RootIOTypedCnv< PerType, TranType >::m_perInObj [protected]

Definition at line 40 of file RootIOTypedCnv.h.

template<class PerType, class TranType>
PerType * RootIOTypedCnv< PerType, TranType >::m_perOutObj [protected]

Definition at line 40 of file RootIOTypedCnv.h.

IRootIOSvc* RootIOBaseCnv::m_rioSvc [protected, inherited]

Pointer to the IRootIOSvc interface of RootIOCnvSvc.

Definition at line 96 of file RootIOBaseCnv.h.

IConversionSvc* RootIOBaseCnv::m_cnvSvc [protected, inherited]

Pointer to the conversion service interface of RootIOCnvSvc.

Definition at line 99 of file RootIOBaseCnv.h.

RootInputStream* RootIOBaseCnv::m_ris [protected, inherited]

Current RootInputStream, set just before PerObjectToTranObject() is called.

Definition at line 103 of file RootIOBaseCnv.h.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:18:21 2011 for RootIOSvc by doxygen 1.4.7