diff --git a/Calorimeter/CaloRec/CaloRec/ToolWithConstantsMixin.h b/Calorimeter/CaloRec/CaloRec/ToolWithConstantsMixin.h deleted file mode 100644 index 960a3b9ad98157fcd86ca97700206834c29990e5..0000000000000000000000000000000000000000 --- a/Calorimeter/CaloRec/CaloRec/ToolWithConstantsMixin.h +++ /dev/null @@ -1,576 +0,0 @@ -// This file's extension implies that it's C, but it's really -*- C++ -*-. - -/* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file ToolWithConstantsMixin.h - * @author scott snyder <snyder@bnl.gov> - * @date March, 2006, updated from June, 2004 - * @brief A mixin class to hold a set of constants for an Algorithm, - * Tool, or Service. - */ - -#ifndef TOOLWITHCONSTANTSMIXIN_H -#define TOOLWITHCONSTANTSMIXIN_H - - -#include "GaudiKernel/IProperty.h" -#include "GaudiKernel/INamedInterface.h" -#include "GaudiKernel/IToolSvc.h" -#include "CaloConditions/Array.h" -#include "CaloConditions/ToolConstants.h" -#include "AthenaKernel/IOVSvcDefs.h" -#include "StoreGate/DataHandle.h" - -class Blob2ToolConstants; - -namespace CaloRec { - -/** - * @class ToolWithConstantsMixin - * @brief A mixin class to hold a set of constants for an Algorithm, - * Tool, or Service. - * - * Certain tools, such as correction tools, have a large number of constants - * associated with them. One does not want to hard-code these constants; - * instead, the tools should be able to get them either from job options - * or from a pool database. - * - * The interface works just like the property service, except that instead - * of using @c declareProperty, one uses @c declareConstant. - * This may be used either for fundamental types, like floats or ints, - * or for the @c Array<N> classes. - * - * This is structured as a mixin class. To use it, derive both from - * this class (the `mixin class') and some class that derives from - * one of @c Algorithm, @c AlgTool, or @c Service (the `base class'). - * Add a call to @c finish_ctor to your class's constructor. - * You then must then define the three methods @c initialize - * and @c setProperty with the signatures given below. - * In each, you should first call the corresponding method - * from the base class, followed by the one from the mixin class - * (followed by anything needed by your class). - * - - * The constants can come from three sources: jobOptions, a POOL file - * or COOL-inline storage. The object stored in the database is the - * @c ToolConstants class defined in CaloConditions. In case of COOL - * inline storage, a method from ToolConstants2Blob.h is used to - * convert the AttributeListCollection into a ToolConstants object. - * The constants for several different correction tools may be merged - * together in a single @c ToolConstants object; each tool has a string - * prefix (unique within such a group) that is added to the constant name - * when looking it up in the @c ToolConstants object. The constants - * object itself is located in the detector store under the key - * given by the @c m_detStoreKey property. The @c ToolConstants - * instance found in StoreGate (if any) is referenced via - * @c m_DBconstants; the private @c m_constants object holds - * settings which were made via job options. - * - * Here is how things work: When @c declareConstant is called, we declare - * the name to the property service with @c declareProperty. If the - * call is for a fundamental type, we can do it directly; otherwise, - * if the call is for an @c Array<N>, we allocate a @c std::string - * as a buffer and use that as the target. - * - * After everything is declared, the job options service will - * make the actual property settings by calling the virtual - * method @c setProperty for each variable that is indeed - * by jobOptions.We override this method so that we can - * get control. When we get called, we take the value we're given - * and use it to make an entry in the @c ToolConstants object. - * Further, if the call is for an @c Array<N>, we also at this point - * initialize the original target @c Array from the @c Arrayrep. - * - * In our @c initialize method, we check if a @c ToolConstants object with - * the key @c m_detStoreKey is present in the DetectorStore. If so, we - * register a IOV-Callback function for this object that gets in general - * called on the first event. If no such object can be found, all constants - * must have been initialized by job options. We check if this is the case - * and complain if not. - * - * In the callback function, we loop through all declared constants and - * check which ones have been already initialized by the JobOptionsSvc. - * The ones that have not been initialized at this point are now initialized - * by the values loaded from the database. Thus, constants can be either - * set from job options or from the database. - * - * Possible problems and desired improvements: - * - * 1) I am not sure what happens if the first event is outside of any - * valid IOV. If the callback function is not triggered, some constants - * might be uninitialized without any warning or error message. - * - * 2) If (some of) the constants get initialized by jobOptions, no up-to-date - * @c ToolConstants objects is recorded to the DetectorStore. Some downstream - * algorithm (E.g. @c MyAnalysis) that wants to know what constants have been - * used might not get the right values. Some problems related the const-ness - * of objects loaded from the DB need to be solved. - */ -class ToolWithConstantsMixin - : virtual public IProperty, - virtual public INamedInterface -{ -public: - // Constructor. - ToolWithConstantsMixin(); - - /** - * @brief Remainder of constructor code, that needs the complete - * class to be initialized. - * @param toolcls Name of derived C++ class. - * This is used only for @c mergeConstants; further, - * it can be safely defaulted for the @c AlgTool case. - * - * This needs to be called from the derived class's constructor. - */ - void finish_ctor (const std::string& toolcls = ""); - - - /** - * @brief Destructor. - */ - virtual ~ToolWithConstantsMixin(); - - /** - * @brief Initialize method. - * @return Gaudi status code. - * - * Here, we check that all declared constants actually received values. - * - * The class using this must override @c initialize and call first - * the standard @c AlgTool::initialize followed by - * @c ToolWithConstantsMixin::initialize. - */ - virtual StatusCode initialize(); - - - /** - * @brief IOVDB callback function - * @param Macro defined in AthenaKernel/IOVSvcDefs.h - * - * This function is called when ToolConstants are loaded from pool. - * Calls fillFromDB - */ - virtual StatusCode processConstantsFromDB(IOVSVC_CALLBACK_ARGS); - - - /* @brief Set parameters coming from DB - * @param constants Pointer to the ToolConstants object loaded from DB - * - * This method - * It checks which constants have been already set by the PropertySvc, - * other constants are set by this function. - */ - virtual StatusCode fillFromDB(const ToolConstants* constants); - - /* @brief Dump method (for debugging) - * @param stream Ostream to write to - * @param name Name to go in output - */ - virtual void writeConstants(std::ostream& stream, const std::string& name) const; - - - /** - * @brief Merge our constants into @c out with the proper prefix. - * @param[out] out Object to receive our constants. - */ - virtual StatusCode mergeConstants (ToolConstants& out) const; - - /** - * @brief Declare a constant. - * @param name The name of the constant. - * @param c Variable to receive the constant value. - * @param deflt If true, then this constant may be defaulted. - * - * This should be called from a tool constructor. - * The @a c variable will be initialized either from the pool - * database or from job options, as appropriate. If the initialization - * is from job options, it won't happen until after the constructor - * returns. - * - * The @a c variable may be a fundamental numeric type, or it may - * be an instance of one of the @c Array<N> classes. - */ - template <class T> - void declareConstant (const std::string& name, - T& c, - bool deflt = false); - - - /** - * @brief Return the version number for this tool. - * - * A saved set of constants includes both the C++ class name and - * a version number. The idea is that the version number can - * be bumped whenever there's a backwards-incompatible change; - * this gives some protection against trying to use an old version - * of a tool with an incompatible newer set of constants. - * - * If you want a tool to have a version number, override this method. - * Otherwise, it will default to a version number of 0. - */ - virtual int version() const; - - - //*********************************************************************** - // The following methods are called only internally. - // - - using IProperty::setProperty; - /** - * @brief Method to set a property value. - * @param propname The name of the property to set. - * @param value The value to which to set it. - * @return Gaudi status code. - * - * The property service calls this method when it actually makes a property - * setting. We override it in order to hook our own code into the process. - * If this property corresponds to one of our declared - * constants, we install it in the @c ToolConstants structure. - * If needed, we also complete initialization of the declared - * variable here. - * - * The class using this must override this method, and call first - * @c AlgTool::setProperty - * followed by @c ToolWithConstantsMixin::setProperty. - * You may need to use a using directive to prevent warnings - * (like above, but using the other base class). - * - * This version is used by Gaudi up to at least v16. - */ - virtual StatusCode setProperty (const std::string& propname, - const std::string& value); - - /** - * @brief Method to set a property value. - * @param p The property name/value to set. - * @return Gaudi status code. - * - * The property service calls this method when it actually makes a property - * setting. We override it in order to hook our own code into the process. - * If this property corresponds to one of our declared - * constants, we install it in the @c ToolConstants structure. - * If needed, we also complete initialization of the declared - * variable here. - * - * The class using this must override this method, and call first - * @c AlgTool::setProperty - * followed by @c ToolWithConstantsMixin::setProperty. - * You may need to use a using directive to prevent warnings - * (like above, but using the other base class). - * - * This version is used by Gaudi as of v19. - */ - virtual StatusCode setProperty (const Gaudi::Details::PropertyBase& p); - - -private: - /** - * @class Propinfo_Base - * @brief Base class for registered constants. - * - * For each constant that's registered, we create an instance of a - * class deriving from @c Propinfo_Base. The derived class depends - * on the type of constant we're setting. In the base class, we record - * the constant name and a flag telling whether this constant has - * been initialized. - */ - struct Propinfo_Base - { - /** - * @brief Constructor. - * @param name The name of the constant. - * @param deflt If true, then this constant may be defaulted. - */ - Propinfo_Base (const std::string& name, bool deflt); - - /** - * @brief Destructor. - * - * Just so that this class gets a vtable. - */ - virtual ~Propinfo_Base(); - - /** - * @brief Finish up initialization of this constant. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * This is called from @c setProperty after the property manager - * has finished its work, and after we've installed the constant - * in the @c ToolConstants structure. We get the - * @c Arrayrep from the @c ToolConstants for this constant. - * - * The action needed here depends on the constant type. - * This default implementation doesn't do anything. - */ - virtual StatusCode set (const Arrayrep& rep, - ToolWithConstantsMixin& tool); - - - /** - * @brief Set a constant from the Database. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * Called explicitly by the callback function. - * - * The action needed here depends on the constant type. - * This default implementation doesn't do anything. - */ - virtual StatusCode setFromDB (const Arrayrep& rep, - ToolWithConstantsMixin& tool); - - /// The constant name. - std::string m_name; - - /// This is set to true once this constant has been initialized by jobO. - bool m_set; - - /// This is set to true once this constant has been filled from the DB - bool m_setDB; - - /// This is set of this constant has a usable default value. - /// If true, don't complain if this constant doesn't get set. - bool m_default; - - }; - - - /** - * @class Propinfo_Val - * @brief @c Propinfo class for numeric constants. - * - * This class derives from @c Propinfo_Base and serves to describe - * constants that are simple numbers. - */ - template <class T> - struct Propinfo_Val - : public Propinfo_Base - { - /** - * @brief Constructor. - * @param name The name of the constant. - * @param c Reference to the constant. - * @param deflt If true, then this constant may be defaulted. - * - * The constant gets declared to the property service. - */ - Propinfo_Val (const std::string& name, T& c, bool deflt); - - /** - * @brief Set a constant (not an Array) from the DB. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * The data-base representation of a constant is Arrayrep event if is a - * single number. We require that the array size is 1 and take the - * element [0]. It is casted from const float to the templated type T. - */ - StatusCode setFromDB(const Arrayrep& rep, - ToolWithConstantsMixin& tool); - - /** - * @brief Finish up initialization of this constant. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * This is called from @c setProperty after the property manager - * has finished its work, and after we've installed the constant - * in the @c ToolConstants structure. We get the - * @c Arrayrep from the @c ToolConstants for this constant. - * - * For a simple number, the target will have already been filled - * in by Gaudi. However, it turns out that the floating-point - * parsing done by Gaudi isn't exactly equivalent to that done - * by C++. The Array parsing machinery uses the C++ iostream - * mechanism to do the conversion, and will convert the string - * `1.525' to the float 1.52499998. Gaudi, however, uses - * the Spirit parser, which will convert the same string - * to the float 1.5250001. So, reset the target here - * for consistency. - */ - virtual StatusCode set (const Arrayrep& rep, - ToolWithConstantsMixin& tool); - - /// Reference to the constant. - T& m_c; - }; - - - /** - * @class Propinfo_Array<N> - * @brief @c Propinfo class for multidimensional arrays. - * - * This class derives from @c Propinfo_Base and serves to describe - * constants that are instances of @c Array<N>. - */ - template <unsigned int N> - struct Propinfo_Array - : public Propinfo_Base - { - /** - * @brief Constructor. - * @param name The name of the constant. - * @param c Reference to the constant. - * @param deflt If true, then this constant may be defaulted. - */ - Propinfo_Array (const std::string& name, Array<N>& c, bool deflt); - - /** - * @brief Finish up initialization of this constant. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * This is called from @c setProperty after the property manager - * has finished its work, and after we've installed the constant - * in the @c ToolConstants structure. We get the - * @c Arrayrep from the @c ToolConstants for this constant. - * - * For an @c Array<N>, we need to initialize the actual @c Array<N> - * instance from the @c Arrayrep we've gotten from the - * @c ToolConstants structure. - */ - virtual StatusCode set (const Arrayrep& rep, - ToolWithConstantsMixin& tool); - - - /** - * @brief Setting an Array-constant from the DB. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * Simply forwards to the normal set function - */ - virtual StatusCode setFromDB (const Arrayrep& rep, - ToolWithConstantsMixin& tool); - - /// Reference to the constant. - Array<N>& m_c; - - /// String buffer that we use in the declaration to the property service. - std::string m_buf; - }; - - - /** - * @brief Add a new constant to our store. - * @param pi The @c Propinfo instance describing this constant. - */ - void add_constant (Propinfo_Base* pi); - - - /** - * @brief Construct a new @c Propinfo_* instance for @a c. - * @param name The name of the constant being declared. - * @param c The constant being declared. - * @param deflt If true, then this constant may be defaulted. - * @return A new instance of a class deriving from @c Propinfo_Base. - * - * This family of overloaded functions creates a new instance - * of a class deriving from @c Propinfo_Base that is appropriate - * for the type of the constant @c. - * - * This one makes a @c Propinfo_Val<T> instance, - * appropriate for numeric types, and declares it to the property service. - */ - template <class T> - Propinfo_Base* makeinfo (const std::string& name, T& c, bool deflt); - - - /** - * @brief Construct a new @c Propinfo_* instance for @a c. - * @param name The name of the constant being declared. - * @param c The constant being declared. - * @param deflt If true, then this constant may be defaulted. - * @return A new instance of a class deriving from @c Propinfo_Base. - * - * This family of overloaded functions creates a new instance - * of a class deriving from @c Propinfo_Base that is appropriate - * for the type of the constant @c. - * - * This one makes a @c Propinfo_Array<N> instance, - * appropriate for multidimensional array types, and declares - * it to the property service. - */ - template <unsigned int N> - Propinfo_Base* makeinfo (const std::string& name, Array<N>& c, bool deflt); - - - /// Information about declared constants. - std::vector<Propinfo_Base*> m_infos; - - /// Contains a copy of all declared constants. - ToolConstants m_constants; - - /// Point to object loaded from Database: - const DataHandle<ToolConstants> m_DBconstants; - - /// Point to AttributeListCollection for COOL inline storage (alternativ to m_DBconstants) - //const DataHandle<CondAttrListCollection> m_COOLconstants; - - /// The COOL folder in case of COOL inline storage of the constants - std::string m_folderName; - - /// Detector Store Service: - StoreGateSvc* m_detStore; - - -protected: - /// StoreGate key for conditions object. - /// If empty, then we don't try to read from the database. - std::string m_detStoreKey; - - /// Prefix for finding our constants within the ToolConstants - /// object we retrieve from SG. - std::string m_prefix; - - /// Flag that we want to set up the callback for the constants. - /// This should be on for reading from cool, and off for reading - /// from pool. - // (Why should it be off for pool? If it's on, then IOVSvc will try - // to call CondProxyProvider::updateAddress on our proxy, and this - // will fail [just returns FAILURE]. This will then cause IOVSvc - // to give up on making any callbacks, which can break other tools.) - bool m_use_callback; - - /// Name of the tool/algorithm/service. - std::string m_toolcls; - - /// Used to fix the ordering of tools when we're initializing from COOL - /// based on a hierarchical tag. Tools should be executed in order - /// of increasing m_order. - int m_order; - - /// If true, then this is a dummy tool that should not be executed. - /// This is used for the case of reading from COOL using hierarchical - /// tags: we need to have such tags associated with some object in - /// each folder, regardless of whether or not the correction from - /// that folder is actually used. - /// [Every folder that IOVDbSvc knows about at configuration time - /// needs to have a valid object for the configured tag, else IOVDbSvc - /// will raise a fatal error. But we don't know at configuration time - /// which folders we're actually going to need, so we gotta configure - /// all of them.] - bool m_isdummy; - - /// Public AlgTool to convert COOL inline data into ToolConstants objects - Blob2ToolConstants* m_coolInlineTool; - - ///Pointer to ToolSvc - IToolSvc* m_toolSvc; - -}; - - -} // namespace CaloRec - - -#include "CaloRec/ToolWithConstantsMixin.icc" - - -#endif // not TOOLWITHCONSTANTS_H - diff --git a/Calorimeter/CaloRec/CaloRec/ToolWithConstantsMixin.icc b/Calorimeter/CaloRec/CaloRec/ToolWithConstantsMixin.icc deleted file mode 100644 index febb8cf4745359ceaeb403aa44bde56a045d75f7..0000000000000000000000000000000000000000 --- a/Calorimeter/CaloRec/CaloRec/ToolWithConstantsMixin.icc +++ /dev/null @@ -1,296 +0,0 @@ -// This file's extension implies that it's C, but it's really -*- C++ -*-. - -/* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file ToolWithConstantsMixin.icc - * @author scott snyder <snyder@bnl.gov> - * @date March, 2006, updated from June, 2004 - * @brief A mixin class to hold a set of constants for an Algorithm, - * Tool, or Service. - */ - - -#include "AthenaKernel/errorcheck.h" -#include "GaudiKernel/AlgTool.h" -#include "GaudiKernel/Algorithm.h" -#include "GaudiKernel/Service.h" - - -namespace CaloRec { - - -namespace TWC { // For internal free functions. - - -/** - * @brief Declare a property to the job options service. - * @param self The object on which the property is to be defined. - * @param name The property name. - * @param c The property value. - * - * @c self must be dynamically convertible to an @c Algorithm, - * @c AlgTool, or @c Service. - */ -template <class T> -StatusCode do_declare (ToolWithConstantsMixin* self, - const std::string& name, - T& c) -{ - if (AlgTool* x = dynamic_cast<AlgTool*> (self)) { - x->declareProperty (name, c); - return StatusCode::SUCCESS; - } else if (Gaudi::Algorithm* x = dynamic_cast<Gaudi::Algorithm*> (self)) { - x->declareProperty (name, c); - return StatusCode::SUCCESS; - } else if (Service* x = dynamic_cast<Service*> (self)) { - x->declareProperty (name, c); - return StatusCode::SUCCESS; - } else { - REPORT_ERROR_WITH_CONTEXT(StatusCode::FAILURE, self->name()) - << "Not an Algorithm, AlgTool, or Service."; - return StatusCode::FAILURE; - } -} - - -} // namespace TWC - - -/** - * @brief Declare a constant. - * @param name The name of the constant. - * @param c Variable to receive the constant value. - * @param deflt If true, then this constant may be defaulted. - * - * This should be called from a tool constructor. - * The @a c variable will be initialized either from the pool - * database or from job options, as appropriate. If the initialization - * is from job options, it won't happen until after the constructor - * returns. - * - * The @a c variable may be a fundamental numeric type, or it may - * be an instance of one of the @c Array<N> classes. - */ -template <class T> -void -ToolWithConstantsMixin::declareConstant (const std::string& name, - T& c, - bool deflt /*= false*/) -{ - c = T(); - add_constant (makeinfo (name, c, deflt)); -} - - -/** - * @brief Constructor. - * @param name The name of the constant. - * @param c Reference to the constant. - * @param deflt If true, then this constant may be defaulted. - */ -template <class T> -ToolWithConstantsMixin::Propinfo_Val<T>::Propinfo_Val (const std::string& name, - T& c, - bool deflt) - : Propinfo_Base (name, deflt), m_c(c) -{ -} - -/** - * @brief Setting a constant (not an Array) from the DB. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * The database representation of a constant is Arrayrep event if is a - * single number. We require that the array size is 1 and take the - * element [0]. It is cast from const float to the templated type T. - */ -template <class T> -StatusCode -ToolWithConstantsMixin::Propinfo_Val<T>::setFromDB (const Arrayrep& rep, - ToolWithConstantsMixin& tool) -{ - // Check that the dimensions match. - if (rep.m_data.size()!=1) - REPORT_ERROR_WITH_CONTEXT (StatusCode::FAILURE, tool.name()) - << "Attempt to initialize a number by an array"; - else { - // Make the assignment. - // The element in the array is a float (typedef'd) - // but T might be any numeric value (e.g. int) - m_c = static_cast<T>(rep.m_data[0]); - } - return StatusCode::SUCCESS; -} - - -/** - * @brief Finish up initialization of this constant. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * This is called from @c setProperty after the property manager - * has finished its work, and after we've installed the constant - * in the @c ToolConstants structure. We get the - * @c Arrayrep from the @c ToolConstants for this constant. - * - * For a simple number, the target will have already been filled - * in by Gaudi. However, it turns out that the floating-point - * parsing done by Gaudi isn't exactly equivalent to that done - * by C++. The Array parsing machinery uses the C++ iostream - * mechanism to do the conversion, and will convert the string - * `1.525' to the float 1.52499998. Gaudi, however, uses - * the Spirit parser, which will convert the same string - * to the float 1.5250001. So, reset the target here - * for consistency. - */ -template <class T> -StatusCode -ToolWithConstantsMixin::Propinfo_Val<T>::set (const Arrayrep& rep, - ToolWithConstantsMixin& /*tool*/) -{ - CxxUtils::Array<0> arr (rep); - m_c = arr; - return StatusCode::SUCCESS; -} - - -/** - * @brief Constructor. - * @param name The name of the constant. - * @param c Reference to the constant. - * @param deflt If true, then this constant may be defaulted. - */ -template <unsigned int N> -ToolWithConstantsMixin::Propinfo_Array<N>::Propinfo_Array ( - const std::string& name, - Array<N>& c, - bool deflt) - : Propinfo_Base (name, deflt), m_c (c) -{ -} - - -/** - * @brief Finish up initialization of this constant. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * This is called from @c setProperty after the property manager - * has finished its work, and after we've installed the constant - * in the @c ToolConstants structure. We get the - * @c Arrayrep from the @c ToolConstants for this constant. - * - * For an @c Array<N>, we need to initialize the actual @c Array<N> - * instance from the @c Arrayrep we've gotten from the - * @c ToolConstants structure. - */ -template <unsigned int N> -StatusCode -ToolWithConstantsMixin::Propinfo_Array<N>::set (const Arrayrep& rep, - ToolWithConstantsMixin& tool) -{ - // Check that the dimensions match. - if (rep.m_shape.size() != N) { - REPORT_ERROR_WITH_CONTEXT (StatusCode::FAILURE, tool.name()) - << "Dimensionality from job options (" << rep.m_shape.size() - << ") doesn't match declared dimensionality (" << N - << ") for constant " << m_name; - return StatusCode::FAILURE; - } - - // Make the assignment. - m_c = CaloRec::Array<N> (rep); - return StatusCode::SUCCESS; -} - - -/** - * @brief Setting an Array-constant from the DB. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * For arrays, we can simply call the normal set function - */ -template <unsigned int N> -StatusCode -ToolWithConstantsMixin::Propinfo_Array<N>::setFromDB (const Arrayrep& rep, - ToolWithConstantsMixin& tool) -{ - return set(rep, tool); -} - - -/** - * @brief Construct a new @c Propinfo_* instance for @a c. - * @param name The name of the constant being declared. - * @param c The constant being declared. - * @param deflt If true, then this constant may be defaulted. - * @return A new instance of a class deriving from @c Propinfo_Base. - * - * This family of overloaded functions creates a new instance - * of a class deriving from @c Propinfo_Base that is appropriate - * for the type of the constant @c. - * - * This one makes a @c Propinfo_Val<T> instance, - * appropriate for numeric types, and declares it to the property service. - */ -template <class T> -ToolWithConstantsMixin::Propinfo_Base* -ToolWithConstantsMixin::makeinfo (const std::string& name, T& c, bool deflt) -{ - Propinfo_Val<T>* pi = new Propinfo_Val<T> (name, c, deflt); - StatusCode sc = TWC::do_declare (this, name, c); - if (sc.isFailure()) { - REPORT_ERROR (sc) << "Error from property service when declaring " << name; - delete pi; - return 0; - } - return pi; -} - - -/** - * @brief Construct a new @c Propinfo_* instance for @a c. - * @param name The name of the constant being declared. - * @param c The constant being declared. - * @param deflt If true, then this constant may be defaulted. - * @return A new instance of a class deriving from @c Propinfo_Base. - * - * This family of overloaded functions creates a new instance - * of a class deriving from @c Propinfo_Base that is appropriate - * for the type of the constant @c. - * - * This one makes a @c Propinfo_Array<N> instance, - * appropriate for multidimensional array types, and declares - * it to the property service. - */ -template <unsigned int N> -ToolWithConstantsMixin::Propinfo_Base* -ToolWithConstantsMixin::makeinfo (const std::string& name, - Array<N>& c, - bool deflt) -{ - Propinfo_Array<N>* pi = new Propinfo_Array<N> (name, c, deflt); - - // The property service doesn't know about @c Array<N>, so we can't - // declare it directly. Instead, we give it a string buffer; we'll - // do the conversion later. - StatusCode sc = TWC::do_declare (this, name, pi->m_buf); - if (sc.isFailure()) { - REPORT_ERROR (sc) << "Error from property service when declaring " << name; - delete pi; - return 0; - } - - // We can get rid of the property string at this point. - // These can potentially be very large! - pi->m_buf.clear(); - return pi; -} - - -} // namespace CaloRec diff --git a/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.cxx b/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.cxx index 1ea957fb5ec0bfd4ab2ff815f275c9dc198a72c3..a527c2d1a30b71128d367314ee77771e3a8e1a43 100644 --- a/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.cxx +++ b/Calorimeter/CaloRec/src/CaloClusterCorrDBWriter.cxx @@ -11,7 +11,6 @@ #include "CaloClusterCorrDBWriter.h" #include "GaudiKernel/ThreadLocalContext.h" -#include "CaloRec/ToolWithConstantsMixin.h" #include "CaloConditions/ToolConstants.h" #include "AthenaKernel/errorcheck.h" diff --git a/Calorimeter/CaloRec/src/ToolWithConstantsMixin.cxx b/Calorimeter/CaloRec/src/ToolWithConstantsMixin.cxx deleted file mode 100755 index 164516aa328f3a89dfd0fe85b404f2bf6b4ee4c2..0000000000000000000000000000000000000000 --- a/Calorimeter/CaloRec/src/ToolWithConstantsMixin.cxx +++ /dev/null @@ -1,540 +0,0 @@ -// This file's extension implies that it's C, but it's really -*- C++ -*-. - -/* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration -*/ - -/** - * @file ToolWithConstantsMixin.cxx - * @author scott snyder <snyder@bnl.gov> - * @date March, 2006, updated from June, 2004 - * @brief A mixin class to hold a set of constants for an Algorithm, - * Tool, or Service. - */ - - -#include "CaloRec/ToolWithConstantsMixin.h" -#include "AthenaKernel/errorcheck.h" -#include "GaudiKernel/Bootstrap.h" -#include "GaudiKernel/IService.h" -#include "GaudiKernel/ISvcLocator.h" -#include "GaudiKernel/AlgTool.h" -#include "GaudiKernel/Algorithm.h" -#include "GaudiKernel/Service.h" -#include "AthenaKernel/getMessageSvc.h" - -#include "CoralBase/AttributeListException.h" -#include "CoralBase/Blob.h" -//#include "CoolKernel/StorageType.h" - -#include "CaloRec/Blob2ToolConstants.h" -#include <stdexcept> - - -namespace CaloRec { - - -/** - * @brief Constructor. - * - * The only reason we need this is that SG stupidly requires that the - * DataHandle be const. - */ -ToolWithConstantsMixin::ToolWithConstantsMixin() - : m_detStore(nullptr), - m_use_callback(true), - m_order(0), - m_isdummy(false), - m_coolInlineTool (nullptr), - m_toolSvc (nullptr) -{ -} - - -/** - * @brief Remainder of constructor code, that needs the complete - * class to be initialized. - * @param toolcls Name of derived C++ class. - * This is used only for @c mergeConstants; further, - * it can be safely defaulted for the @c AlgTool case. - * - * This needs to be called from the derived class's constructor. - */ -void -ToolWithConstantsMixin::finish_ctor (const std::string& toolcls /*= ""*/) -{ - m_use_callback = true; - m_toolcls = toolcls; - - if (AlgTool* thistool = dynamic_cast<AlgTool*> (this)) { - thistool->declareProperty ("detStoreKey", m_detStoreKey); - thistool->declareProperty ("prefix", m_prefix); - thistool->declareProperty ("useCallback", m_use_callback); - thistool->declareProperty ("COOLFolder", m_folderName); - if (m_toolcls.empty()) - m_toolcls = thistool->type(); - } - else if (Gaudi::Algorithm* thisalg = dynamic_cast<Gaudi::Algorithm*> (this)) { - thisalg->declareProperty ("detStoreKey", m_detStoreKey); - thisalg->declareProperty ("prefix", m_prefix); - thisalg->declareProperty ("useCallback", m_use_callback); - thisalg->declareProperty ("COOLFolder", m_folderName); - } - else if (Service* thissvc = dynamic_cast<Service*> (this)) { - thissvc->declareProperty ("detStoreKey", m_detStoreKey); - thissvc->declareProperty ("prefix", m_prefix); - thissvc->declareProperty ("useCallback", m_use_callback); - thissvc->declareProperty ("COOLFolder", m_folderName); - } - else - std::abort(); - - declareConstant ("order", m_order = 0, true); - declareConstant ("isDummy", m_isdummy = false, true); -} - - -/** - * @brief Destructor. - */ -ToolWithConstantsMixin::~ToolWithConstantsMixin() -{ - // Delete the Propinfo_* structures that we've allocated. - for (unsigned int i=0; i < m_infos.size(); i++) - delete m_infos[i]; -} - - -/** - * @brief Initialize method. - * - * Here, we check that all declared constants actually received values. - * - * The class using this must override @c initialize and call first - * the standard @c AlgTool::initialize followed by - * @c ToolWithConstantsMixin::initialize. - */ -StatusCode ToolWithConstantsMixin::initialize() -{ - ISvcLocator* svcLoc = Gaudi::svcLocator( ); - if (!svcLoc) { - REPORT_MESSAGE(MSG::ERROR) << "Could not get svcLocator!"; - return StatusCode::FAILURE; - } - - CHECK(svcLoc->service("ToolSvc",m_toolSvc)); - CHECK(svcLoc->service("DetectorStore", m_detStore)); - - REPORT_MESSAGE(MSG::DEBUG) << "Source of constants: DetStoreKey: '" << m_detStoreKey << "' FolderName: '" << m_folderName << "'"; - - // The SG key should be set via job options. - // Don't try to read from pool if there isn't one set. - StatusCode sc = StatusCode::SUCCESS; - - - if (!m_detStoreKey.empty() && !m_folderName.empty() && m_detStore->contains<CondAttrListCollection>(m_folderName)) { - //First case: Read constants from COOL inline - REPORT_MESSAGE(MSG::DEBUG) << "Reading constants from COOL-inline storage. Folder " << m_folderName - << " channel " << m_detStoreKey; - - // ...register callback. - if (m_use_callback) { - CHECK(m_toolSvc->retrieveTool("Blob2ToolConstants",m_coolInlineTool)); - CHECK(m_coolInlineTool->addFolder(m_folderName,m_detStoreKey)); - CHECK(m_detStore->regFcn(&Blob2ToolConstants::fillObjects, - m_coolInlineTool, - &CaloRec::ToolWithConstantsMixin::processConstantsFromDB, - dynamic_cast<CaloRec::ToolWithConstantsMixin*>(this), - true)); - } - else { - CHECK (m_detStore->bind (m_DBconstants,m_detStoreKey)); - int i=0; - std::list<std::string> l; - CHECK(processConstantsFromDB (i, l) ); - } - } - else if (!m_detStoreKey.empty() && m_detStore->contains<ToolConstants>(m_detStoreKey)) { - REPORT_MESSAGE(MSG::DEBUG) << "Reading constants from POOL storage. SG Key " << m_detStoreKey; - //Second case: Read from POOL (relayed via COOL or CondProxyProviderSvc) - // ...register callback. - if (m_use_callback) { - CHECK(m_detStore->regFcn( - &CaloRec::ToolWithConstantsMixin::processConstantsFromDB, - dynamic_cast<CaloRec::ToolWithConstantsMixin*>(this), - m_DBconstants,m_detStoreKey)); - } - else { - CHECK (m_detStore->bind (m_DBconstants, m_detStoreKey)); - int i=0; - std::list<std::string> l; - CHECK( processConstantsFromDB (i, l) ); - } - } - else { - REPORT_MESSAGE(MSG::INFO) << "No database info found. Loading all from jobOpts"; - // Check to be sure that all constants have been initialized. - if (!m_isdummy) { - for (unsigned int i=0; i < m_infos.size(); i++) { - if (!m_infos[i]->m_set && !m_infos[i]->m_default) { - REPORT_ERROR(StatusCode::FAILURE) - << "Constant named " << m_infos[i]->m_name - << " did not get initialized. "; - sc = StatusCode::FAILURE; - } - } - if (sc.isFailure()) - REPORT_ERROR(StatusCode::FAILURE) - << "One or more constants were not set by jobO " - << "and could not be loaded from the DetStore!"; - } - } - return sc; -} - - -/** - * @brief IOVDB callback function - * @param Macro defined in AthenaKernel/IOVSvcDefs.h - * - * This function is called when ToolConstants are loaded from pool. - * It checks which constants have been already set by the PropertySvc, - * other constants are set by this function. - */ -StatusCode -ToolWithConstantsMixin::processConstantsFromDB (IOVSVC_CALLBACK_ARGS_K(keys)) -{ - MsgStream log(Athena::getMessageSvc(), name()); - log << MSG::DEBUG - << "In Callback function ToolWithConstants::processConstantsFromDB" - << endmsg; - - if (!m_folderName.empty()) { - //COOL-inline case - if (std::find(keys.begin(),keys.end(),m_folderName)==keys.end()) { - log << MSG::DEBUG - << "The cool folder we care about (" << m_folderName<< ") is not in the list of keys. Do nothing." << endmsg; - return StatusCode::SUCCESS; - } - else - log << MSG::DEBUG - << "Found cool folder " << m_folderName << " in the list of keys." << endmsg; - } - - // Check validity - //if (!m_DBconstants.isValid()) { - if (m_detStore->retrieve(m_DBconstants, m_detStoreKey).isFailure()) { - log << MSG::ERROR << "DataHandle of ToolConstants object invalid!" - << endmsg; - return StatusCode::FAILURE; - } - - return fillFromDB(m_DBconstants); -} - -StatusCode -ToolWithConstantsMixin::fillFromDB(const ToolConstants* constants) { - MsgStream log(Athena::getMessageSvc(), name()); - // Check what's already set and what's missing - for (unsigned int i=0;i<m_infos.size();i++) { - if (m_infos[i]->m_set) { - log << MSG::DEBUG << "Property '" << m_infos[i]->m_name - << "' set by jobOptions." << endmsg; - } - else if (constants->hasrep (m_prefix + m_infos[i]->m_name)) { - try { - const Arrayrep& rep = - constants->getrep(name(), //context (tool name) - m_prefix + m_infos[i]->m_name); // Prop name - - // remember that this constant is set. - m_infos[i]->m_setDB = true; - CHECK(m_infos[i]->setFromDB(rep, *this)); - - if (m_infos[i]->m_setDB) - log << MSG::DEBUG << "Property '" << m_infos[i]->m_name - << "' updated from database." << endmsg; - else - log << MSG::DEBUG << "Property '" << m_infos[i]->m_name - << "' loaded from database."<< endmsg; - } - catch (GaudiException& e) - { - } - } // end else - } // end for - - // Now check if all constants were set (either be jobO or DB) - StatusCode sc = StatusCode::SUCCESS; - if (!m_isdummy) { - for (unsigned int i=0; i < m_infos.size(); i++) { - if (!m_infos[i]->m_set && !m_infos[i]->m_setDB && !m_infos[i]->m_default) - { - REPORT_ERROR(StatusCode::FAILURE) - << "Constant named " << m_infos[i]->m_name - << " did not get initialized from jobOptions " - << "and could not be loaded from DB."; - sc = StatusCode::FAILURE; - } - } - - // Check version. - if (constants->version() > version()) { - REPORT_ERROR(StatusCode::FAILURE) - << "Constants for tool " << name() << " require code version " - << m_DBconstants->version() << " but only version " - << version() << " is available."; - sc = StatusCode::FAILURE; - } - } - - return sc; -} - - -/** - * @brief Method to set a property value. - * @param propname The name of the property to set. - * @param value The value to which to set it. - * @return Gaudi status code. - * - * The property service calls this method when it actually makes a property - * setting. We override it in order to hook our own code into the process. - * If this property corresponds to one of our declared - * constants, we install it in the @c ToolConstants structure. - * If needed, we also complete initialization of the declared - * variable here. - * - * The class using this must override this method, and call first - * @c AlgTool::setProperty - * followed by @c ToolWithConstantsMixin::setProperty. - * You may need to use a using directive to prevent warnings - * (like above, but using the other base class). - * - * This version is used by Gaudi up to at least v16. - */ -StatusCode -ToolWithConstantsMixin::setProperty (const std::string& propname, - const std::string& value) -{ - // Don't do anything if this was defaulted. - // We'll either read it from pool later or give an error. - if (value.empty() || value == "\"\"") - return StatusCode::SUCCESS; - - // Loop through the declared constants, and see if there's one that - // matches the input name. It's ok if there's no match. - for (unsigned int i=0; i < m_infos.size(); i++) { - if (m_infos[i]->m_name == propname) { - // Found a match. Remember that we've seen this. - m_infos[i]->m_set = true; - - // Install this name in the @c ToolConstants structure. - try { - const Arrayrep& rep = m_constants.newrep (name(), - propname, - value); - - // Complete any other (type-dependent) needed initialization. - CHECK( m_infos[i]->set (rep, *this) ); - } - catch (const std::runtime_error& e) { - REPORT_MESSAGE (MSG::ERROR) << "Error reading from job options: " - << e.what(); - return StatusCode::FAILURE; - } - - break; - } - } - - // Done. - return StatusCode::SUCCESS; -} - - -/** - * @brief Method to set a property value. - * @param p The property name/value to set. - * @return Gaudi status code. - * - * The property service calls this method when it actually makes a property - * setting. We override it in order to hook our own code into the process. - * If this property corresponds to one of our declared - * constants, we install it in the @c ToolConstants structure. - * If needed, we also complete initialization of the declared - * variable here. - * - * The class using this must override this method, and call first - * @c AlgTool::setProperty - * followed by @c ToolWithConstantsMixin::setProperty. - * You may need to use a using directive to prevent warnings - * (like above, but using the other base class). - * - * This version is used by Gaudi as of v19. - */ -StatusCode -ToolWithConstantsMixin::setProperty (const Gaudi::Details::PropertyBase& p) -{ - return CaloRec::ToolWithConstantsMixin::setProperty (p.name(), p.toString()); -} - - - -/** - * @brief Add a new constant to our store. - * @param pi The @c Propinfo instance describing this constant. - */ -void ToolWithConstantsMixin::add_constant (Propinfo_Base* pi) -{ - if (!pi) - return; - - // Make sure that a name isn't duplicated. - for (unsigned int i=0; i < m_infos.size(); i++) - if (m_infos[i]->m_name == pi->m_name) { - REPORT_ERROR(StatusCode::FAILURE) - << "Duplicate constant: " << pi->m_name; - delete pi; - return; - } - - // Record this declaration in @c m_infos. - // @c makeinfo is one of an overloaded family of functions that - // creates the @c Propinfo_* structure for the type of @a c. - m_infos.push_back (pi); -} - - -/** - * @brief Constructor. - * @param name The name of the constant. - */ -ToolWithConstantsMixin::Propinfo_Base::Propinfo_Base (const std::string& name, - bool deflt) - : m_name (name), - m_set (false), - m_setDB (false), - m_default (deflt) -{ -} - - -/** - * @brief Destructor. - * - * Just so that this class gets a vtable. - */ -ToolWithConstantsMixin::Propinfo_Base::~Propinfo_Base () -{ -} - - -/** - * @brief Finish up initialization of this constant. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * This is called from @c setProperty after the property manager - * has finished its work, and after we've installed the constant - * in the @c ToolConstants structure. We get the - * @c Arrayrep from the @c ToolConstants for this constant. - * - * The action needed here depends on the constant type. - * This default implementation doesn't do anything. - */ -StatusCode -ToolWithConstantsMixin::Propinfo_Base::set (const Arrayrep& /*rep*/, - ToolWithConstantsMixin& /*tool*/) -{ - return StatusCode::SUCCESS; -} - - -/** - * @brief Set a constant from the Database. - * @param rep The @c Arrayrep for this constant. - * @param tool The @c ToolWithConstants instance, for error reporting. - * - * Called explicitly by the callback function. - * - * The action needed here depends on the constant type. - * This default implementation doesn't do anything. - */ -StatusCode -ToolWithConstantsMixin::Propinfo_Base::setFromDB (const Arrayrep& /*rep*/, - ToolWithConstantsMixin& /*tool*/) -{ - return StatusCode::SUCCESS; -} - - -/** - * @brief Merge our constants into @c out with the proper prefix. - * @param[out] out Object to receive our constants. - */ -StatusCode -ToolWithConstantsMixin::mergeConstants (ToolConstants& out) const -{ - if (out.clsname().empty()) { - out.clsname (m_toolcls); - out.version (version()); - } - else if (out.clsname() != m_toolcls) { - REPORT_ERROR(StatusCode::FAILURE) - << "Trying to write to ToolConstants for tools of differing types: " - << out.clsname() << " and " << m_toolcls; - return StatusCode::FAILURE; - } - else if (out.version() != version()) { - REPORT_ERROR(StatusCode::FAILURE) - << "Trying to write to ToolConstants for differing versions of tool " - << out.clsname() << ": " << out.version() << " and " << version(); - return StatusCode::FAILURE; - } - - for (unsigned int i=0; i < m_infos.size(); i++) { - // Decide which source block to use. - const ToolConstants& source = (m_infos[i]->m_setDB ? - *m_DBconstants : - m_constants); - if (!m_isdummy || m_infos[i]->m_name == "isDummy") - out.setrep (m_prefix + m_infos[i]->m_name, - source.getrep (name(), m_infos[i]->m_name)); - } - return StatusCode::SUCCESS; -} - - -/** - * @brief Return the version number for this tool. - * - * A saved set of constants includes both the C++ class name and - * a version number. The idea is that the version number can - * be bumped whenever there's a backwards-incompatible change; - * this gives some protection against trying to use an old version - * of a tool with an incompatible newer set of constants. - * - * If you want a tool to have a version number, override this method. - * Otherwise, it will default to a version number of 0. - */ -int ToolWithConstantsMixin::version() const -{ - return 0; -} - - -void ToolWithConstantsMixin::writeConstants(std::ostream& stream, const std::string& name) const { - stream << "Member: m_constants" << std::endl; - m_constants.writeConstants(stream,name); - if (m_DBconstants) { - stream << "Member: m_DBconstants" << std::endl; - m_DBconstants->writeConstants(stream,name); - } - //stream << "Member m_COOLconstants" << std::endl; - //m_COOLconstants->writeConstants(stream,name); - return; -} - -} // namespace CaloRec -