/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 | Private Member Functions
UserDataCnv Class Reference

Converter between UserDataHeader and PerHeaderObject+RootIOUserData. More...

#include <UserDataCnv.h>

Inheritance diagram for UserDataCnv:
Inheritance graph
[legend]
Collaboration diagram for UserDataCnv:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 UserDataCnv (ISvcLocator *svc)
virtual ~UserDataCnv ()
StatusCode PerToTran (const PerHeaderObject &tobj, DayaBay::UserDataHeader &dobj)
 Copy data from TObject based class of type TType to DataObject based class of type DOType.
StatusCode TranToPer (const DayaBay::UserDataHeader &dobj, PerHeaderObject &tobj)
 Copy data from DataObject based class of type DOType to TObject based class of type TType.
StatusCode fillRepRefs (IOpaqueAddress *addr, DataObject *dobj)
StatusCode fillObjRefs (IOpaqueAddress *addr, DataObject *dobj)
PerType & getPerInputObject ()
PerType & getPerOutputObject ()
const RootIOBaseObjectgetBaseInputObject ()
const RootIOBaseObjectgetBaseOutputObject ()
virtual StatusCode PerToTran (const PerType &pobj, TranType &tobj)=0
virtual StatusCode TranToPer (const TranType &tobj, PerType &pobj)=0
virtual StatusCode TranObjectToPerObject (DataObject &dat, const RootOutputAddress &)
virtual StatusCode PerObjectToTranObject (DataObject *&dat)
virtual RootInputStreammakeInputStream (const RootInputAddress &ria)
virtual RootOutputStreammakeOutputStream (const RootOutputAddress &ria)
virtual long repSvcType () const
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode createObj (IOpaqueAddress *addr, DataObject *&dat)
virtual StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress)
int commit (const RootOutputAddress &roa)
RootIOBaseCnvotherConverter (int clID)

Static Public Member Functions

static const CLID & classID ()
static unsigned char storageType ()
static const InterfaceID & interfaceID ()

Protected Attributes

std::string m_perclassName
PerType * m_perInObj
PerType * m_perOutObj
IRootIOSvcm_rioSvc
IConversionSvc * m_cnvSvc
RootInputStreamm_ris

Private Member Functions

StatusCode InitializeProxies (const DayaBay::UserDataHeader &udh, RootIOUserData::ProxyCollection &proxies)

Detailed Description

Converter between UserDataHeader and PerHeaderObject+RootIOUserData.

Created by: dandwyer@caltech.edu, 2011/02/16 Refactored bv@bnl.gov Fri Feb 25 17:27:13 2011

Definition at line 20 of file UserDataCnv.h.


Constructor & Destructor Documentation

UserDataCnv::UserDataCnv ( ISvcLocator *  svc)

Definition at line 9 of file UserDataCnv.cc.

UserDataCnv::~UserDataCnv ( ) [virtual]

Definition at line 15 of file UserDataCnv.cc.

{
}

Member Function Documentation

static const CLID& UserDataCnv::classID ( ) [inline, static]

Definition at line 24 of file UserDataCnv.h.

                                 {
        return DayaBay::CLID_UserDataHeader;
    }
StatusCode UserDataCnv::PerToTran ( const PerHeaderObject tobj,
DayaBay::UserDataHeader dobj 
)

Copy data from TObject based class of type TType to DataObject based class of type DOType.

Definition at line 20 of file UserDataCnv.cc.

{
    MsgStream log(msgSvc(), "UserDataCnv::PerToTran");
    StatusCode sc = HeaderObjectCnv::toTran(perobj,tranobj);
    if(sc.isFailure()) return sc;

    // Convert user-defined data
    tranobj.clearData();

    RootIOUserData ud;
    RootIOUserData::ProxyCollection& proxies = ud.input(m_ris->path());
    RootIOUserData::ProxyCollection::iterator pit, pdone = proxies.end();
    log << MSG::DEBUG 
        << "got " << proxies.size() << " proxies from "
        << m_ris->path() << " for input" << endreq;

    for (pit = proxies.begin(); pit != pdone; ++pit) {
        RootIOUserDataProxy* proxy = pit->second;

        const std::string& typeName = proxy->cppType(); 
        const std::string& varName = proxy->varName(); 

        // handle supported types
        UserData* userdata = 0;
        if (typeName == "int") {
            userdata = new UserInt(varName, proxy->value<int>());
        }
        else if (typeName == "float") {
            userdata = new UserFloat(varName, proxy->value<float>());
        }
        else if (typeName == "vector<int>") {
            userdata = new UserIntArray(varName, proxy->value< std::vector<int> >());
        }
        else if (typeName == "vector<float>") {
            userdata = new UserFloatArray(varName, proxy->value< std::vector<float> >());
        }
        else {
            log << MSG::ERROR
                << "got unknown POD type: \"" << typeName
                << "\" for user data \"" << varName
                << "\" skipping."
                << endreq;
            return StatusCode::FAILURE;
        }
        tranobj.data().push_back(userdata);
    }
    return StatusCode::SUCCESS;
}
StatusCode UserDataCnv::TranToPer ( const DayaBay::UserDataHeader dobj,
PerHeaderObject tobj 
)

Copy data from DataObject based class of type DOType to TObject based class of type TType.

Definition at line 70 of file UserDataCnv.cc.

{
    MsgStream log(msgSvc(), "UserDataCnv::TranToPer");
    std::string tespath = udh.registry()->identifier();

    RootIOUserData ud;
    RootIOUserData::ProxyCollection& proxies = ud.output(tespath);

    log << MSG::DEBUG 
        << "got " << proxies.size() << " proxies from "
        << tespath << " for output" << endreq;

    StatusCode sc;

    if (!proxies.size()) {
        log << MSG::DEBUG << "No proxies for " 
            << tespath << " initializing" << endreq;
        sc = this->InitializeProxies(udh, proxies);
        if (sc.isFailure()) return sc;
    }

    sc = HeaderObjectCnv::toPer(udh,perobj);
    if (sc.isFailure()) return sc;

    const UserDataHeader::UserDataList& datalist = udh.data();

    for (size_t ind=0; ind < datalist.size(); ++ind) {
        const UserData* data = datalist[ind];

        const std::string& varName = data->name();

        RootIOUserDataProxy* proxy = proxies[varName];

        if (!proxy) {
            log << MSG::ERROR << "Failed to find proxy: " << varName
                << "    "
                << "Make sure you set all user data variables for every event!"
                << endreq;
            return StatusCode::FAILURE;
        }
      
        const std::string& cppType = proxy->cppType();

        log << MSG::DEBUG 
            << "Proxy: name:" << varName << " and type:" << cppType
            << endreq;

        switch (data->type()) {

        case UserData::Float:
            proxy->value<float>() = dynamic_cast<const UserFloat*>(data)->value();
            break;

        case UserData::Int:
            proxy->value<int>() = dynamic_cast<const UserInt*>(data)->value();
            break;


        case UserData::FloatArray:
            proxy->value< vector<float> >() = dynamic_cast<const UserFloatArray*>(data)->value();
            break;

        case UserData::IntArray:
            proxy->value< vector<int> >() = dynamic_cast<const UserIntArray*>(data)->value();
            break;

        default:
            log << MSG::ERROR
                << "unknown type: " << data->type() 
                << " for user data \"" << varName << "\""
                << endreq;
            return StatusCode::FAILURE;
            break;
        }
    }

    return StatusCode::SUCCESS;
}
StatusCode UserDataCnv::fillRepRefs ( IOpaqueAddress *  addr,
DataObject *  dobj 
) [virtual]

Reimplemented from RootIOTypedCnv< PerHeaderObject, DayaBay::UserDataHeader >.

Definition at line 150 of file UserDataCnv.cc.

                                                                     {
  
    MsgStream log(msgSvc(), "UserDataCnv::fillRepRefs");
    UserDataHeader* header = dynamic_cast<UserDataHeader*>(dobj);

    log << MSG::DEBUG
        << "Saving links to " << header->inputHeaders().size() 
        << " input headers" << endreq;
  
    StatusCode sc = HeaderObjectCnv::fillPer(m_rioSvc,*header,*m_perOutObj);

    if (sc.isFailure()) {
        log << MSG::ERROR << "Failed to fill HeaderObject part" << endreq;
        return sc;
    }
  
    return sc;
}
StatusCode UserDataCnv::fillObjRefs ( IOpaqueAddress *  addr,
DataObject *  dobj 
) [virtual]

Reimplemented from RootIOTypedCnv< PerHeaderObject, DayaBay::UserDataHeader >.

Definition at line 169 of file UserDataCnv.cc.

                                                                     {
    MsgStream log(msgSvc(), "UserDataCnv::fillObjRefs");
    HeaderObject* hobj = dynamic_cast<HeaderObject*>(dobj);

    StatusCode sc = HeaderObjectCnv::fillTran(m_rioSvc,*m_perInObj,*hobj);
    if (sc.isFailure()) {
        log << MSG::ERROR << "Failed to fill HeaderObject part" << endreq;
        return sc;
    }
  
    log << MSG::DEBUG
        << "Restored links to " << hobj->inputHeaders().size() 
        << " input headers" << endreq;
  
    return sc;
}
StatusCode UserDataCnv::InitializeProxies ( const DayaBay::UserDataHeader udh,
RootIOUserData::ProxyCollection proxies 
) [private]

Definition at line 187 of file UserDataCnv.cc.

{
    // Setup any required proxies for output
    MsgStream log(msgSvc(), "UserDataCnv::InitializeProxies");
    log << MSG::DEBUG << "Initializing dynamic branches" << endreq;

    const UserDataHeader::UserDataList& datalist = udh.data();

    for (size_t ind=0; ind < datalist.size(); ++ind) {
        const UserData* userdata = datalist[ind];

        const std::string& varName = userdata->name();

        log << MSG::DEBUG 
            << "\tprocessing user data: " << varName 
            << " type: " << userdata->type()
            << endreq;

        RootIOUserDataProxy* proxy = 0;
        switch (userdata->type()) {

        case UserData::Int:
            proxy = new RootIOUserDataProxy(varName,"int",
                                            (char*)new int);
            break;

        case UserData::Float:
            proxy = new RootIOUserDataProxy(varName,"float",
                                            (char*)new float);
            break;

        case UserData::IntArray:
            proxy = new RootIOUserDataProxy(varName,"vector<int>",
                                            (char*)new vector<int>);
            break;

        case UserData::FloatArray:
            proxy = new RootIOUserDataProxy(varName,"vector<float>",
                                            (char*)new vector<float>);
            break;

        default:
            log << MSG::ERROR << "         unknown type: " << userdata->type() << endreq;
            return StatusCode::FAILURE;
            break;
        }
        proxies[varName] = proxy;
    }
    return StatusCode::SUCCESS;
}
PerType & RootIOTypedCnv< class, class >::getPerInputObject ( ) [inherited]
PerType & RootIOTypedCnv< class, class >::getPerOutputObject ( ) [inherited]
const RootIOBaseObject * RootIOTypedCnv< class, class >::getBaseInputObject ( ) [virtual, inherited]

Implements RootIOBaseCnv.

const RootIOBaseObject * RootIOTypedCnv< class, class >::getBaseOutputObject ( ) [virtual, inherited]

Implements RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::PerToTran ( const PerType &  pobj,
TranType &  tobj 
) [pure virtual, inherited]
virtual StatusCode RootIOTypedCnv< class, class >::TranToPer ( const TranType &  tobj,
PerType &  pobj 
) [pure virtual, inherited]
virtual StatusCode RootIOTypedCnv< class, class >::TranObjectToPerObject ( DataObject &  dat,
const RootOutputAddress  
) [virtual, inherited]

Implements RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::PerObjectToTranObject ( DataObject *&  dat) [virtual, inherited]

Implements RootIOBaseCnv.

virtual RootInputStream * RootIOTypedCnv< class, class >::makeInputStream ( const RootInputAddress ria) [virtual, inherited]

Implements RootIOBaseCnv.

virtual RootOutputStream * RootIOTypedCnv< class, class >::makeOutputStream ( const RootOutputAddress ria) [virtual, inherited]

Implements RootIOBaseCnv.

virtual long RootIOTypedCnv< class, class >::repSvcType ( ) const [virtual, inherited]

Reimplemented from RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::initialize ( ) [virtual, inherited]

Reimplemented from RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::finalize ( ) [virtual, inherited]

Reimplemented from RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::createObj ( IOpaqueAddress *  addr,
DataObject *&  dat 
) [virtual, inherited]

Reimplemented from RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::createRep ( DataObject *  pObject,
IOpaqueAddress *&  refpAddress 
) [virtual, inherited]

Reimplemented from RootIOBaseCnv.

int RootIOTypedCnv< class, class >::commit ( const RootOutputAddress roa) [inherited]

Reimplemented from RootIOBaseCnv.

RootIOBaseCnv * RootIOTypedCnv< class, class >::otherConverter ( int  clID) [inherited]

Reimplemented from RootIOBaseCnv.

static unsigned char RootIOTypedCnv< class, class >::storageType ( ) [static, inherited]

Reimplemented from RootIOBaseCnv.

static const InterfaceID & RootIOTypedCnv< class, class >::interfaceID ( ) [static, inherited]

Reimplemented from RootIOBaseCnv.


Member Data Documentation

std::string RootIOTypedCnv< class, class >::m_perclassName [protected, inherited]
PerType * RootIOTypedCnv< class, class >::m_perInObj [protected, inherited]
PerType * RootIOTypedCnv< class, class >::m_perOutObj [protected, inherited]
IRootIOSvc * RootIOTypedCnv< class, class >::m_rioSvc [protected, inherited]

Reimplemented from RootIOBaseCnv.

IConversionSvc * RootIOTypedCnv< class, class >::m_cnvSvc [protected, inherited]

Reimplemented from RootIOBaseCnv.

RootInputStream * RootIOTypedCnv< class, class >::m_ris [protected, inherited]

Reimplemented from RootIOBaseCnv.


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

Generated on Fri May 16 2014 09:58:52 for PerUserData by doxygen 1.7.4