The Gaudi Framework  v33r0 (d5ea422b)
TupleDetail.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIALG_TUPLEDETAIL_H
12 #define GAUDIALG_TUPLEDETAIL_H 1
13 // ============================================================================
14 // Include files
15 // ============================================================================
16 #include "GaudiAlg/Tuple.h"
17 #include "GaudiAlg/TupleObj.h"
18 #include "GaudiAlg/Tuples.h"
19 // ============================================================================
20 
21 // ============================================================================
27 // ============================================================================
28 
29 namespace Tuples {
36  namespace detail {
85  template <class HANDLER1, class HANDLER2>
86  class TupleObjImp : public TupleObj {
87  public:
96  TupleObjImp( HANDLER1 handler1, HANDLER2 handler2, const std::string& name, NTuple::Tuple* tuple,
97  const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE )
98  : TupleObj( name, tuple, clid, type ), m_handler1( handler1 ), m_handler2( handler2 ) {}
99 
100  public:
101  StatusCode Error( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const override {
102  m_handler1( name() + " " + msg, sc );
103  return sc;
104  }
105 
106  StatusCode Warning( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const override {
107  m_handler2( name() + " " + msg, sc );
108  return sc;
109  }
110 
111  private:
112  HANDLER1 m_handler1;
113  HANDLER2 m_handler2;
114  };
115 
144  template <class HANDLER1, class HANDLER2>
145  auto createTupleObj( HANDLER1 handler1, HANDLER2 handler2, const std::string& name, NTuple::Tuple* tuple,
146  const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE ) {
147  return std::make_unique<TupleObjImp<HANDLER1, HANDLER2>>( handler1, handler2, name, tuple, clid, type );
148  }
149 
160  template <class OBJECT, class FUNCTION>
161  class ErrorHandler {
162  public:
164  ErrorHandler( const OBJECT* obj, FUNCTION fun ) : m_obj( obj ), m_fun( fun ) {}
165 
166  public:
168  StatusCode operator()( const std::string& msg, const StatusCode sc, const size_t mp = 10 ) const {
169  return ( m_obj->*m_fun )( msg, sc, mp );
170  }
171 
172  private:
173  // default constructor is private
174  ErrorHandler();
175 
176  private:
177  const OBJECT* m_obj = nullptr;
178  FUNCTION m_fun;
179  };
180 
200  template <class OBJECT, class FUNCTION>
201  inline ErrorHandler<OBJECT, FUNCTION> make_handler( const OBJECT* object, FUNCTION function ) {
202  return ErrorHandler<OBJECT, FUNCTION>( object, function );
203  }
204  } // namespace detail
205 
224  template <class OWNER>
225  auto createTupleObj( const OWNER* owner, const std::string& name, NTuple::Tuple* tuple,
226  const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE ) {
227  return detail::createTupleObj( detail::make_handler( owner, &OWNER::Error ),
228  detail::make_handler( owner, &OWNER::Warning ), name, tuple, clid, type );
229  }
230 
231 } // end of namespace Tuples
232 
233 // ============================================================================
234 // The END
235 // ============================================================================
236 #endif // GAUDIALG_TUPLEDETAIL_H
StatusCode operator()(const std::string &msg, const StatusCode sc, const size_t mp=10) const
the only one 'useful' method
Definition: TupleDetail.h:168
ErrorHandler(const OBJECT *obj, FUNCTION fun)
constructor
Definition: TupleDetail.h:164
Header file for class TupleObj.
auto 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:145
const CLID & clid() const
accessor to the N-Tuple CLID
Definition: TupleObj.h:1869
The simplest concrete implementation of class TupleObj with 3 arbitrary error handlers Any types (cla...
Definition: TupleDetail.h:86
Tuples::Type type() const
accessor to the N-Tuple type
Definition: TupleObj.h:1872
STL class.
StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const override
Definition: TupleDetail.h:101
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:209
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:96
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:1861
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:385
auto createTupleObj(const OWNER *owner, 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:225
const std::string & name() const
get the name
Definition: TupleObj.h:1856
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:201
constexpr static const auto FAILURE
Definition: StatusCode.h:97
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40
Type
the list of available types for ntuples
Definition: TupleObj.h:89
Header file for class : Tuple.
Concrete error handlers for dealing with classes, which supports member functions Error,...
Definition: TupleDetail.h:161
StatusCode Warning(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const override
Definition: TupleDetail.h:106
General namespace for Tuple properties.
Definition: Maps.h:43