/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Static Public Member Functions | Protected Attributes
RootIOTypedCnv< PerType, TranType > Class Template Reference

Base class for RootIO converters. More...

#include <RootIOTypedCnv.h>

Inheritance diagram for RootIOTypedCnv< PerType, TranType >:
Inheritance graph
[legend]
Collaboration diagram for RootIOTypedCnv< PerType, TranType >:
Collaboration graph
[legend]

List of all members.

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 &)
 Satisfy RootIOBaseCnv requirements:
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.

Static Public Member Functions

static unsigned char storageType ()
 Storage type and class ID.
static const InterfaceID & interfaceID ()

Protected Attributes

std::string m_perclassName
PerType * m_perInObj
PerType * m_perOutObj
IRootIOSvcm_rioSvc
 Pointer to the IRootIOSvc interface of RootIOCnvSvc.
IConversionSvc * m_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.

        : RootIOBaseCnv(clid,svc)
        , m_perclassName(class_name)
        , m_perInObj(new PerType)
        , m_perOutObj(new PerType)
    {
        m_perOutObj->clID = m_perInObj->clID = TranType::classID(); 
    }
template<class PerType , class TranType >
virtual RootIOTypedCnv< PerType, TranType >::~RootIOTypedCnv ( ) [inline, virtual]

Definition at line 54 of file RootIOTypedCnv.h.

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

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.

{ return *m_perInObj; }
template<class PerType , class TranType >
PerType& RootIOTypedCnv< PerType, TranType >::getPerOutputObject ( ) [inline]

Definition at line 62 of file RootIOTypedCnv.h.

{ 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.

{ 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.

{ 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]

Satisfy RootIOBaseCnv requirements:

Do the concrete conversion from TDS to ROOT

Implements RootIOBaseCnv.

Definition at line 80 of file RootIOTypedCnv.h.

    {
        MsgStream log(msgSvc(), m_perclassName + "Cnv");
        TranType* tranobj = dynamic_cast<TranType*>(&dat);
        if (!tranobj) {
            log << MSG::ERROR
                << "Given a DataObject which does not corespond to "
                << m_perclassName << " at location "
                << dat.registry()->identifier()
                << endreq;
            return StatusCode::FAILURE;
        }
        
        // Delegate actual copying to subclass.
        return this->TranToPer(*tranobj,*m_perOutObj);
    }
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.

                                                               {
        MsgStream log(msgSvc(), m_perclassName + "Cnv");
        TranType* tranobj = new TranType;
        StatusCode sc = this->PerToTran(*m_perInObj,*tranobj);
        if (sc.isFailure()) {
            delete tranobj;
            dat = 0;
            return sc;
        }
        dat = tranobj;

        log << MSG::DEBUG << "Converted " << m_perclassName << endreq;

        return sc;
    }
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.

                                                                          {
        RootInputStream* ris = 
            new RootInputStream(&m_perInObj, ria.tespath(), ria.branchname());

        MsgStream log(msgSvc(), m_perclassName + "Cnv");
        log << MSG::DEBUG
            << "Made input stream for " << ria.tespath()
            << endreq;
        return ris;
    }
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.

                                                                             {
        MsgStream log(msgSvc(), m_perclassName + "Cnv");
        log << MSG::DEBUG
            << "Making output stream with class " << m_perclassName 
            << " and tespath " << ria.tespath()
            << " and branchname " << ria.branchname()
            << endreq;

        return new RootOutputStream((void*)&m_perOutObj,m_perclassName.c_str(),
                                    ria.tespath(),ria.branchname());
    }
static unsigned char RootIOBaseCnv::storageType ( ) [inline, static, inherited]

Storage type and class ID.

Definition at line 35 of file RootIOBaseCnv.h.

                                       {
        return ROOT_StorageType; 
    }
virtual long RootIOBaseCnv::repSvcType ( ) const [inline, virtual, inherited]

Class type.

Definition at line 40 of file RootIOBaseCnv.h.

                                    {
        return ROOT_StorageType; 
    }
StatusCode RootIOBaseCnv::initialize ( ) [virtual, inherited]

Converter interface.

Definition at line 17 of file RootIOBaseCnv.cc.

{
    StatusCode sc = Converter::initialize();
    if (sc.isFailure()) return sc;

    MsgStream log(msgSvc(), "RootIOBaseCnv");

    IService* isvc=0;
    sc = serviceLocator()->service("RootIOCnvSvc", isvc, false);
    if (sc.isFailure()) {
        log << MSG::ERROR << "Conversion service RootIOCnvSvc"
            << " could not be retrieved" << endreq;
        return sc;
    }
    isvc->addRef();

    sc = isvc->queryInterface(IRootIOSvc::interfaceID(), (void**)&m_rioSvc);
    if (sc.isFailure()) {
        log << MSG::ERROR << "Conversion service RootIOCnvSvc"
            << " does not implement IRootIOCnvSvc" << endreq;
        return sc;
    }

    sc = isvc->queryInterface(IConversionSvc::interfaceID(),(void**)&m_cnvSvc);
    if (sc.isFailure()) {
        log << MSG::ERROR 
            << "RootIOCnvSvc does not implement IConversionSvc" << endreq;
        return sc;
    }    

    return sc;
}
StatusCode RootIOBaseCnv::finalize ( ) [virtual, inherited]

Definition at line 142 of file RootIOBaseCnv.cc.

{
    return StatusCode::SUCCESS;
}
StatusCode RootIOBaseCnv::createObj ( IOpaqueAddress *  addr,
DataObject *&  dat 
) [virtual, inherited]

Convert the persistent object to transient.

IMPLEMENTED, sub class should not override.

Definition at line 51 of file RootIOBaseCnv.cc.

{
    MsgStream log(msgSvc(), "RootIOBaseCnv::createObj");
    log << MSG::DEBUG << "createObj " << objType() << endreq;

    RootInputAddress* ria = dynamic_cast<RootInputAddress*>(addr);
    if (!ria) {
        log << MSG::ERROR << "was not given a RootInputAddress" << endreq;
        return StatusCode::FAILURE;
    }
    
    RootInputStream* ris = ria->stream();
    if (!ris) {
        log << MSG::ERROR << "RootInputAddress did not have stream" << endreq;
        return StatusCode::FAILURE;
    }

    // Read in persistent object unless already done so.
    if (!ria->readIsDone()) {
        bool okay = false;
        int fileNumber = ria->fileNumber();

        // Set entry but don't read.
        if (fileNumber == -1) {
            log << MSG::DEBUG << "setEntry(" << ria->entry() <<")"<< endreq;
            okay = ris->setEntry(ria->entry(),false);
        }
        else {
            log << MSG::DEBUG << "setFileEntry(" << fileNumber 
                <<","<< ria->entry() <<")"<< endreq;
            okay = ris->setFileEntry(fileNumber,ria->entry(),false);
            if (!okay) {
                log << MSG::ERROR << "failed to set " << objType() 
                    << " entry to " << ria->entry() << " fileNumber=" << fileNumber
                    << endreq;
                return StatusCode::FAILURE;
            }
        }

        // Now read
        okay = ris->read();
        if (!okay) {
            log << MSG::ERROR << "failed to read " << objType() 
                << " entry " << ria->entry()
                << endreq;
            return StatusCode::FAILURE;
        }
        ria->readDone();
    }

    m_ris = ris;
    return PerObjectToTranObject(dat);
}
StatusCode RootIOBaseCnv::createRep ( DataObject *  pObject,
IOpaqueAddress *&  refpAddress 
) [virtual, inherited]

Convert the transient object to the requested representation.

IMPLEMENTED, sub class should not override

Definition at line 105 of file RootIOBaseCnv.cc.

{

    // Purpose and Method: Convert the transient object to ROOT

    MsgStream log(msgSvc(), "RootIOBaseCnv");
    log << MSG::DEBUG << "createRep " << objType() << endreq;

    // get the corresponding address 
    RootOutputAddress *roa = 0;
    StatusCode sc = m_rioSvc->createAddress(obj,roa);
    addr = roa;
    
    //  do the real conversion in the derived converter
    sc = TranObjectToPerObject(*obj,*roa);
    if (sc.isFailure()) {
        log << MSG::ERROR << "Could not transform object" << endreq;
        return sc;
    }

    return StatusCode::SUCCESS;
}
StatusCode RootIOBaseCnv::fillRepRefs ( IOpaqueAddress *  pAddress,
DataObject *  pObject 
) [virtual, inherited]

Resolve the references of the converted object.

UNIMPLEMENTED (empty), subclass may override.

Definition at line 129 of file RootIOBaseCnv.cc.

{
    MsgStream log(msgSvc(), "RootIOBaseCnv");
    log << MSG::DEBUG << "fillRepRefs " << objType() << endreq;

    return StatusCode::SUCCESS;
}
StatusCode RootIOBaseCnv::fillObjRefs ( IOpaqueAddress *  pAddress,
DataObject *  pObject 
) [virtual, inherited]

Resolve the references of the converted object.

UNIMPLEMENTED (empty), subclass may override.

Definition at line 137 of file RootIOBaseCnv.cc.

{
    return StatusCode::SUCCESS;
}
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.

{
    RootOutputStream* ros = m_rioSvc->outputStream(roa);
    if (!ros) return StatusCode::FAILURE;
    //int entries = ros->entries();
    int entries = ros->fileEntries();
    bool okay = ros->write();
    if (okay) return entries;
    return -1;
}
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.

{
    MsgStream log(msgSvc(), "RootIOBaseCnv::otherConverter");

    IConversionSvc* cnvSvc = this->conversionSvc();
    if (!cnvSvc) {
        log << MSG::WARNING
            << "Failed to get conversion service" << endreq;
        return 0;
    }
    IConverter* cnv = cnvSvc->converter(clID);
    if (!cnv) {
        log << MSG::WARNING
            << "Failed to get converter for class ID #" << clID << endreq;
        return 0;
    }

    RootIOBaseCnv* base = dynamic_cast<RootIOBaseCnv*>(cnv);
    if (!base) {
        log << MSG::WARNING
            << "Failed to dynamic_cast converter to RootIOBaseCnv" << endreq;
    }
    return base;
}
static const InterfaceID& IRootIOCnv::interfaceID ( ) [inline, static, inherited]

Definition at line 19 of file IRootIOCnv.h.

{ 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 Fri May 16 2014 09:58:18 for RootIOSvc by doxygen 1.7.4