CMS 3D CMS Logo

CustomStreamer.h

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

Generated on Tue Jun 9 17:39:10 2009 for CMSSW by  doxygen 1.5.4