Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

TuplePut.h

Go to the documentation of this file.
00001 // $Id: TuplePut.h,v 1.2 2007/05/24 14:22:58 hmd Exp $
00002 // =============================================================================
00003 #ifndef GAUDIALG_TUPLEPUT_H
00004 #define GAUDIALG_TUPLEPUT_H 1
00005 // =============================================================================
00006 // Include files
00007 // =============================================================================
00008 // GaudiKernel
00009 // =============================================================================
00010 #include "GaudiKernel/System.h"
00011 // =============================================================================
00012 // GaudiAlg
00013 // =============================================================================
00014 #include "GaudiAlg/TupleObj.h"
00015 // ============================================================================
00016 // Reflex
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       // find the item by name
00059       typename Store::iterator ifound = m_map.find( key ) ;
00060       // existing item?
00061       if ( m_map.end() != ifound ) { return ifound->second ; }        // RETURN
00062       // check the tuple for booking:
00063       if ( 0 == tuple ) { return 0 ; }
00064       // check the existence of the name
00065       if ( !tuple->goodItem ( key ) )
00066       {
00067         tuple -> Error ( "ItemStore::getItem('" + key
00068                          + "') item name is not unique").ignore() ;
00069         return 0 ;                                                    // RETURN
00070       }
00071       // get the underlying object
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 ;                                                   // RETURN
00078       }
00079       // create new item:
00080       NTuple::Item<VALUE>* item = new NTuple::Item<VALUE>() ;
00081       // add it into N-tuple
00082       StatusCode sc = tup->addItem( key , *item ) ;                 // ATTENTION!
00083       if ( sc.isFailure() )
00084       {
00085         tuple -> Error   ( "ItemStore::getItem('" + key
00086                            + "') cannot addItem" , sc ).ignore() ;
00087         return 0 ;                                                  // RETURN
00088       }
00089       // check the name again
00090       if ( !tuple->addItem( key , System::typeinfoName ( typeid ( VALUE ) ) ) )
00091       {
00092         tuple -> Warning ( "ItemStore::getItem('" + key
00093                            + "') the item not unique " ).ignore() ;
00094       }
00095       // add the newly created item into the store:
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 ;                                                  // RETURN
00103     }
00104   private:
00105     // copy constructor is disabled
00106     ItemStore           ( const ItemStore& ) ; 
00107     // assignment is disabled
00108     ItemStore& operator=( const ItemStore& ) ; 
00109   private:
00111     Store m_map ; 
00112   } ;
00113 } // end of namespace Tuples
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     ; }   // RETURN
00130   if ( !evtColType () ) { return InvalidOperation ; }   // RETURN
00131 
00132   // static block: The Reflex type description & the flag
00133   static bool               s_fail = false ;                // STATIC
00134   static ROOT::Reflex::Type s_type         ;                // STATIC
00135   // check the status
00136   if      (  s_fail  ) { return InvalidItem ; }                           // RETURN
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 ) ;    // RETURN
00146     }
00147   }
00148   // the local storage of items
00149   static Tuples::ItemStore<TYPE*> s_map ;
00150   // get the variable by name:
00151   NTuple::Item<TYPE*>* item = s_map.getItem ( name , this ) ;
00152   if ( 0 == item )
00153   { return Error ( " put('" + name + "'): invalid item detected", InvalidItem ) ; }
00154   // assign the item!
00155   (*item) = const_cast<TYPE*> ( obj ) ;                    // THATS ALL!!
00156   //
00157   return StatusCode::SUCCESS ;                             // RETURN
00158 }
00159 // ============================================================================
00160 
00161 // ============================================================================
00162 // The END
00163 // ============================================================================
00164 #endif // GAUDIALG_TUPLEPUT_H
00165 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:26 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004