|
||||
File indexing completed on 2025-01-18 09:57:34
0001 /***********************************************************************************\ 0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations * 0003 * * 0004 * This software is distributed under the terms of the Apache version 2 licence, * 0005 * copied verbatim in the file "LICENSE". * 0006 * * 0007 * In applying this licence, CERN does not waive the privileges and immunities * 0008 * granted to it by virtue of its status as an Intergovernmental Organization * 0009 * or submit itself to any jurisdiction. * 0010 \***********************************************************************************/ 0011 #ifndef GAUDIALG_TUPLEDETAIL_H 0012 #define GAUDIALG_TUPLEDETAIL_H 1 0013 // ============================================================================ 0014 // Include files 0015 // ============================================================================ 0016 #include "GaudiAlg/Tuple.h" 0017 #include "GaudiAlg/TupleObj.h" 0018 #include "GaudiAlg/Tuples.h" 0019 // ============================================================================ 0020 0021 // ============================================================================ 0022 /** @file 0023 * Collection of few 'technical' methods for instantiation of tuples 0024 * @author Ivan BELYAEV 0025 * @date 2004-01-27 0026 */ 0027 // ============================================================================ 0028 0029 namespace Tuples { 0030 /** @namespace detail TupleObj.h GaudiAlg/TupleObj.h 0031 * namespace with few technical implementations 0032 * 0033 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 0034 * @date 2004-01-23 0035 */ 0036 namespace detail { 0037 /** @class TupleObjImp 0038 * 0039 * The simplest concrete implementation of class TupleObj 0040 * with 3 arbitrary error handlers 0041 * Any types (classes, functions, etc.) which supports the 0042 * semantics 0043 * 0044 * @code 0045 * 0046 * HANDLER obj = .. ; 0047 * 0048 * StatusCode obj( msg , sc ) 0049 * 0050 * @endcode 0051 * 0052 * can be used as error handler, e.g. 0053 * 0054 * @code 0055 * 0056 * void print_error ( const std::string& msg , StatusCode sc ) 0057 * { std::cout << 0058 * "Error" << msg << " code " << sc.getCode() << std::endl ; } 0059 * void print_warning ( const std::string& msg , StatusCode sc ) 0060 * { std::cout << 0061 * "Warning" << msg << " code " << sc.getCode() << std::endl ; } 0062 * void print_print ( const std::string& msg , StatusCode sc ) 0063 * { std::cout << msg << " code " << sc.getCode() << std::endl ; } 0064 * 0065 * NTuple::Tuple* tuple = ... ; 0066 * TupleObj* obj = 0067 * createTupleObj( print_errror , 0068 * print_warning , 0069 * print_print , 0070 * " my tuple " , ntuple ) ; 0071 * 0072 * @endcode 0073 * 0074 * Templated helper functions allow to avoid heavy semantics of 0075 * dealing with explicit type 0076 * 0077 * Few concrete error handlers for dealing with classes, 0078 * which supports member functions Error and Warning 0079 * ( e.g. class GaudiAlgorithm or class GaudiTool ) 0080 * are provided 0081 * 0082 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 0083 * @date 2004-1-24 0084 */ 0085 template <class HANDLER1, class HANDLER2> 0086 class TupleObjImp : public TupleObj { 0087 public: 0088 /** constructor 0089 * @param handler1 error handler 0090 * @param handler2 warning handler 0091 * @param name Name of the NTuple 0092 * @param tuple NTuple itself 0093 * @param clid NTuple CLID 0094 * @param type NTuple type 0095 */ 0096 TupleObjImp( HANDLER1 handler1, HANDLER2 handler2, const std::string& name, NTuple::Tuple* tuple, 0097 const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE ) 0098 : TupleObj( name, tuple, clid, type ), m_handler1( handler1 ), m_handler2( handler2 ) {} 0099 0100 public: 0101 StatusCode Error( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const override { 0102 return m_handler1( name() + " " + msg, sc ); 0103 } 0104 0105 StatusCode Warning( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const override { 0106 return m_handler2( name() + " " + msg, sc ); 0107 } 0108 0109 private: 0110 HANDLER1 m_handler1; 0111 HANDLER2 m_handler2; 0112 }; 0113 0114 /** Templated helper functions allow to avoid heavy semantics of 0115 * dealing with explicit type of class TupleObjImp 0116 * 0117 * @code 0118 * 0119 * void print_error ( const std::string& msg , StatusCode sc ) 0120 * { std::cout << 0121 * "Error" << msg << " code " << sc.getCode() << std::endl ; } 0122 * void print_warning ( const std::string& msg , StatusCode sc ) 0123 * { std::cout << 0124 * "Warning" << msg << " code " << sc.getCode() << std::endl ; } 0125 * 0126 * NTuple::Tuple* tuple = ... ; 0127 * TupleObj* obj = 0128 * createTupleObj( print_errror , 0129 * print_warning , 0130 * " my tuple " , ntuple ) ; 0131 * 0132 * @endcode 0133 * 0134 * Few concrete error handlers for dealing with classes, 0135 * which supports member functions Error,Warning and Print 0136 * ( e.g. class GaudiAlgorithm or class GaudiTool ) 0137 * are provided 0138 * 0139 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 0140 * @date 2004-1-24 0141 */ 0142 template <class HANDLER1, class HANDLER2> 0143 auto createTupleObj( HANDLER1 handler1, HANDLER2 handler2, const std::string& name, NTuple::Tuple* tuple, 0144 const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE ) { 0145 return std::make_unique<TupleObjImp<HANDLER1, HANDLER2>>( handler1, handler2, name, tuple, clid, type ); 0146 } 0147 0148 /** @class ErrorHandler 0149 * 0150 * Concrete error handlers for dealing with classes, 0151 * which supports member functions Error,Warning and Print 0152 * ( e.g. class GaudiAlgorithm or class GaudiTool ) 0153 * are provided 0154 * 0155 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 0156 * @date 2004-1-24 0157 */ 0158 template <class OBJECT, class FUNCTION> 0159 class ErrorHandler { 0160 public: 0161 /// constructor 0162 ErrorHandler( const OBJECT* obj, FUNCTION fun ) : m_obj( obj ), m_fun( fun ) {} 0163 0164 /// the only one 'useful' method 0165 StatusCode operator()( const std::string& msg, const StatusCode sc, const size_t mp = 10 ) const { 0166 return ( m_obj->*m_fun )( msg, sc, mp ); 0167 } 0168 0169 private: 0170 // default constructor is private 0171 ErrorHandler(); 0172 0173 private: 0174 const OBJECT* m_obj = nullptr; 0175 FUNCTION m_fun; 0176 }; 0177 0178 /** Templated helper functions allow to avoid heavy semantics of 0179 * dealing with explicit type of class ErrorHandler 0180 * 0181 * @code 0182 * 0183 * const GaudiAlgorithm* algo = ... ; 0184 * 0185 * // error handler using GaudiAlgorithm::Error member function 0186 * make_handler( algo , &GaudiAlgorithm::Error ) ; 0187 * 0188 * const GaudiTool* tool = .... ; 0189 * // error handler using GaudiTool::Print member function 0190 * make_handler( tool , &GaudiTool::Print ) ; 0191 * 0192 * @endcode 0193 * 0194 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 0195 * @date 2004-1-24 0196 */ 0197 template <class OBJECT, class FUNCTION> 0198 ErrorHandler<OBJECT, FUNCTION> make_handler( const OBJECT* object, FUNCTION function ) { 0199 return ErrorHandler( object, function ); 0200 } 0201 } // namespace detail 0202 0203 /** Templated helper functions allow to avoid heavy semantics of 0204 * dealing with explicit type of class TupleObjImp 0205 * 0206 * @code 0207 * 0208 * const GaudiAlgorithm* algo = ... ; 0209 * NTuple::Tuple* tuple = ... ; 0210 * TupleObj* obj = createTupleObj( algo , " my tuple 1 " , ntuple ) ; 0211 * 0212 * const GaudiTool* tool = ... ; 0213 * NTuple::Tuple* tuple2 = ... ; 0214 * TupleObj* obj2 = createTupleObj( tool , " my tuple 2 " , ntuple2 ) ; 0215 * 0216 * @endcode 0217 * 0218 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 0219 * @date 2004-1-24 0220 */ 0221 template <class OWNER> 0222 auto createTupleObj( const OWNER* owner, const std::string& name, NTuple::Tuple* tuple, 0223 const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE ) { 0224 return detail::createTupleObj( detail::make_handler( owner, &OWNER::Error ), 0225 detail::make_handler( owner, &OWNER::Warning ), name, tuple, clid, type ); 0226 } 0227 0228 } // end of namespace Tuples 0229 0230 // ============================================================================ 0231 // The END 0232 // ============================================================================ 0233 #endif // GAUDIALG_TUPLEDETAIL_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |