Go to the documentation of this file.00001
00002
00003 #ifndef GAUDIALG_TUPLEPUT_H
00004 #define GAUDIALG_TUPLEPUT_H 1
00005
00006
00007
00008
00009
00010 #include "GaudiKernel/System.h"
00011
00012
00013
00014 #include "GaudiAlg/TupleObj.h"
00015
00016
00017
00018 #include "Reflex/Reflex.h"
00019
00025
00026 namespace Tuples
00027 {
00037 template <class VALUE>
00038 class ItemStore
00039 {
00040 friend class TupleObj ;
00041 private:
00042 typedef GaudiUtils::HashMap<std::string,NTuple::Item<VALUE>*> Store;
00043 public:
00045 ItemStore() : m_map() {}
00047 ~ItemStore()
00048 {
00049 for ( typename Store::iterator ientry = m_map.begin() ;
00050 m_map.end() != ientry ; ++ientry )
00051 { if ( 0 != ientry->second ) { delete ientry->second ; } }
00052 }
00053 protected:
00055 inline NTuple::Item<VALUE>* getItem
00056 ( const std::string& key , Tuples::TupleObj* tuple )
00057 {
00058
00059 typename Store::iterator ifound = m_map.find( key ) ;
00060
00061 if ( m_map.end() != ifound ) { return ifound->second ; }
00062
00063 if ( 0 == tuple ) { return 0 ; }
00064
00065 if ( !tuple->goodItem ( key ) )
00066 {
00067 tuple -> Error ( "ItemStore::getItem('" + key
00068 + "') item name is not unique").ignore() ;
00069 return 0 ;
00070 }
00071
00072 NTuple::Tuple* tup = tuple->tuple() ;
00073 if ( 0 == tup )
00074 {
00075 tuple -> Error ( "ItemStore::getItem('" + key
00076 + "') invalid NTuple::Tuple*" ).ignore() ;
00077 return 0 ;
00078 }
00079
00080 NTuple::Item<VALUE>* item = new NTuple::Item<VALUE>() ;
00081
00082 StatusCode sc = tup->addItem( key , *item ) ;
00083 if ( sc.isFailure() )
00084 {
00085 tuple -> Error ( "ItemStore::getItem('" + key
00086 + "') cannot addItem" , sc ).ignore() ;
00087 return 0 ;
00088 }
00089
00090 if ( !tuple->addItem( key , System::typeinfoName ( typeid ( VALUE ) ) ) )
00091 {
00092 tuple -> Warning ( "ItemStore::getItem('" + key
00093 + "') the item not unique " ).ignore() ;
00094 }
00095
00096 if ( !m_map.insert ( std::make_pair ( key , item ) ).second )
00097 {
00098 tuple -> Warning ( "ItemStore::getItem('" + key
00099 + "') item is not inserted!" ).ignore() ;
00100 }
00101
00102 return item ;
00103 }
00104 private:
00105
00106 ItemStore ( const ItemStore& ) ;
00107
00108 ItemStore& operator=( const ItemStore& ) ;
00109 private:
00111 Store m_map ;
00112 } ;
00113 }
00114
00124
00125 template <class TYPE>
00126 inline StatusCode Tuples::TupleObj::put
00127 ( const std::string& name , const TYPE* obj )
00128 {
00129 if ( invalid () ) { return InvalidTuple ; }
00130 if ( !evtColType () ) { return InvalidOperation ; }
00131
00132
00133 static bool s_fail = false ;
00134 static ROOT::Reflex::Type s_type ;
00135
00136 if ( s_fail ) { return InvalidItem ; }
00137 else if ( !s_type )
00138 {
00139 const std::string class_name = System::typeinfoName ( typeid ( TYPE ) ) ;
00140 s_type = ROOT::Reflex::Type::ByName( class_name ) ;
00141 if ( !s_type )
00142 {
00143 s_fail = true ;
00144 return Error ( " put('"+name+"'," + class_name +
00145 ") :Invalid ROOT::Reflex::Type", InvalidItem ) ;
00146 }
00147 }
00148
00149 static Tuples::ItemStore<TYPE*> s_map ;
00150
00151 NTuple::Item<TYPE*>* item = s_map.getItem ( name , this ) ;
00152 if ( 0 == item )
00153 { return Error ( " put('" + name + "'): invalid item detected", InvalidItem ) ; }
00154
00155 (*item) = const_cast<TYPE*> ( obj ) ;
00156
00157 return StatusCode::SUCCESS ;
00158 }
00159
00160
00161
00162
00163
00164 #endif // GAUDIALG_TUPLEPUT_H
00165