00001 // $Id: EventFileHandler.cc,v 1.19 2012/04/04 12:17:00 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 uint64_t& maxFileSize 00020 ) : 00021 FileHandler(fileRecord, dbFileHandler, maxFileSize), 00022 writer_(new edm::StreamerFileWriter(fileRecord->completeFileName())) 00023 { 00024 writeHeader(view); 00025 } 00026 00027 00028 void EventFileHandler::writeHeader(InitMsgSharedPtr view) 00029 { 00030 InitMsgView initView(&(*view)[0]); 00031 writer_->doOutputHeader(initView); 00032 fileRecord_->fileSize += view->size(); 00033 lastEntry_ = utils::getCurrentTime(); 00034 } 00035 00036 00037 void EventFileHandler::do_writeEvent(const I2OChain& event) 00038 { 00039 edm::StreamerFileWriterEventParams evtParams; 00040 00041 event.hltTriggerBits(evtParams.hltBits); 00042 evtParams.headerPtr = (char*) event.headerLocation(); 00043 evtParams.headerSize = event.headerSize(); 00044 00045 unsigned int fragCount = event.fragmentCount(); 00046 evtParams.fragmentCount = fragCount; 00047 00048 for (unsigned int idx = 0; idx < fragCount; ++idx) 00049 { 00050 evtParams.fragmentIndex = idx; 00051 evtParams.dataPtr = (char*) event.dataLocation(idx); 00052 evtParams.dataSize = event.dataSize(idx); 00053 00054 writer_->doOutputEventFragment(evtParams); 00055 } 00056 } 00057 00058 00059 void EventFileHandler::closeFile(const FilesMonitorCollection::FileRecord::ClosingReason& reason) 00060 { 00061 if ( ! fileRecord_->isOpen ) return; 00062 00063 if (writer_) 00064 { 00065 // if writer was reset, we already closed the stream but failed to move the file to the closed position 00066 writer_->stop(); 00067 fileRecord_->fileSize += writer_->getStreamEOFSize(); 00068 fileRecord_->adler32 = writer_->get_adler32(); 00069 writer_.reset(); // Destruct the writer to flush the file stream 00070 } 00071 moveFileToClosed(reason); 00072 updateDatabase(); 00073 } 00074 00075 } // namespace stor 00076 00077