EUDAQ
 All Classes Namespaces Files Functions Variables Pages
FileSerializer.hh
1 #ifndef EUDAQ_INCLUDED_FileSerializer
2 #define EUDAQ_INCLUDED_FileSerializer
3 
4 #include <string>
5 #include <cstdio>
6 #include "eudaq/Serializer.hh"
7 #include "eudaq/Exception.hh"
8 #include "eudaq/BufferSerializer.hh"
9 #include <memory>
10 namespace eudaq {
11  class Event;
12  class DLLEXPORT FileSerializer : public Serializer {
13  public:
14  FileSerializer(const std::string &fname, bool overwrite = false);
15  virtual void Flush();
16  uint64_t FileBytes() const { return m_filebytes; }
17  ~FileSerializer();
18 
19  private:
20  virtual void Serialize(const unsigned char *data, size_t len);
21  FILE *m_file;
22  uint64_t m_filebytes;
23  };
24 
25  class DLLEXPORT FileDeserializer : public Deserializer {
26  public:
27  FileDeserializer(const std::string &fname, bool faileof = false,
28  size_t buffersize = 65536);
29  virtual bool HasData();
30  template <typename T> T peek() {
31  FillBuffer();
32  BufferSerializer buf(m_start, m_stop);
33  T result;
34  buf.read(result);
35  return result;
36  }
37  bool ReadEvent(int ver, std::shared_ptr<eudaq::Event> &ev, size_t skip = 0);
38 
39  private:
40  virtual void Deserialize(unsigned char *data, size_t len);
41  size_t FillBuffer(size_t min = 0);
42  size_t level() const { return m_stop - m_start; }
43  typedef unsigned char *ptr_t;
44  FILE *m_file;
45  bool m_faileof;
46  std::vector<unsigned char> m_buf;
47  ptr_t m_start, m_stop;
48  };
49 }
50 
51 #endif // EUDAQ_INCLUDED_FileSerializer
Definition: FileSerializer.hh:12
Definition: Serializer.hh:156
Definition: FileSerializer.hh:25
Definition: Serializer.hh:19
Definition: BufferSerializer.hh:12