CMS 3D CMS Logo

ConcurrentMonitorElement.h
Go to the documentation of this file.
1 #ifndef DQMServices_Core_ConcurrentMonitorElement_h
2 #define DQMServices_Core_ConcurrentMonitorElement_h
3 
4 /* Encapsulate of MonitorElement to expose *limited* support for concurrency.
5  *
6  * ...
7  */
8 
9 #include <mutex>
10 #include <tbb/spin_mutex.h>
11 
13 
15 {
16 private:
17  mutable MonitorElement* me_;
18  mutable tbb::spin_mutex lock_;
19 
20 public:
22  me_(nullptr)
23  { }
24 
26  me_(me)
27  { }
28 
29  // non-copiable
31 
32  // movable
34  {
35  std::lock_guard<tbb::spin_mutex> guard(other.lock_);
36  me_ = other.me_;
37  other.me_ = nullptr;
38  }
39 
40  // not copy-assignable
42 
43  // move-assignable
45  {
46  // FIXME replace with std::scoped_lock once C++17 is available
47  std::lock(lock_, other.lock_);
48  std::lock_guard<tbb::spin_mutex> ours(lock_, std::adopt_lock);
49  std::lock_guard<tbb::spin_mutex> others(other.lock_, std::adopt_lock);
50  me_ = other.me_;
51  other.me_ = nullptr;
52  return *this;
53  }
54 
55  // nothing to do, we do not own the MonitorElement
56  ~ConcurrentMonitorElement(void) = default;
57 
58  // expose as a const method to mean that it is concurrent-safe
59  template <typename... Args>
60  void fill(Args && ... args) const
61  {
62  std::lock_guard<tbb::spin_mutex> guard(lock_);
63  me_->Fill(std::forward<Args>(args)...);
64  }
65 
66  // expose as a const method to mean that it is concurrent-safe
67  void shiftFillLast(double y, double ye = 0., int32_t xscale = 1) const
68  {
69  std::lock_guard<tbb::spin_mutex> guard(lock_);
70  me_->ShiftFillLast(y, ye, xscale);
71  }
72 
73  // reset the internal pointer
74  void reset()
75  {
76  std::lock_guard<tbb::spin_mutex> guard(lock_);
77  me_ = nullptr;
78  }
79 
80  operator bool() const
81  {
82  std::lock_guard<tbb::spin_mutex> guard(lock_);
83  return (me_ != nullptr);
84  }
85 
86  // non-const methods to manipulate axes and titles.
87  // these are not concurrent-safe, and should be used only when the underlying
88  // MonitorElement is being booked.
89  void setTitle(std::string const& title)
90  {
91  me_->setTitle(title);
92  }
93 
95  {
96  me_->getTH1()->SetXTitle(title.c_str());
97  }
98 
99  void setXTitle(const char* title)
100  {
101  me_->getTH1()->SetXTitle(title);
102  }
103 
105  {
106  me_->getTH1()->SetYTitle(title.c_str());
107  }
108 
109  void setYTitle(const char* title)
110  {
111  me_->getTH1()->SetYTitle(title);
112  }
113 
114  void setAxisRange(double xmin, double xmax, int axis = 1)
115  {
116  me_->setAxisRange(xmin, xmax, axis);
117  }
118 
119  void setAxisTitle(std::string const& title, int axis = 1)
120  {
121  me_->setAxisTitle(title, axis);
122  }
123 
124  void setAxisTimeDisplay(int value, int axis = 1)
125  {
126  me_->setAxisTimeDisplay(value, axis);
127  }
128 
129  void setAxisTimeFormat(const char* format = "", int axis = 1)
130  {
131  me_->setAxisTimeFormat(format, axis);
132  }
133 
134  void setBinLabel(int bin, std::string const& label, int axis = 1)
135  {
136  me_->setBinLabel(bin, label, axis);
137  }
138 
139  void enableSumw2()
140  {
141  me_->getTH1()->Sumw2();
142  }
143 
145  {
146  me_->getTH1()->GetXaxis()->SetNoAlphanumeric(false);
147  me_->getTH1()->GetYaxis()->SetNoAlphanumeric(false);
148  }
149 
150  void setOption(const char* option) {
151  me_->getTH1()->SetOption(option);
152  }
153 };
154 
155 #endif // DQMServices_Core_ConcurrentMonitorElement_h
ConcurrentMonitorElement(ConcurrentMonitorElement &&other)
void shiftFillLast(double y, double ye=0., int32_t xscale=1) const
void setYTitle(std::string const &title)
void setAxisRange(double xmin, double xmax, int axis=1)
set x-, y- or z-axis range (axis=1, 2, 3 respectively)
void setAxisTimeFormat(const char *format="", int axis=1)
set the format of the time values that are displayed on an axis
void setAxisTimeDisplay(int value, int axis=1)
TH1 * getTH1() const
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
ConcurrentMonitorElement & operator=(ConcurrentMonitorElement &&other)
void setOption(const char *option)
#define nullptr
void Fill(long long x)
char const * label
void ShiftFillLast(double y, double ye=0., int32_t xscale=1)
void setAxisTimeDisplay(int value, int axis=1)
set x-, y-, or z-axis to display time values
void setTitle(std::string const &title)
ConcurrentMonitorElement(MonitorElement *me)
void setYTitle(const char *title)
Definition: value.py:1
bin
set the eta bin as selection string.
void setTitle(const std::string &title)
set (ie. change) histogram/profile title
~ConcurrentMonitorElement(void)=default
void setAxisTitle(std::string const &title, int axis=1)
void setBinLabel(int bin, std::string const &label, int axis=1)
void setAxisRange(double xmin, double xmax, int axis=1)
void fill(Args &&...args) const
void setAxisTimeFormat(const char *format="", int axis=1)
ConcurrentMonitorElement & operator=(ConcurrentMonitorElement const &)=delete
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void setXTitle(const char *title)
void setXTitle(std::string const &title)