Belle II Software  release-05-01-25
NSMDataStore.h
1 #ifndef _Belle2_NSMDataHeader_h
2 #define _Belle2_NSMDataHeader_h
3 
4 #include <daq/slc/system/SharedMemory.h>
5 #include "daq/slc/system/MMutex.h"
6 #include "daq/slc/system/MCond.h"
7 
8 namespace Belle2 {
14  class NSMDataStore {
15 
16  public:
17  static NSMDataStore& getStore()
18  {
19  return g_store;
20  }
21 
22  private:
23  static NSMDataStore g_store;
24 
25  public:
26  struct Header {
27  unsigned short maxentries;
28  unsigned short nentries;
29  };
30 
31  public:
32  struct Entry {
33  unsigned short id;
34  unsigned short rid;
35  unsigned int addr;
36  unsigned int size;
37  unsigned int utime;
38  unsigned int revision;
39  char name[32];
40  char format[32];
41  };
42 
43  private:
44  NSMDataStore()
45  {
46  m_buf = NULL;
47  m_header = NULL;
48  m_entries = NULL;
49  }
50 
51  public:
52  bool isOpend() { return m_buf != NULL; }
53  bool open(unsigned short max = 0);
54  void init();
55  Entry* add(unsigned int addr,
56  unsigned int size,
57  unsigned int revision,
58  const std::string& name,
59  const std::string& format,
60  unsigned int rid);
61  void unlink();
62  Header* getHeader() { return m_header; }
63  Entry* get(const std::string& name);
64  Entry* get(unsigned int id);
65  Entry* get(unsigned int addr, unsigned int rid);
66  void lock() { m_mutex.lock(); }
67  void unlock() { m_mutex.unlock(); }
68  bool wait(int second)
69  {
70  return m_cond.wait(m_mutex, second, 0);
71  }
72  void signal() { m_cond.broadcast(); }
73 
74  private:
75  char* m_buf;
76  Header* m_header;
77  Entry* m_entries;
78  SharedMemory m_mem;
79  MMutex m_mutex;
80  MCond m_cond;
81  };
82 
84 }
85 
86 #endif
Belle2::NSMDataStore
Definition: NSMDataStore.h:14
Belle2::NSMDataStore::Header
Definition: NSMDataStore.h:26
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::NSMDataStore::Entry
Definition: NSMDataStore.h:32