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.15 2011/03/07 15:31:32 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,
22  AlarmHandlerPtr ah,
24  ) :
25  MonitorCollection(updateInterval),
26  eventIDsReceived_(updateInterval, boost::posix_time::seconds(1)),
27  errorEventIDsReceived_(updateInterval, boost::posix_time::seconds(1)),
28  unwantedEventIDsReceived_(updateInterval, boost::posix_time::seconds(1)),
29  runNumbersSeen_(updateInterval, boost::posix_time::seconds(1)),
30  lumiSectionsSeen_(updateInterval, boost::posix_time::seconds(1)),
31  eolsSeen_(updateInterval, boost::posix_time::seconds(1)),
32  alarmHandler_(ah),
33  sharedResources_(sr)
34  {}
35 
36 
38  {
39  alarmParams_ = alarmParams;
40  }
41 
42 
44  {
51 
53  }
54 
55 
57  {
63  eolsSeen_.reset();
64 
65  unwantedEventsMap_.clear();
66  }
67 
68 
70  {
71  infoSpaceItems.push_back(std::make_pair("runNumber", &runNumber_));
72  infoSpaceItems.push_back(std::make_pair("dataEvents", &dataEvents_));
73  infoSpaceItems.push_back(std::make_pair("errorEvents", &errorEvents_));
74  infoSpaceItems.push_back(std::make_pair("unwantedEvents", &unwantedEvents_));
75  }
76 
77 
79  {
80  MonitoredQuantity::Stats runNumberStats;
81  runNumbersSeen_.getStats(runNumberStats);
82  runNumber_ = static_cast<xdata::UnsignedInteger32>(
83  static_cast<unsigned int>(runNumberStats.getLastSampleValue()));
84 
85  MonitoredQuantity::Stats eventIDsReceivedStats;
86  eventIDsReceived_.getStats(eventIDsReceivedStats);
87  dataEvents_ = static_cast<xdata::UnsignedInteger32>(
88  static_cast<unsigned int>(eventIDsReceivedStats.getSampleCount()));
89 
90  MonitoredQuantity::Stats errorEventIDsReceivedStats;
91  errorEventIDsReceived_.getStats(errorEventIDsReceivedStats);
92  errorEvents_ = static_cast<xdata::UnsignedInteger32>(
93  static_cast<unsigned int>(errorEventIDsReceivedStats.getSampleCount()));
94 
95  MonitoredQuantity::Stats unwantedEventStats;
96  unwantedEventIDsReceived_.getStats(unwantedEventStats);
97  unwantedEvents_ = static_cast<xdata::UnsignedInteger32>(
98  static_cast<unsigned int>(unwantedEventStats.getSampleCount()));
99  }
100 
101 
103  {
104  if ( ioc.faulty() || !ioc.complete() ) return;
105 
107 
108  uint32_t outputModuleId = ioc.outputModuleId();
109 
110  boost::mutex::scoped_lock sl(unwantedEventMapLock_);
111 
112  UnwantedEventsMap::iterator pos = unwantedEventsMap_.lower_bound(outputModuleId);
113 
114  if(pos != unwantedEventsMap_.end() &&
115  !(unwantedEventsMap_.key_comp()(outputModuleId, pos->first)))
116  {
117  // key already exists
118  ++(pos->second.count);
119  }
120  else
121  {
122  UnwantedEvent newEvent(ioc);
123  unwantedEventsMap_.insert(pos, UnwantedEventsMap::value_type(outputModuleId, newEvent));
124  }
125  }
126 
127 
129  {
131 
132  boost::mutex::scoped_lock sl(unwantedEventMapLock_);
133  std::for_each(unwantedEventsMap_.begin(), unwantedEventsMap_.end(),
134  boost::bind(&RunMonitorCollection::alarmUnwantedEvents, this, _1));
135  }
136 
137 
139  {
140  if ( ! alarmParams_.isProductionSystem_ ) return;
141 
142  const std::string alarmName("ErrorEvents");
143 
147 
148  if ( count >= alarmParams_.errorEvents_ )
149  {
150  std::ostringstream msg;
151  msg << "Received " << count << " error events in the last "
152  << stats.getDuration(MonitoredQuantity::RECENT).total_seconds() << "s.";
153  XCEPT_DECLARE( stor::exception::ErrorEvents, xcept, msg.str() );
154  alarmHandler_->raiseAlarm( alarmName, AlarmHandler::ERROR, xcept );
155  }
156  else
157  {
158  alarmHandler_->revokeAlarm( alarmName );
159  }
160  }
161 
162 
164  {
165  if ( ! alarmParams_.isProductionSystem_ ) return;
166 
167  if ( (val.second.count - val.second.previousCount) > alarmParams_.unwantedEvents_ )
168  {
169  std::ostringstream msg;
170  msg << "Received " << val.second.count << " events"
171  << " not tagged for any stream or consumer."
172  << " Output module " <<
173  sharedResources_->initMsgCollection_->getOutputModuleName(val.first)
174  << " (id " << val.first << ")"
175  << " HLT trigger bits: ";
176 
177  // This code snipped taken from evm:EventSelector::acceptEvent
178  int byteIndex = 0;
179  int subIndex = 0;
180  for (unsigned int pathIndex = 0;
181  pathIndex < val.second.hltTriggerCount;
182  ++pathIndex)
183  {
184  int state = val.second.bitList[byteIndex] >> (subIndex * 2);
185  state &= 0x3;
186  msg << state << " ";
187  ++subIndex;
188  if (subIndex == 4)
189  { ++byteIndex;
190  subIndex = 0;
191  }
192  }
193 
194  XCEPT_DECLARE( stor::exception::UnwantedEvents, xcept, msg.str() );
195  alarmHandler_->raiseAlarm( val.second.alarmName, AlarmHandler::ERROR, xcept );
196 
197  val.second.previousCount = val.second.count;
198  }
199  else if (val.second.count == val.second.previousCount)
200  // no more unwanted events arrived
201  {
202  alarmHandler_->revokeAlarm( val.second.alarmName );
203  }
204  }
205 
206 
208  : count(1), previousCount(0)
209  {
210  std::ostringstream str;
211  str << "UnwantedEvent_" << nextId++;
212  alarmName = str.str();
214  ioc.hltTriggerBits(bitList);
215  }
216 
218 
219 } // namespace stor
220 
xdata::UnsignedInteger32 dataEvents_
void configureAlarms(AlarmParams const &)
double seconds()
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:555
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_
boost::shared_ptr< AlarmHandler > AlarmHandlerPtr
Definition: AlarmHandler.h:91
xdata::UnsignedInteger32 unwantedEvents_
MonitoredQuantity unwantedEventIDsReceived_
std::vector< std::pair< std::string, xdata::Serializable * > > InfoSpaceItems
char state
Definition: procUtils.cc:75
MonitoredQuantity eventIDsReceived_
RunMonitorCollection(const utils::Duration_t &updateInterval, AlarmHandlerPtr, SharedResourcesPtr)
unsigned int errorEvents_
uint32_t hltTriggerCount() const
Definition: I2OChain.cc:545
void addUnwantedEvent(const I2OChain &)
virtual void do_appendInfoSpaceItems(InfoSpaceItems &)
xdata::UnsignedInteger32 errorEvents_
uint32_t eventNumber() const
Definition: I2OChain.cc:595
bool faulty() const
Definition: I2OChain.cc:125
uint32_t outputModuleId() const
Definition: I2OChain.cc:505