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