| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

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 // CVS tag $Name: GAUDI_v20r4-pre $, verison $Revison:$
00004 // =============================================================================
00005 #ifndef GAUDIALG_TUPLEPUT_H 
00006 #define GAUDIALG_TUPLEPUT_H 1
00007 // =============================================================================
00008 // Include files
00009 // =============================================================================
00010 // GaudiKernel
00011 // =============================================================================
00012 #include "GaudiKernel/System.h"
00013 // =============================================================================
00014 // GaudiAlg
00015 // =============================================================================
00016 #include "GaudiAlg/TupleObj.h"
00017 // ============================================================================
00018 // Reflex
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       // find the item by name 
00061       typename Store::iterator ifound = m_map.find( key ) ;
00062       // existing item?
00063       if ( m_map.end() != ifound ) { return ifound->second ; }        // RETURN
00064       // check the tuple for booking:
00065       if ( 0 == tuple ) { return 0 ; }
00066       // check the existrence of the name 
00067       if ( !tuple->goodItem ( key ) ) 
00068       {
00069         tuple -> Error ( "ItemStore::getItem('" + key 
00070                          + "') item name is not unique").ignore() ;
00071         return 0 ;                                                    // RETURN 
00072       }
00073       // get the underlying object      
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 ;                                                   // RETURN
00080       }  
00081       // create new item:
00082       NTuple::Item<VALUE>* item = new NTuple::Item<VALUE>() ;
00083       // add it into N-tuple 
00084       StatusCode sc = tup->addItem( key , *item ) ;                 // ATTENTION!
00085       if ( sc.isFailure() ) 
00086       {
00087         tuple -> Error   ( "ItemStore::getItem('" + key 
00088                            + "') cannot addItem" , sc ).ignore() ;
00089         return 0 ;                                                  // RETURN 
00090       }
00091       // check the name again 
00092       if ( !tuple->addItem( key , System::typeinfoName ( typeid ( VALUE ) ) ) ) 
00093       {
00094         tuple -> Warning ( "ItemStore::getItem('" + key 
00095                            + "') the item not unique " ).ignore() ;
00096       }    
00097       // add the newly created item into the store:
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 ;                                                  // RETURN 
00105     }
00106   private:
00107     // copy constructor is disabled 
00108     ItemStore           ( const ItemStore& ) ; 
00109     // assignement is disabled 
00110     ItemStore& operator=( const ItemStore& ) ; 
00111   private:
00113     Store m_map ; 
00114   } ;
00115 } // end of namespace Tuples 
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     ; }   // RETURN
00132   if ( !evtColType () ) { return InvalidOperation ; }   // RETURN 
00133   
00134   // static block: The Reflex type description & the flag 
00135   static bool               s_fail = false ;                // STATIC 
00136   static ROOT::Reflex::Type s_type         ;                // STATIC 
00137   // check the status 
00138   if      (  s_fail  ) { return InvalidItem ; }                           // RETURN 
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 ) ;    // RETURN 
00148     }
00149   }
00150   // the local storage of items 
00151   static Tuples::ItemStore<TYPE*> s_map ;
00152   // get the variable by name:
00153   NTuple::Item<TYPE*>* item = s_map.getItem ( name , this ) ;
00154   if ( 0 == item )
00155   { return Error ( " put('" + name + "'): invalid item detected", InvalidItem ) ; }
00156   // assign the item!
00157   (*item) = const_cast<TYPE*> ( obj ) ;                    // THATS ALL!!
00158   //
00159   return StatusCode::SUCCESS ;                             // RETURN
00160 }
00161 // ============================================================================
00162 
00163 // ============================================================================
00164 // The END 
00165 // ============================================================================
00166 #endif // GAUDIALG_TUPLEPUT_H
00167 // ============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:58:14 2011 for GaudiAlg by doxygen 1.4.7