00001 // $Id: EventFileHandler.cc,v 1.16 2011/03/07 15:31:32 mommsen Exp $ 00003 00004 #include <EventFilter/StorageManager/interface/EventFileHandler.h> 00005 #include <EventFilter/StorageManager/interface/Exception.h> 00006 #include <EventFilter/StorageManager/interface/I2OChain.h> 00007 #include <IOPool/Streamer/interface/EventMessage.h> 00008 00009 #include <iostream> 00010 00011 00012 namespace stor { 00013 00014 EventFileHandler::EventFileHandler 00015 ( 00016 InitMsgSharedPtr view, 00017 FilesMonitorCollection::FileRecordPtr fileRecord, 00018 const DbFileHandlerPtr dbFileHandler, 00019 const DiskWritingParams& dwParams, 00020 const uint64_t& maxFileSize 00021 ) : 00022 FileHandler(fileRecord, dbFileHandler, dwParams, maxFileSize), 00023 writer_(new edm::StreamerFileWriter(fileRecord->completeFileName())) 00024 { 00025 writeHeader(view); 00026 } 00027 00028 00029 void EventFileHandler::writeHeader(InitMsgSharedPtr view) 00030 { 00031 InitMsgView initView(&(*view)[0]); 00032 writer_->doOutputHeader(initView); 00033 fileRecord_->fileSize += view->size(); 00034 lastEntry_ = utils::getCurrentTime(); 00035 } 00036 00037 00038 void EventFileHandler::do_writeEvent(const I2OChain& event) 00039 { 00040 edm::StreamerFileWriterEventParams evtParams; 00041 00042 event.hltTriggerBits(evtParams.hltBits); 00043 evtParams.headerPtr = (char*) event.headerLocation(); 00044 evtParams.headerSize = event.headerSize(); 00045 00046 unsigned int fragCount = event.fragmentCount(); 00047 evtParams.fragmentCount = fragCount; 00048 00049 for (unsigned int idx = 0; idx < fragCount; ++idx) 00050 { 00051 evtParams.fragmentIndex = idx; 00052 evtParams.dataPtr = (char*) event.dataLocation(idx); 00053 evtParams.dataSize = event.dataSize(idx); 00054 00055 writer_->doOutputEventFragment(evtParams); 00056 } 00057 } 00058 00059 00060 void EventFileHandler::closeFile(const FilesMonitorCollection::FileRecord::ClosingReason& reason) 00061 { 00062 if ( ! fileRecord_->isOpen ) return; 00063 00064 if (writer_) 00065 { 00066 // if writer was reset, we already closed the stream but failed to move the file to the closed position 00067 writer_->stop(); 00068 fileRecord_->fileSize += writer_->getStreamEOFSize(); 00069 setAdler(writer_->get_adler32()); 00070 writer_.reset(); // Destruct the writer to flush the file stream 00071 } 00072 moveFileToClosed(reason); 00073 writeToSummaryCatalog(); 00074 updateDatabase(); 00075 } 00076 00077 } // namespace stor 00078 00079