#include <RootIOUserDataProxy.h>
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 |
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.
RootIOUserDataProxy::RootIOUserDataProxy | ( | const std::string & | varName, | |
const std::string & | cppType, | |||
char * | address | |||
) |
Definition at line 8 of file RootIOUserDataProxy.cc.
00011 : m_varName(varName), 00012 m_cppType(cppType), 00013 m_address(address) 00014 { 00015 // If ccpType is not one of these then it is assumed to be an object 00016 const char* knownPOD[] = { "int", "float", 0 }; 00017 const char* rootTypes[] = { "Int_t", "Float_t", 0 }; 00018 00019 m_isObject = true; 00020 for (int ind=0; knownPOD[ind]; ++ind) { 00021 if (m_cppType == knownPOD[ind]) { 00022 m_isObject = false; 00023 break; 00024 } 00025 if (m_cppType == rootTypes[ind]) { 00026 m_cppType = knownPOD[ind]; 00027 m_isObject = false; 00028 break; 00029 } 00030 } 00031 }
RootIOUserDataProxy::~RootIOUserDataProxy | ( | ) | [virtual] |
const std::string& RootIOUserDataProxy::varName | ( | ) | [inline] |
Access the variable name.
Definition at line 30 of file RootIOUserDataProxy.h.
00030 { return m_varName; }
const std::string& RootIOUserDataProxy::cppType | ( | ) | [inline] |
Access the variable type name.
Definition at line 33 of file RootIOUserDataProxy.h.
00033 { 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.
00036 { return m_isObject; }
bool RootIOUserDataProxy::branch | ( | TTree * | tree | ) |
Call TTree::Branch(), return false on failure.
Definition at line 38 of file RootIOUserDataProxy.cc.
00039 { 00040 // handle known object types needing template to trigger write Branch() call 00041 if (m_cppType == "int") { 00042 tree->Branch(m_varName.c_str(),address<void>(),"Int_t/I"); 00043 return true; 00044 } 00045 00046 if (m_cppType == "float") { 00047 tree->Branch(m_varName.c_str(),address<void>(),"Float_t/F"); 00048 return true; 00049 } 00050 00051 if (m_cppType == "vector<int>") { 00052 tree->Branch(m_varName.c_str(), address< std::vector<int> >()); 00053 return true; 00054 } 00055 00056 if (m_cppType == "vector<float>") { 00057 tree->Branch(m_varName.c_str(), address< std::vector<float> >()); 00058 return true; 00059 } 00060 00061 return false; 00062 }
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.
00043 { 00044 return *(DTYPE*)(m_address); 00045 }
DTYPE* RootIOUserDataProxy::address | ( | ) | [inline] |
Definition at line 46 of file RootIOUserDataProxy.h.
00046 { 00047 return (DTYPE*)(m_address); 00048 }
void RootIOUserDataProxy::resetAddress | ( | char * | address | ) | [inline] |
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.
char* RootIOUserDataProxy::m_address [private] |
Definition at line 58 of file RootIOUserDataProxy.h.
bool RootIOUserDataProxy::m_isObject [private] |
Definition at line 59 of file RootIOUserDataProxy.h.