Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ]   [ 15.*.* ] 

001 // $Id: TuplePut.h,v 1.2 2007/05/24 14:22:58 hmd Exp $
002 // =============================================================================
003 // CVS tag $Name:  $, verison $Revison:$
004 // =============================================================================
005 #ifndef GAUDIALG_TUPLEPUT_H 
006 #define GAUDIALG_TUPLEPUT_H 1
007 // =============================================================================
008 // Include files
009 // =============================================================================
010 // GaudiKernel
011 // =============================================================================
012 #include "GaudiKernel/System.h"
013 // =============================================================================
014 // GaudiAlg
015 // =============================================================================
016 #include "GaudiAlg/TupleObj.h"
017 // ============================================================================
018 // Reflex
019 // ============================================================================
020 #include "Reflex/Reflex.h"
021 // =============================================================================
022 /** @file
023  *  Implementation file for Tuple::TupleObj::put method 
024  *  @author Vanya BELYAEV ibelyaev@physics.syr.edu
025  *  @date 2007-04-08
026  */
027 // =============================================================================
028 namespace Tuples 
029 { 
030   /** @class ItemStore ItemStore.h GaudiAlg/ItemStore.h
031    * 
032    *  Simple class, which represents the local storage of N-tupel items
033    *  of the given type. Essentially it is a restricted 
034    *  GaudiUtils::HashMap with the ownership of the newly created entries 
035    *
036    *  @author Vanya BELYAEV ibelyaev@physics.syr.edu
037    *  @date   2007-04-08
038    */
039   template <class VALUE> 
040   class ItemStore 
041   {
042     friend class TupleObj ;
043   private:
044     typedef GaudiUtils::HashMap<std::string,NTuple::Item<VALUE>*>  Store;
045   public:
046     /// constructor : create empty map 
047     ItemStore() : m_map() {}
048     /// destructor : delete all known entries 
049     ~ItemStore() 
050     {
051       for ( typename Store::iterator ientry  = m_map.begin() ; 
052             m_map.end() != ientry ; ++ientry ) 
053       { if ( 0 != ientry->second ) { delete ientry->second ; } } 
054     } ;
055   protected:
056     /// the only one method: 
057     inline NTuple::Item<VALUE>* getItem 
058     ( const std::string& key , Tuples::TupleObj* tuple )
059     {
060       // find the item by name 
061       typename Store::iterator ifound = m_map.find( key ) ;
062       // existing item?
063       if ( m_map.end() != ifound ) { return ifound->second ; }        // RETURN
064       // check the tuple for booking:
065       if ( 0 == tuple ) { return 0 ; }
066       // check the existrence of the name 
067       if ( !tuple->goodItem ( key ) ) 
068       {
069         tuple -> Error ( "ItemStore::getItem('" + key 
070                          + "') item name is not unique").ignore() ;
071         return 0 ;                                                    // RETURN 
072       }
073       // get the underlying object      
074       NTuple::Tuple* tup = tuple->tuple() ;
075       if ( 0 == tup ) 
076       {
077         tuple -> Error ( "ItemStore::getItem('" + key 
078                          + "') invalid NTuple::Tuple*" ).ignore() ;
079         return 0 ;                                                   // RETURN
080       }  
081       // create new item:
082       NTuple::Item<VALUE>* item = new NTuple::Item<VALUE>() ;
083       // add it into N-tuple 
084       StatusCode sc = tup->addItem( key , *item ) ;                 // ATTENTION!
085       if ( sc.isFailure() ) 
086       {
087         tuple -> Error   ( "ItemStore::getItem('" + key 
088                            + "') cannot addItem" , sc ).ignore() ;
089         return 0 ;                                                  // RETURN 
090       }
091       // check the name again 
092       if ( !tuple->addItem( key , System::typeinfoName ( typeid ( VALUE ) ) ) ) 
093       {
094         tuple -> Warning ( "ItemStore::getItem('" + key 
095                            + "') the item not unique " ).ignore() ;
096       }    
097       // add the newly created item into the store:
098       if ( !m_map.insert ( std::make_pair ( key , item ) ).second ) 
099       {
100         tuple -> Warning ( "ItemStore::getItem('" + key 
101                            + "') item is not inserted!" ).ignore() ;        
102       }
103       //
104       return item ;                                                  // RETURN 
105     }
106   private:
107     // copy constructor is disabled 
108     ItemStore           ( const ItemStore& ) ; ///< no copy is allowed 
109     // assignement is disabled 
110     ItemStore& operator=( const ItemStore& ) ; ///< no assignement is allowed 
111   private:
112     /// the underlying map 
113     Store m_map ; ///< the underlying map 
114   } ;
115 } // end of namespace Tuples 
116 // =============================================================================
117 /** The function allows to add almost arbitrary object into N-tuple 
118  *  @attention it requires POOL persistency 
119  *
120  *  @param name column name 
121  *  @param obj  pointer to the object  
122  *
123  *  @author Vanya BELYAEV ibelyaev@physics.syr.edu
124  *  @date 2007-04-08
125  */        
126 // =============================================================================
127 template <class TYPE>
128 inline StatusCode Tuples::TupleObj::put 
129 ( const std::string& name , const TYPE* obj ) 
130 {
131   if (  invalid    () ) { return InvalidTuple     ; }   // RETURN
132   if ( !evtColType () ) { return InvalidOperation ; }   // RETURN 
133   
134   // static block: The Reflex type description & the flag 
135   static bool               s_fail = false ;                // STATIC 
136   static ROOT::Reflex::Type s_type         ;                // STATIC 
137   // check the status 
138   if      (  s_fail  ) { return InvalidItem ; }                           // RETURN 
139   else if ( !s_type  ) 
140   { 
141     const std::string class_name = System::typeinfoName ( typeid ( TYPE ) ) ;
142     s_type = ROOT::Reflex::Type::ByName( class_name  ) ;
143     if ( !s_type ) 
144     {
145       s_fail = true ; 
146       return Error ( " put('"+name+"'," + class_name + 
147                      ") :Invalid ROOT::Reflex::Type", InvalidItem ) ;    // RETURN 
148     }
149   }
150   // the local storage of items 
151   static Tuples::ItemStore<TYPE*> s_map ;
152   // get the variable by name:
153   NTuple::Item<TYPE*>* item = s_map.getItem ( name , this ) ;
154   if ( 0 == item )
155   { return Error ( " put('" + name + "'): invalid item detected", InvalidItem ) ; }
156   // assign the item!
157   (*item) = const_cast<TYPE*> ( obj ) ;                    // THATS ALL!!
158   //
159   return StatusCode::SUCCESS ;                             // RETURN
160 }
161 // ============================================================================
162 
163 // ============================================================================
164 // The END 
165 // ============================================================================
166 #endif // GAUDIALG_TUPLEPUT_H
167 // ============================================================================
168 

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!