Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
// -*- C++ -*-
//
// Package:     FWCore/Framework
// Class  :     OutputModuleBase
//
// Implementation:
//     [Notes on implementation]
//
//

// system include files
#include <cassert>

// user include files
#include "FWCore/Framework/interface/global/OutputModuleBase.h"

#include "FWCore/Framework/interface/EventForOutput.h"
#include "FWCore/Framework/interface/PreallocationConfiguration.h"
#include "FWCore/Framework/src/EventAcquireSignalsSentry.h"

namespace edm {
  namespace global {

    // -------------------------------------------------------
    OutputModuleBase::OutputModuleBase(ParameterSet const& pset) : core::OutputModuleCore(pset) {}

    void OutputModuleBase::doPreallocate(PreallocationConfiguration const& iPC) {
      auto nstreams = iPC.numberOfStreams();
      preallocStreams(nstreams);
      core::OutputModuleCore::doPreallocate_(iPC);
      preallocate(iPC);
    }

    void OutputModuleBase::doBeginJob() { core::OutputModuleCore::doBeginJob_(); }

    bool OutputModuleBase::doEvent(EventTransitionInfo const& info,
                                   ActivityRegistry* act,
                                   ModuleCallingContext const* mcc) {
      { core::OutputModuleCore::doEvent_(info, act, mcc); }

      auto remainingEvents = remainingEvents_.load();
      bool keepTrying = remainingEvents > 0;
      while (keepTrying) {
        auto newValue = remainingEvents - 1;
        keepTrying = !remainingEvents_.compare_exchange_strong(remainingEvents, newValue);
        if (keepTrying) {
          // the exchange failed because the value was changed by another thread.
          // remainingEvents was changed to be the new value of remainingEvents_;
          keepTrying = remainingEvents > 0;
        }
      }
      return true;
    }

    void OutputModuleBase::doAcquire(EventTransitionInfo const& info,
                                     ActivityRegistry* act,
                                     ModuleCallingContext const* mcc,
                                     WaitingTaskHolder&& holder) {
      EventForOutput e(info, moduleDescription(), mcc);
      e.setConsumer(this);
      EventAcquireSignalsSentry sentry(act, mcc);
      this->doAcquire_(e.streamID(), e, std::move(holder));
    }
  }  // namespace global
}  // namespace edm