The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  return m_handler1( name() + " " + msg, sc );
103  }
104 
105  StatusCode Warning( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const override {
106  return m_handler2( name() + " " + msg, sc );
107  }
108 
109  private:
110  HANDLER1 m_handler1;
111  HANDLER2 m_handler2;
112  };
113 
142  template <class HANDLER1, class HANDLER2>
143  auto createTupleObj( HANDLER1 handler1, HANDLER2 handler2, const std::string& name, NTuple::Tuple* tuple,
144  const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE ) {
145  return std::make_unique<TupleObjImp<HANDLER1, HANDLER2>>( handler1, handler2, name, tuple, clid, type );
146  }
147 
158  template <class OBJECT, class FUNCTION>
159  class ErrorHandler {
160  public:
162  ErrorHandler( const OBJECT* obj, FUNCTION fun ) : m_obj( obj ), m_fun( fun ) {}
163 
165  StatusCode operator()( const std::string& msg, const StatusCode sc, const size_t mp = 10 ) const {
166  return ( m_obj->*m_fun )( msg, sc, mp );
167  }
168 
169  private:
170  // default constructor is private
172 
173  private:
174  const OBJECT* m_obj = nullptr;
175  FUNCTION m_fun;
176  };
177 
197  template <class OBJECT, class FUNCTION>
198  ErrorHandler<OBJECT, FUNCTION> make_handler( const OBJECT* object, FUNCTION function ) {
199  return ErrorHandler( object, function );
200  }
201  } // namespace detail
202 
221  template <class OWNER>
222  auto createTupleObj( const OWNER* owner, const std::string& name, NTuple::Tuple* tuple,
223  const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE ) {
224  return detail::createTupleObj( detail::make_handler( owner, &OWNER::Error ),
225  detail::make_handler( owner, &OWNER::Warning ), name, tuple, clid, type );
226  }
227 
228 } // end of namespace Tuples
229 
230 // ============================================================================
231 // The END
232 // ============================================================================
233 #endif // GAUDIALG_TUPLEDETAIL_H
Tuples::detail::ErrorHandler
Definition: TupleDetail.h:159
Tuples::detail::ErrorHandler::operator()
StatusCode operator()(const std::string &msg, const StatusCode sc, const size_t mp=10) const
the only one 'useful' method
Definition: TupleDetail.h:165
Tuples::detail::ErrorHandler::ErrorHandler
ErrorHandler(const OBJECT *obj, FUNCTION fun)
constructor
Definition: TupleDetail.h:162
Tuple.h
std::string
STL class.
Tuples::TupleObj::type
Tuples::Type type() const
accessor to the N-Tuple type
Definition: TupleObj.h:1873
Tuples.h
bug_34121.name
name
Definition: bug_34121.py:20
Tuples::TupleObj::tuple
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:1862
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
Tuples::detail::TupleObjImp
Definition: TupleDetail.h:86
detail
Tuples::detail::make_handler
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:198
Tuples::detail::ErrorHandler::m_obj
const OBJECT * m_obj
Definition: TupleDetail.h:174
Tuples
Definition: Maps.h:43
Tuples::NTUPLE
@ NTUPLE
Definition: TupleObj.h:92
Tuples::detail::TupleObjImp::TupleObjImp
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
Tuples::TupleObj
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:211
StatusCode
Definition: StatusCode.h:65
TupleObj.h
Tuples::detail::ErrorHandler::m_fun
FUNCTION m_fun
Definition: TupleDetail.h:175
Tuples::detail::TupleObjImp::Error
StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const override
Definition: TupleDetail.h:101
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
Tuples::createTupleObj
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:222
gaudirun.type
type
Definition: gaudirun.py:160
Tuples::TupleObj::clid
const CLID & clid() const
accessor to the N-Tuple CLID
Definition: TupleObj.h:1870
NTuple::Tuple
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:387
Tuples::Type
Type
Definition: TupleObj.h:91
Tuples::detail::createTupleObj
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:143
DataObject
Definition: DataObject.h:40
Tuples::detail::TupleObjImp::Warning
StatusCode Warning(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const override
Definition: TupleDetail.h:105
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Tuples::detail::ErrorHandler::ErrorHandler
ErrorHandler()
Tuples::detail::TupleObjImp::m_handler1
HANDLER1 m_handler1
Definition: TupleDetail.h:110
Tuples::detail::TupleObjImp::m_handler2
HANDLER2 m_handler2
Definition: TupleDetail.h:111
Tuples::TupleObj::name
const std::string & name() const
get the name
Definition: TupleObj.h:1857