00001 // $Id: FileHandler.h,v 1.17 2011/03/07 15:31:31 mommsen Exp $ 00003 00004 #ifndef EventFilter_StorageManager_FileHandler_h 00005 #define EventFilter_StorageManager_FileHandler_h 00006 00007 #include "EventFilter/StorageManager/interface/Configuration.h" 00008 #include "EventFilter/StorageManager/interface/DbFileHandler.h" 00009 #include "EventFilter/StorageManager/interface/FilesMonitorCollection.h" 00010 #include "EventFilter/StorageManager/interface/Utils.h" 00011 #include "IOPool/Streamer/interface/MsgHeader.h" 00012 00013 #include "boost/shared_ptr.hpp" 00014 00015 #include <stdint.h> 00016 #include <string> 00017 #include <sys/types.h> 00018 00019 00020 namespace stor { 00021 00022 class I2OChain; 00023 00032 class FileHandler 00033 { 00034 public: 00035 00036 FileHandler 00037 ( 00038 FilesMonitorCollection::FileRecordPtr, 00039 const DbFileHandlerPtr, 00040 const DiskWritingParams&, 00041 const uint64_t& maxFileSize 00042 ); 00043 00044 virtual ~FileHandler() {}; 00045 00049 void writeEvent(const I2OChain&); 00050 00054 bool tooOld(const utils::TimePoint_t currentTime = utils::getCurrentTime()); 00055 00059 bool isFromLumiSection(const uint32_t lumiSection); 00060 00065 bool tooLarge(const uint64_t& dataSize); 00066 00067 00069 // File parameter getters // 00071 00075 uint32_t events() const; 00076 00080 uint32_t lumiSection() const 00081 { return fileRecord_->lumiSection; } 00082 00086 uint64_t fileSize() const; 00087 00091 virtual void closeFile(const FilesMonitorCollection::FileRecord::ClosingReason&) = 0; 00092 00093 00094 protected: 00095 00099 virtual void do_writeEvent(const I2OChain& event) = 0; 00100 00101 00103 // File parameter setters // 00105 00109 inline void setAdler(uint32_t s) 00110 { adler_ = s; } 00111 00112 00114 // File bookkeeping // 00116 00120 void writeToSummaryCatalog() const; 00121 00126 void updateDatabase() const; 00127 00128 00133 void insertFileInDatabase() const; 00134 00135 00137 // File system interaction // 00139 00143 void moveFileToClosed 00144 ( 00145 const FilesMonitorCollection::FileRecord::ClosingReason& 00146 ); 00147 00148 00149 private: 00150 00155 uint64_t checkFileSizeMatch(const std::string& fileName, const uint64_t& size) const; 00156 00160 bool sizeMismatch(const uint64_t& initialSize, const uint64_t& finalSize) const; 00161 00165 void makeFileReadOnly(const std::string& fileName) const; 00166 00170 void renameFile(const std::string& openFileName, const std::string& closedFileName) const; 00171 00176 void checkDirectories() const; 00177 00181 std::string logFile(const DiskWritingParams&) const; 00182 00186 double calcPctDiff(const uint64_t&, const uint64_t&) const; 00187 00188 00189 private: 00190 00191 //Prevent copying of the FileHandler 00192 FileHandler(FileHandler const&); 00193 FileHandler& operator=(FileHandler const&); 00194 00195 00196 protected: 00197 00198 FilesMonitorCollection::FileRecordPtr fileRecord_; 00199 const DbFileHandlerPtr dbFileHandler_; 00200 00201 utils::TimePoint_t firstEntry_; // time when first event was writen 00202 utils::TimePoint_t lastEntry_; // time when latest event was writen 00203 00204 const DiskWritingParams& diskWritingParams_; 00205 00206 private: 00207 00208 const uint64_t maxFileSize_; // maximal file size in bytes 00209 00210 const std::string logPath_; // log path 00211 const std::string logFile_; // log file including path 00212 std::string cmsver_; // CMSSW version string 00213 00214 uint32_t adler_; // adler32 checksum for streamer file 00215 }; 00216 00217 } // stor namespace 00218 00219 #endif // EventFilter_StorageManager_FileHandler_h 00220 00221