CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

evf::SMProxy Class Reference

#include <SMProxy.h>

List of all members.

Public Member Functions

UInt_t sendDataEvent (UInt_t fuResourceId, UInt_t runNumber, UInt_t evtNumber, UInt_t outModId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize) throw (evf::Exception)
UInt_t sendDqmEvent (UInt_t fuDqmId, UInt_t runNumber, UInt_t evtAtUpdate, UInt_t folderId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize) throw (evf::Exception)
UInt_t sendErrorEvent (UInt_t fuResourceId, UInt_t runNumber, UInt_t evtNumber, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize) throw (evf::Exception)
UInt_t sendInitMessage (UInt_t fuResourceId, UInt_t outModId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize) throw (evf::Exception)
 SMProxy (xdaq::ApplicationDescriptor *fuAppDesc, xdaq::ApplicationDescriptor *smAppDesc, xdaq::ApplicationContext *fuAppContext, toolbox::mem::Pool *i2oPool)
virtual ~SMProxy ()

Private Member Functions

MemRef_tcreateFragmentChain (UShort_t i2oFunctionCode, UInt_t headerSize, UChar_t *data, UInt_t dataSize, UInt_t &totalSize) throw (evf::Exception)

Private Attributes

UInt_t dataHeaderSize_
UInt_t dqmHeaderSize_
xdaq::ApplicationContext * fuAppContext_
xdaq::ApplicationDescriptor * fuAppDesc_
std::string fuClassName_
std::string fuUrl_
toolbox::mem::Pool * i2oPool_
UInt_t initHeaderSize_
Logger log_
xdaq::ApplicationDescriptor * smAppDesc_

Detailed Description

Definition at line 16 of file SMProxy.h.


Constructor & Destructor Documentation

SMProxy::SMProxy ( xdaq::ApplicationDescriptor *  fuAppDesc,
xdaq::ApplicationDescriptor *  smAppDesc,
xdaq::ApplicationContext *  fuAppContext,
toolbox::mem::Pool *  i2oPool 
)

Definition at line 36 of file SMProxy.cc.

References fuAppDesc_, fuClassName_, fuUrl_, and MAX_I2O_SM_URLCHARS.

  : log_(fuAppContext->getLogger())
  , fuAppDesc_(fuAppDesc)
  , smAppDesc_(smAppDesc)
  , fuAppContext_(fuAppContext)
  , i2oPool_(i2oPool)
  , initHeaderSize_(sizeof(I2O_SM_PREAMBLE_MESSAGE_FRAME))
  , dataHeaderSize_(sizeof(I2O_SM_DATA_MESSAGE_FRAME))
  , dqmHeaderSize_(sizeof(I2O_SM_DQM_MESSAGE_FRAME))
{
  fuUrl_=fuAppDesc_->getContextDescriptor()->getURL();
  if (fuUrl_.size()>=MAX_I2O_SM_URLCHARS)
    fuUrl_=fuUrl_.substr(0,MAX_I2O_SM_URLCHARS-1);
  
  fuClassName_=fuAppDesc_->getClassName();
  if (fuClassName_.size()>=MAX_I2O_SM_URLCHARS)
    fuClassName_=fuClassName_.substr(0,MAX_I2O_SM_URLCHARS-1);
}
SMProxy::~SMProxy ( ) [virtual]

Definition at line 60 of file SMProxy.cc.

{

}

Member Function Documentation

MemRef_t * SMProxy::createFragmentChain ( UShort_t  i2oFunctionCode,
UInt_t  headerSize,
UChar_t data,
UInt_t  dataSize,
UInt_t totalSize 
) throw (evf::Exception) [private]

Definition at line 245 of file SMProxy.cc.

References filterCSVwithJSON::copy, runTheMatrix::data, _I2O_SM_MULTIPART_MESSAGE_FRAME::dataSize, Exception, _I2O_SM_MULTIPART_MESSAGE_FRAME::frameCount, _I2O_SM_MULTIPART_MESSAGE_FRAME::hltClassName, _I2O_SM_MULTIPART_MESSAGE_FRAME::hltInstance, _I2O_SM_MULTIPART_MESSAGE_FRAME::hltLocalId, _I2O_SM_MULTIPART_MESSAGE_FRAME::hltTid, _I2O_SM_MULTIPART_MESSAGE_FRAME::hltURL, i, I2O_MAX_SIZE, runTheMatrix::msg, _I2O_SM_MULTIPART_MESSAGE_FRAME::numFrames, and _I2O_SM_MULTIPART_MESSAGE_FRAME::originalSize.

{
  totalSize=0;
  
  UInt_t fragmentDataSizeMax=I2O_MAX_SIZE-headerSize;
  UInt_t fragmentCount=(dataSize/fragmentDataSizeMax);
  if (dataSize%fragmentDataSizeMax) ++fragmentCount;
  
  UInt_t currentPosition  =0;
  UInt_t remainingDataSize=dataSize;
  
  MemRef_t *head(0);
  MemRef_t *tail(0);
  
  try {
    
    for (UInt_t iFragment=0;iFragment<fragmentCount;iFragment++) {

      UInt_t fragmentDataSize=fragmentDataSizeMax;
      UInt_t fragmentSize    =fragmentDataSize+headerSize;
      
      if (remainingDataSize<fragmentDataSizeMax) {
        fragmentDataSize=remainingDataSize;
        fragmentSize=fragmentDataSize+headerSize;
        if (fragmentSize&0x7) fragmentSize = ((fragmentSize >> 3) + 1) << 3;
      }
      
      // allocate the fragment buffer from the pool
      toolbox::mem::Reference *bufRef =
        toolbox::mem::getMemoryPoolFactory()->getFrame(i2oPool_,fragmentSize);
      
      // set up pointers to the allocated message buffer
      I2O_MESSAGE_FRAME              *stdMsg;
      I2O_PRIVATE_MESSAGE_FRAME      *pvtMsg;
      I2O_SM_MULTIPART_MESSAGE_FRAME *msg;
      
      stdMsg=(I2O_MESSAGE_FRAME*)bufRef->getDataLocation();
      pvtMsg=(I2O_PRIVATE_MESSAGE_FRAME*)stdMsg;
      msg   =(I2O_SM_MULTIPART_MESSAGE_FRAME*)stdMsg;
      
      stdMsg->VersionOffset   =0;
      stdMsg->MsgFlags        =0;  // normal message (not multicast)
      stdMsg->MessageSize     =fragmentSize >> 2;
      stdMsg->Function        =I2O_PRIVATE_MESSAGE;
      stdMsg->InitiatorAddress=i2o::utils::getAddressMap()->getTid(fuAppDesc_);
      stdMsg->TargetAddress   =i2o::utils::getAddressMap()->getTid(smAppDesc_);
      
      pvtMsg->XFunctionCode   =i2oFunctionCode;
      pvtMsg->OrganizationID  =XDAQ_ORGANIZATION_ID;

      msg->dataSize           =fragmentDataSize;
      msg->hltLocalId         =fuAppDesc_->getLocalId();
      msg->hltInstance        =fuAppDesc_->getInstance();
      msg->hltTid             =i2o::utils::getAddressMap()->getTid(fuAppDesc_);
      msg->numFrames          =fragmentCount;
      msg->frameCount         =iFragment;
      msg->originalSize       =dataSize;
      
      for (UInt_t i=0;i<fuUrl_.size();i++)
      msg->hltURL[i]=fuUrl_[i];
      msg->hltURL[fuUrl_.size()]='\0';
      
      for (UInt_t i=0;i<fuClassName_.size();i++)
      msg->hltClassName[i]=fuClassName_[i];
      msg->hltClassName[fuClassName_.size()]='\0';

      if (iFragment==0) {
        head=bufRef;
        tail=bufRef;
      }
      else {
        tail->setNextReference(bufRef);
        tail=bufRef;
      }

      if (fragmentDataSize!=0) {
        UChar_t* targetAddr=(UChar_t*)msg+headerSize;
        std::copy(data+currentPosition,
                  data+currentPosition+fragmentDataSize,
                  targetAddr);
      }
      
      bufRef->setDataSize(fragmentSize);
      remainingDataSize-=fragmentDataSize;
      currentPosition  +=fragmentDataSize;
      totalSize        +=fragmentSize;

    } // for (iFragment ...)
  }
  catch(toolbox::mem::exception::Exception& e) {
    if (0!=head) head->release();
    totalSize=0;
    string errmsg="Failed to allocate buffer reference.";
    LOG4CPLUS_FATAL(log_,errmsg);
    XCEPT_RETHROW(evf::Exception,errmsg,e);
  }
  catch(xdaq::exception::ApplicationDescriptorNotFound& e) {
    if (0!=head) head->release();
    totalSize=0;
    string errmsg="Failed to get tid.";
    LOG4CPLUS_FATAL(log_,errmsg);
    XCEPT_RETHROW(evf::Exception,errmsg,e);
  }
  
  return head;
}
UInt_t SMProxy::sendDataEvent ( UInt_t  fuResourceId,
UInt_t  runNumber,
UInt_t  evtNumber,
UInt_t  outModId,
UInt_t  fuProcessId,
UInt_t  fuGuid,
UChar_t data,
UInt_t  dataSize 
) throw (evf::Exception)

Definition at line 110 of file SMProxy.cc.

References runTheMatrix::data, _I2O_SM_DATA_MESSAGE_FRAME::eventID, Exception, _I2O_SM_DATA_MESSAGE_FRAME::fuGUID, _I2O_SM_DATA_MESSAGE_FRAME::fuProcID, I2O_SM_DATA, runTheMatrix::msg, _I2O_SM_DATA_MESSAGE_FRAME::outModID, _I2O_SM_DATA_MESSAGE_FRAME::rbBufferID, _I2O_SM_DATA_MESSAGE_FRAME::runID, and inputsource_file_cfi::runNumber.

{
  UInt_t    totalSize=0;
  MemRef_t* bufRef   =createFragmentChain(I2O_SM_DATA,
                                          dataHeaderSize_,
                                          data,
                                          dataSize,
                                          totalSize);
  
  I2O_SM_DATA_MESSAGE_FRAME *msg;
  MemRef_t* next=bufRef;
  do {
    msg=(I2O_SM_DATA_MESSAGE_FRAME*)next->getDataLocation();
    msg->rbBufferID=fuResourceId;
    msg->runID   =runNumber;
    msg->eventID =evtNumber;
    msg->outModID=outModId;
    msg->fuProcID=fuProcessId;
    msg->fuGUID=fuGuid;
  }
  while ((next=next->getNextReference()));
  
  try {
    fuAppContext_->postFrame(bufRef,fuAppDesc_,smAppDesc_);
  }
  catch (xdaq::exception::Exception &e) {
    string errmsg="Failed to post DATA Message.";
    LOG4CPLUS_FATAL(log_,errmsg);
    XCEPT_RETHROW(evf::Exception,errmsg,e);
  }
  
  return totalSize;
}
UInt_t SMProxy::sendDqmEvent ( UInt_t  fuDqmId,
UInt_t  runNumber,
UInt_t  evtAtUpdate,
UInt_t  folderId,
UInt_t  fuProcessId,
UInt_t  fuGuid,
UChar_t data,
UInt_t  dataSize 
) throw (evf::Exception)

Definition at line 197 of file SMProxy.cc.

References runTheMatrix::data, _I2O_SM_DQM_MESSAGE_FRAME::eventAtUpdateID, Exception, _I2O_SM_DQM_MESSAGE_FRAME::folderID, _I2O_SM_DQM_MESSAGE_FRAME::fuGUID, _I2O_SM_DQM_MESSAGE_FRAME::fuProcID, I2O_SM_DQM, runTheMatrix::msg, _I2O_SM_DQM_MESSAGE_FRAME::rbBufferID, _I2O_SM_DQM_MESSAGE_FRAME::runID, and inputsource_file_cfi::runNumber.

{
  UInt_t    totalSize=0;
  MemRef_t* bufRef   =createFragmentChain(I2O_SM_DQM,
                                          dqmHeaderSize_,
                                          data,
                                          dataSize,
                                          totalSize);
  
  I2O_SM_DQM_MESSAGE_FRAME *msg;
  MemRef_t* next=bufRef;
  do {
    msg=(I2O_SM_DQM_MESSAGE_FRAME*)next->getDataLocation();
    msg->rbBufferID     =fuDqmId;
    msg->runID          =runNumber;
    msg->eventAtUpdateID=evtAtUpdate;
    msg->folderID       =folderId;
    msg->fuProcID       =fuProcessId;
    msg->fuGUID         =fuGuid;
  }
  while ((next=next->getNextReference()));
  
  try {
    fuAppContext_->postFrame(bufRef,fuAppDesc_,smAppDesc_);
  }
  catch (xdaq::exception::Exception &e) {
    string errmsg="Failed to post DQM Message.";
    LOG4CPLUS_FATAL(log_,errmsg);
    XCEPT_RETHROW(evf::Exception,errmsg,e);
  }
 
  return totalSize;
}
UInt_t SMProxy::sendErrorEvent ( UInt_t  fuResourceId,
UInt_t  runNumber,
UInt_t  evtNumber,
UInt_t  fuProcessId,
UInt_t  fuGuid,
UChar_t data,
UInt_t  dataSize 
) throw (evf::Exception)

Definition at line 154 of file SMProxy.cc.

References runTheMatrix::data, _I2O_SM_DATA_MESSAGE_FRAME::eventID, Exception, _I2O_SM_DATA_MESSAGE_FRAME::fuGUID, _I2O_SM_DATA_MESSAGE_FRAME::fuProcID, I2O_SM_ERROR, runTheMatrix::msg, _I2O_SM_DATA_MESSAGE_FRAME::outModID, _I2O_SM_DATA_MESSAGE_FRAME::rbBufferID, _I2O_SM_DATA_MESSAGE_FRAME::runID, and inputsource_file_cfi::runNumber.

{
  UInt_t    totalSize=0;
  MemRef_t* bufRef   =createFragmentChain(I2O_SM_ERROR,
                                          dataHeaderSize_,
                                          data,
                                          dataSize,
                                          totalSize);
  
  I2O_SM_DATA_MESSAGE_FRAME *msg;
  MemRef_t* next=bufRef;
  do {
    msg=(I2O_SM_DATA_MESSAGE_FRAME*)next->getDataLocation();
    msg->rbBufferID=fuResourceId;
    msg->runID   =runNumber;
    msg->eventID =evtNumber;
    msg->outModID=0xffffffff;
    msg->fuProcID=fuProcessId;
    msg->fuGUID=fuGuid;
  }
  while ((next=next->getNextReference()));
  
  try {
    fuAppContext_->postFrame(bufRef,fuAppDesc_,smAppDesc_);
  }
  catch (xdaq::exception::Exception &e) {
    string errmsg="Failed to post ERROR Message.";
    LOG4CPLUS_FATAL(log_,errmsg);
    XCEPT_RETHROW(evf::Exception,errmsg,e);
  }
  
  return totalSize;
}
UInt_t SMProxy::sendInitMessage ( UInt_t  fuResourceId,
UInt_t  outModId,
UInt_t  fuProcessId,
UInt_t  fuGuid,
UChar_t data,
UInt_t  dataSize 
) throw (evf::Exception)

Definition at line 71 of file SMProxy.cc.

References runTheMatrix::data, Exception, _I2O_SM_PREAMBLE_MESSAGE_FRAME::fuGUID, _I2O_SM_PREAMBLE_MESSAGE_FRAME::fuProcID, I2O_SM_PREAMBLE, runTheMatrix::msg, _I2O_SM_PREAMBLE_MESSAGE_FRAME::outModID, and _I2O_SM_PREAMBLE_MESSAGE_FRAME::rbBufferID.

{
  UInt_t    totalSize=0;
  MemRef_t* bufRef   =createFragmentChain(I2O_SM_PREAMBLE,
                                          initHeaderSize_,
                                          data,
                                          dataSize,
                                          totalSize);
  
  I2O_SM_PREAMBLE_MESSAGE_FRAME *msg;
  MemRef_t* next=bufRef;
  do {
    msg=(I2O_SM_PREAMBLE_MESSAGE_FRAME*)next->getDataLocation();
    msg->rbBufferID=fuResourceId;
    msg->outModID=outModId;
    msg->fuProcID=fuProcessId;
    msg->fuGUID=fuGuid;
  }
  while ((next=next->getNextReference()));

  try {
    fuAppContext_->postFrame(bufRef,fuAppDesc_,smAppDesc_);
  }
  catch (xdaq::exception::Exception &e) {
    string msg="Failed to post INIT Message.";
    XCEPT_RETHROW(evf::Exception,msg,e);
  }
  
  return totalSize;
}

Member Data Documentation

Definition at line 87 of file SMProxy.h.

Definition at line 88 of file SMProxy.h.

xdaq::ApplicationContext* evf::SMProxy::fuAppContext_ [private]

Definition at line 83 of file SMProxy.h.

xdaq::ApplicationDescriptor* evf::SMProxy::fuAppDesc_ [private]

Definition at line 81 of file SMProxy.h.

Referenced by SMProxy().

std::string evf::SMProxy::fuClassName_ [private]

Definition at line 91 of file SMProxy.h.

Referenced by SMProxy().

std::string evf::SMProxy::fuUrl_ [private]

Definition at line 90 of file SMProxy.h.

Referenced by SMProxy().

toolbox::mem::Pool* evf::SMProxy::i2oPool_ [private]

Definition at line 84 of file SMProxy.h.

Definition at line 86 of file SMProxy.h.

Logger evf::SMProxy::log_ [private]

Definition at line 80 of file SMProxy.h.

xdaq::ApplicationDescriptor* evf::SMProxy::smAppDesc_ [private]

Definition at line 82 of file SMProxy.h.