CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/SMProxyServer/interface/DataRetrieverMonitorCollection.h

Go to the documentation of this file.
00001 // $Id: DataRetrieverMonitorCollection.h,v 1.3 2011/05/09 11:03:25 mommsen Exp $
00003 
00004 #ifndef EventFilter_SMProxyServer_DataRetrieverMonitorCollection_h
00005 #define EventFilter_SMProxyServer_DataRetrieverMonitorCollection_h
00006 
00007 #include "EventFilter/SMProxyServer/interface/Configuration.h"
00008 #include "EventFilter/SMProxyServer/interface/ConnectionID.h"
00009 #include "EventFilter/StorageManager/interface/AlarmHandler.h"
00010 #include "EventFilter/StorageManager/interface/DQMEventConsumerRegistrationInfo.h"
00011 #include "EventFilter/StorageManager/interface/EventConsumerRegistrationInfo.h"
00012 #include "EventFilter/StorageManager/interface/MonitorCollection.h"
00013 #include "EventFilter/StorageManager/interface/MonitoredQuantity.h"
00014 #include "EventFilter/StorageManager/interface/RegistrationInfoBase.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016 
00017 #include <boost/shared_ptr.hpp>
00018 #include <boost/thread.hpp>
00019 
00020 #include <map>
00021 #include <string>
00022 #include <vector>
00023 
00024 
00025 namespace smproxy {
00026 
00035   class DataRetrieverMonitorCollection : public stor::MonitorCollection
00036   {
00037   public:
00038 
00039     enum ConnectionStatus { CONNECTED, CONNECTION_FAILED, DISCONNECTED, UNKNOWN };
00040 
00041     struct EventStats
00042     {
00043       stor::MonitoredQuantity::Stats sizeStats; //kB
00044       stor::MonitoredQuantity::Stats corruptedEventsStats;
00045     };
00046     
00047     struct SummaryStats
00048     {
00049       size_t registeredSMs;
00050       size_t activeSMs;
00051       EventStats totals;
00052 
00053       typedef std::pair<stor::RegPtr, EventStats> EventTypeStats;
00054       typedef std::vector<EventTypeStats> EventTypeStatList;
00055       EventTypeStatList eventTypeStats;
00056     };
00057 
00058     typedef std::map<std::string, EventStats> ConnectionStats;
00059 
00060     struct EventTypePerConnectionStats
00061     {
00062       stor::RegPtr regPtr;
00063       ConnectionStatus connectionStatus;
00064       EventStats eventStats;
00065 
00066       bool operator<(const EventTypePerConnectionStats&) const;
00067     };
00068     typedef std::vector<EventTypePerConnectionStats> EventTypePerConnectionStatList;
00069     
00070     
00071     DataRetrieverMonitorCollection
00072     (
00073       const stor::utils::Duration_t& updateInterval,
00074       stor::AlarmHandlerPtr
00075     );
00076     
00081     ConnectionID addNewConnection(const stor::RegPtr);
00082 
00086     bool setConnectionStatus(const ConnectionID&, const ConnectionStatus&);
00087 
00092     bool getEventTypeStatsForConnection(const ConnectionID&, EventTypePerConnectionStats&);
00093 
00098     bool addRetrievedSample(const ConnectionID&, const unsigned int& size);
00099 
00104     bool receivedCorruptedEvent(const ConnectionID&);
00105 
00109     void getSummaryStats(SummaryStats&) const;
00110 
00114     void getStatsByConnection(ConnectionStats&) const;
00115 
00119     void getStatsByEventTypesPerConnection(EventTypePerConnectionStatList&) const;
00120 
00124     void configureAlarms(AlarmParams const&);
00125 
00126   private:
00127     
00128     struct EventMQ
00129     {
00130       stor::MonitoredQuantity size_;       //kB
00131       stor::MonitoredQuantity corruptedEvents_;
00132 
00133       EventMQ(const stor::utils::Duration_t& updateInterval);
00134       void getStats(EventStats&) const;
00135       void calculateStatistics();
00136       void reset();
00137     };
00138     typedef boost::shared_ptr<EventMQ> EventMQPtr;
00139 
00140     struct DataRetrieverMQ
00141     {
00142       stor::RegPtr regPtr_;
00143       ConnectionStatus connectionStatus_;
00144       EventMQPtr eventMQ_;
00145 
00146       DataRetrieverMQ
00147       (
00148         stor::RegPtr,
00149         const stor::utils::Duration_t& updateInterval
00150       );
00151     };
00152 
00153     //Prevent copying of the DataRetrieverMonitorCollection
00154     DataRetrieverMonitorCollection(DataRetrieverMonitorCollection const&);
00155     DataRetrieverMonitorCollection& operator=(DataRetrieverMonitorCollection const&);
00156 
00157     const stor::utils::Duration_t updateInterval_;
00158     stor::AlarmHandlerPtr alarmHandler_;
00159 
00160     AlarmParams alarmParams_;
00161     EventMQ totals_;
00162 
00163     typedef boost::shared_ptr<DataRetrieverMQ> DataRetrieverMQPtr;
00164     typedef std::map<ConnectionID, DataRetrieverMQPtr> RetrieverMqMap;
00165     RetrieverMqMap retrieverMqMap_;
00166 
00167     typedef std::map<std::string, EventMQPtr> ConnectionMqMap;
00168     ConnectionMqMap connectionMqMap_;
00169 
00170     mutable boost::mutex statsMutex_;
00171     ConnectionID nextConnectionId_;
00172 
00173     void sendAlarms();
00174     void checkForCorruptedEvents();
00175     virtual void do_calculateStatistics();
00176     virtual void do_reset();
00177     // virtual void do_appendInfoSpaceItems(InfoSpaceItems&);
00178     // virtual void do_updateInfoSpaceItems();
00179 
00180     class EventTypeMqMap
00181     {
00182     public:
00183 
00184       EventTypeMqMap(const stor::utils::Duration_t& updateInterval)
00185       : updateInterval_(updateInterval) {}
00186 
00187       bool insert(const stor::RegPtr);
00188       bool addSample(const stor::RegPtr, const double& sizeKB);
00189       bool receivedCorruptedEvent(const stor::RegPtr);
00190       void getStats(SummaryStats::EventTypeStatList&) const;
00191       void calculateStatistics();
00192       void clear();
00193 
00194     private:
00195 
00196       bool insert(const stor::EventConsRegPtr);
00197       bool insert(const stor::DQMEventConsRegPtr);
00198       bool addSample(const stor::EventConsRegPtr, const double& sizeKB);
00199       bool addSample(const stor::DQMEventConsRegPtr, const double& sizeKB);
00200       bool receivedCorruptedEvent(const stor::EventConsRegPtr);
00201       bool receivedCorruptedEvent(const stor::DQMEventConsRegPtr);
00202       
00203       typedef std::map<stor::EventConsRegPtr, EventMQPtr,
00204                        stor::utils::ptrComp<stor::EventConsumerRegistrationInfo>
00205                        > EventMap;
00206       EventMap eventMap_;
00207       
00208       typedef std::map<stor::DQMEventConsRegPtr, EventMQPtr,
00209                      stor::utils::ptrComp<stor::DQMEventConsumerRegistrationInfo>
00210                      > DQMEventMap;
00211       DQMEventMap dqmEventMap_;
00212       
00213       const stor::utils::Duration_t updateInterval_;
00214     };
00215 
00216     EventTypeMqMap eventTypeMqMap_;
00217 
00218   };
00219 
00220   std::ostream& operator<<(std::ostream&, const DataRetrieverMonitorCollection::ConnectionStatus&);
00221 
00222   
00223 } // namespace smproxy
00224 
00225 #endif // EventFilter_SMProxyServer_DataRetrieverMonitorCollection_h 
00226 
00227