CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/Provenance/interface/TransientStreamer.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Provenance_TransientStreamer_h
00002 #define DataFormats_Provenance_TransientStreamer_h
00003 
00004 #include <string>
00005 #include "TROOT.h"
00006 #include "TClassStreamer.h"
00007 #include "TClassRef.h"
00008 #include "FWCore/Utilities/interface/TypeID.h"
00009 class TBuffer;
00010 
00011 namespace edm {
00012   template <typename T>
00013   class TransientStreamer : public TClassStreamer {
00014   public:
00015     typedef T element_type;
00016     TransientStreamer();
00017     void operator() (TBuffer &R__b, void *objp);
00018   private:
00019     std::string className_;
00020     TClassRef cl_;
00021   };
00022 
00023   template <typename T>
00024   TransientStreamer<T>::TransientStreamer() :
00025     className_(TypeID(typeid(T)).className()),
00026     cl_(className_.c_str())
00027   {}
00028 
00029   template <typename T>
00030   void
00031   TransientStreamer<T>::operator()(TBuffer &R__b, void *objp) {
00032     if (R__b.IsReading()) {
00033       cl_->ReadBuffer(R__b, objp);
00034       // Fill with default constructed object;
00035       T* obj = static_cast<T *>(objp);
00036       *obj = T();
00037     } else {
00038       cl_->WriteBuffer(R__b, objp);
00039     }
00040   }
00041 
00042   template <typename T>
00043   void
00044   SetTransientStreamer() {
00045     TClass *cl = gROOT->GetClass(TypeID(typeid(T)).className().c_str());
00046     if (cl->GetStreamer() == 0) {
00047       cl->AdoptStreamer(new TransientStreamer<T>());
00048     }
00049   }
00050 
00051   template <typename T>
00052   void
00053   SetTransientStreamer(T const&) {
00054     TClass *cl = gROOT->GetClass(TypeID(typeid(T)).className().c_str());
00055     if (cl->GetStreamer() == 0) {
00056       cl->AdoptStreamer(new TransientStreamer<T>());
00057     }
00058   }
00059 
00060   void setTransientStreamers();
00061 }
00062 
00063 #endif