Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:10

0001 #include "IOPool/Output/interface/TimeoutPoolOutputModule.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 
0006 namespace edm {
0007 
0008   void TimeoutPoolOutputModule::write(EventForOutput const& e) {
0009     eventsWrittenInCurrentFile++;
0010     PoolOutputModule::write(e);
0011   }
0012 
0013   TimeoutPoolOutputModule::TimeoutPoolOutputModule(ParameterSet const& ps)
0014       : edm::one::OutputModuleBase::OutputModuleBase(ps),
0015         PoolOutputModule(ps),
0016         m_lastEvent(time(nullptr)),
0017         eventsWrittenInCurrentFile(0),
0018         m_timeout(-1)  // we want the first event right away
0019   {}
0020 
0021   void TimeoutPoolOutputModule::fillDescriptions(ConfigurationDescriptions& descriptions) {
0022     ParameterSetDescription desc;
0023     PoolOutputModule::fillDescription(desc);
0024     descriptions.add("TimeoutPoolOutputModule", desc);
0025   }
0026 
0027   bool TimeoutPoolOutputModule::shouldWeCloseFile() const {
0028     time_t now(time(nullptr));
0029     if (PoolOutputModule::shouldWeCloseFile()) {
0030       edm::LogVerbatim("TimeoutPoolOutputModule")
0031           << " Closing file " << currentFileName() << " with " << eventsWrittenInCurrentFile << " events.";
0032       eventsWrittenInCurrentFile = 0;
0033       m_lastEvent = now;
0034       return true;
0035     }
0036     //    std::cout <<" Events "<< eventsWrittenInCurrentFile<<" time "<< now - m_lastEvent<<std::endl;
0037     if (eventsWrittenInCurrentFile == 0)
0038       return false;
0039     if (now - m_lastEvent < m_timeout)
0040       return false;
0041     // next files are needed in 15, 30 and 60 sec
0042     m_lastEvent = now;
0043     if (m_timeout == 30)
0044       m_timeout = 60;
0045     if (m_timeout == 15)
0046       m_timeout = 30;
0047     if (m_timeout == -1)
0048       m_timeout = 15;
0049 
0050     edm::LogVerbatim("TimeoutPoolOutputModule")
0051         << " Closing file " << currentFileName() << " with " << eventsWrittenInCurrentFile << " events.";
0052     eventsWrittenInCurrentFile = 0;
0053     return true;
0054   }
0055 }  // namespace edm