The Gaudi Framework  v29r0 (ff2e7097)
TupleDetail.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_TUPLEDETAIL_H
2 #define GAUDIALG_TUPLEDETAIL_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 #include "GaudiAlg/Tuple.h"
7 #include "GaudiAlg/TupleObj.h"
8 #include "GaudiAlg/Tuples.h"
9 // ============================================================================
10 
11 // ============================================================================
17 // ============================================================================
18 
19 namespace Tuples
20 {
27  namespace detail
28  {
77  template <class HANDLER1, class HANDLER2>
78  class TupleObjImp : public TupleObj
79  {
80  public:
89  TupleObjImp( HANDLER1 handler1, HANDLER2 handler2, const std::string& name, NTuple::Tuple* tuple,
90  const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE )
91  : TupleObj( name, tuple, clid, type ), m_handler1( handler1 ), m_handler2( handler2 )
92  {
93  }
94 
95  public:
96  StatusCode Error( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const override
97  {
98  m_handler1( name() + " " + msg, sc );
99  return sc;
100  }
101 
102  StatusCode Warning( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const override
103  {
104  m_handler2( name() + " " + msg, sc );
105  return sc;
106  }
107 
108  protected:
110  ~TupleObjImp() override = default;
111 
112  private:
113  HANDLER1 m_handler1;
114  HANDLER2 m_handler2;
115  };
116 
145  template <class HANDLER1, class HANDLER2>
146  inline TupleObj* createTupleObj( HANDLER1 handler1, HANDLER2 handler2, const std::string& name,
147  NTuple::Tuple* tuple, const CLID& clid = CLID_ColumnWiseTuple,
149  {
150  return new TupleObjImp<HANDLER1, HANDLER2>( handler1, handler2, name, tuple, clid, type );
151  }
152 
163  template <class OBJECT, class FUNCTION>
165  {
166  public:
168  ErrorHandler( const OBJECT* obj, FUNCTION fun ) : m_obj( obj ), m_fun( fun ) {}
169 
170  public:
172  StatusCode operator()( const std::string& msg, const StatusCode sc, const size_t mp = 10 ) const
173  {
174  return ( m_obj->*m_fun )( msg, sc, mp );
175  }
176 
177  private:
178  // default constructor is private
179  ErrorHandler();
180 
181  private:
182  const OBJECT* m_obj = nullptr;
183  FUNCTION m_fun;
184  };
185 
205  template <class OBJECT, class FUNCTION>
206  inline ErrorHandler<OBJECT, FUNCTION> make_handler( const OBJECT* object, FUNCTION function )
207  {
208  return ErrorHandler<OBJECT, FUNCTION>( object, function );
209  }
210  }
211 
230  template <class OWNER>
231  inline TupleObj* createTupleObj( const OWNER* owner, const std::string& name, NTuple::Tuple* tuple,
232  const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE )
233  {
234  return detail::createTupleObj( detail::make_handler( owner, &OWNER::Error ),
235  detail::make_handler( owner, &OWNER::Warning ), name, tuple, clid, type );
236  }
237 
238 } // end of namespace Tuples
239 
240 // ============================================================================
241 // The END
242 // ============================================================================
243 #endif // GAUDIALG_TUPLEDETAIL_H
244 // ============================================================================
TupleObj * createTupleObj(HANDLER1 handler1, HANDLER2 handler2, const std::string &name, NTuple::Tuple *tuple, const CLID &clid=CLID_ColumnWiseTuple, const Tuples::Type type=Tuples::NTUPLE)
Templated helper functions allow to avoid heavy semantics of dealing with explicit type of class Tupl...
Definition: TupleDetail.h:146
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:1935
~TupleObjImp() override=default
empty protected destructor
ErrorHandler(const OBJECT *obj, FUNCTION fun)
constructor
Definition: TupleDetail.h:168
Header file for class TupleObj.
The simplest concrete implementation of class TupleObj with 3 arbitrary error handlers Any types (cla...
Definition: TupleDetail.h:78
STL class.
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:199
TupleObjImp(HANDLER1 handler1, HANDLER2 handler2, const std::string &name, NTuple::Tuple *tuple, const CLID &clid=CLID_ColumnWiseTuple, const Tuples::Type type=Tuples::NTUPLE)
constructor
Definition: TupleDetail.h:89
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:412
StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const override
Definition: TupleDetail.h:96
StatusCode operator()(const std::string &msg, const StatusCode sc, const size_t mp=10) const
the only one &#39;useful&#39; method
Definition: TupleDetail.h:172
Tuples::Type type() const
accessor to the N-Tuple type
Definition: TupleObj.h:1962
ErrorHandler< OBJECT, FUNCTION > make_handler(const OBJECT *object, FUNCTION function)
Templated helper functions allow to avoid heavy semantics of dealing with explicit type of class Erro...
Definition: TupleDetail.h:206
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
StatusCode Warning(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const override
Definition: TupleDetail.h:102
const CLID & clid() const
accessor to the N-Tuple CLID
Definition: TupleObj.h:1959
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
Type
the list of available types for ntuples
Definition: TupleObj.h:84
const std::string & name() const
get the name
Definition: TupleObj.h:1930
Header file for class : Tuple.
Concrete error handlers for dealing with classes, which supports member functions Error...
Definition: TupleDetail.h:164
General namespace for Tuple properties.
Definition: Maps.h:34