Belle II Software  release-05-02-19
HistMemory.h
1 #ifndef _Belle2_HistMemory_h
2 #define _Belle2_HistMemory_h
3 
4 #include <framework/pcore/MsgHandler.h>
5 
6 #include <daq/slc/system/SharedMemory.h>
7 #include <daq/slc/system/MMutex.h>
8 
9 #include <TH1.h>
10 
11 #include <string>
12 #include <vector>
13 
14 namespace Belle2 {
23  class HistMemory {
24 
25  public:
29  struct Header {
31  unsigned int nbytes;
33  unsigned int updateid;
35  unsigned int timestamp;
36  };
37 
38  public:
40  static const unsigned int BUFFER_SIZE = 100000000; //100MB
41 
42  public:
43  HistMemory() : m_path(), m_size(0),
44  m_handler(0), m_fd(0), m_body(NULL), m_buf(NULL), m_updateid(0), m_header(NULL) {}
45  ~HistMemory() {}
46 
47  public:
54  void open(const char* path, unsigned int size,
55  const char* mode = "");
59  void init();
63  void serialize();
68  std::vector<TH1*>& deserialize(Header* header = NULL);
72  std::vector<TH1*>& get() { return m_hist; }
77  TH1* add(TH1* h)
78  {
79  if (h == NULL) return NULL;
80  m_hist.push_back(h);
81  return h;
82  }
83 
84  private:
86  std::string m_path;
88  unsigned int m_size;
92  int m_fd;
94  char* m_body;
96  char* m_buf;
98  unsigned int m_updateid;
106  std::vector<TH1*> m_hist;
107 
108  };
109 
111 }
112 
113 #endif
Belle2::HistMemory::m_header
Header * m_header
The header for the message.
Definition: HistMemory.h:104
Belle2::MMutex
Definition: MMutex.h:19
Belle2::HistMemory::Header::timestamp
unsigned int timestamp
Timestamp of last update.
Definition: HistMemory.h:35
Belle2::HistMemory::init
void init()
Initialize the shared memory.
Definition: HistMemory.cc:50
Belle2::HistMemory::Header::updateid
unsigned int updateid
Id of the update.
Definition: HistMemory.h:33
Belle2::HistMemory::m_size
unsigned int m_size
The size of the shared memory.
Definition: HistMemory.h:88
Belle2::HistMemory::deserialize
std::vector< TH1 * > & deserialize(Header *header=NULL)
Deserialize the shared memory.
Definition: HistMemory.cc:76
Belle2::SharedMemory
Definition: SharedMemory.h:12
Belle2::HistMemory::m_memory
SharedMemory m_memory
The shared memory to hold the histograms.
Definition: HistMemory.h:100
Belle2::HistMemory
Class to manipulate histograms in shared memory.
Definition: HistMemory.h:23
Belle2::HistMemory::m_buf
char * m_buf
The buffer to hold the message.
Definition: HistMemory.h:96
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::HistMemory::m_hist
std::vector< TH1 * > m_hist
The list of the histograms.
Definition: HistMemory.h:106
Belle2::HistMemory::m_path
std::string m_path
The name of the shared memory.
Definition: HistMemory.h:86
Belle2::HistMemory::m_updateid
unsigned int m_updateid
The id of the udpate.
Definition: HistMemory.h:98
Belle2::HistMemory::Header::nbytes
unsigned int nbytes
Number of bytes.
Definition: HistMemory.h:31
Belle2::HistMemory::m_body
char * m_body
The pointer to the body of the message.
Definition: HistMemory.h:94
Belle2::HistMemory::get
std::vector< TH1 * > & get()
Get the list of the histograms.
Definition: HistMemory.h:72
Belle2::HistMemory::serialize
void serialize()
Serialize the shared memory.
Definition: HistMemory.cc:59
Belle2::HistMemory::open
void open(const char *path, unsigned int size, const char *mode="")
Open shared memory.
Definition: HistMemory.cc:13
Belle2::HistMemory::m_mutex
MMutex m_mutex
The mutex lock for the shared memory.
Definition: HistMemory.h:102
Belle2::HistMemory::m_handler
MsgHandler m_handler
The message handler.
Definition: HistMemory.h:90
Belle2::HistMemory::BUFFER_SIZE
static const unsigned int BUFFER_SIZE
The size of the buffer for shared memory.
Definition: HistMemory.h:40
Belle2::HistMemory::add
TH1 * add(TH1 *h)
Add histogram to the list of histograms.
Definition: HistMemory.h:77
Belle2::MsgHandler
A class to encode/decode an EvtMessage.
Definition: MsgHandler.h:104
Belle2::HistMemory::m_fd
int m_fd
The file descriptor.
Definition: HistMemory.h:92
Belle2::HistMemory::Header
Header information to deseriale the shared memory.
Definition: HistMemory.h:29