CMS 3D CMS Logo

UserData.h
Go to the documentation of this file.
1 #ifndef DataFormats_PatCandidates_UserData_h
2 #define DataFormats_PatCandidates_UserData_h
3 
16 #include <string>
17 #include <vector>
18 #include <typeinfo>
20 
21 
22 namespace pat {
23 
24  class UserData {
25  public:
26  UserData() {}
27  virtual ~UserData() {}
28 
30  virtual UserData * clone() const = 0;
31 
33  virtual const std::type_info & typeId() const = 0;
35  virtual const std::string & typeName() const = 0;
36 
38  /* I don't think there is an easy way to get it working with generic type T,
39  barrying the use of ROOT::Reflex and all the edm::Ptr technicalities.
40  I'd say we can live without polymorphic storage of polymorphic data */
41  template<typename T> const T * get() const {
42  if (typeid(T) != typeId()) return 0;
43  return static_cast<const T *>(data_());
44  }
45 
48  // Really needed for CINT? I would really like to avoid this
49  const void * bareData() const { return data_(); }
50 
53  template<typename T>
54  static std::unique_ptr<UserData> make(const T &value, bool transientOnly=false) ;
55 
56  protected:
58  virtual const void * data_ () const = 0;
59  static std::string typeNameFor(std::type_info const& iInfo);
60 
61  private:
62  static void checkDictionaries(const std::type_info &type) ;
63 
64  };
65 
66  template<typename T>
67  class UserHolder : public UserData {
68  public:
69  UserHolder() : obj_() {}
70  UserHolder(const T &data) : obj_(data) {}
72  UserHolder<T> * clone() const override { return new UserHolder<T>(*this); }
74  const std::type_info & typeId() const override { return typeid(T); }
76  const std::string & typeName() const override { return typeName_(); }
77  protected:
78  const void * data_() const override { return &obj_; }
79  private:
81  static const std::string & typeName_() ;
82  };
83 
85 }
86 
87 
88 template<typename T>
89 std::unique_ptr<pat::UserData> pat::UserData::make(const T &value, bool transientOnly) {
90  if (!transientOnly) {
91  checkDictionaries(typeid(T));
93  }
94  return std::unique_ptr<UserData>(new pat::UserHolder<T>(value));
95 }
96 
97 template<typename T>
99  static const std::string name(typeNameFor(typeid(T)));
100  return name;
101 }
102 
103 #endif
type
Definition: HCALResponse.h:21
UserHolder(const T &data)
Definition: UserData.h:70
UserHolder< T > * clone() const override
Clone.
Definition: UserData.h:72
static std::unique_ptr< UserData > make(const T &value, bool transientOnly=false)
Definition: HeavyIon.h:7
const std::string & typeName() const override
Human readable name of the concrete type of stored data.
Definition: UserData.h:76
virtual const std::type_info & typeId() const =0
Concrete type of stored data.
virtual const void * data_() const =0
Get out the data (can&#39;t template non virtual functions)
virtual const std::string & typeName() const =0
Human readable name of the concrete type of stored data.
const std::type_info & typeId() const override
Concrete type of stored data.
Definition: UserData.h:74
Definition: value.py:1
virtual UserData * clone() const =0
Necessary for deep copy in OwnVector.
static std::string typeNameFor(std::type_info const &iInfo)
Definition: UserData.cc:28
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const void * data_() const override
Get out the data (can&#39;t template non virtual functions)
Definition: UserData.h:78
edm::OwnVector< pat::UserData > UserDataCollection
Definition: UserData.h:84
Base class for data that users can add to pat objects.
Definition: UserData.h:24
static const std::string & typeName_()
Definition: UserData.h:98
long double T
virtual ~UserData()
Definition: UserData.h:27
const void * bareData() const
Definition: UserData.h:49
static void checkDictionaries(const std::type_info &type)
Definition: UserData.cc:7