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 
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  virtual UserHolder<T> * clone() const { return new UserHolder<T>(*this); }
74  virtual const std::type_info & typeId() const { return typeid(T); }
76  virtual const std::string & typeName() const { return typeName_(); }
77  protected:
78  virtual const void * data_() const { return &obj_; }
79  private:
81  static const std::string & typeName_() ;
82  };
83 
85 }
86 
87 
88 template<typename T>
89 std::auto_ptr<pat::UserData> pat::UserData::make(const T &value, bool transientOnly) {
90  if (!transientOnly) {
91  checkDictionaries(typeid(T));
93  }
94  return std::auto_ptr<UserData>(new pat::UserHolder<T>(value));
95 }
96 
97 template<typename T>
99  static int status = 0;
100  static const char * demangled = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
101  static const std::string name(status == 0 ? demangled : "[UNKNOWN]");
102  return name;
103 }
104 
105 #endif
type
Definition: HCALResponse.h:21
UserHolder(const T &data)
Definition: UserData.h:70
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:74
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.
virtual const std::string & typeName() const
Human readable name of the concrete type of stored data.
Definition: UserData.h:76
virtual UserHolder< T > * clone() const
Clone.
Definition: UserData.h:72
virtual const void * data_() const
Get out the data (can&#39;t template non virtual functions)
Definition: UserData.h:78
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:84
Base class for data that users can add to pat objects.
Definition: UserData.h:25
tuple status
Definition: ntuplemaker.py:245
static const std::string & typeName_()
Definition: UserData.h:98
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