Belle II Software  release-06-02-00
HistMemory.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <framework/pcore/MsgHandler.h>
11 
12 #include <daq/slc/system/SharedMemory.h>
13 #include <daq/slc/system/MMutex.h>
14 
15 #include <TH1.h>
16 
17 #include <string>
18 #include <vector>
19 
20 namespace Belle2 {
29  class HistMemory {
30 
31  public:
35  struct Header {
37  unsigned int nbytes;
39  unsigned int updateid;
41  unsigned int timestamp;
42  };
43 
44  public:
46  static const unsigned int BUFFER_SIZE = 100000000; //100MB
47 
48  public:
49  HistMemory() : m_path(), m_size(0),
50  m_handler(0), m_fd(0), m_body(NULL), m_buf(NULL), m_updateid(0), m_header(NULL) {}
51  ~HistMemory() {}
52 
53  public:
60  void open(const char* path, unsigned int size,
61  const char* mode = "");
65  void init();
69  void serialize();
74  std::vector<TH1*>& deserialize(Header* header = NULL);
78  std::vector<TH1*>& get() { return m_hist; }
83  TH1* add(TH1* h)
84  {
85  if (h == NULL) return NULL;
86  m_hist.push_back(h);
87  return h;
88  }
89 
90  private:
92  std::string m_path;
94  unsigned int m_size;
98  int m_fd;
100  char* m_body;
102  char* m_buf;
104  unsigned int m_updateid;
112  std::vector<TH1*> m_hist;
113 
114  };
115 
117 }
Class to manipulate histograms in shared memory.
Definition: HistMemory.h:29
void init()
Initialize the shared memory.
Definition: HistMemory.cc:57
TH1 * add(TH1 *h)
Add histogram to the list of histograms.
Definition: HistMemory.h:83
char * m_body
The pointer to the body of the message.
Definition: HistMemory.h:100
Header * m_header
The header for the message.
Definition: HistMemory.h:110
char * m_buf
The buffer to hold the message.
Definition: HistMemory.h:102
std::vector< TH1 * > & get()
Get the list of the histograms.
Definition: HistMemory.h:78
MsgHandler m_handler
The message handler.
Definition: HistMemory.h:96
std::string m_path
The name of the shared memory.
Definition: HistMemory.h:92
unsigned int m_updateid
The id of the udpate.
Definition: HistMemory.h:104
std::vector< TH1 * > m_hist
The list of the histograms.
Definition: HistMemory.h:112
SharedMemory m_memory
The shared memory to hold the histograms.
Definition: HistMemory.h:106
std::vector< TH1 * > & deserialize(Header *header=NULL)
Deserialize the shared memory.
Definition: HistMemory.cc:83
void open(const char *path, unsigned int size, const char *mode="")
Open shared memory.
Definition: HistMemory.cc:20
static const unsigned int BUFFER_SIZE
The size of the buffer for shared memory.
Definition: HistMemory.h:46
int m_fd
The file descriptor.
Definition: HistMemory.h:98
MMutex m_mutex
The mutex lock for the shared memory.
Definition: HistMemory.h:108
unsigned int m_size
The size of the shared memory.
Definition: HistMemory.h:94
void serialize()
Serialize the shared memory.
Definition: HistMemory.cc:66
A class to encode/decode an EvtMessage.
Definition: MsgHandler.h:103
Abstract base class for different kinds of events.
Header information to deseriale the shared memory.
Definition: HistMemory.h:35
unsigned int nbytes
Number of bytes.
Definition: HistMemory.h:37
unsigned int updateid
Id of the update.
Definition: HistMemory.h:39
unsigned int timestamp
Timestamp of last update.
Definition: HistMemory.h:41