Belle II Software  release-05-02-19
HistMemory Class Reference

Class to manipulate histograms in shared memory. More...

#include <HistMemory.h>

Collaboration diagram for HistMemory:

Classes

struct  Header
 Header information to deseriale the shared memory. More...
 

Public Member Functions

void open (const char *path, unsigned int size, const char *mode="")
 Open shared memory. More...
 
void init ()
 Initialize the shared memory.
 
void serialize ()
 Serialize the shared memory.
 
std::vector< TH1 * > & deserialize (Header *header=NULL)
 Deserialize the shared memory. More...
 
std::vector< TH1 * > & get ()
 Get the list of the histograms.
 
TH1 * add (TH1 *h)
 Add histogram to the list of histograms. More...
 

Static Public Attributes

static const unsigned int BUFFER_SIZE = 100000000
 The size of the buffer for shared memory.
 

Private Attributes

std::string m_path
 The name of the shared memory.
 
unsigned int m_size
 The size of the shared memory.
 
MsgHandler m_handler
 The message handler.
 
int m_fd
 The file descriptor.
 
char * m_body
 The pointer to the body of the message.
 
char * m_buf
 The buffer to hold the message.
 
unsigned int m_updateid
 The id of the udpate.
 
SharedMemory m_memory
 The shared memory to hold the histograms.
 
MMutex m_mutex
 The mutex lock for the shared memory.
 
Headerm_header
 The header for the message.
 
std::vector< TH1 * > m_hist
 The list of the histograms.
 

Detailed Description

Class to manipulate histograms in shared memory.

Definition at line 23 of file HistMemory.h.

Member Function Documentation

◆ add()

TH1* add ( TH1 *  h)
inline

Add histogram to the list of histograms.

Parameters
hThe histogram to be added.

Definition at line 77 of file HistMemory.h.

78  {
79  if (h == NULL) return NULL;
80  m_hist.push_back(h);
81  return h;
82  }

◆ deserialize()

std::vector< TH1 * > & deserialize ( Header header = NULL)

Deserialize the shared memory.

Parameters
headerThe Header of the shared memory.

Definition at line 76 of file HistMemory.cc.

77 {
78  m_hist = std::vector<TH1*>();
79  m_mutex.lock();
80  if (m_header->updateid <= m_updateid) {
81  m_mutex.unlock();
82  return m_hist;
83  }
84  if (header != NULL) {
85  memcpy(header, m_header, sizeof(Header));
86  }
88  memcpy(m_buf, m_body, m_header->nbytes);
89  m_mutex.unlock();
90 
91  for (size_t i = 0; i < m_hist.size(); i++) {
92  delete m_hist[i];
93  }
94 
95  EvtMessage* msg = new EvtMessage(m_buf);
96  std::vector<TObject*> objlist;
97  std::vector<std::string> strlist;
98  m_handler.decode_msg(msg, objlist, strlist);
99  int nobjs = (msg->header())->reserved[1];
100  for (int i = 0; i < nobjs; i++) {
101  add((TH1*)objlist[i]->Clone());
102  }
103  delete msg;
104  return m_hist;
105 }

◆ open()

void open ( const char *  path,
unsigned int  size,
const char *  mode = "" 
)

Open shared memory.

Parameters
pathThe name of the shared memory.
sizeThe size of the shared memory.
modeThe open mode: read or write.

Definition at line 13 of file HistMemory.cc.


The documentation for this class was generated from the following files:
Belle2::HistMemory::m_header
Header * m_header
The header for the message.
Definition: HistMemory.h:104
Belle2::EvtMessage
Class to manage streamed object.
Definition: EvtMessage.h:60
Belle2::HistMemory::Header::updateid
unsigned int updateid
Id of the update.
Definition: HistMemory.h:33
Belle2::HistMemory::m_buf
char * m_buf
The buffer to hold the message.
Definition: HistMemory.h:96
Belle2::HistMemory::m_hist
std::vector< TH1 * > m_hist
The list of the histograms.
Definition: HistMemory.h:106
Belle2::HistMemory::m_updateid
unsigned int m_updateid
The id of the udpate.
Definition: HistMemory.h:98
Belle2::MsgHandler::decode_msg
virtual void decode_msg(EvtMessage *msg, std::vector< TObject * > &objlist, std::vector< std::string > &namelist)
Decode an EvtMessage into a vector list of objects with names.
Definition: MsgHandler.cc:107
Belle2::HistMemory::Header::nbytes
unsigned int nbytes
Number of bytes.
Definition: HistMemory.h:31
Belle2::EvtMessage::header
EvtHeader * header()
Get pointer to EvtHeader.
Definition: EvtMessage.cc:162
Belle2::HistMemory::m_body
char * m_body
The pointer to the body of the message.
Definition: HistMemory.h:94
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::add
TH1 * add(TH1 *h)
Add histogram to the list of histograms.
Definition: HistMemory.h:77