Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 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 // ROOT TClass
17 // ============================================================================
18 #include "TClass.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 type description & the flag
133  static bool s_fail = false ; // STATIC
134  static TClass* s_type = 0 ; // STATIC
135  // check the status
136  if ( s_fail ) { return InvalidItem ; } // RETURN
137  else if ( !s_type )
138  {
139  s_type = TClass::GetClass(typeid(TYPE));
140  if ( !s_type )
141  {
142  s_fail = true ;
143  return Error ( " put('"+name+"'," + System::typeinfoName(typeid(TYPE)) +
144  ") :Invalid ROOT Type", InvalidItem ) ; // RETURN
145  }
146  }
147  // the local storage of items
148  static Tuples::ItemStore<TYPE*> s_map ;
149  // get the variable by name:
150  NTuple::Item<TYPE*>* item = s_map.getItem ( name , this ) ;
151  if ( 0 == item )
152  { return Error ( " put('" + name + "'): invalid item detected", InvalidItem ) ; }
153  // assign the item!
154  (*item) = const_cast<TYPE*> ( obj ) ; // THATS ALL!!
155  //
156  return StatusCode::SUCCESS ; // RETURN
157 }
158 // ============================================================================
159 
160 // ============================================================================
161 // The END
162 // ============================================================================
163 #endif // GAUDIALG_TUPLEPUT_H
164 // ============================================================================

Generated at Mon Feb 17 2014 14:37:38 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004