00001 #include "ntupleWriterSvc/INTupleWriterSvc.h"
00002 INTupleWriterSvc* rootTupleSvc;
00003
00004
00005
00006 class Item {
00007 public:
00008 Item(std::string name, char typecode=' ')
00009 {
00010 std::string type = rootTupleSvc->getItem(treename, name, m_pvalue);
00011 if( typecode==' ') {
00012 m_isFloat = type==rootType('F');
00013 if( !m_isFloat && type!=rootType('D')){
00014 throw std::invalid_argument("McCoordsAlg: type of "+name+ " is not "+ rootType('F')+" or "+rootType('D'));
00015 }
00016 }else if( type!= rootType(typecode) ){
00017 throw std::invalid_argument("McCoordsAlg: type of "+name+ " is not "+ rootType(typecode));
00018 }
00019 }
00020
00021 operator double()const
00022 {
00023 return m_isFloat? *(float*)m_pvalue : *(double*)m_pvalue;
00024 }
00025
00026
00027
00028 static std::string rootType(char code){
00029 if( code=='i') return "UInt_t";
00030 if( code=='l') return "ULong64_t";
00031 if( code=='I') return "Int_t";
00032 if( code=='F') return "Float_t";
00033 if( code=='D') return "Double_t";
00034
00035 return "unknown";
00036 }
00037 void* m_pvalue;
00038 bool m_isFloat;
00039 };
00040
00041 template<typename T, char typecode>
00042 class TypedItem : public Item {
00043 public:
00044 TypedItem(std::string name): Item(name, typecode){}
00045 T value() const{ return *static_cast<T*>(m_pvalue); }
00046 operator T()const{return value();}
00047 };
00048 template <typename T>
00049 void addItem(std::string name, const T & value)
00050 {
00051 rootTupleSvc->addItem(treename, name, &value);
00052 }
00053