Belle II Software  release-06-01-15
HistMemory Class Reference
Packages ยป dqm

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 29 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 83 of file HistMemory.h.

84  {
85  if (h == NULL) return NULL;
86  m_hist.push_back(h);
87  return h;
88  }
std::vector< TH1 * > m_hist
The list of the histograms.
Definition: HistMemory.h:112

โ—† deserialize()

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

Deserialize the shared memory.

Parameters
headerThe Header of the shared memory.

Definition at line 83 of file HistMemory.cc.

84 {
85  m_hist = std::vector<TH1*>();
86  m_mutex.lock();
87  if (m_header->updateid <= m_updateid) {
88  m_mutex.unlock();
89  return m_hist;
90  }
91  if (header != NULL) {
92  memcpy(header, m_header, sizeof(Header));
93  }
95  memcpy(m_buf, m_body, m_header->nbytes);
96  m_mutex.unlock();
97 
98  for (size_t i = 0; i < m_hist.size(); i++) {
99  delete m_hist[i];
100  }
101 
102  EvtMessage* msg = new EvtMessage(m_buf);
103  std::vector<TObject*> objlist;
104  std::vector<std::string> strlist;
105  m_handler.decode_msg(msg, objlist, strlist);
106  int nobjs = (msg->header())->reserved[1];
107  for (int i = 0; i < nobjs; i++) {
108  add((TH1*)objlist[i]->Clone());
109  }
110  delete msg;
111  return m_hist;
112 }
Class to manage streamed object.
Definition: EvtMessage.h:59
EvtHeader * header()
Get pointer to EvtHeader.
Definition: EvtMessage.cc:161
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
MsgHandler m_handler
The message handler.
Definition: HistMemory.h:96
unsigned int m_updateid
The id of the udpate.
Definition: HistMemory.h:104
MMutex m_mutex
The mutex lock for the shared memory.
Definition: HistMemory.h:108
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:106
unsigned int nbytes
Number of bytes.
Definition: HistMemory.h:37
unsigned int updateid
Id of the update.
Definition: HistMemory.h:39

โ—† 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 20 of file HistMemory.cc.


The documentation for this class was generated from the following files: