00001 // $Id: FileHandler.h,v 1.21 2012/04/04 12:16:57 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 uint64_t& maxFileSize 00041 ); 00042 00043 virtual ~FileHandler() {}; 00044 00048 void writeEvent(const I2OChain&); 00049 00053 bool tooOld(const utils::TimePoint_t currentTime = utils::getCurrentTime()); 00054 00058 bool isFromLumiSection(const uint32_t lumiSection); 00059 00064 bool tooLarge(const uint64_t& dataSize); 00065 00066 00068 // File parameter getters // 00070 00074 uint32_t events() const; 00075 00079 uint32_t lumiSection() const 00080 { return fileRecord_->lumiSection; } 00081 00085 uint64_t fileSize() const; 00086 00090 virtual void closeFile(const FilesMonitorCollection::FileRecord::ClosingReason&) = 0; 00091 00092 00093 protected: 00094 00098 virtual void do_writeEvent(const I2OChain& event) = 0; 00099 00100 00102 // File bookkeeping // 00104 00109 void updateDatabase() const; 00110 00111 00116 void insertFileInDatabase() const; 00117 00118 00120 // File system interaction // 00122 00126 void moveFileToClosed 00127 ( 00128 const FilesMonitorCollection::FileRecord::ClosingReason& 00129 ); 00130 00131 00132 private: 00133 00138 uint64_t checkFileSizeMatch(const std::string& fileName, const uint64_t& size) const; 00139 00143 bool sizeMismatch(const uint64_t& initialSize, const uint64_t& finalSize) const; 00144 00148 void makeFileReadOnly(const std::string& fileName) const; 00149 00153 void checkAdler32(const std::string& fileName) const; 00154 00158 void renameFile(const std::string& openFileName, const std::string& closedFileName) const; 00159 00164 void checkDirectories() const; 00165 00169 double calcPctDiff(const uint64_t&, const uint64_t&) const; 00170 00171 00172 private: 00173 00174 //Prevent copying of the FileHandler 00175 FileHandler(FileHandler const&); 00176 FileHandler& operator=(FileHandler const&); 00177 00178 00179 protected: 00180 00181 FilesMonitorCollection::FileRecordPtr fileRecord_; 00182 const DbFileHandlerPtr dbFileHandler_; 00183 00184 utils::TimePoint_t firstEntry_; // time when first event was writen 00185 utils::TimePoint_t lastEntry_; // time when latest event was writen 00186 00187 const DiskWritingParams& diskWritingParams_; 00188 00189 private: 00190 00191 const uint64_t maxFileSize_; // maximal file size in bytes 00192 00193 const std::string logPath_; // log path 00194 const std::string logFile_; // log file including path 00195 std::string cmsver_; // CMSSW version string 00196 }; 00197 00198 } // stor namespace 00199 00200 #endif // EventFilter_StorageManager_FileHandler_h 00201 00202