CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/StorageManager/interface/StreamsMonitorCollection.h

Go to the documentation of this file.
00001 // $Id: StreamsMonitorCollection.h,v 1.16 2011/06/20 16:38:51 mommsen Exp $
00003 
00004 #ifndef EventFilter_StorageManager_StreamsMonitorCollection_h
00005 #define EventFilter_StorageManager_StreamsMonitorCollection_h
00006 
00007 #include <sstream>
00008 #include <iomanip>
00009 #include <vector>
00010 #include <set>
00011 
00012 #include <boost/thread/mutex.hpp>
00013 #include <boost/shared_ptr.hpp>
00014 
00015 #include "xdata/Double.h"
00016 #include "xdata/String.h"
00017 #include "xdata/UnsignedInteger32.h"
00018 #include "xdata/Vector.h"
00019 
00020 #include "EventFilter/StorageManager/interface/DbFileHandler.h"
00021 #include "EventFilter/StorageManager/interface/MonitorCollection.h"
00022 #include "EventFilter/StorageManager/interface/Utils.h"
00023 
00024 
00025 namespace stor {
00026 
00035   class StreamsMonitorCollection : public MonitorCollection
00036   {
00037   public:
00038 
00039     struct StreamRecord
00040     {
00041       StreamRecord
00042       (
00043         StreamsMonitorCollection* coll,
00044         const utils::Duration_t& updateInterval,
00045         const utils::Duration_t& timeWindowForRecentResults
00046       ) :
00047       fileCount(updateInterval,timeWindowForRecentResults),
00048       volume(updateInterval,timeWindowForRecentResults),
00049       bandwidth(updateInterval,timeWindowForRecentResults),
00050       parentCollection(coll) {}
00051 
00052       ~StreamRecord()
00053       { fileCountPerLS.clear(); }
00054 
00055       void incrementFileCount(const uint32_t lumiSection);
00056       void addSizeInBytes(double);
00057       bool reportLumiSectionInfo
00058       (
00059         const uint32_t& lumiSection,
00060         std::string& str
00061       );
00062       
00063       std::string streamName;       // name of the stream
00064       double fractionToDisk;        // fraction of events written to disk
00065       MonitoredQuantity fileCount;  // number of files written for this stream
00066       MonitoredQuantity volume;     // data in MBytes stored in this stream
00067       MonitoredQuantity bandwidth;  // bandwidth in MBytes for this stream
00068 
00069       StreamsMonitorCollection* parentCollection;
00070 
00071       typedef std::map<uint32_t, unsigned int> FileCountPerLumiSectionMap;
00072       FileCountPerLumiSectionMap fileCountPerLS;
00073     };
00074 
00075     // We do not know how many streams there will be.
00076     // Thus, we need a vector of them.
00077     typedef boost::shared_ptr<StreamRecord> StreamRecordPtr;
00078     typedef std::vector<StreamRecordPtr> StreamRecordList;
00079 
00080 
00081     struct EndOfRunReport
00082     {
00083       EndOfRunReport() { reset(); }
00084 
00085       void reset()
00086       { latestLumiSectionWritten = eolsCount = lsCountWithFiles = 0; }
00087 
00088       void updateLatestWrittenLumiSection(uint32_t ls)
00089       {
00090         if (ls > latestLumiSectionWritten) latestLumiSectionWritten = ls;
00091       }
00092 
00093       uint32_t latestLumiSectionWritten;
00094       unsigned int eolsCount;
00095       unsigned int lsCountWithFiles;
00096     };
00097     typedef boost::shared_ptr<EndOfRunReport> EndOfRunReportPtr;
00098 
00099 
00100     explicit StreamsMonitorCollection(const utils::Duration_t& updateInterval);
00101 
00102     StreamRecordPtr getNewStreamRecord();
00103 
00104     void getStreamRecords(StreamRecordList&) const;
00105 
00106     bool streamRecordsExist() const;
00107 
00108     const MonitoredQuantity& getAllStreamsFileCountMQ() const {
00109       return allStreamsFileCount_;
00110     }
00111     MonitoredQuantity& getAllStreamsFileCountMQ() {
00112       return allStreamsFileCount_;
00113     }
00114 
00115     const MonitoredQuantity& getAllStreamsVolumeMQ() const {
00116       return allStreamsVolume_;
00117     }
00118     MonitoredQuantity& getAllStreamsVolumeMQ() {
00119       return allStreamsVolume_;
00120     }
00121 
00122     const MonitoredQuantity& getAllStreamsBandwidthMQ() const {
00123       return allStreamsBandwidth_;
00124     }
00125     MonitoredQuantity& getAllStreamsBandwidthMQ() {
00126       return allStreamsBandwidth_;
00127     }
00128 
00129     void reportAllLumiSectionInfos(DbFileHandlerPtr, EndOfRunReportPtr);
00130 
00131 
00132   private:
00133 
00134     //Prevent copying of the StreamsMonitorCollection
00135     StreamsMonitorCollection(StreamsMonitorCollection const&);
00136     StreamsMonitorCollection& operator=(StreamsMonitorCollection const&);
00137 
00138     typedef std::set<uint32_t> UnreportedLS;
00139     void getListOfAllUnreportedLS(UnreportedLS&);
00140 
00141     virtual void do_calculateStatistics();
00142     virtual void do_reset();
00143     virtual void do_appendInfoSpaceItems(InfoSpaceItems&);
00144     virtual void do_updateInfoSpaceItems();
00145 
00146     StreamRecordList streamRecords_;
00147     mutable boost::mutex streamRecordsMutex_;
00148 
00149     const utils::Duration_t updateInterval_;
00150     const utils::Duration_t timeWindowForRecentResults_;
00151 
00152     MonitoredQuantity allStreamsFileCount_;
00153     MonitoredQuantity allStreamsVolume_;
00154     MonitoredQuantity allStreamsBandwidth_;
00155 
00156     xdata::UnsignedInteger32 storedEvents_;   // number of events stored in all streams
00157     xdata::Double storedVolume_;              // total volume in MB stored on disk
00158     xdata::Double bandwidthToDisk_;           // recent bandwidth in MB/s written to disk
00159     xdata::Vector<xdata::String> streamNames_; // names of all streams written
00160     xdata::Vector<xdata::UnsignedInteger32> eventsPerStream_; // total number of events stored per stream
00161     xdata::Vector<xdata::Double> ratePerStream_; // recent event rate (Hz) per stream
00162     xdata::Vector<xdata::Double> bandwidthPerStream_; // recent bandwidth (MB/s) per stream
00163   };
00164   
00165 } // namespace stor
00166 
00167 #endif // EventFilter_StorageManager_StreamsMonitorCollection_h 
00168 
00169