CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/EventFilter/StorageManager/interface/FileHandler.h

Go to the documentation of this file.
00001 // $Id: FileHandler.h,v 1.20 2011/07/07 09:22:44 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 bookkeeping //
00105 
00110     void updateDatabase() const;
00111 
00112 
00117     void insertFileInDatabase() const;
00118 
00119     
00121     // File system interaction //
00123     
00127     void moveFileToClosed
00128     (
00129       const FilesMonitorCollection::FileRecord::ClosingReason&
00130     );
00131 
00132 
00133   private:
00134 
00139     uint64_t checkFileSizeMatch(const std::string& fileName, const uint64_t& size) const;
00140 
00144     bool sizeMismatch(const uint64_t& initialSize, const uint64_t& finalSize) const;
00145 
00149     void makeFileReadOnly(const std::string& fileName) const;
00150 
00154     void checkAdler32(const std::string& fileName) const;
00155     
00159     void renameFile(const std::string& openFileName, const std::string& closedFileName) const;
00160     
00165     void checkDirectories() const;
00166     
00170     std::string logFile(const DiskWritingParams&) const;
00171 
00175     double calcPctDiff(const uint64_t&, const uint64_t&) const;
00176     
00177 
00178   private:
00179 
00180     //Prevent copying of the FileHandler
00181     FileHandler(FileHandler const&);
00182     FileHandler& operator=(FileHandler const&);
00183 
00184 
00185   protected:
00186 
00187     FilesMonitorCollection::FileRecordPtr fileRecord_;
00188     const DbFileHandlerPtr dbFileHandler_;
00189 
00190     utils::TimePoint_t firstEntry_;                // time when first event was writen
00191     utils::TimePoint_t lastEntry_;                 // time when latest event was writen
00192 
00193     const DiskWritingParams& diskWritingParams_;
00194     
00195   private:
00196     
00197     const uint64_t maxFileSize_;                    // maximal file size in bytes
00198     
00199     const std::string  logPath_;                    // log path
00200     const std::string  logFile_;                    // log file including path
00201     std::string  cmsver_;                           // CMSSW version string
00202   };
00203   
00204 } // stor namespace
00205 
00206 #endif // EventFilter_StorageManager_FileHandler_h
00207 
00208