CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/IOPool/Output/src/TimeoutPoolOutputModule.cc

Go to the documentation of this file.
00001 #include "IOPool/Output/interface/TimeoutPoolOutputModule.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 namespace edm {
00005 
00006   void TimeoutPoolOutputModule::write(EventPrincipal const& e) {
00007     eventsWrittenInCurrentFile++;
00008     PoolOutputModule::write(e);
00009   }
00010   
00011   TimeoutPoolOutputModule::TimeoutPoolOutputModule(ParameterSet const& ps):
00012       PoolOutputModule(ps), 
00013       m_lastEvent(time(NULL)),
00014       eventsWrittenInCurrentFile(0),
00015       m_timeout(-1) // we want the first event right away
00016   {  }
00017 
00018   bool TimeoutPoolOutputModule::shouldWeCloseFile() const {
00019     time_t now(time(NULL));
00020     if ( PoolOutputModule::shouldWeCloseFile() ) {
00021       edm::LogVerbatim("TimeoutPoolOutputModule")  <<" Closing file "<< currentFileName()<< " with "<< eventsWrittenInCurrentFile  <<" events.";
00022       eventsWrittenInCurrentFile = 0;
00023       m_lastEvent = now;
00024       return true;
00025     }
00026     //    std::cout <<" Events "<< eventsWrittenInCurrentFile<<" time "<< now - m_lastEvent<<std::endl;
00027     if (eventsWrittenInCurrentFile==0) return false;
00028     if ( now - m_lastEvent < m_timeout ) return false;
00029     // next files are needed in 15, 30 and 60 sec
00030     m_lastEvent = now;
00031     if (m_timeout == 30) m_timeout = 60;
00032     if (m_timeout == 15) m_timeout = 30;
00033     if (m_timeout == -1) m_timeout = 15;
00034     
00035     edm::LogVerbatim("TimeoutPoolOutputModule")  <<" Closing file "<< currentFileName()<< " with "<< eventsWrittenInCurrentFile  <<" events.";
00036     eventsWrittenInCurrentFile = 0;
00037     return true;
00038   }
00039 }
00040