00001 // $Id: FRDFileHandler.cc,v 1.19 2012/04/04 12:17:02 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 uint64_t& maxFileSize 00019 ) : 00020 FileHandler(fileRecord, dbFileHandler, maxFileSize), 00021 writer_(new FRDEventFileWriter(fileRecord->completeFileName())) 00022 {} 00023 00024 00025 void FRDFileHandler::do_writeEvent(const I2OChain& chain) 00026 { 00027 unsigned int fragCount = chain.fragmentCount(); 00028 for (unsigned int idx = 0; idx < fragCount; ++idx) 00029 { 00030 writer_->doOutputEventFragment( 00031 chain.dataLocation(idx), 00032 chain.dataSize(idx)); 00033 } 00034 } 00035 00036 00037 void FRDFileHandler::closeFile(const FilesMonitorCollection::FileRecord::ClosingReason& reason) 00038 { 00039 if ( ! fileRecord_->isOpen ) return; 00040 00041 if (writer_) 00042 { 00043 // if writer was reset, we already closed the stream but failed to move the file to the closed position 00044 writer_->stop(); 00045 fileRecord_->adler32 = writer_->adler32(); 00046 writer_.reset(); // Destruct the writer to flush the file stream 00047 } 00048 moveFileToClosed(reason); 00049 updateDatabase(); 00050 } 00051 00052 } // namespace stor 00053