Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:14

0001 #ifndef FWCore_SharedMemory_ROOTDeserializer_h
0002 #define FWCore_SharedMemory_ROOTDeserializer_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/SharedMemory
0006 // Class  :     ROOTDeserializer
0007 //
0008 /**\class ROOTDeserializer ROOTDeserializer.h " FWCore/SharedMemory/interface/ROOTDeserializer.h"
0009 
0010  Description: Use ROOT dictionaries to deserialize object from a buffer
0011 
0012  Usage:
0013     Used in conjunction with ROOTSerializer.
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 READBUFFER>
0031   class ROOTDeserializer {
0032   public:
0033     ROOTDeserializer(READBUFFER& iBuffer)
0034         : buffer_{iBuffer}, class_{TClass::GetClass(typeid(T))}, bufferFile_(TBuffer::kRead) {}
0035 
0036     ROOTDeserializer(const ROOTDeserializer&) = delete;
0037     const ROOTDeserializer& operator=(const ROOTDeserializer&) = delete;
0038     ROOTDeserializer(ROOTDeserializer&&) = delete;
0039     const ROOTDeserializer& operator=(ROOTDeserializer&&) = delete;
0040 
0041     // ---------- const member functions ---------------------
0042 
0043     // ---------- member functions ---------------------------
0044     T deserialize() {
0045       T value;
0046       if (previousBufferIdentifier_ != buffer_.bufferIdentifier()) {
0047         auto buff = buffer_.buffer();
0048         bufferFile_.SetBuffer(buff.first, buff.second, kFALSE);
0049         previousBufferIdentifier_ = buffer_.bufferIdentifier();
0050       }
0051 
0052       class_->ReadBuffer(bufferFile_, &value);
0053       bufferFile_.Reset();
0054       return value;
0055     }
0056 
0057   private:
0058     // ---------- member data --------------------------------
0059     READBUFFER& buffer_;
0060     TClass* const class_;
0061     TBufferFile bufferFile_;
0062     int previousBufferIdentifier_ = 0;
0063   };
0064 }  // namespace edm::shared_memory
0065 
0066 #endif