CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SQLMonitoringService.cc
Go to the documentation of this file.
1 #include "SQLMonitoringService.h"
2 #include "RelationalAccess/MonitoringException.h"
3 #include "CoralBase/MessageStream.h"
4 #include "CoralKernel/Context.h"
5 #include "CoralKernel/IHandle.h"
7 
8 namespace cond
9 {
11  : active( false ), level( coral::monitor::Default ), stream()
12  {
13  }
14 
15  SessionMonitor::SessionMonitor( bool act, coral::monitor::Level lvl )
16  : active( act ), level( lvl ), stream()
17  {
18  }
19 
21  : coral::Service( key ),
22  m_events()
23  {
24  }
25 
27  {
28  }
29 
30  void SQLMonitoringService::setLevel( const std::string& contextKey, coral::monitor::Level level )
31  {
32  Repository::const_iterator rit;
33 
34  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
35  {
36  m_events[contextKey] = SessionMonitor();
37  m_monitoredDS.insert( contextKey );
38  }
39 
40  m_events[contextKey].level = level;
41 
42  if( level == coral::monitor::Off )
43  {
44  m_events[contextKey].active = false;
45  }
46  else
47  {
48  m_events[contextKey].active = true;
49  }
50  }
51 
52  coral::monitor::Level SQLMonitoringService::level( const std::string& contextKey ) const
53  {
54  Repository::const_iterator rit;
55 
56  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
57  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::level", this->name() );
58 
59  return (*rit).second.level;
60  }
61 
62  bool SQLMonitoringService::active( const std::string& contextKey ) const
63  {
64  Repository::const_iterator rit;
65 
66  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
67  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::active", this->name() );
68 
69  return (*rit).second.active;
70  }
71 
72  void SQLMonitoringService::enable( const std::string& contextKey )
73  {
74  Repository::iterator rit;
75 
76  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
77  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::enable", this->name() );
78 
79  (*rit).second.active = true;
80  }
81 
82  void SQLMonitoringService::disable( const std::string& contextKey )
83  {
84  Repository::iterator rit;
85 
86  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
87  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::disable", this->name() );
88 
89  (*rit).second.active = false;
90  }
91 
92  //relaxing filter on coral monitoring level due to a bug in the connection pool
93  void SQLMonitoringService::record( const std::string& contextKey, coral::monitor::Source source, coral::monitor::Type type, const std::string& description )
94  {
95  Repository::iterator rit;
96 
97  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
98  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
99 
100  bool active = (*rit).second.active;
101  //coral::monitor::Level level = (*rit).second.level;
102 
103  if( active/* && (type & level)*/ )
104  {
105  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description ) );
106  }
107  }
108 
109  void SQLMonitoringService::record( const std::string& contextKey, coral::monitor::Source source, coral::monitor::Type type, const std::string& description, int data )
110  {
111  Repository::iterator rit;
112 
113  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
114  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
115 
116  bool active = (*rit).second.active;
117  //coral::monitor::Level level = (*rit).second.level;
118 
119  if( active/* && (type & level)*/ )
120  {
121  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description, data ) );
122  }
123  }
124 
125  void SQLMonitoringService::record( const std::string& contextKey, coral::monitor::Source source, coral::monitor::Type type, const std::string& description, long long data )
126  {
127  Repository::iterator rit;
128 
129  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
130  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
131 
132  bool active = (*rit).second.active;
133  //coral::monitor::Level level = (*rit).second.level;
134 
135  if( active/* && (type & level)*/ )
136  {
137  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description, data ) );
138  }
139  }
140 
141  void SQLMonitoringService::record( const std::string& contextKey, coral::monitor::Source source, coral::monitor::Type type, const std::string& description, double data )
142  {
143  Repository::iterator rit;
144 
145  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
146  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
147 
148  bool active = (*rit).second.active;
149  //coral::monitor::Level level = (*rit).second.level;
150 
151  if( active/* && (type & level)*/ )
152  {
153  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description, data ) );
154  }
155  }
156 
157  void SQLMonitoringService::record( const std::string& contextKey, coral::monitor::Source source, coral::monitor::Type type, const std::string& description, const std::string& data )
158  {
159  Repository::iterator rit;
160 
161  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
162  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
163 
164  bool active = (*rit).second.active;
165  //coral::monitor::Level level = (*rit).second.level;
166 
167  if( active /*&& (type & level)*/ )
168  {
169  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description, data ) );
170  }
171  }
172 
173  const coral::IMonitoringReporter& SQLMonitoringService::reporter() const
174  {
175  return( static_cast<const coral::IMonitoringReporter&>(*this) );
176  }
177 
178  // The coral::IMonitoringReporter interface implementation
179  std::set< std::string > SQLMonitoringService::monitoredDataSources() const
180  {
181  return m_monitoredDS;
182  }
183 
184  void SQLMonitoringService::report( unsigned int /*level*/ ) const
185  {
186  Repository::const_iterator rit;
187  coral::MessageStream log( "MonitoringService" );
188 
189  // Dummy reporting so far
190  for( rit = m_events.begin(); rit != m_events.end(); ++rit )
191  reportForSession( rit, log );
192  }
193 
194  void SQLMonitoringService::report( const std::string& contextKey, unsigned int /* level */ ) const
195  {
196  Repository::const_iterator rit;
197 
198  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
199  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
200 
201  // Dummy reporting so far
202  coral::MessageStream log( "MonitoringService" );
203 
204  reportForSession( rit, log );
205  }
206 
207  void SQLMonitoringService::reportToOutputStream( const std::string& contextKey, std::ostream& os, unsigned int /* level */ ) const
208  {
209  Repository::const_iterator rit;
210 
211  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
212  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
213 
214  // Dummy reporting so far
215  coral::MessageStream log( "MonitoringService" );
216 
217  reportForSession( rit, os );
218  }
219 
220  void SQLMonitoringService::reportOnEvent( EventStream::const_iterator& it, std::ostream& os ) const
221  {
222  if(it->m_source == coral::monitor::Statement)
223  {
224  os << (*it).m_description << ";"<< std::endl;
225  }
226  }
227 
228 
229  void SQLMonitoringService::reportOnEvent( EventStream::const_iterator& it,coral::MessageStream& os ) const
230  {
231  if(it->m_source == coral::monitor::Statement)
232  {
233  os << (*it).m_description <<coral::MessageStream::flush;
234  }
235  }
236 
237  void SQLMonitoringService::reportForSession( Repository::const_iterator& it, std::ostream& os ) const
238  {
239  const EventStream& evsref = (*it).second.stream;
240 
241  for( EventStream::const_iterator evit = evsref.begin(); evit != evsref.end(); ++evit )
242  {
243  reportOnEvent( evit, os );
244  }
245  }
246 
247  void SQLMonitoringService::reportForSession( Repository::const_iterator& it, coral::MessageStream& os ) const
248  {
249  const EventStream& evsref = (*it).second.stream;
250 
251  for( EventStream::const_iterator evit = evsref.begin(); evit != evsref.end(); ++evit )
252  {
253  reportOnEvent( evit, os );
254  }
255 
256  }
257 
258 } // namespace cond
259 
260 DEFINE_CORALSERVICE(cond::SQLMonitoringService,"COND/Services/SQLMonitoringService");
SQLMonitoringService(const std::string &)
type
Definition: HCALResponse.h:22
#define Default
Definition: vmac.h:109
virtual void disable(const std::string &contextKey)
void reportOnEvent(EventStream::const_iterator &it, std::ostream &os) const
#define DEFINE_CORALSERVICE(type, name)
virtual void record(const std::string &contextKey, coral::monitor::Source source, coral::monitor::Type type, const std::string &description)
virtual void reportToOutputStream(const std::string &contextKey, std::ostream &os, unsigned int level) const
virtual std::set< std::string > monitoredDataSources() const
virtual void report(unsigned int level) const
virtual void setLevel(const std::string &contextKey, coral::monitor::Level level)
std::vector< coral::monitor::Event::Record > EventStream
The raw stream of recorder monitoring events.
tuple description
Definition: idDealer.py:66
virtual const coral::IMonitoringReporter & reporter() const
The session related book-keeping of monitored events.
Log< T >::type log(const T &t)
Definition: Log.h:22
virtual void enable(const std::string &contextKey)
Repository m_events
The all events repository classified by the sessions&#39; keys.
void reportForSession(Repository::const_iterator &it, std::ostream &os) const
list key
Definition: combine.py:13
virtual coral::monitor::Level level(const std::string &contextKey) const
tuple level
Definition: testEve_cfg.py:34
virtual bool active(const std::string &contextKey) const
std::set< std::string > m_monitoredDS