CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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>
19 #include <cxxabi.h>
21 
22 
23 namespace pat {
24 
25  class UserData {
26  public:
27  UserData() {}
28  virtual ~UserData() {}
29 
31  virtual UserData * clone() const = 0;
32 
34  virtual const std::type_info & typeId() const = 0;
36  virtual const std::string & typeName() const = 0;
37 
39  /* I don't think there is an easy way to get it working with generic type T,
40  barrying the use of ROOT::Reflex and all the edm::Ptr technicalities.
41  I'd say we can live without polymorphic storage of polymorphic data */
42  template<typename T> const T * get() const {
43  if (typeid(T) != typeId()) return 0;
44  return static_cast<const T *>(data_());
45  }
46 
49  // Really needed for CINT? I would really like to avoid this
50  const void * bareData() const { return data_(); }
51 
54  template<typename T>
55  static std::auto_ptr<UserData> make(const T &value, bool transientOnly=false) ;
56 
57  protected:
59  virtual const void * data_ () const = 0;
60  static std::string demangleName(const char* iMangledName);
61 
62  private:
63  static void checkDictionaries(const std::type_info &type) ;
64 
65  };
66 
67  template<typename T>
68  class UserHolder : public UserData {
69  public:
70  UserHolder() : obj_() {}
71  UserHolder(const T &data) : obj_(data) {}
73  virtual UserHolder<T> * clone() const { return new UserHolder<T>(*this); }
75  virtual const std::type_info & typeId() const { return typeid(T); }
77  virtual const std::string & typeName() const { return typeName_(); }
78  protected:
79  virtual const void * data_() const { return &obj_; }
80  private:
82  static const std::string & typeName_() ;
83  };
84 
86 }
87 
88 
89 template<typename T>
90 std::auto_ptr<pat::UserData> pat::UserData::make(const T &value, bool transientOnly) {
91  if (!transientOnly) {
92  checkDictionaries(typeid(T));
94  }
95  return std::auto_ptr<UserData>(new pat::UserHolder<T>(value));
96 }
97 
98 template<typename T>
100  static const std::string name(demangleName(typeid(T).name()));
101  return name;
102 }
103 
104 #endif
type
Definition: HCALResponse.h:21
UserHolder(const T &data)
Definition: UserData.h:71
virtual const void * data_() const =0
Get out the data (can&#39;t template non virtual functions)
virtual const std::type_info & typeId() const
Concrete type of stored data.
Definition: UserData.h:75
static std::auto_ptr< UserData > make(const T &value, bool transientOnly=false)
virtual const std::type_info & typeId() const =0
Concrete type of stored data.
static std::string demangleName(const char *iMangledName)
Definition: UserData.cc:28
virtual const std::string & typeName() const
Human readable name of the concrete type of stored data.
Definition: UserData.h:77
virtual UserHolder< T > * clone() const
Clone.
Definition: UserData.h:73
virtual const void * data_() const
Get out the data (can&#39;t template non virtual functions)
Definition: UserData.h:79
virtual UserData * clone() const =0
Necessary for deep copy in OwnVector.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual const std::string & typeName() const =0
Human readable name of the concrete type of stored data.
edm::OwnVector< pat::UserData > UserDataCollection
Definition: UserData.h:85
Base class for data that users can add to pat objects.
Definition: UserData.h:25
static const std::string & typeName_()
Definition: UserData.h:99
long double T
virtual ~UserData()
Definition: UserData.h:28
const void * bareData() const
Definition: UserData.h:50
static void checkDictionaries(const std::type_info &type)
Definition: UserData.cc:6