CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/EventFilter/SMProxyServer/interface/DataRetrieverMonitorCollection.h

Go to the documentation of this file.
00001 // $Id: DataRetrieverMonitorCollection.h,v 1.1.4.2 2011/03/07 12:01:12 mommsen Exp $
00003 
00004 #ifndef EventFilter_SMProxyServer_DataRetrieverMonitorCollection_h
00005 #define EventFilter_SMProxyServer_DataRetrieverMonitorCollection_h
00006 
00007 #include "EventFilter/SMProxyServer/interface/ConnectionID.h"
00008 #include "EventFilter/StorageManager/interface/DQMEventConsumerRegistrationInfo.h"
00009 #include "EventFilter/StorageManager/interface/EventConsumerRegistrationInfo.h"
00010 #include "EventFilter/StorageManager/interface/MonitorCollection.h"
00011 #include "EventFilter/StorageManager/interface/MonitoredQuantity.h"
00012 #include "EventFilter/StorageManager/interface/RegistrationInfoBase.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 
00015 #include <boost/shared_ptr.hpp>
00016 #include <boost/thread.hpp>
00017 
00018 #include <map>
00019 #include <string>
00020 #include <vector>
00021 
00022 
00023 namespace smproxy {
00024 
00033   class DataRetrieverMonitorCollection : public stor::MonitorCollection
00034   {
00035   public:
00036 
00037     enum ConnectionStatus { CONNECTED, CONNECTION_FAILED, DISCONNECTED, UNKNOWN };
00038     
00039     struct SummaryStats
00040     {
00041       size_t registeredSMs;
00042       size_t activeSMs;
00043       stor::MonitoredQuantity::Stats sizeStats;         //kB
00044 
00045       typedef std::pair<stor::RegPtr, stor::MonitoredQuantity::Stats> EventTypeStats;
00046       typedef std::vector<EventTypeStats> EventTypeStatList;
00047       EventTypeStatList eventTypeStats;
00048     };
00049 
00050     typedef std::map<std::string, stor::MonitoredQuantity::Stats> ConnectionStats;
00051 
00052     struct EventTypeStats
00053     {
00054       stor::RegPtr regPtr;
00055       ConnectionStatus connectionStatus;
00056       stor::MonitoredQuantity::Stats sizeStats;         //kB
00057 
00058       bool operator<(const EventTypeStats&) const;
00059     };
00060     typedef std::vector<EventTypeStats> EventTypeStatList;
00061     
00062     
00063     explicit DataRetrieverMonitorCollection(const stor::utils::Duration_t& updateInterval);
00064     
00069     ConnectionID addNewConnection(const stor::RegPtr);
00070 
00074     bool setConnectionStatus(const ConnectionID&, const ConnectionStatus&);
00075 
00080     bool getEventTypeStatsForConnection(const ConnectionID&, EventTypeStats&);
00081 
00086     bool addRetrievedSample(const ConnectionID&, const unsigned int& size);
00087     
00091     void getSummaryStats(SummaryStats&) const;
00092 
00096     void getStatsByConnection(ConnectionStats&) const;
00097 
00101     void getStatsByEventTypes(EventTypeStatList&) const;
00102     
00103 
00104   private:
00105     
00106     stor::MonitoredQuantity totalSize_;
00107 
00108     struct DataRetrieverMQ
00109     {
00110       stor::RegPtr regPtr_;
00111       ConnectionStatus connectionStatus_;
00112       stor::MonitoredQuantity size_;       //kB
00113 
00114       DataRetrieverMQ
00115       (
00116         stor::RegPtr,
00117         const stor::utils::Duration_t& updateInterval
00118       );
00119     };
00120 
00121     //Prevent copying of the DataRetrieverMonitorCollection
00122     DataRetrieverMonitorCollection(DataRetrieverMonitorCollection const&);
00123     DataRetrieverMonitorCollection& operator=(DataRetrieverMonitorCollection const&);
00124 
00125     const stor::utils::Duration_t updateInterval_;
00126     typedef boost::shared_ptr<DataRetrieverMQ> DataRetrieverMQPtr;
00127     typedef std::map<ConnectionID, DataRetrieverMQPtr> RetrieverMqMap;
00128     RetrieverMqMap retrieverMqMap_;
00129 
00130     typedef std::map<std::string, stor::MonitoredQuantityPtr> ConnectionMqMap;
00131     ConnectionMqMap connectionMqMap_;
00132 
00133     mutable boost::mutex statsMutex_;
00134     ConnectionID nextConnectionId_;
00135 
00136     virtual void do_calculateStatistics();
00137     virtual void do_reset();
00138     // virtual void do_appendInfoSpaceItems(InfoSpaceItems&);
00139     // virtual void do_updateInfoSpaceItems();
00140 
00141     class EventTypeMqMap
00142     {
00143     public:
00144 
00145       EventTypeMqMap(const stor::utils::Duration_t& updateInterval)
00146       : updateInterval_(updateInterval) {}
00147 
00148       bool insert(const stor::RegPtr);
00149       bool addSample(const stor::RegPtr, const double& sizeKB);
00150       void getStats(SummaryStats::EventTypeStatList&) const;
00151       void calculateStatistics();
00152       void clear();
00153 
00154     private:
00155 
00156       bool insert(const stor::EventConsRegPtr);
00157       bool insert(const stor::DQMEventConsRegPtr);
00158       bool addSample(const stor::EventConsRegPtr, const double& sizeKB);
00159       bool addSample(const stor::DQMEventConsRegPtr, const double& sizeKB);
00160       
00161       typedef std::map<stor::EventConsRegPtr, stor::MonitoredQuantityPtr,
00162                        stor::utils::ptrComp<stor::EventConsumerRegistrationInfo>
00163                        > EventMap;
00164       EventMap eventMap_;
00165       
00166       typedef std::map<stor::DQMEventConsRegPtr, stor::MonitoredQuantityPtr,
00167                      stor::utils::ptrComp<stor::DQMEventConsumerRegistrationInfo>
00168                      > DQMEventMap;
00169       DQMEventMap dqmEventMap_;
00170       
00171       const stor::utils::Duration_t updateInterval_;
00172     };
00173 
00174     EventTypeMqMap eventTypeMqMap_;
00175 
00176   };
00177 
00178   std::ostream& operator<<(std::ostream&, const DataRetrieverMonitorCollection::ConnectionStatus&);
00179 
00180   
00181 } // namespace smproxy
00182 
00183 #endif // EventFilter_SMProxyServer_DataRetrieverMonitorCollection_h 
00184 
00185