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