Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:07

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Framework
0004 // Class  :     OutputModuleBase
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 //
0010 
0011 // system include files
0012 #include <cassert>
0013 
0014 // user include files
0015 #include "FWCore/Framework/interface/global/OutputModuleBase.h"
0016 
0017 #include "FWCore/Framework/interface/EventForOutput.h"
0018 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0019 #include "FWCore/Framework/src/EventAcquireSignalsSentry.h"
0020 
0021 namespace edm {
0022   namespace global {
0023 
0024     // -------------------------------------------------------
0025     OutputModuleBase::OutputModuleBase(ParameterSet const& pset) : core::OutputModuleCore(pset) {}
0026 
0027     void OutputModuleBase::doPreallocate(PreallocationConfiguration const& iPC) {
0028       auto nstreams = iPC.numberOfStreams();
0029       preallocStreams(nstreams);
0030       core::OutputModuleCore::doPreallocate_(iPC);
0031       preallocate(iPC);
0032     }
0033 
0034     void OutputModuleBase::doBeginJob() { core::OutputModuleCore::doBeginJob_(); }
0035 
0036     bool OutputModuleBase::doEvent(EventTransitionInfo const& info,
0037                                    ActivityRegistry* act,
0038                                    ModuleCallingContext const* mcc) {
0039       { core::OutputModuleCore::doEvent_(info, act, mcc); }
0040 
0041       auto remainingEvents = remainingEvents_.load();
0042       bool keepTrying = remainingEvents > 0;
0043       while (keepTrying) {
0044         auto newValue = remainingEvents - 1;
0045         keepTrying = !remainingEvents_.compare_exchange_strong(remainingEvents, newValue);
0046         if (keepTrying) {
0047           // the exchange failed because the value was changed by another thread.
0048           // remainingEvents was changed to be the new value of remainingEvents_;
0049           keepTrying = remainingEvents > 0;
0050         }
0051       }
0052       return true;
0053     }
0054 
0055     void OutputModuleBase::doAcquire(EventTransitionInfo const& info,
0056                                      ActivityRegistry* act,
0057                                      ModuleCallingContext const* mcc,
0058                                      WaitingTaskWithArenaHolder& holder) {
0059       EventForOutput e(info, moduleDescription(), mcc);
0060       e.setConsumer(this);
0061       EventAcquireSignalsSentry sentry(act, mcc);
0062       this->doAcquire_(e.streamID(), e, holder);
0063     }
0064   }  // namespace global
0065 }  // namespace edm