CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes

edm::FUShmOutputModule Class Reference

#include <FUShmOutputModule.h>

Inheritance diagram for edm::FUShmOutputModule:
evf::OutputModule

List of all members.

Public Member Functions

void doOutputEvent (EventMsgBuilder const &eventMessage)
void doOutputHeader (InitMsgBuilder const &initMessage)
 FUShmOutputModule (edm::ParameterSet const &ps)
unsigned int getCounts ()
void sendPostponedInitMsg ()
void sendPostponedStart ()
void setNExpectedEPs (unsigned int EPs)
void setPostponeInitMsg ()
void start ()
void stop ()
void unregisterFromShm ()
 ~FUShmOutputModule ()

Static Public Member Functions

static void fillDescription (ParameterSetDescription &)

Private Attributes

unsigned int count_
unsigned char * initBuf_
unsigned int initBufSize_
std::string name_
unsigned int nExpectedEPs_
bool postponeInitMsg_
bool postponeStart_
bool sentInitMsg_
evf::FUShmBuffershmBuffer_

Static Private Attributes

static uint32 fuGuidValue_ = 0
static bool fuIdsInitialized_ = false

Detailed Description

Definition at line 56 of file FUShmOutputModule.h.


Constructor & Destructor Documentation

edm::FUShmOutputModule::FUShmOutputModule ( edm::ParameterSet const &  ps)

Definition at line 45 of file FUShmOutputModule.cc.

References FDEBUG, fuGuidValue_, fuIdsInitialized_, dttmaxenums::L, name_, and edm::Guid::toString().

                                                               :
    shmBuffer_(0)
    , name_(ps.getParameter<std::string>( "@module_label" ))
    , count_(0)
    , postponeInitMsg_(false)
    , sentInitMsg_(false)
    , initBuf_(nullptr)
    , initBufSize_(0)
    , postponeStart_(false)
    , nExpectedEPs_(0)
  {
    FDEBUG(9) << "FUShmOutputModule: constructor" << endl;
    if(edm::Service<evf::ShmOutputModuleRegistry>())
      edm::Service<evf::ShmOutputModuleRegistry>()->registerModule(name_, this);  
    if (! fuIdsInitialized_) {
      fuIdsInitialized_ = true;

      edm::Guid guidObj(true);
      std::string guidString = guidObj.toString();

      uLong crc = crc32(0L, Z_NULL, 0);
      Bytef* buf = (Bytef*)guidString.data();
      crc = crc32(crc, buf, guidString.length());
      fuGuidValue_ = crc;
    }
  }
edm::FUShmOutputModule::~FUShmOutputModule ( )

Definition at line 72 of file FUShmOutputModule.cc.

References SM_SharedMemoryHandle::detachShmBuffer(), FDEBUG, and sm_sharedmemory.

  {
    FDEBUG(9) << "FUShmOutputModule: FUShmOutputModule destructor" << endl;
    sm_sharedmemory.detachShmBuffer();
    //shmdt(shmBuffer_);
  }

Member Function Documentation

void edm::FUShmOutputModule::doOutputEvent ( EventMsgBuilder const &  eventMessage)

Definition at line 154 of file FUShmOutputModule.cc.

References count_, FDEBUG, fuGuidValue_, SM_SharedMemoryHandle::getShmBuffer(), postponeInitMsg_, runTheMatrix::ret, EventMsgView::run(), sendPostponedInitMsg(), sentInitMsg_, shmBuffer_, findQualityFiles::size, EventMsgBuilder::size(), sm_sharedmemory, EventMsgBuilder::startAddress(), and evf::FUShmBuffer::writeRecoEventData().

  {
    if (!sentInitMsg_ && postponeInitMsg_) sendPostponedInitMsg();
    if(!shmBuffer_) edm::LogError("FUShmOutputModule") 
      << " Invalid shared memory buffer at first event"
      << " Make sure you configure the ResourceBroker before the FUEventProcessor! "
      << " No event is sent - this is fatal! Should throw here";
    else
    {
      count_++;
      unsigned char* buffer = (unsigned char*) eventMessage.startAddress();
      unsigned int size = eventMessage.size();
      EventMsgView eventView(eventMessage.startAddress());
      unsigned int runid = eventView.run();
      unsigned int eventid = eventView.event();
      unsigned int outModId = eventView.outModId();
      FDEBUG(10) << "FUShmOutputModule: event size = " << size << std::endl;
      //bool ret = shmBuffer_->writeRecoEventData(runid, eventid, outModId, buffer, size);
      bool ret = sm_sharedmemory.getShmBuffer()->writeRecoEventData(runid, eventid, outModId, getpid(), fuGuidValue_, buffer, size);
      if(!ret) edm::LogError("FUShmOutputModule") << " Error with writing data to ShmBuffer";
    }
  }
void edm::FUShmOutputModule::doOutputHeader ( InitMsgBuilder const &  initMessage)

Definition at line 79 of file FUShmOutputModule.cc.

References count_, FDEBUG, fuGuidValue_, SM_SharedMemoryHandle::getShmBuffer(), initBuf_, initBufSize_, nExpectedEPs_, InitMsgView::outputModuleId(), postponeInitMsg_, runTheMatrix::ret, sentInitMsg_, shmBuffer_, findQualityFiles::size, InitMsgBuilder::size(), sm_sharedmemory, InitMsgBuilder::startAddress(), and evf::FUShmBuffer::writeRecoInitMsg().

  {
    //saving message for later if postpone is on
    if (postponeInitMsg_) {
      sentInitMsg_=false;
      if (initBuf_) delete initBuf_;//clean up if there are leftovers from last run
      //copy message for later sending
      initBufSize_ = initMessage.size();
      initBuf_ = new unsigned char[initBufSize_];
      memcpy(initBuf_, (unsigned char*) initMessage.startAddress(),sizeof(unsigned char)*initBufSize_);
      return;
    }

    sentInitMsg_=true;
    count_ = 0;
    if(!shmBuffer_) shmBuffer_ = sm_sharedmemory.getShmBuffer();
    if(!shmBuffer_) edm::LogError("FUShmOutputModule") 
      << " Error getting shared memory buffer for INIT. " 
      << " Make sure you configure the ResourceBroker before the FUEventProcessor! "
      << " No INIT is sent - this is probably fatal!";
    if(shmBuffer_)
    {
      unsigned char* buffer = (unsigned char*) initMessage.startAddress();
      unsigned int size = initMessage.size();
      FDEBUG(10) << "writing out INIT message with size = " << size << std::endl;
      // no method in InitMsgBuilder to get the output module id, recast
      InitMsgView dummymsg(buffer);
      uint32 dmoduleId = dummymsg.outputModuleId();

      //bool ret = shmBuffer_->writeRecoInitMsg(dmoduleId, buffer, size);
      bool ret = sm_sharedmemory.getShmBuffer()->writeRecoInitMsg(dmoduleId, getpid(), fuGuidValue_, buffer, size,nExpectedEPs_);
      if(!ret) edm::LogError("FUShmOutputModule") << " Error writing preamble to ShmBuffer";
    }
  }
static void edm::FUShmOutputModule::fillDescription ( ParameterSetDescription ) [inline, static]

Definition at line 71 of file FUShmOutputModule.h.

{}
unsigned int edm::FUShmOutputModule::getCounts ( ) [inline, virtual]

Implements evf::OutputModule.

Definition at line 65 of file FUShmOutputModule.h.

References count_.

                            {
      return count_;
    }
void edm::FUShmOutputModule::sendPostponedInitMsg ( )

Definition at line 126 of file FUShmOutputModule.cc.

References FDEBUG, fuGuidValue_, SM_SharedMemoryHandle::getShmBuffer(), initBuf_, initBufSize_, nExpectedEPs_, InitMsgView::outputModuleId(), postponeInitMsg_, postponeStart_, runTheMatrix::ret, sentInitMsg_, shmBuffer_, sm_sharedmemory, start(), and evf::FUShmBuffer::writeRecoInitMsg().

Referenced by doOutputEvent().

  {
    if (postponeStart_) {
      postponeStart_=false;
      start();
    }
    if (!sentInitMsg_ && postponeInitMsg_) {
      if(!shmBuffer_) shmBuffer_ = sm_sharedmemory.getShmBuffer();
      if(!shmBuffer_) edm::LogError("FUShmOutputModule")
        << " Error getting shared memory buffer for INIT. "
        << " Make sure you configure the ResourceBroker before the FUEventProcessor! "
        << " No INIT is sent - this is probably fatal!";
      if(shmBuffer_)
      {
        FDEBUG(10) << "writing out (postponed) INIT message with size = " << initBufSize_ << std::endl;
        InitMsgView dummymsg(initBuf_);
        uint32 dmoduleId = dummymsg.outputModuleId();
        bool ret = sm_sharedmemory.getShmBuffer()->writeRecoInitMsg(dmoduleId, getpid(), fuGuidValue_, initBuf_, initBufSize_,nExpectedEPs_);
        if(!ret) edm::LogError("FUShmOutputModule") << " Error writing preamble to ShmBuffer";
      }
      sentInitMsg_=true;
      if (initBuf_) delete initBuf_;
      initBufSize_=0;
      initBuf_=nullptr;
    }
  }
void edm::FUShmOutputModule::sendPostponedStart ( )

Definition at line 186 of file FUShmOutputModule.cc.

References postponeStart_, and start().

                                             {
      postponeStart_=false;
      start();
  }
void edm::FUShmOutputModule::setNExpectedEPs ( unsigned int  EPs)

Definition at line 201 of file FUShmOutputModule.cc.

References nExpectedEPs_.

                                                          {
    nExpectedEPs_ = EPs;
  }
void edm::FUShmOutputModule::setPostponeInitMsg ( )

Definition at line 114 of file FUShmOutputModule.cc.

References initBuf_, initBufSize_, postponeInitMsg_, postponeStart_, and sentInitMsg_.

  {
    //postpone start and Init message for after beginRun
    postponeInitMsg_=true;
    postponeStart_=true;
    //reset this on each run
    if (initBuf_) delete initBuf_;
    initBufSize_=0;
    initBuf_=nullptr;
    sentInitMsg_=false;
  }
void edm::FUShmOutputModule::start ( void  )

Definition at line 177 of file FUShmOutputModule.cc.

References SM_SharedMemoryHandle::getShmBuffer(), postponeStart_, shmBuffer_, and sm_sharedmemory.

Referenced by sendPostponedInitMsg(), and sendPostponedStart().

  {
    if (postponeStart_) return;
    //shmBuffer_ = evf::FUShmBuffer::getShmBuffer();
    shmBuffer_ = sm_sharedmemory.getShmBuffer();
    if(0==shmBuffer_) 
      edm::LogError("FUShmOutputModule")<<"Failed to attach to shared memory";
  }
void edm::FUShmOutputModule::stop ( )

Definition at line 191 of file FUShmOutputModule.cc.

References SM_SharedMemoryHandle::detachShmBuffer(), FDEBUG, shmBuffer_, and sm_sharedmemory.

  {
    FDEBUG(9) << "FUShmOutputModule: sending terminate run" << std::endl;
    if(0!=shmBuffer_){
      sm_sharedmemory.detachShmBuffer();
      //shmdt(shmBuffer_);
      shmBuffer_ = 0;
    }
  }
void edm::FUShmOutputModule::unregisterFromShm ( )

Member Data Documentation

unsigned int edm::FUShmOutputModule::count_ [private]

Definition at line 76 of file FUShmOutputModule.h.

Referenced by doOutputEvent(), doOutputHeader(), and getCounts().

bool edm::FUShmOutputModule::fuIdsInitialized_ = false [static, private]

Initialize the static variables for the filter unit identifiers.

Definition at line 78 of file FUShmOutputModule.h.

Referenced by FUShmOutputModule().

unsigned char* edm::FUShmOutputModule::initBuf_ [private]

Definition at line 82 of file FUShmOutputModule.h.

Referenced by doOutputHeader(), sendPostponedInitMsg(), and setPostponeInitMsg().

unsigned int edm::FUShmOutputModule::initBufSize_ [private]

Definition at line 83 of file FUShmOutputModule.h.

Referenced by doOutputHeader(), sendPostponedInitMsg(), and setPostponeInitMsg().

std::string edm::FUShmOutputModule::name_ [private]

Definition at line 75 of file FUShmOutputModule.h.

Referenced by FUShmOutputModule().

unsigned int edm::FUShmOutputModule::nExpectedEPs_ [private]

Definition at line 85 of file FUShmOutputModule.h.

Referenced by doOutputHeader(), sendPostponedInitMsg(), and setNExpectedEPs().