Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:05

0001 #include "DataFormats/Common/interface/RefCoreStreamer.h"
0002 #include "DataFormats/Common/interface/RefCore.h"
0003 #include "DataFormats/Common/interface/RefCoreWithIndex.h"
0004 #include "FWCore/Utilities/interface/EDMException.h"
0005 #include "DataFormats/Common/interface/EDProductGetter.h"
0006 #include "DataFormats/Provenance/interface/ProductID.h"
0007 #include "TBuffer.h"
0008 #include "TClass.h"
0009 
0010 namespace edm {
0011 
0012   /*NOTE: This design came from Philippe Canal as the minimum storage (2bytes) we can do but still
0013    have ROOT call our custom streamer. The trick is to only store the version # and not the class ID.
0014    The '#if #else #endif' are there because the default choice is known to work for root 5.27-5.28 and
0015    Philippe believes is unlikely to ever change but the alternate choice is slightly slower but more
0016    guaranteed to be forwards compatible.
0017    */
0018 
0019   void RefCoreStreamer::operator()(TBuffer& R__b, void* objp) {
0020     if (R__b.IsReading()) {
0021       cl_->ReadBuffer(R__b, objp);
0022     } else {
0023       //If transient, throw
0024       RefCore* obj = static_cast<RefCore*>(objp);
0025       if (obj->isTransient()) {
0026         throw Exception(errors::InvalidReference, "Inconsistency")
0027             << "RefCoreStreamer: transient Ref or Ptr cannot be made persistent.";
0028       }
0029 #if 1
0030       R__b << cl_->GetClassVersion();
0031 #else
0032       R__b.WriteVersion(cl_, kFALSE);
0033 #endif
0034       //Must match the order the data appears in the class declaration
0035       const ProductID& id = obj->id();
0036       R__b << id.processIndex();
0037       R__b << id.productIndex();
0038     }
0039   }
0040 
0041   void RefCoreWithIndexStreamer::operator()(TBuffer& R__b, void* objp) {
0042     if (R__b.IsReading()) {
0043       cl_->ReadBuffer(R__b, objp);
0044     } else {
0045       //If transient, throw
0046       RefCoreWithIndex* obj = static_cast<RefCoreWithIndex*>(objp);
0047       if (obj->isTransient()) {
0048         throw Exception(errors::InvalidReference, "Inconsistency")
0049             << "RefCoreStreamer: transient Ref or Ptr cannot be made persistent.";
0050       }
0051 #if 1
0052       R__b << cl_->GetClassVersion();
0053 #else
0054       R__b.WriteVersion(cl_, kFALSE);
0055 #endif
0056       //Must match the order the data appears in the class declaration
0057       const ProductID& id = obj->id();
0058       R__b << id.processIndex();
0059       R__b << id.productIndex();
0060       R__b << obj->index();
0061     }
0062   }
0063 
0064   TClassStreamer* RefCoreStreamer::Generate() const { return new RefCoreStreamer(*this); }
0065 
0066   TClassStreamer* RefCoreWithIndexStreamer::Generate() const { return new RefCoreWithIndexStreamer(*this); }
0067 
0068   void setRefCoreStreamerInTClass() {
0069     {
0070       TClass* tClass = TClass::GetClass("edm::RefCore");
0071       if (tClass->GetStreamer() == nullptr) {
0072         tClass->AdoptStreamer(new RefCoreStreamer());
0073       }
0074     }
0075     {
0076       TClass* tClass = TClass::GetClass("edm::RefCoreWithIndex");
0077       if (tClass->GetStreamer() == nullptr) {
0078         tClass->AdoptStreamer(new RefCoreWithIndexStreamer());
0079       }
0080     }
0081   }
0082 
0083   void setRefCoreStreamer(bool) { EDProductGetter::switchProductGetter(nullptr); }
0084 
0085   EDProductGetter const* setRefCoreStreamer(EDProductGetter const* ep) {
0086     EDProductGetter const* returnValue = nullptr;
0087     if (ep != nullptr) {
0088       returnValue = edm::EDProductGetter::switchProductGetter(ep);
0089     }
0090     return returnValue;
0091   }
0092 }  // namespace edm