Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:08

0001 #ifndef FWCore_SharedMemory_ROOTSerializer_h
0002 #define FWCore_SharedMemory_ROOTSerializer_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/SharedMemory
0006 // Class  :     ROOTSerializer
0007 //
0008 /**\class ROOTSerializer ROOTSerializer.h " FWCore/SharedMemory/interface/ROOTSerializer.h"
0009 
0010  Description: Use ROOT dictionaries to serialize object to a buffer
0011 
0012  Usage:
0013     This is used in conjuction with ROOTDeserializer.
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  22/01/2020
0019 //
0020 
0021 // system include files
0022 #include "TClass.h"
0023 #include "TBufferFile.h"
0024 
0025 // user include files
0026 
0027 // forward declarations
0028 
0029 namespace edm::shared_memory {
0030   template <typename T, typename WRITEBUFFER>
0031   class ROOTSerializer {
0032   public:
0033     ROOTSerializer(WRITEBUFFER& iBuffer)
0034         : buffer_(iBuffer), class_{TClass::GetClass(typeid(T))}, bufferFile_{TBuffer::kWrite} {}
0035 
0036     ROOTSerializer(const ROOTSerializer&) = delete;
0037     const ROOTSerializer& operator=(const ROOTSerializer&) = delete;
0038     ROOTSerializer(ROOTSerializer&&) = delete;
0039     const ROOTSerializer& operator=(ROOTSerializer&&) = delete;
0040 
0041     // ---------- const member functions ---------------------
0042 
0043     // ---------- member functions ---------------------------
0044     void serialize(T& iValue) {
0045       bufferFile_.Reset();
0046       class_->WriteBuffer(bufferFile_, &iValue);
0047 
0048       buffer_.copyToBuffer(bufferFile_.Buffer(), bufferFile_.Length());
0049     }
0050 
0051   private:
0052     // ---------- member data --------------------------------
0053     WRITEBUFFER& buffer_;
0054     TClass* const class_;
0055     TBufferFile bufferFile_;
0056   };
0057 }  // namespace edm::shared_memory
0058 
0059 #endif