test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CustomStreamer.h
Go to the documentation of this file.
1 #ifndef IOPool_Common_CustomStreamer_h
2 #define IOPool_Common_CustomStreamer_h
3 
4 #include <string>
5 #include "TClass.h"
6 #include "TClassStreamer.h"
7 #include "TClassRef.h"
9 class TBuffer;
10 
11 namespace edm {
12  template <typename T>
13  class CustomStreamer : public TClassStreamer {
14  public:
15  typedef T element_type;
17  void operator() (TBuffer &R__b, void *objp);
18  private:
20  TClassRef cl_;
21  };
22 
23  template <typename T>
25  className_(TypeID(typeid(T)).className()),
26  cl_(className_.c_str())
27  {}
28 
29  template <typename T>
30  void
31  CustomStreamer<T>::operator()(TBuffer &R__b, void *objp) {
32  if (R__b.IsReading()) {
33  cl_->ReadBuffer(R__b, objp);
34  } else {
35  cl_->WriteBuffer(R__b, objp);
36  }
37  }
38 
39  template <typename T>
40  void
42  TClass *cl = TClass::GetClass(typeid(T));
43  if (cl->GetStreamer() == 0) {
44  cl->AdoptStreamer(new CustomStreamer<T>());
45  }
46  }
47 
48  template <typename T>
49  void
50  SetCustomStreamer(T const&) {
51  TClass *cl = TClass::GetClass(typeid(T));
52  if (cl->GetStreamer() == 0) {
53  cl->AdoptStreamer(new CustomStreamer<T>());
54  }
55  }
56 }
57 
58 #endif
std::string className_
long double T
void operator()(TBuffer &R__b, void *objp)
std::string className(const T &t)
Definition: ClassName.h:30
void SetCustomStreamer()