Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TuplePut.h
Go to the documentation of this file.
1 // $Id: TuplePut.h,v 1.2 2007/05/24 14:22:58 hmd Exp $
2 // =============================================================================
3 #ifndef GAUDIALG_TUPLEPUT_H
4 #define GAUDIALG_TUPLEPUT_H 1
5 // =============================================================================
6 // Include files
7 // =============================================================================
8 // GaudiKernel
9 // =============================================================================
10 #include "GaudiKernel/System.h"
11 // =============================================================================
12 // GaudiAlg
13 // =============================================================================
14 #include "GaudiAlg/TupleObj.h"
15 // ============================================================================
16 // Reflex
17 // ============================================================================
18 #include "Reflex/Reflex.h"
19 // =============================================================================
25 // =============================================================================
26 namespace Tuples
27 {
37  template <class VALUE>
38  class ItemStore
39  {
40  friend class TupleObj ;
41  private:
43  public:
45  ItemStore() : m_map() {}
48  {
49  for ( typename Store::iterator ientry = m_map.begin() ;
50  m_map.end() != ientry ; ++ientry )
51  { if ( 0 != ientry->second ) { delete ientry->second ; } }
52  }
53  protected:
56  ( const std::string& key , Tuples::TupleObj* tuple )
57  {
58  // find the item by name
59  typename Store::iterator ifound = m_map.find( key ) ;
60  // existing item?
61  if ( m_map.end() != ifound ) { return ifound->second ; } // RETURN
62  // check the tuple for booking:
63  if ( 0 == tuple ) { return 0 ; }
64  // check the existence of the name
65  if ( !tuple->goodItem ( key ) )
66  {
67  tuple -> Error ( "ItemStore::getItem('" + key
68  + "') item name is not unique").ignore() ;
69  return 0 ; // RETURN
70  }
71  // get the underlying object
72  NTuple::Tuple* tup = tuple->tuple() ;
73  if ( 0 == tup )
74  {
75  tuple -> Error ( "ItemStore::getItem('" + key
76  + "') invalid NTuple::Tuple*" ).ignore() ;
77  return 0 ; // RETURN
78  }
79  // create new item:
81  // add it into N-tuple
82  StatusCode sc = tup->addItem( key , *item ) ; // ATTENTION!
83  if ( sc.isFailure() )
84  {
85  tuple -> Error ( "ItemStore::getItem('" + key
86  + "') cannot addItem" , sc ).ignore() ;
87  return 0 ; // RETURN
88  }
89  // check the name again
90  if ( !tuple->addItem( key , System::typeinfoName ( typeid ( VALUE ) ) ) )
91  {
92  tuple -> Warning ( "ItemStore::getItem('" + key
93  + "') the item not unique " ).ignore() ;
94  }
95  // add the newly created item into the store:
96  if ( !m_map.insert ( std::make_pair ( key , item ) ).second )
97  {
98  tuple -> Warning ( "ItemStore::getItem('" + key
99  + "') item is not inserted!" ).ignore() ;
100  }
101  //
102  return item ; // RETURN
103  }
104  private:
105  // copy constructor is disabled
106  ItemStore ( const ItemStore& ) ;
107  // assignment is disabled
108  ItemStore& operator=( const ItemStore& ) ;
109  private:
112  } ;
113 } // end of namespace Tuples
114 // =============================================================================
124 // =============================================================================
125 template <class TYPE>
127 ( const std::string& name , const TYPE* obj )
128 {
129  if ( invalid () ) { return InvalidTuple ; } // RETURN
130  if ( !evtColType () ) { return InvalidOperation ; } // RETURN
131 
132  // static block: The Reflex type description & the flag
133  static bool s_fail = false ; // STATIC
134  static ROOT::Reflex::Type s_type ; // STATIC
135  // check the status
136  if ( s_fail ) { return InvalidItem ; } // RETURN
137  else if ( !s_type )
138  {
139  const std::string class_name = System::typeinfoName ( typeid ( TYPE ) ) ;
140  s_type = ROOT::Reflex::Type::ByName( class_name ) ;
141  if ( !s_type )
142  {
143  s_fail = true ;
144  return Error ( " put('"+name+"'," + class_name +
145  ") :Invalid ROOT::Reflex::Type", InvalidItem ) ; // RETURN
146  }
147  }
148  // the local storage of items
149  static Tuples::ItemStore<TYPE*> s_map ;
150  // get the variable by name:
151  NTuple::Item<TYPE*>* item = s_map.getItem ( name , this ) ;
152  if ( 0 == item )
153  { return Error ( " put('" + name + "'): invalid item detected", InvalidItem ) ; }
154  // assign the item!
155  (*item) = const_cast<TYPE*> ( obj ) ; // THATS ALL!!
156  //
157  return StatusCode::SUCCESS ; // RETURN
158 }
159 // ============================================================================
160 
161 // ============================================================================
162 // The END
163 // ============================================================================
164 #endif // GAUDIALG_TUPLEPUT_H
165 // ============================================================================

Generated at Wed Jan 30 2013 17:13:37 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004