Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:22

0001 #ifndef NPSTAT_STORABLEMULTIVARIATEFUNCTOR_HH_
0002 #define NPSTAT_STORABLEMULTIVARIATEFUNCTOR_HH_
0003 
0004 /*!
0005 // \file StorableMultivariateFunctor.h
0006 //
0007 // \brief Interface definition for storable multivariate functors
0008 //
0009 // Author: I. Volobouev
0010 //
0011 // July 2012
0012 */
0013 
0014 #include <string>
0015 #include <iostream>
0016 #include <typeinfo>
0017 
0018 #include "Alignment/Geners/interface/ClassId.hh"
0019 #include "JetMETCorrections/InterpolationTables/interface/AbsMultivariateFunctor.h"
0020 
0021 namespace npstat {
0022   /** Base class for storable multivariate functors */
0023   class StorableMultivariateFunctor : public AbsMultivariateFunctor {
0024   public:
0025     inline StorableMultivariateFunctor() {}
0026 
0027     /** Functor description can be an arbitrary string */
0028     inline explicit StorableMultivariateFunctor(const std::string& descr)
0029         : AbsMultivariateFunctor(), description_(descr) {}
0030 
0031     inline ~StorableMultivariateFunctor() override {}
0032 
0033     /** Retrieve the functor description */
0034     inline const std::string& description() const { return description_; }
0035 
0036     /** Change the functor description */
0037     inline void setDescription(const std::string& newDescription) { description_ = newDescription; }
0038 
0039     /**
0040         // This method will throw npstat::NpstatRuntimeError in case
0041         // functor description is different from the provided argument
0042         */
0043     void validateDescription(const std::string& description) const;
0044 
0045     //@{
0046     /**
0047         // Do not override comparison operators in the derived classes,
0048         // override the method "isEqual" instead.
0049         */
0050     inline bool operator==(const StorableMultivariateFunctor& r) const {
0051       return (typeid(*this) == typeid(r)) && this->isEqual(r);
0052     }
0053     inline bool operator!=(const StorableMultivariateFunctor& r) const { return !(*this == r); }
0054     //@}
0055 
0056     //@{
0057     /** Method related to "geners" I/O */
0058     virtual gs::ClassId classId() const = 0;
0059     virtual bool write(std::ostream& of) const = 0;
0060     //@}
0061 
0062     // I/O methods needed for reading
0063     static inline const char* classname() { return "npstat::StorableMultivariateFunctor"; }
0064     static inline unsigned version() { return 1; }
0065     static StorableMultivariateFunctor* read(const gs::ClassId& id, std::istream& in);
0066 
0067   protected:
0068     /**
0069         // Method needed to compare objects for equality.
0070         // Must be overriden by derived classes. It is left
0071         // up to the derived classes to decide whether they
0072         // should compare description strings in order to
0073         // establish equality.
0074         */
0075     virtual bool isEqual(const StorableMultivariateFunctor&) const = 0;
0076 
0077   private:
0078     std::string description_;
0079   };
0080 }  // namespace npstat
0081 
0082 #endif  // NPSTAT_STORABLEMULTIVARIATEFUNCTOR_HH_