CMS 3D CMS Logo

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

evf::FUResource Class Reference

#include <FUResource.h>

List of all members.

Public Member Functions

void allocate (FUShmRawCell *shmCell)
void appendBlockToSuperFrag (MemRef_t *bufRef)
UInt_t buResourceId () const
void checkDataBlockPayload (MemRef_t *bufRef) throw (evf::Exception)
bool crcBeingChecked ()
void doCrcCheck (bool doCrcCheck)
UInt_t evtNumber () const
bool fatalError () const
void fillSuperFragPayload () throw (evf::Exception)
void findFEDs () throw (evf::Exception)
 FUResource (UInt_t fuResourceId, log4cplus::Logger, EvffedFillerRB *, xdaq::Application *)
UInt_t fuResourceId () const
void incNbSent ()
bool isAllocated () const
bool isComplete () const
UInt_t nbBytes (bool reset=true)
UInt_t nbCrcErrors (bool reset=true)
UInt_t nbErrors (bool reset=true)
UInt_t nbSent () const
void process (MemRef_t *bufRef)
void processDataBlock (MemRef_t *bufRef) throw (evf::Exception)
void release ()
void releaseSuperFrag ()
void removeLastAppendedBlockFromSuperFrag ()
void scheduleCRCError ()
evf::FUShmRawCellshmCell ()
void superFragSize () throw (evf::Exception)
virtual ~FUResource ()

Static Public Member Functions

static void doFedIdCheck (bool doFedIdCheck)
static void useEvmBoard (bool useEvmBoard)

Private Attributes

xdaq::Application * app_
UInt_t buResourceId_
bool doCrcCheck_
UInt_t eventPayloadSize_
UInt_t eventSize_
UInt_t evtNumber_
bool fatalError_
UInt_t fedSize_ [1024]
EvffedFillerRBfrb_
UInt_t fuResourceId_
UInt_t iBlock_
UInt_t iSuperFrag_
log4cplus::Logger log_
UInt_t nbBytes_
UInt_t nbCrcErrors_
UInt_t nbErrors_
UInt_t nBlock_
UInt_t nbSent_
bool nextEventWillHaveCRCError_
UInt_t nFedMax_
UInt_t nSuperFrag_
UInt_t nSuperFragMax_
evf::FUShmRawCellshmCell_
MemRef_tsuperFragHead_
UInt_t superFragSize_
MemRef_tsuperFragTail_

Static Private Attributes

static bool doFedIdCheck_ = true
static unsigned int gtpDaqId_ = FEDNumbering::MAXTriggerGTPFEDID
static unsigned int gtpeId_ = FEDNumbering::MINTriggerEGTPFEDID
static unsigned int gtpEvmId_ = FEDNumbering::MINTriggerGTPFEDID
static bool useEvmBoard_ = true

Detailed Description

Definition at line 23 of file FUResource.h.


Constructor & Destructor Documentation

FUResource::FUResource ( UInt_t  fuResourceId,
log4cplus::Logger  logger,
EvffedFillerRB frb,
xdaq::Application *  app 
)

Definition at line 58 of file FUResource.cc.

References release().

FUResource::~FUResource ( ) [virtual]

Definition at line 77 of file FUResource.cc.

{
  
}

Member Function Documentation

void FUResource::allocate ( FUShmRawCell shmCell)
void FUResource::appendBlockToSuperFrag ( MemRef_t bufRef)

Definition at line 481 of file FUResource.cc.

References superFragHead_, and superFragTail_.

{
  if (0==superFragHead_) {
    superFragHead_=bufRef;
    superFragTail_=bufRef;
  }
  else {
    superFragTail_->setNextReference(bufRef);
    superFragTail_=bufRef;
  }
  return;
}
UInt_t evf::FUResource::buResourceId ( ) const [inline]

Definition at line 67 of file FUResource.h.

References buResourceId_.

{ return buResourceId_; }
void FUResource::checkDataBlockPayload ( MemRef_t bufRef) throw (evf::Exception)

Definition at line 380 of file FUResource.cc.

References createPayload::block.

{
  UInt_t   frameSize      =0;
  UInt_t   bufSize        =0;
  UInt_t   segSize        =0;
  UInt_t   segSizeExpected=0;

  frlh_t  *frlHeader      =0;
  
  UChar_t *blockAddr      =0;
  UChar_t *frlHeaderAddr  =0;
  
  frameSize    =sizeof(I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME);

  blockAddr    =(UChar_t*)bufRef->getDataLocation();
  frlHeaderAddr=blockAddr+frameSize;
  frlHeader    =(frlh_t*)frlHeaderAddr;
  
  I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME *block
    =(I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME*)blockAddr;
    

  // check that FRL trigno is consistent with FU evtNumber
  if(evtNumber_!=frlHeader->trigno) {
    nbErrors_++;
    std::stringstream oss;
    oss<<"FRL header \"trigno\" does not match "
       <<"FU  \"evtNumber\"."
       <<" trigno:"<<frlHeader->trigno
       <<" evtNumber:"<<evtNumber_;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  

  // check that FRL trigno is consistent with RU eventNumber
  if(block->eventNumber!=frlHeader->trigno) {
    nbErrors_++;
    std::stringstream oss;
    oss<<"FRL header \"trigno\" does not match "
       <<"RU builder header \"eventNumber\"."
       <<" trigno:"<<frlHeader->trigno
       <<" eventNumber:"<<block->eventNumber;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  

  // check that block numbers reported by FRL / RU are consistent
  if(block->blockNb!=frlHeader->segno) {
    nbErrors_++;
    std::stringstream oss;
    oss<<"FRL header \"segno\" does not match"
       <<"RU builder header \"blockNb\"."
       <<" segno:"<<frlHeader->segno
       <<" blockNb:"<<block->blockNb;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  
  
  // reported block number consistent with expectation
  if(block->blockNb!=iBlock_) {
    nbErrors_++;
    std::stringstream oss;
    oss<<"Incorrect block number."
       <<" Expected:"<<iBlock_
       <<" Received:"<<block->blockNb;
    XCEPT_RAISE(evf::Exception, oss.str());
  }
  
  
  // reported payload size consistent with expectation
  bufSize        =bufRef->getDataSize();
  segSizeExpected=bufSize-frameSize-sizeof(frlh_t);
  segSize        =frlHeader->segsize & FRL_SEGSIZE_MASK;
  if(segSize!=segSizeExpected) {
    nbErrors_++;
    std::stringstream oss;
    oss<<"FRL header segment size is not as expected."
       <<" Expected:"<<segSizeExpected
       <<" Received:"<<segSize;
    XCEPT_RAISE(evf::Exception, oss.str());
  }
  
  
  // Check that FU and FRL headers agree on end of super-fragment
  bool fuLastBlockInSuperFrag =(block->blockNb==(block->nbBlocksInSuperFragment-1));
  bool frlLastBlockInSuperFrag=((frlHeader->segsize & FRL_LAST_SEGM)!=0);
  if (fuLastBlockInSuperFrag!=frlLastBlockInSuperFrag) {
    nbErrors_++;
    std::stringstream oss;
    oss<<"FU / FRL header end-of-superfragment mismatch."
       <<" FU header:"<<fuLastBlockInSuperFrag
       <<" FRL header:"<<frlLastBlockInSuperFrag;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  
  return;
}
bool evf::FUResource::crcBeingChecked ( ) [inline]

Definition at line 60 of file FUResource.h.

References doCrcCheck_.

{ return doCrcCheck_; }
void evf::FUResource::doCrcCheck ( bool  doCrcCheck) [inline]

Definition at line 58 of file FUResource.h.

References doCrcCheck(), and doCrcCheck_.

Referenced by evf::FUResourceTable::buildResource(), and doCrcCheck().

static void evf::FUResource::doFedIdCheck ( bool  doFedIdCheck) [inline, static]
UInt_t evf::FUResource::evtNumber ( ) const [inline]

Definition at line 68 of file FUResource.h.

References evtNumber_.

Referenced by findFEDs().

{ return evtNumber_; }
bool evf::FUResource::fatalError ( ) const [inline]

Definition at line 62 of file FUResource.h.

References fatalError_.

Referenced by evf::FUResourceTable::buildResource(), and process().

{ return fatalError_; }
void FUResource::fillSuperFragPayload ( ) throw (evf::Exception)

Definition at line 555 of file FUResource.cc.

References evtNumber_, fuResourceId_, iSuperFrag_, evf::FUShmRawCell::markSuperFrag(), nbBytes(), nbBytes_, nbErrors_, shmCell_, superFragHead_, superFragSize_, and evf::FUShmRawCell::writeData().

{
  UChar_t *blockAddr    =0;
  UChar_t *frlHeaderAddr=0;
  UChar_t *fedAddr      =0;
  UInt_t   nbBytes      =0;
  UInt_t   nbBytesTot   =0;
  frlh_t  *frlHeader    =0;
  UChar_t *bufferPos    =0;
  UChar_t *startPos     =0;
  
  MemRef_t* bufRef=superFragHead_;
  while(bufRef != 0) {
    blockAddr    =(UChar_t*)bufRef->getDataLocation();
    frlHeaderAddr=blockAddr+sizeof(I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME);
    fedAddr      =frlHeaderAddr+sizeof(frlh_t);
    frlHeader    =(frlh_t*)frlHeaderAddr;
    nbBytes      =frlHeader->segsize & FRL_SEGSIZE_MASK;
    nbBytesTot  +=nbBytes;
    
    // check if still within limits
    if(nbBytesTot>superFragSize_) {
      nbErrors_++;
      stringstream oss;
      oss<<"Reached end of buffer."
         <<" fuResourceId:"<<fuResourceId_
         <<" evtNumber:"<<evtNumber_
         <<" iSuperFrag:"<<iSuperFrag_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    bufferPos=shmCell_->writeData(fedAddr,nbBytes);
    if (0==startPos) startPos=bufferPos;
    
    nbBytes_+=nbBytes;
    bufRef=bufRef->getNextReference();
  }
  
  if (!shmCell_->markSuperFrag(iSuperFrag_,superFragSize_,startPos)) {
    nbErrors_++;
    stringstream oss;
    oss<<"Failed to mark super fragment in shared mem buffer."
       <<" fuResourceId:"<<fuResourceId_
       <<" evtNumber:"<<evtNumber_
       <<" iSuperFrag:"<<iSuperFrag_;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  
  return;
}
void FUResource::findFEDs ( ) throw (evf::Exception)

Definition at line 608 of file FUResource.cc.

References app_, evf::compute_crc(), fedt_struct::conscheck, evf::evtn::daq_board_sense(), doCrcCheck_, doFedIdCheck_, fedh_struct::eventid, fedt_struct::eventsize, evf::evtn::evm_board_sense(), evtNumber(), evtNumber_, FED_CRCS_MASK, FED_CRCS_SHIFT, FED_EVSZ_MASK, FED_HCTRLID, FED_HCTRLID_MASK, FED_LVL1_MASK, FED_RBIT_MASK, FED_TCTRLID, FED_TCTRLID_MASK, fedSize_, evf::evtn::get(), evf::evtn::getlbn(), gtpDaqId_, evf::evtn::gtpe_board_sense(), evf::evtn::gtpe_get(), gtpeId_, gtpEvmId_, FEDNumbering::inRange(), iSuperFrag_, log_, evf::FUShmRawCell::markFed(), nbCrcErrors_, nbErrors_, nextEventWillHaveCRCError_, random, REAL_SOID_MASK, evf::FUShmRawCell::setEvtNumber(), evf::FUShmRawCell::setLumiSection(), shmCell_, fedh_struct::sourceid, evf::FUShmRawCell::superFragAddr(), evf::FUShmRawCell::superFragSize(), superFragSize(), and useEvmBoard_.

{
  UChar_t* superFragAddr =0;
  UInt_t   superFragSize =0;
  
  UChar_t *fedTrailerAddr=0;
  UChar_t *fedHeaderAddr =0;
  
  UInt_t   fedSize       =0;
  UInt_t   sumOfFedSizes =0;
  UInt_t   evtNumber     =0;
  
  UShort_t crc           =0;
  UShort_t crcChk        =0;
  
  fedt_t  *fedTrailer    =0;
  fedh_t  *fedHeader     =0;


  
  superFragAddr =shmCell_->superFragAddr(iSuperFrag_);
  superFragSize =shmCell_->superFragSize(iSuperFrag_);
  fedTrailerAddr=superFragAddr+superFragSize-sizeof(fedt_t);
  
  while (fedTrailerAddr>superFragAddr) {
    
    fedTrailer    =(fedt_t*)fedTrailerAddr;
    fedSize       =(fedTrailer->eventsize & FED_EVSZ_MASK) << 3;
    sumOfFedSizes+=fedSize;
    
    // check for fed trailer id
    if ((fedTrailer->eventsize & FED_TCTRLID_MASK)!=FED_TCTRLID) {
      nbErrors_++;
      stringstream oss;
      oss<<"Missing FED trailer id."
         <<" evtNumber:"<<evtNumber_
         <<" iSuperFrag:"<<iSuperFrag_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    fedHeaderAddr=fedTrailerAddr-fedSize+sizeof(fedt_t);
    
    // check that fed header is within buffer
    if(fedHeaderAddr<superFragAddr) {
      nbErrors_++;
      stringstream oss;
      oss<<"FED header address out-of-bounds."
         <<" evtNumber:"<<evtNumber_
         <<" iSuperFrag:"<<iSuperFrag_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    // check that payload starts within buffer
    if((fedHeaderAddr+sizeof(fedh_t))>(superFragAddr+superFragSize)) {
      nbErrors_++;
      stringstream oss;
      oss<<"FED payload out-of-bounds."
         <<" evtNumber:"<<evtNumber_
         <<" iSuperFrag:"<<iSuperFrag_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    fedHeader  =(fedh_t*)fedHeaderAddr;
    
    // check for fed header id
    if ((fedHeader->eventid & FED_HCTRLID_MASK)!=FED_HCTRLID) {
      nbErrors_++;
      stringstream oss;
      oss<<"Missing FED header id."
         <<" evtNumber:"<<evtNumber_
         <<" iSuperFrag:"<<iSuperFrag_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    UInt_t fedId=(fedHeader->sourceid & REAL_SOID_MASK) >> 8;
    
    // check evtNumber consisency
    evtNumber=fedHeader->eventid & FED_LVL1_MASK;
    if (evtNumber!=evtNumber_) {
      nbErrors_++;
      stringstream oss;
      oss<<"FU / FED evtNumber mismatch."
         <<" FU:"<<evtNumber_
         <<" FED:"<<evtNumber
         <<" fedid:"<<fedId;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
  
    // check that fedid is within valid ranges
    if (fedId>=1024||
        (doFedIdCheck_&&(!FEDNumbering::inRange(fedId)))) {
      LOG4CPLUS_WARN(log_,"Invalid fedid. Data will still be logged"
                     <<" evtNumber:"<<evtNumber_
                     <<" fedid:"<<fedId);
      nbErrors_++;
    }

    // check if a previous fed has already claimed same fed id

    if(fedSize_[fedId]!=0) {
      LOG4CPLUS_ERROR(log_,"Duplicated fedid. Data will be lost for"
                      <<" evtNumber:"<<evtNumber_
                      <<" fedid:"<<fedId);
      nbErrors_++;
    }
    
    if (fedId<1024) fedSize_[fedId]=fedSize;

    //if gtp EVM block is available set cell event number to global partition-independent trigger number
    //daq block partition-independent event number is left as an option in case of problems

    if(fedId == gtpeId_)
      if(evf::evtn::gtpe_board_sense(fedHeaderAddr)) shmCell_->setEvtNumber(evf::evtn::gtpe_get(fedHeaderAddr));
    if(useEvmBoard_ && (fedId == gtpEvmId_))
      if(evf::evtn::evm_board_sense(fedHeaderAddr,fedSize)) {
        shmCell_->setEvtNumber(evf::evtn::get(fedHeaderAddr, true));
        shmCell_->setLumiSection(evf::evtn::getlbn(fedHeaderAddr));
      }
    if(!useEvmBoard_ && (fedId == gtpDaqId_))
      if(evf::evtn::daq_board_sense(fedHeaderAddr)) {
        shmCell_->setEvtNumber(evf::evtn::get(fedHeaderAddr, false));
      }
    // crc check
    if (doCrcCheck_) {
      UInt_t conscheck=fedTrailer->conscheck;
      crc=((fedTrailer->conscheck & FED_CRCS_MASK) >> FED_CRCS_SHIFT);
      fedTrailer->conscheck &= (~FED_CRCS_MASK);
      fedTrailer->conscheck &= (~FED_RBIT_MASK);
      crcChk=compute_crc(fedHeaderAddr,fedSize);
      if(nextEventWillHaveCRCError_ && random() > RAND_MAX/2){
        crc--;
        nextEventWillHaveCRCError_ = false;
      }
      if (crc!=crcChk) {
        std::ostringstream oss;
        oss << "crc check failed."
            <<" evtNumber:"<<evtNumber_
            <<" fedid:"<<fedId
            <<" crc:"<<crc
            <<" chk:"<<crcChk;
        LOG4CPLUS_INFO(log_,oss.str());
        XCEPT_DECLARE(evf::Exception,
                      sentinelException, oss.str());
        app_->notifyQualified("error",sentinelException);
        nbErrors_++;
        nbCrcErrors_++;
      }
      fedTrailer->conscheck=conscheck;
    }
    
    
    // mark fed
    if (!shmCell_->markFed(fedId,fedSize,fedHeaderAddr)) {
      nbErrors_++;
      stringstream oss;
      oss<<"Failed to mark fed in buffer."
         <<" evtNumber:"<<evtNumber_
         <<" fedId:"<<fedId
         <<" fedSize:"<<fedSize
         <<" fedAddr:0x"<<hex<<(unsigned long)fedHeaderAddr<<dec;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    // Move to the next fed trailer
    fedTrailerAddr=fedTrailerAddr-fedSize;
  }
  
  // check that we indeed end up on the starting address of the buffer
  if ((fedTrailerAddr+sizeof(fedh_t))!=superFragAddr) {
    std::stringstream oss;
    oss<<"First FED in superfragment ouf-of-bound."
       <<" evtNumber:"<<evtNumber_
       <<" iSuperFrag:"<<iSuperFrag_;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  
  return;
}
UInt_t evf::FUResource::fuResourceId ( ) const [inline]

Definition at line 66 of file FUResource.h.

References fuResourceId_.

{ return fuResourceId_; }
void evf::FUResource::incNbSent ( ) [inline]

Definition at line 71 of file FUResource.h.

References nbSent_.

{ nbSent_++; }
bool evf::FUResource::isAllocated ( ) const [inline]

Definition at line 63 of file FUResource.h.

References shmCell_.

Referenced by evf::FUResourceTable::buildResource().

{ return 0!=shmCell_; }
bool evf::FUResource::isComplete ( ) const [inline]

Definition at line 146 of file FUResource.h.

References iBlock_, iSuperFrag_, nBlock_, and nSuperFrag_.

Referenced by evf::FUResourceTable::buildResource(), and process().

UInt_t FUResource::nbBytes ( bool  reset = true)

Definition at line 818 of file FUResource.cc.

References nbBytes_, and query::result.

Referenced by fillSuperFragPayload().

{
  UInt_t result=nbBytes_;
  if (reset) nbBytes_=0;
  return result;
}
UInt_t FUResource::nbCrcErrors ( bool  reset = true)

Definition at line 809 of file FUResource.cc.

References nbCrcErrors_, and query::result.

Referenced by evf::FUResourceTable::buildResource().

UInt_t FUResource::nbErrors ( bool  reset = true)

Definition at line 800 of file FUResource.cc.

References nbErrors_, and query::result.

Referenced by evf::FUResourceTable::buildResource().

UInt_t evf::FUResource::nbSent ( ) const [inline]

Definition at line 70 of file FUResource.h.

References nbSent_.

{ return nbSent_; }
void FUResource::process ( MemRef_t bufRef)

Definition at line 144 of file FUResource.cc.

References evtNumber_, Exception, fatalError(), fatalError_, evf::EvffedFillerRB::fedId(), fedSize_, frb_, fuResourceId_, evf::EvffedFillerRB::getPayload(), isComplete(), iSuperFrag_, log_, evf::FUShmRawCell::markFed(), evf::FUShmRawCell::markSuperFrag(), nbErrors_, processDataBlock(), evf::EvffedFillerRB::putHeader(), evf::EvffedFillerRB::putTrailer(), shmCell_, evf::EvffedFillerRB::size(), superFragSize_, and evf::FUShmRawCell::writeData().

Referenced by evf::FUResourceTable::buildResource().

{
  if (fatalError()) {
    LOG4CPLUS_WARN(log_,"THIS SHOULD *NEVER* HAPPEN!."); // DEBUG
    bufRef->release();
    return;
  }
  
  MemRef_t* itBufRef = bufRef;
  while(0!=itBufRef&&!fatalError()) {
    MemRef_t* next=itBufRef->getNextReference();
    itBufRef->setNextReference(0);
    try {
      processDataBlock(itBufRef);
    }
    catch (xcept::Exception& e) {
      LOG4CPLUS_ERROR(log_,"EVENT LOST:"
                      <<xcept::stdformat_exception_history(e));
      fatalError_=true;
      itBufRef->setNextReference(next); 
    }
    
    itBufRef=next;
  }
  if(isComplete()){
    frb_->putHeader(evtNumber_,0);
    frb_->putTrailer();
    fedSize_[frb_->fedId()]=frb_->size();  
    UChar_t *startPos = shmCell_->writeData(frb_->getPayload(),frb_->size());
    superFragSize_=frb_->size();
    if (!shmCell_->markSuperFrag(iSuperFrag_,superFragSize_,startPos)) {
      nbErrors_++;
      stringstream oss;
      oss<<"Failed to mark super fragment in shared mem buffer."
         <<" fuResourceId:"<<fuResourceId_
         <<" evtNumber:"<<evtNumber_
         <<" iSuperFrag:"<<iSuperFrag_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    if (!shmCell_->markFed(frb_->fedId(),frb_->size(),startPos)) {
      nbErrors_++;
      stringstream oss;
      oss<<"Failed to mark fed in buffer."
         <<" evtNumber:"<<evtNumber_
         <<" fedId:"<<frb_->fedId()
         <<" fedSize:"<<frb_->size()
         <<" fedAddr:0x"<<hex<<(unsigned long)frb_->getPayload()<<dec;
      XCEPT_RAISE(evf::Exception,oss.str());
    }

  }
  return;
}
void FUResource::processDataBlock ( MemRef_t bufRef) throw (evf::Exception)

Definition at line 201 of file FUResource.cc.

References createPayload::block, and Exception.

Referenced by process().

{
  // reset iBlock_/nBlock_ counters
  if (iBlock_==nBlock_) {
    iBlock_=0;
    nBlock_=0xffffffff;
  }
  
  I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME *block=
    (I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME*)bufRef->getDataLocation();
  
  UInt_t iBlock      =block->blockNb;
  UInt_t nBlock      =block->nbBlocksInSuperFragment;
  UInt_t iSuperFrag  =block->superFragmentNb;
  UInt_t nSuperFrag  =block->nbSuperFragmentsInEvent;
  
  UInt_t fuResourceId=block->fuTransactionId;
  UInt_t buResourceId=block->buResourceId;
  UInt_t evtNumber   =block->eventNumber;
  stringstream oss;
  oss << "TransId:" << fuResourceId << " BUResourceId:" 
      << buResourceId << " eventNumber:" << evtNumber << " "; 
  // check fuResourceId consistency
  if (fuResourceId!=fuResourceId_) {
    nbErrors_++;

    oss<<"RU/FU fuResourceId mismatch."
       <<" Received:"<<fuResourceId
       <<" Expected:"<<fuResourceId_;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  
  // check iBlock consistency
  if (iBlock!=iBlock_) {
    nbErrors_++;
    oss<<"RU/FU block number mismatch."
       <<" Received:"<<iBlock
       <<" Expected:"<<iBlock_;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  
  // check iSuperFrag consistency
  if (iSuperFrag!=iSuperFrag_) {
    nbErrors_++;
    oss<<"RU/FU superfragment number mismatch."
       <<" Received:"<<iSuperFrag
       <<" Expected:"<<iSuperFrag_;
    XCEPT_RAISE(evf::Exception,oss.str());
  }

  // assign nBlock_
  if (iBlock==0) {
    nBlock_=nBlock;
  }
  else {
    // check nBlock_
    if (nBlock!=nBlock_) {
      nbErrors_++;
      oss<<"RU/FU number of blocks mismatch."
         <<" Received:"<<nBlock
         <<" Expected:"<<nBlock_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
  }
  
  
  // if this is the first block in the event,
  // *assign* evtNumber,buResourceId,nSuperFrag ...
  if (iBlock==0&&iSuperFrag==0) {
    evtNumber_   =evtNumber;
    buResourceId_=buResourceId;
    nSuperFrag_  =nSuperFrag;
    
    shmCell_->setEvtNumber(evtNumber);
    shmCell_->setBuResourceId(buResourceId);

    // check that buffers are allocated for nSuperFrag superfragments
    if(nSuperFrag_>nSuperFragMax_) {
      nbErrors_++;
      oss<<"Invalid maximum number of superfragments."
         <<" fuResourceId:"<<fuResourceId_
         <<" evtNumber:"<<evtNumber_
         <<" nSuperFrag:"<<nSuperFrag_
         <<" nSuperFragMax:"<<nSuperFragMax_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
  }
  // ... otherwise,
  // *check* evtNumber,buResourceId,nSuperFrag
  else {
    // check evtNumber
    if (evtNumber!=evtNumber_) {
      nbErrors_++;
      oss<<"RU/FU evtNumber mismatch."
         <<" Received:"<<evtNumber
         <<" Expected:"<<evtNumber_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    // check buResourceId
    if (buResourceId!=buResourceId_) {
      nbErrors_++;
      oss<<"RU/FU buResourceId mismatch."
         <<" Received:"<<buResourceId
         <<" Expected:"<<buResourceId_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
    
    // check nSuperFrag
    if (nSuperFrag!=nSuperFrag_) {
      nbErrors_++;
      oss<<"RU/FU number of superfragments mismatch."
         <<" Received:"<<nSuperFrag
         <<" Expected:"<<nSuperFrag_;
      XCEPT_RAISE(evf::Exception,oss.str());
    }
  }
  
  
  // check payload
  try {
    checkDataBlockPayload(bufRef);
  }
  catch (xcept::Exception& e) {
    oss<<"data block payload failed check."
       <<" evtNumber:"<<evtNumber_
       <<" buResourceId:"<<buResourceId_
       <<" iSuperFrag:"<<iSuperFrag_;
    XCEPT_RETHROW(evf::Exception,oss.str(),e);
  }
  
  appendBlockToSuperFrag(bufRef);

  // increment iBlock_, as expected for the next message
  iBlock_++;
  
  // superfragment complete ...
  bool lastBlockInSuperFrag=(iBlock==nBlock-1);
  if (lastBlockInSuperFrag) {
    
    // ... fill the FED buffers contained in the superfragment
    try {
      superFragSize();
      fillSuperFragPayload();
      findFEDs();
    }
    catch (xcept::Exception& e) {
      oss<<"Invalid super fragment."
         <<" evtNumber:"<<evtNumber_
         <<" buResourceId:"<<buResourceId_
         <<" iSuperFrag:"<<iSuperFrag_;
      removeLastAppendedBlockFromSuperFrag();
      XCEPT_RETHROW(evf::Exception,oss.str(),e);
    }
    
    // ... release the buffers associated with the superfragment
    try {
      releaseSuperFrag();
    }
    catch (xcept::Exception& e) {
      nbErrors_++;
      oss<<"Failed to release super fragment."
         <<" evtNumber:"<<evtNumber_
         <<" buResourceId:"<<buResourceId_
         <<" iSuperFrag:"<<iSuperFrag_;
      XCEPT_RETHROW(evf::Exception,oss.str(),e);
    }

    // increment iSuperFrag_, as expected for the next message(s)
    iSuperFrag_++;
    
  } // lastBlockInSuperFragment
  
  return;
}
void FUResource::release ( )

Definition at line 102 of file FUResource.cc.

References buResourceId_, doCrcCheck_, eventSize_, evtNumber_, Exception, fatalError_, fedSize_, i, iBlock_, iSuperFrag_, log_, nbCrcErrors_, nbErrors_, nBlock_, nbSent_, nSuperFrag_, shmCell_, superFragHead_, and superFragTail_.

Referenced by evf::FUResourceTable::buildResource(), and FUResource().

{
  doCrcCheck_   =false;
  fatalError_   =false;
  
  buResourceId_ =0xffffffff;
  evtNumber_    =0xffffffff;
  
  if (0!=superFragHead_) {
    try {
      superFragHead_->release();
    }
    catch (xcept::Exception& e) {
      LOG4CPLUS_ERROR(log_,"Failed to release superFragHead: "
                      <<xcept::stdformat_exception_history(e));
    }
  }
  
  superFragHead_=0;
  superFragTail_=0;
  
  iBlock_       =0;
  nBlock_       =0xffffffff;
  iSuperFrag_   =0;
  nSuperFrag_   =0xffffffff;

  nbSent_       =0;
  
  nbErrors_     =0;
  nbCrcErrors_  =0;

  for (UInt_t i=0;i<1024;i++) fedSize_[i]=0;
  eventSize_    =0;
  
  if (0!=shmCell_) {
    shmdt(shmCell_);
    shmCell_=0;
  }
}
void FUResource::releaseSuperFrag ( )

Definition at line 789 of file FUResource.cc.

References superFragHead_, and superFragTail_.

{
  if (0==superFragHead_) return;
  superFragHead_->release(); // throws xcept::Exception
  superFragHead_=0;
  superFragTail_=0;
  return;
}
void FUResource::removeLastAppendedBlockFromSuperFrag ( )

Definition at line 495 of file FUResource.cc.

References cond::rpcobimon::current, superFragHead_, and superFragTail_.

{
  if (0==superFragHead_) {
    //nothing to do... why did we get here then ???
  }
  else if(superFragHead_==superFragTail_){
    superFragHead_ = 0; 
    superFragTail_ = 0;
  }
  else{
    MemRef_t *next = 0;
    MemRef_t *current = superFragHead_;
    while((next=current->getNextReference()) != superFragTail_){
      //get to the next-to-last block
    }
    superFragTail_ = current;
    current->setNextReference(0);
  }
  return;
}
void evf::FUResource::scheduleCRCError ( ) [inline]

Definition at line 79 of file FUResource.h.

References nextEventWillHaveCRCError_.

evf::FUShmRawCell* evf::FUResource::shmCell ( ) [inline]

Definition at line 77 of file FUResource.h.

References shmCell_.

Referenced by allocate(), and evf::FUResourceTable::buildResource().

{ return shmCell_; }
void FUResource::superFragSize ( ) throw (evf::Exception)

Definition at line 518 of file FUResource.cc.

References eventPayloadSize_, eventSize_, evtNumber_, fuResourceId_, iSuperFrag_, nbErrors_, superFragHead_, and superFragSize_.

Referenced by findFEDs().

{
  UChar_t *blockAddr    =0;
  UChar_t *frlHeaderAddr=0;
  frlh_t  *frlHeader    =0;

  superFragSize_=0;

  UInt_t frameSize=sizeof(I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME);
  MemRef_t* bufRef=superFragHead_;
  
  while (0!=bufRef) {
    blockAddr      =(UChar_t*)bufRef->getDataLocation();
    frlHeaderAddr  =blockAddr+frameSize;
    frlHeader      =(frlh_t*)frlHeaderAddr;
    superFragSize_+=frlHeader->segsize & FRL_SEGSIZE_MASK; 
    bufRef         =bufRef->getNextReference();
  }
  
  eventSize_+=superFragSize_;

  if (eventSize_>eventPayloadSize_) {  
    nbErrors_++;
    stringstream oss;
    oss<<"Event size exceeds maximum size."
       <<" fuResourceId:"<<fuResourceId_
       <<" evtNumber:"<<evtNumber_
       <<" iSuperFrag:"<<iSuperFrag_
       <<" eventSize:"<<eventSize_
       <<" eventPayloadSize:"<<eventPayloadSize_;
    XCEPT_RAISE(evf::Exception,oss.str());
  }
  
}
static void evf::FUResource::useEvmBoard ( bool  useEvmBoard) [inline, static]

Member Data Documentation

xdaq::Application* evf::FUResource::app_ [private]

Definition at line 123 of file FUResource.h.

Referenced by findFEDs().

Definition at line 95 of file FUResource.h.

Referenced by buResourceId(), and release().

Definition at line 91 of file FUResource.h.

Referenced by crcBeingChecked(), doCrcCheck(), findFEDs(), and release().

bool FUResource::doFedIdCheck_ = true [static, private]

Definition at line 88 of file FUResource.h.

Referenced by doFedIdCheck(), and findFEDs().

Definition at line 101 of file FUResource.h.

Referenced by allocate(), and superFragSize().

Definition at line 118 of file FUResource.h.

Referenced by release(), and superFragSize().

Definition at line 96 of file FUResource.h.

Referenced by evtNumber(), fillSuperFragPayload(), findFEDs(), process(), release(), and superFragSize().

Definition at line 92 of file FUResource.h.

Referenced by fatalError(), process(), and release().

Definition at line 116 of file FUResource.h.

Referenced by findFEDs(), process(), and release().

Definition at line 121 of file FUResource.h.

Referenced by process().

Definition at line 94 of file FUResource.h.

Referenced by allocate(), fillSuperFragPayload(), fuResourceId(), process(), and superFragSize().

unsigned int FUResource::gtpDaqId_ = FEDNumbering::MAXTriggerGTPFEDID [static, private]

Definition at line 127 of file FUResource.h.

Referenced by findFEDs().

unsigned int FUResource::gtpeId_ = FEDNumbering::MINTriggerEGTPFEDID [static, private]

Definition at line 129 of file FUResource.h.

Referenced by findFEDs().

unsigned int FUResource::gtpEvmId_ = FEDNumbering::MINTriggerGTPFEDID [static, private]

Definition at line 128 of file FUResource.h.

Referenced by findFEDs().

Definition at line 105 of file FUResource.h.

Referenced by isComplete(), and release().

log4cplus::Logger evf::FUResource::log_ [private]

Definition at line 85 of file FUResource.h.

Referenced by findFEDs(), process(), and release().

Definition at line 114 of file FUResource.h.

Referenced by fillSuperFragPayload(), and nbBytes().

Definition at line 113 of file FUResource.h.

Referenced by findFEDs(), nbCrcErrors(), and release().

Definition at line 112 of file FUResource.h.

Referenced by fillSuperFragPayload(), findFEDs(), nbErrors(), process(), release(), and superFragSize().

Definition at line 106 of file FUResource.h.

Referenced by isComplete(), and release().

Definition at line 110 of file FUResource.h.

Referenced by incNbSent(), nbSent(), and release().

Definition at line 125 of file FUResource.h.

Referenced by findFEDs(), and scheduleCRCError().

Definition at line 102 of file FUResource.h.

Referenced by allocate().

Definition at line 108 of file FUResource.h.

Referenced by isComplete(), and release().

Definition at line 103 of file FUResource.h.

Referenced by allocate().

Definition at line 117 of file FUResource.h.

Referenced by fillSuperFragPayload(), process(), and superFragSize().

bool FUResource::useEvmBoard_ = true [static, private]

Definition at line 90 of file FUResource.h.

Referenced by findFEDs(), and useEvmBoard().