Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:32

0001 #ifndef PhysicsTools_Utilities_Variables_h
0002 #define PhysicsTools_Utilities_Variables_h
0003 #include "PhysicsTools/Utilities/interface/ParametricTrait.h"
0004 #include <iostream>
0005 
0006 #define DEFINE_VARIABLE_T(T, X, NAME)                                                                         \
0007   namespace funct {                                                                                           \
0008     struct X {                                                                                                \
0009       typedef T type;                                                                                         \
0010       X() {}                                                                                                  \
0011       X(const T& x) { set(x); }                                                                               \
0012       inline operator T() const { return value; }                                                             \
0013       inline T operator()() const { return value; }                                                           \
0014       inline static const char* name() {                                                                      \
0015         static const char* name = NAME;                                                                       \
0016         return name;                                                                                          \
0017       }                                                                                                       \
0018       inline X operator=(const T& x) {                                                                        \
0019         set(x);                                                                                               \
0020         return *this;                                                                                         \
0021       }                                                                                                       \
0022       inline static void set(const T& x) { value = x; }                                                       \
0023                                                                                                               \
0024     private:                                                                                                  \
0025       static T value;                                                                                         \
0026     };                                                                                                        \
0027                                                                                                               \
0028     NON_PARAMETRIC(X);                                                                                        \
0029                                                                                                               \
0030     inline std::ostream& operator<<(std::ostream& cout, const funct::X&) { return cout << funct::X::name(); } \
0031   }                                                                                                           \
0032                                                                                                               \
0033   struct __useless_ignoreme
0034 
0035 #define IMPLEMENT_VARIABLE_T(T, X) \
0036   namespace funct {                \
0037     T X::value;                    \
0038   }                                \
0039                                    \
0040   struct __useless_ignoreme
0041 
0042 #define DEFINE_VARIABLE(X, NAME) DEFINE_VARIABLE_T(double, X, NAME)
0043 
0044 #define IMPLEMENT_VARIABLE(X) IMPLEMENT_VARIABLE_T(double, X)
0045 
0046 #define DEFINE_INT_VARIABLE(X, NAME) DEFINE_VARIABLE_T(int, X, NAME)
0047 
0048 #define IMPLEMENT_INT_VARIABLE(X) IMPLEMENT_VARIABLE_T(int, X)
0049 
0050 DEFINE_VARIABLE(DefaultVariable, "_");
0051 DEFINE_VARIABLE(X, "x");
0052 DEFINE_VARIABLE(Y, "y");
0053 DEFINE_VARIABLE(Z, "z");
0054 
0055 #endif