CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RunMonitorCollection.cc
Go to the documentation of this file.
1 // $Id: RunMonitorCollection.cc,v 1.18 2012/06/08 10:20:33 mommsen Exp $
3 
4 #include <string>
5 #include <sstream>
6 #include <iomanip>
7 #include <algorithm>
8 
9 #include <boost/bind.hpp>
10 
15 
16 
17 namespace stor {
18 
20  (
21  const utils::Duration_t& updateInterval,
23  ) :
24  MonitorCollection(updateInterval),
25  eventIDsReceived_(updateInterval, boost::posix_time::seconds(1)),
26  errorEventIDsReceived_(updateInterval, boost::posix_time::seconds(1)),
27  unwantedEventIDsReceived_(updateInterval, boost::posix_time::seconds(1)),
28  runNumbersSeen_(updateInterval, boost::posix_time::seconds(1)),
29  lumiSectionsSeen_(updateInterval, boost::posix_time::seconds(1)),
30  eolsSeen_(updateInterval, boost::posix_time::seconds(1)),
31  sharedResources_(sr)
32  {}
33 
34 
36  {
37  alarmParams_ = alarmParams;
38  }
39 
40 
42  {
49 
51  }
52 
53 
55  {
61  eolsSeen_.reset();
62 
63  unwantedEventsMap_.clear();
64  }
65 
66 
68  {
69  infoSpaceItems.push_back(std::make_pair("runNumber", &runNumber_));
70  infoSpaceItems.push_back(std::make_pair("dataEvents", &dataEvents_));
71  infoSpaceItems.push_back(std::make_pair("errorEvents", &errorEvents_));
72  infoSpaceItems.push_back(std::make_pair("unwantedEvents", &unwantedEvents_));
73  }
74 
75 
77  {
78  MonitoredQuantity::Stats runNumberStats;
79  runNumbersSeen_.getStats(runNumberStats);
80  runNumber_ = static_cast<xdata::UnsignedInteger32>(
81  static_cast<unsigned int>(runNumberStats.getLastSampleValue()));
82 
83  MonitoredQuantity::Stats eventIDsReceivedStats;
84  eventIDsReceived_.getStats(eventIDsReceivedStats);
85  dataEvents_ = static_cast<xdata::UnsignedInteger32>(
86  static_cast<unsigned int>(eventIDsReceivedStats.getSampleCount()));
87 
88  MonitoredQuantity::Stats errorEventIDsReceivedStats;
89  errorEventIDsReceived_.getStats(errorEventIDsReceivedStats);
90  errorEvents_ = static_cast<xdata::UnsignedInteger32>(
91  static_cast<unsigned int>(errorEventIDsReceivedStats.getSampleCount()));
92 
93  MonitoredQuantity::Stats unwantedEventStats;
94  unwantedEventIDsReceived_.getStats(unwantedEventStats);
95  unwantedEvents_ = static_cast<xdata::UnsignedInteger32>(
96  static_cast<unsigned int>(unwantedEventStats.getSampleCount()));
97  }
98 
99 
101  {
102  if ( ! alarmParams_.careAboutUnwantedEvents_ ) return;
103  if ( ioc.faulty() || !ioc.complete() ) return;
104 
106 
107  uint32_t outputModuleId = ioc.outputModuleId();
108 
109  boost::mutex::scoped_lock sl(unwantedEventMapLock_);
110 
111  UnwantedEventsMap::iterator pos = unwantedEventsMap_.lower_bound(outputModuleId);
112 
113  if(pos != unwantedEventsMap_.end() &&
114  !(unwantedEventsMap_.key_comp()(outputModuleId, pos->first)))
115  {
116  // key already exists
117  ++(pos->second.count);
118  }
119  else
120  {
121  UnwantedEvent newEvent(ioc);
122  unwantedEventsMap_.insert(pos, UnwantedEventsMap::value_type(outputModuleId, newEvent));
123  }
124  }
125 
126 
128  {
130 
131  boost::mutex::scoped_lock sl(unwantedEventMapLock_);
132  std::for_each(unwantedEventsMap_.begin(), unwantedEventsMap_.end(),
133  boost::bind(&RunMonitorCollection::alarmUnwantedEvents, this, _1));
134  }
135 
136 
138  {
139  if ( ! alarmParams_.isProductionSystem_ ) return;
140 
141  const std::string alarmName("ErrorEvents");
142 
146 
147  if ( count >= alarmParams_.errorEvents_ )
148  {
149  std::ostringstream msg;
150  msg << "Received " << count << " error events in the last "
151  << stats.getDuration(MonitoredQuantity::RECENT).total_seconds() << "s.";
152  XCEPT_DECLARE( stor::exception::ErrorEvents, xcept, msg.str() );
153  sharedResources_->alarmHandler_->raiseAlarm( alarmName, AlarmHandler::ERROR, xcept );
154  }
155  else
156  {
157  sharedResources_->alarmHandler_->revokeAlarm( alarmName );
158  }
159  }
160 
161 
163  {
164  if ( ! alarmParams_.isProductionSystem_ ) return;
165 
166  if ( (val.second.count - val.second.previousCount) > alarmParams_.unwantedEvents_ )
167  {
168  std::ostringstream msg;
169  msg << "Received " << val.second.count << " events"
170  << " not tagged for any stream or consumer."
171  << " Output module " <<
172  sharedResources_->initMsgCollection_->getOutputModuleName(val.first)
173  << " (id " << val.first << ")"
174  << " HLT trigger bits: ";
175 
176  // This code snipped taken from evm:EventSelector::acceptEvent
177  int byteIndex = 0;
178  int subIndex = 0;
179  for (unsigned int pathIndex = 0;
180  pathIndex < val.second.hltTriggerCount;
181  ++pathIndex)
182  {
183  int state = val.second.bitList[byteIndex] >> (subIndex * 2);
184  state &= 0x3;
185  msg << state << " ";
186  ++subIndex;
187  if (subIndex == 4)
188  { ++byteIndex;
189  subIndex = 0;
190  }
191  }
192 
193  XCEPT_DECLARE( stor::exception::UnwantedEvents, xcept, msg.str() );
194  sharedResources_->alarmHandler_->raiseAlarm( val.second.alarmName, AlarmHandler::ERROR, xcept );
195 
196  val.second.previousCount = val.second.count;
197  }
198  else if (val.second.count == val.second.previousCount)
199  // no more unwanted events arrived
200  {
201  sharedResources_->alarmHandler_->revokeAlarm( val.second.alarmName );
202  }
203  }
204 
205 
207  : count(1), previousCount(0)
208  {
209  std::ostringstream str;
210  str << "UnwantedEvent_" << nextId++;
211  alarmName = str.str();
213  ioc.hltTriggerBits(bitList);
214  }
215 
217 
218 } // namespace stor
219 
xdata::UnsignedInteger32 dataEvents_
void configureAlarms(AlarmParams const &)
double seconds()
RunMonitorCollection(const utils::Duration_t &updateInterval, SharedResourcesPtr)
xdata::UnsignedInteger32 runNumber_
void addSample(const double &value=1)
bool complete() const
Definition: I2OChain.cc:118
MonitoredQuantity errorEventIDsReceived_
uint64_t getSampleCount(DataSetType t=FULL) const
boost::shared_ptr< SharedResources > SharedResourcesPtr
void getStats(Stats &stats) const
void hltTriggerBits(std::vector< unsigned char > &bitList) const
Definition: I2OChain.cc:565
UnwantedEventsMap unwantedEventsMap_
utils::Duration_t getDuration(DataSetType t=FULL) const
void calculateStatistics(const utils::TimePoint_t &currentTime=utils::getCurrentTime())
boost::posix_time::time_duration Duration_t
Definition: Utils.h:41
void alarmUnwantedEvents(UnwantedEventsMap::value_type &)
unsigned int unwantedEvents_
MonitoredQuantity lumiSectionsSeen_
Container::value_type value_type
SharedResourcesPtr sharedResources_
xdata::UnsignedInteger32 unwantedEvents_
MonitoredQuantity unwantedEventIDsReceived_
std::vector< std::pair< std::string, xdata::Serializable * > > InfoSpaceItems
char state
Definition: procUtils.cc:75
MonitoredQuantity eventIDsReceived_
unsigned int errorEvents_
uint32_t hltTriggerCount() const
Definition: I2OChain.cc:555
void addUnwantedEvent(const I2OChain &)
virtual void do_appendInfoSpaceItems(InfoSpaceItems &)
xdata::UnsignedInteger32 errorEvents_
uint32_t eventNumber() const
Definition: I2OChain.cc:605
bool faulty() const
Definition: I2OChain.cc:125
uint32_t outputModuleId() const
Definition: I2OChain.cc:505