00001 // $Id: StreamHandler.h,v 1.15 2011/06/20 16:38:51 mommsen Exp $ 00003 00004 #ifndef EventFilter_StorageManager_StreamHandler_h 00005 #define EventFilter_StorageManager_StreamHandler_h 00006 00007 #include <stdint.h> 00008 00009 #include <boost/shared_ptr.hpp> 00010 00011 #include "EventFilter/StorageManager/interface/FilesMonitorCollection.h" 00012 #include "EventFilter/StorageManager/interface/SharedResources.h" 00013 #include "EventFilter/StorageManager/interface/StatisticsReporter.h" 00014 #include "EventFilter/StorageManager/interface/StreamsMonitorCollection.h" 00015 00016 00017 namespace stor { 00018 00019 class FileHandler; 00020 class I2OChain; 00021 00022 00031 class StreamHandler 00032 { 00033 public: 00034 00035 StreamHandler(const SharedResourcesPtr, const DbFileHandlerPtr); 00036 00037 virtual ~StreamHandler() {}; 00038 00039 00043 void closeAllFiles(); 00044 00048 void closeTimedOutFiles(utils::TimePoint_t currentTime = 00049 utils::getCurrentTime()); 00050 00057 bool closeFilesForLumiSection(const uint32_t& lumiSection, std::string&); 00058 00062 void writeEvent(const I2OChain& event); 00063 00064 00065 protected: 00066 00067 typedef boost::shared_ptr<FileHandler> FileHandlerPtr; 00068 00072 virtual std::string streamLabel() const = 0; 00073 00077 virtual double fractionToDisk() const = 0; 00078 00082 virtual FileHandlerPtr newFileHandler(const I2OChain& event) = 0; 00083 00087 FilesMonitorCollection::FileRecordPtr getNewFileRecord(const I2OChain& event); 00088 00092 virtual int getStreamMaxFileSize() const = 0; 00093 00097 unsigned long long getMaxFileSize() const; 00098 00099 00103 virtual FileHandlerPtr getFileHandler(const I2OChain& event); 00104 00105 private: 00106 00111 bool fileTooLarge(const FileHandlerPtr, const unsigned long& dataSize) const; 00112 00116 std::string getBaseFilePath(const uint32_t& runNumber, uint32_t fileCount) const; 00117 00121 std::string getFileSystem(const uint32_t& runNumber, uint32_t fileCount) const; 00122 00126 std::string getCoreFileName(const uint32_t& runNumber, const uint32_t& lumiSection) const; 00127 00131 unsigned int getFileCounter(const std::string& coreFileName); 00132 00133 00134 protected: 00135 00136 const SharedResourcesPtr sharedResources_; 00137 const StatisticsReporterPtr statReporter_; 00138 const StreamsMonitorCollection::StreamRecordPtr streamRecord_; 00139 const DiskWritingParams diskWritingParams_; 00140 const DbFileHandlerPtr dbFileHandler_; 00141 00142 typedef std::vector<FileHandlerPtr> FileHandlers; 00143 FileHandlers fileHandlers_; 00144 00145 typedef std::map<std::string, unsigned int> CoreFileNamesMap; 00146 CoreFileNamesMap usedCoreFileNames_; 00147 00148 00149 private: 00150 00151 //Prevent copying of the StreamHandler 00152 StreamHandler(StreamHandler const&); 00153 StreamHandler& operator=(StreamHandler const&); 00154 00155 }; 00156 00157 } // namespace stor 00158 00159 #endif // EventFilter_StorageManager_StreamHandler_h 00160 00161