Ticker.cxx
Go to the documentation of this file.
1 ///
2 /// \file Ticker.cxx
3 /// \brief Notify subscribers when certain time/event intervals have elapsed
4 /// \version $Id: Ticker.cxx,v 1.5 2012-02-04 02:56:25 messier Exp $
5 /// \author messier@indiana.edu
6 ///
9 #include <iostream>
10 using namespace om;
11 
13  fLastRun (kUninitRun),
14  fLastSubrun(kUninitRun),
15  fLast30Sec (kUninitTime),
16  fLast1Min (kUninitTime),
17  fLast5Min (kUninitTime),
18  fLast10Min (kUninitTime),
19  fLast30Min (kUninitTime),
20  fLastHour (kUninitTime),
21  fLast24Hr (kUninitTime)
22 { }
23 
24 //......................................................................
25 
27 {
28  static Ticker johnbonham;
29  return johnbonham;
30 }
31 
32 //......................................................................
33 
34 void Ticker::Update(unsigned int run, unsigned int subrun)
35 {
36  // Get current UNIX time in seconds
37  time_t tt = time(0);
38  struct tm t;
39  gmtime_r(&tt, &t);
40 
41  //
42  // Initialize the counters if we have to.
43  //
46  if (fLast30Sec ==kUninitTime) fLast30Sec = t.tm_sec;
47  if (fLast1Min ==kUninitTime) fLast1Min = t.tm_min;
48  if (fLast5Min ==kUninitTime) fLast5Min = t.tm_min;
49  if (fLast10Min ==kUninitTime) fLast10Min = t.tm_min;
50  if (fLast30Min ==kUninitTime) fLast30Min = t.tm_min;
51  if (fLastHour ==kUninitTime) fLastHour = t.tm_hour;
52  if (fLast24Hr ==kUninitTime) fLast24Hr = t.tm_yday;
53 
54  bool do30sec = (t.tm_sec !=fLast30Sec && (t.tm_sec%30==0));
55  bool do1min = (t.tm_min !=fLast1Min);
56  bool do5min = (t.tm_min !=fLast5Min && (t.tm_min%5==0));
57  bool do10min = (t.tm_min !=fLast10Min && (t.tm_min%10==0));
58  bool do30min = (t.tm_min !=fLast30Min && (t.tm_min%30==0));
59  bool dohour = (t.tm_hour!=fLastHour);
60  bool do24hr = (t.tm_yday!=fLast24Hr);
61 
62  /*
63  std::cout << "**" << std::endl;
64  std::cout << "30s:\t"<<t.tm_sec<<"\t"<<fLast30Sec<<"\t"<<do30sec<<std::endl;
65  std::cout << "1m:\t" <<t.tm_min<<"\t"<<fLast1Min <<"\t"<<do1min <<std::endl;
66  std::cout << "5m:\t" <<t.tm_min<<"\t"<<fLast5Min <<"\t"<<do5min <<std::endl;
67  std::cout << "10m:\t"<<t.tm_min<<"\t"<<fLast10Min<<"\t"<<do10min<<std::endl;
68  std::cout << "30m:\t"<<t.tm_min<<"\t"<<fLast30Min<<"\t"<<do30min<<std::endl;
69  std::cout << "1h:\t" <<t.tm_hour<<"\t"<<fLastHour<<"\t"<<dohour<<std::endl;
70  std::cout << "24h:\t"<<t.tm_yday<<"\t"<<fLast24Hr<<"\t"<<do24hr<<std::endl;
71  */
72 
73  if (do30sec) { fLast30Sec = t.tm_sec; this->Publish30Sec(); }
74  if (do1min) { fLast1Min = t.tm_min; this->Publish1Min(); }
75  if (do5min) { fLast5Min = t.tm_min; this->Publish5Min(); }
76  if (do10min) { fLast10Min = t.tm_min; this->Publish10Min(); }
77  if (do30min) { fLast30Min = t.tm_min; this->Publish30Min(); }
78  if (dohour) { fLastHour = t.tm_hour; this->PublishHour(); }
79  if (do24hr) { fLast24Hr = t.tm_yday; this->Publish24Hr(); }
80 
81  //
82  // Check the run/subrun tickers and publish if we need to. Note that
83  // the "run update" should also trigger a "subrun update" since
84  // logically the last subrun of a run ends just prior to the end of
85  // the run (try saying that ten times fast!). When publishing, be
86  // sure to update the run and subrun numbers of the last update.
87  //
88  if (fLastRun!=run) {
89  fLastRun = run;
91  this->PublishSubrun();
92  this->PublishRun();
93  }
94  if (fLastSubrun!=subrun) {
96  this->PublishSubrun();
97  }
98 }
99 
100 //......................................................................
101 
103 {
104  std::list<TickerSubscriber*>::iterator i(fRunSubscribers.begin());
105  std::list<TickerSubscriber*>::iterator e(fRunSubscribers.end());
106  for (; i!=e; ++i) (*i)->RunTicker();
107 }
108 
109 //......................................................................
110 
112 {
113  std::list<TickerSubscriber*>::iterator i(fSubrunSubscribers.begin());
114  std::list<TickerSubscriber*>::iterator e(fSubrunSubscribers.end());
115  for (; i!=e; ++i) (*i)->SubrunTicker();
116 }
117 
118 //......................................................................
119 
121 {
122  std::list<TickerSubscriber*>::iterator i(f30SecSubscribers.begin());
123  std::list<TickerSubscriber*>::iterator e(f30SecSubscribers.end());
124  for (; i!=e; ++i) (*i)->ThirtySecTicker();
125 }
126 
127 //......................................................................
128 
130 {
131  std::list<TickerSubscriber*>::iterator i(f1MinSubscribers.begin());
132  std::list<TickerSubscriber*>::iterator e(f1MinSubscribers.end());
133  for (; i!=e; ++i) (*i)->OneMinTicker();
134 }
135 
136 //......................................................................
137 
139 {
140  std::list<TickerSubscriber*>::iterator i(f5MinSubscribers.begin());
141  std::list<TickerSubscriber*>::iterator e(f5MinSubscribers.end());
142  for (; i!=e; ++i) (*i)->FiveMinTicker();
143 }
144 
145 //......................................................................
146 
148 {
149  std::list<TickerSubscriber*>::iterator i(f10MinSubscribers.begin());
150  std::list<TickerSubscriber*>::iterator e(f10MinSubscribers.end());
151  for (; i!=e; ++i) (*i)->TenMinTicker();
152 }
153 
154 //......................................................................
155 
157 {
158  std::list<TickerSubscriber*>::iterator i(f30MinSubscribers.begin());
159  std::list<TickerSubscriber*>::iterator e(f30MinSubscribers.end());
160  for (; i!=e; ++i) (*i)->ThirtyMinTicker();
161 }
162 
163 //......................................................................
164 
166 {
167  std::list<TickerSubscriber*>::iterator i(fHourSubscribers.begin());
168  std::list<TickerSubscriber*>::iterator e(fHourSubscribers.end());
169  for (; i!=e; ++i) (*i)->HourTicker();
170 }
171 
172 //......................................................................
173 
175 {
176  std::list<TickerSubscriber*>::iterator i(f24HrSubscribers.begin());
177  std::list<TickerSubscriber*>::iterator e(f24HrSubscribers.end());
178  for (; i!=e; ++i) (*i)->TwentyFourHrTicker();
179 }
180 
181 //......................................................................
182 
183 void Ticker::Subscribe(TickerSubscriber* s, unsigned int which)
184 {
185  if ((which&TickerSubscriber::kRun)!=0) {
186  fRunSubscribers.push_back(s);
187  }
188  if ((which&TickerSubscriber::kSubrun)!=0) {
189  fSubrunSubscribers.push_back(s);
190  }
191  if ((which&TickerSubscriber::k30sec)!=0) {
192  f30SecSubscribers.push_back(s);
193  }
194  if ((which&TickerSubscriber::k1min)!=0) {
195  f1MinSubscribers.push_back(s);
196  }
197  if ((which&TickerSubscriber::k5min)!=0) {
198  f5MinSubscribers.push_back(s);
199  }
200  if ((which&TickerSubscriber::k10min)!=0) {
201  f10MinSubscribers.push_back(s);
202  }
203  if ((which&TickerSubscriber::k30min)!=0) {
204  f30MinSubscribers.push_back(s);
205  }
206  if ((which&TickerSubscriber::kHour)!=0) {
207  fHourSubscribers.push_back(s);
208  }
209  if ((which&TickerSubscriber::k24hr)!=0) {
210  f24HrSubscribers.push_back(s);
211  }
212 }
213 
214 ////////////////////////////////////////////////////////////////////////
static const unsigned int kUninitRun
Define what an uninitialized run/subrun number looks like.
Definition: Ticker.h:37
std::list< TickerSubscriber * > fSubrunSubscribers
Definition: Ticker.h:60
std::list< TickerSubscriber * > fHourSubscribers
Definition: Ticker.h:57
void Publish10Min()
Definition: Ticker.cxx:147
std::list< TickerSubscriber * > f10MinSubscribers
Definition: Ticker.h:55
unsigned int fLastRun
Run number of last update.
Definition: Ticker.h:43
void Publish5Min()
Definition: Ticker.cxx:138
void Update(unsigned int run, unsigned int subrun)
Definition: Ticker.cxx:34
std::list< TickerSubscriber * > f30MinSubscribers
Definition: Ticker.h:56
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
std::list< TickerSubscriber * > f30SecSubscribers
Definition: Ticker.h:52
Base class for subscribers to ticker updates.
static const int kUninitTime
Define what an uninitialized time looks like.
Definition: Ticker.h:40
int fLast30Sec
Time of last 30 second update.
Definition: Ticker.h:45
const XML_Char * s
Definition: expat.h:262
Definition: type_traits.h:56
std::list< TickerSubscriber * > fRunSubscribers
Definition: Ticker.h:59
void PublishRun()
Definition: Ticker.cxx:102
void Subscribe(TickerSubscriber *s, unsigned int which)
Definition: Ticker.cxx:183
Notify subscribers when certain time/event intervals have elapsed.
void Publish1Min()
Definition: Ticker.cxx:129
int fLast1Min
Time of last 1 minute update.
Definition: Ticker.h:46
Ticker()
Ticker is a singleton - constructor is private.
Definition: Ticker.cxx:12
std::list< TickerSubscriber * > f1MinSubscribers
Definition: Ticker.h:53
std::list< TickerSubscriber * > f5MinSubscribers
Definition: Ticker.h:54
Definition: run.py:1
static Ticker & Instance()
Definition: Ticker.cxx:26
int fLast30Min
Time of last 30 minute update.
Definition: Ticker.h:49
void Publish30Min()
Definition: Ticker.cxx:156
unsigned int fLastSubrun
Subrun number of last update.
Definition: Ticker.h:44
void Publish24Hr()
Definition: Ticker.cxx:174
void Publish30Sec()
Definition: Ticker.cxx:120
int fLast5Min
Time of last 5 minute update.
Definition: Ticker.h:47
int fLast10Min
Time of last 10 minute update.
Definition: Ticker.h:48
Float_t e
Definition: plot.C:35
int fLast24Hr
Time of last 24 hour update.
Definition: Ticker.h:51
void PublishSubrun()
Definition: Ticker.cxx:111
std::list< TickerSubscriber * > f24HrSubscribers
Definition: Ticker.h:58
int fLastHour
Time of last hour update.
Definition: Ticker.h:50
Online Monitoring package header.
void PublishHour()
Definition: Ticker.cxx:165