CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/EventFilter/StorageManager/src/FRDFileHandler.cc

Go to the documentation of this file.
00001 // $Id: FRDFileHandler.cc,v 1.18 2011/07/07 09:22:44 mommsen Exp $
00003 
00004 #include <EventFilter/StorageManager/interface/FRDFileHandler.h>
00005 #include <EventFilter/StorageManager/interface/Exception.h>
00006 #include <EventFilter/StorageManager/interface/I2OChain.h>
00007 #include <IOPool/Streamer/interface/FRDEventMessage.h>
00008 
00009 #include <iostream>
00010 
00011 
00012 namespace stor {
00013   
00014   FRDFileHandler::FRDFileHandler
00015   (
00016     FilesMonitorCollection::FileRecordPtr fileRecord,
00017     const DbFileHandlerPtr dbFileHandler,
00018     const DiskWritingParams& dwParams,
00019     const uint64_t& maxFileSize
00020   ) :
00021   FileHandler(fileRecord, dbFileHandler, dwParams, maxFileSize),
00022   writer_(new FRDEventFileWriter(fileRecord->completeFileName()))
00023   {}
00024   
00025   
00026   void FRDFileHandler::do_writeEvent(const I2OChain& chain)
00027   {
00028     unsigned int fragCount = chain.fragmentCount();
00029     for (unsigned int idx = 0; idx < fragCount; ++idx)
00030     {
00031       writer_->doOutputEventFragment(
00032         chain.dataLocation(idx),
00033         chain.dataSize(idx));
00034     }
00035   }
00036   
00037   
00038   void FRDFileHandler::closeFile(const FilesMonitorCollection::FileRecord::ClosingReason& reason)
00039   {
00040     if ( ! fileRecord_->isOpen ) return;
00041     
00042     if (writer_)
00043     {
00044       // if writer was reset, we already closed the stream but failed to move the file to the closed position
00045       writer_->stop();
00046       fileRecord_->adler32 = writer_->adler32();
00047       writer_.reset(); // Destruct the writer to flush the file stream
00048     }
00049     moveFileToClosed(reason);
00050     updateDatabase();
00051   }
00052   
00053 } // namespace stor
00054