/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 | Private Attributes
RootIOUserDataProxy Class Reference

A proxy to assist in I/O of user data. More...

#include <RootIOUserDataProxy.h>

List of all members.

Public Member Functions

 RootIOUserDataProxy (const std::string &varName, const std::string &cppType, char *address)
virtual ~RootIOUserDataProxy ()
const std::string & varName ()
 Access the variable name.
const std::string & cppType ()
 Access the variable type name.
bool isObject ()
 True if this is a compound object and not a plain old data.
bool branch (TTree *tree)
 Call TTree::Branch(), return false on failure.
template<class DTYPE >
DTYPE & value ()
 Return reference to value assuming its given type.
template<class DTYPE >
DTYPE * address ()
void resetAddress (char *address)
 Reset the address.

Private Attributes

std::string m_varName
std::string m_cppType
char * m_address
bool m_isObject

Detailed Description

A proxy to assist in I/O of user data.

This is a refactoring of Dan Dwyer's original PerBranch class.

Brett Viren <bv@bnl.gov> Thu Feb 24 09:59:48 2011

Definition at line 21 of file RootIOUserDataProxy.h.


Constructor & Destructor Documentation

RootIOUserDataProxy::RootIOUserDataProxy ( const std::string &  varName,
const std::string &  cppType,
char *  address 
)

Definition at line 8 of file RootIOUserDataProxy.cc.

  : m_varName(varName),
    m_cppType(cppType),
    m_address(address)
{
    // If ccpType is not one of these then it is assumed to be an object
    const char* knownPOD[] = { "int", "float", 0 };
    const char* rootTypes[] = { "Int_t", "Float_t", 0 };

    m_isObject = true;
    for (int ind=0; knownPOD[ind]; ++ind) {
        if (m_cppType == knownPOD[ind]) {
            m_isObject = false;
            break;
        }
        if (m_cppType == rootTypes[ind]) {
            m_cppType = knownPOD[ind];
            m_isObject = false;
            break;
        }
    }
}
RootIOUserDataProxy::~RootIOUserDataProxy ( ) [virtual]

Definition at line 33 of file RootIOUserDataProxy.cc.

{
}

Member Function Documentation

const std::string& RootIOUserDataProxy::varName ( ) [inline]

Access the variable name.

Definition at line 30 of file RootIOUserDataProxy.h.

{ return m_varName; }
const std::string& RootIOUserDataProxy::cppType ( ) [inline]

Access the variable type name.

Definition at line 33 of file RootIOUserDataProxy.h.

{ return m_cppType; }
bool RootIOUserDataProxy::isObject ( ) [inline]

True if this is a compound object and not a plain old data.

Definition at line 36 of file RootIOUserDataProxy.h.

{ return m_isObject; }
bool RootIOUserDataProxy::branch ( TTree *  tree)

Call TTree::Branch(), return false on failure.

Definition at line 38 of file RootIOUserDataProxy.cc.

{
    // handle known object types needing template to trigger write Branch() call
    if (m_cppType == "int") {
        std::string rootName(m_varName);
        rootName.append("/I");
        tree->Branch(m_varName.c_str(),address<void>(),rootName.c_str());
        return true;
    }

    if (m_cppType == "float") {
        std::string rootName(m_varName);
        rootName.append("/F");
        tree->Branch(m_varName.c_str(),address<void>(),rootName.c_str());
        return true;
    }

    if (m_cppType == "vector<int>") {
        tree->Branch(m_varName.c_str(), address< std::vector<int> >());
        return true;
    }
    
    if (m_cppType == "vector<float>") {
        tree->Branch(m_varName.c_str(), address< std::vector<float> >());
        return true;
    }
    
    return false;
}
template<class DTYPE >
DTYPE& RootIOUserDataProxy::value ( ) [inline]

Return reference to value assuming its given type.

No error checks are done!

Definition at line 43 of file RootIOUserDataProxy.h.

                                         {
        return *(DTYPE*)(m_address);
    }
template<class DTYPE >
DTYPE* RootIOUserDataProxy::address ( ) [inline]

Definition at line 46 of file RootIOUserDataProxy.h.

                                           {
        return (DTYPE*)(m_address);
    }
void RootIOUserDataProxy::resetAddress ( char *  address) [inline]

Reset the address.

Definition at line 51 of file RootIOUserDataProxy.h.


Member Data Documentation

std::string RootIOUserDataProxy::m_varName [private]

Definition at line 56 of file RootIOUserDataProxy.h.

std::string RootIOUserDataProxy::m_cppType [private]

Definition at line 57 of file RootIOUserDataProxy.h.

Definition at line 58 of file RootIOUserDataProxy.h.

Definition at line 59 of file RootIOUserDataProxy.h.


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:18 for RootIOSvc by doxygen 1.7.4