CMS 3D CMS Logo

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

evf::BUEvent Class Reference

#include <BUEvent.h>

List of all members.

Public Member Functions

 BUEvent (unsigned int buResourceId, unsigned int bufferSize=0x400000)
unsigned int bufferSize () const
unsigned int buResourceId () const
void dump ()
unsigned int evtNumber () const
unsigned int evtSize () const
unsigned char * fedAddr (unsigned int i) const
unsigned int fedId (unsigned int i) const
unsigned int fedSize (unsigned int i) const
void initialize (unsigned int evtNumber)
unsigned int nFed () const
bool writeFed (unsigned int id, unsigned char *data, unsigned int size)
bool writeFedHeader (unsigned int i)
bool writeFedTrailer (unsigned int i)
virtual ~BUEvent ()

Static Public Member Functions

static bool computeCrc ()
static void setComputeCrc (bool computeCrc)

Private Attributes

unsigned char * buffer_
unsigned int bufferSize_
unsigned int buResourceId_
unsigned int evtNumber_
unsigned int evtSize_
unsigned int * fedId_
unsigned int * fedPos_
unsigned int * fedSize_
unsigned int nFed_

Static Private Attributes

static bool computeCrc_ = true

Detailed Description

Definition at line 8 of file BUEvent.h.


Constructor & Destructor Documentation

BUEvent::BUEvent ( unsigned int  buResourceId,
unsigned int  bufferSize = 0x400000 
)

Definition at line 41 of file BUEvent.cc.

References buffer_, bufferSize(), fedId_, fedPos_, and fedSize_.

  : buResourceId_(buResourceId)
  , evtNumber_(0xffffffff)
  , evtSize_(0)
  , bufferSize_(bufferSize)
  , nFed_(0)
  , fedId_(0)
  , fedPos_(0)
  , fedSize_(0)
  , buffer_(0)
{
  fedId_  = new unsigned int[1024];
  fedPos_ = new unsigned int[1024];
  fedSize_= new unsigned int[1024];
  buffer_ = new unsigned char[bufferSize];
}
BUEvent::~BUEvent ( ) [virtual]

Definition at line 60 of file BUEvent.cc.

References buffer_, fedId_, fedPos_, and fedSize_.

{
  if (0!=fedId_)   delete [] fedId_;
  if (0!=fedPos_)  delete [] fedPos_;
  if (0!=fedSize_) delete [] fedSize_;
  if (0!=buffer_)  delete [] buffer_;
}

Member Function Documentation

unsigned int evf::BUEvent::bufferSize ( ) const [inline]

Definition at line 30 of file BUEvent.h.

References bufferSize_.

Referenced by BUEvent().

{ return bufferSize_; }
unsigned int evf::BUEvent::buResourceId ( ) const [inline]

Definition at line 27 of file BUEvent.h.

References buResourceId_.

Referenced by evf::BU::createMsgChain().

{ return buResourceId_; }
static bool evf::BUEvent::computeCrc ( ) [inline, static]

Definition at line 36 of file BUEvent.h.

References computeCrc_.

Referenced by setComputeCrc(), and writeFedTrailer().

{ return computeCrc_; }
void BUEvent::dump ( void  )

Definition at line 153 of file BUEvent.cc.

References evtNumber(), fedAddr(), fedId(), fedSize(), groupFilesInBlocks::fout, i, j, and nFed().

{
  ostringstream oss; oss<<"/tmp/autobu_evt"<<evtNumber()<<".dump";
  ofstream fout(oss.str().c_str());
  fout.fill('0');
  
  fout<<"#\n# evt "<<evtNumber()<<"\n#\n"<<endl;
  for (unsigned int i=0;i<nFed();i++) {
    if (fedSize(i)==0) continue;
    fout<<"# fedid "<<fedId(i)<<endl;
    unsigned char* addr=fedAddr(i);
    for (unsigned int j=0;j<fedSize(i);j++) {
      fout<<setiosflags(ios::right)<<setw(2)<<hex<<(int)(*addr)<<dec;
      if ((j+1)%8) fout<<" "; else fout<<endl;
      ++addr;
    }
    fout<<endl;
  }
  fout.close();
}
unsigned int evf::BUEvent::evtNumber ( ) const [inline]

Definition at line 28 of file BUEvent.h.

References evtNumber_.

Referenced by evf::BU::createMsgChain(), dump(), and writeFedHeader().

{ return evtNumber_; }
unsigned int evf::BUEvent::evtSize ( ) const [inline]

Definition at line 29 of file BUEvent.h.

References evtSize_.

Referenced by evf::BU::sending().

{ return evtSize_; }
unsigned char * BUEvent::fedAddr ( unsigned int  i) const

Definition at line 146 of file BUEvent.cc.

References buffer_, and fedPos_.

Referenced by evf::BU::createMsgChain(), dump(), writeFed(), writeFedHeader(), and writeFedTrailer().

{
  return (buffer_+fedPos_[i]);
}
unsigned int evf::BUEvent::fedId ( unsigned int  i) const [inline]

Definition at line 32 of file BUEvent.h.

References fedId_, and i.

Referenced by evf::BU::createMsgChain(), dump(), and writeFedHeader().

{ return fedId_[i]; }
unsigned int evf::BUEvent::fedSize ( unsigned int  i) const [inline]

Definition at line 33 of file BUEvent.h.

References fedSize_, and i.

Referenced by evf::BU::createMsgChain(), dump(), and writeFedTrailer().

{ return fedSize_[i]; }
void BUEvent::initialize ( unsigned int  evtNumber)

Definition at line 74 of file BUEvent.cc.

References evtNumber_, evtSize_, and nFed_.

Referenced by evf::BU::generateEvent().

 {
   evtNumber_=evtNumber & 0xFFFFFF; // 24 bits only available in the FED headers
   evtSize_=0;
   nFed_=0;
 }
unsigned int evf::BUEvent::nFed ( ) const [inline]

Definition at line 31 of file BUEvent.h.

References nFed_.

Referenced by evf::BU::createMsgChain(), and dump().

{ return nFed_; }
static void evf::BUEvent::setComputeCrc ( bool  computeCrc) [inline, static]

Definition at line 37 of file BUEvent.h.

References computeCrc(), and computeCrc_.

Referenced by evf::BU::actionPerformed(), and evf::BU::BU().

bool BUEvent::writeFed ( unsigned int  id,
unsigned char *  data,
unsigned int  size 
)

Definition at line 83 of file BUEvent.cc.

References bufferSize_, gather_cfg::cout, evtSize_, fedAddr(), fedId_, fedPos_, fedSize_, nFed_, and findQualityFiles::size.

Referenced by evf::BU::generateEvent().

{
  if (evtSize_+size > bufferSize_) {
    cout<<"BUEvent::writeFed() ERROR: buffer overflow."<<endl;
    return false;
  }
  
  if (nFed_==1024) {
    cout<<"BUEvent::writeFed() ERROR: too many feds (max=1024)."<<endl;
    return false;
  }
  
  fedId_[nFed_]  =id;
  fedPos_[nFed_] =evtSize_;
  fedSize_[nFed_]=size;
  if (0!=data) memcpy(fedAddr(nFed_),data,size);
  ++nFed_;
  evtSize_+=size;
  return true;
}
bool BUEvent::writeFedHeader ( unsigned int  i)

Definition at line 106 of file BUEvent.cc.

References gather_cfg::cout, fedh_struct::eventid, evtNumber(), FED_SOID_MASK, fedAddr(), fedId(), nFed_, and fedh_struct::sourceid.

Referenced by evf::BU::generateEvent().

{
  if (i>=nFed_) {
    cout<<"BUEvent::writeFedHeader() ERROR: invalid fed index '"<<i<<"'."<<endl;
    return false;
  }
  
  fedh_t *fedHeader=(fedh_t*)fedAddr(i);
  fedHeader->eventid =evtNumber();
  fedHeader->eventid|=0x50000000;
  fedHeader->sourceid=(fedId(i) << 8) & FED_SOID_MASK;
  
  return true;
}
bool BUEvent::writeFedTrailer ( unsigned int  i)

Definition at line 123 of file BUEvent.cc.

References evf::compute_crc(), computeCrc(), fedt_struct::conscheck, gather_cfg::cout, fedt_struct::eventsize, FED_CRCS_SHIFT, fedAddr(), fedSize(), and nFed_.

Referenced by evf::BU::generateEvent().

{
  if (i>=nFed_) {
    cout<<"BUEvent::writeFedTrailer() ERROR: invalid fed index '"<<i<<"'."<<endl;
    return false;
  }
  
  fedt_t *fedTrailer=(fedt_t*)(fedAddr(i)+fedSize(i)-sizeof(fedt_t));
  fedTrailer->eventsize =fedSize(i);
  fedTrailer->eventsize/=8; //wc in fed trailer in 64bit words
  fedTrailer->eventsize|=0xa0000000;
  fedTrailer->conscheck =0x0;
  
  if (BUEvent::computeCrc()) {
    unsigned short crc=evf::compute_crc(fedAddr(i),fedSize(i));
    fedTrailer->conscheck=(crc<<FED_CRCS_SHIFT);
  }

  return true;
}

Member Data Documentation

unsigned char* evf::BUEvent::buffer_ [private]

Definition at line 54 of file BUEvent.h.

Referenced by BUEvent(), fedAddr(), and ~BUEvent().

unsigned int evf::BUEvent::bufferSize_ [private]

Definition at line 49 of file BUEvent.h.

Referenced by bufferSize(), and writeFed().

unsigned int evf::BUEvent::buResourceId_ [private]

Definition at line 46 of file BUEvent.h.

Referenced by buResourceId().

bool BUEvent::computeCrc_ = true [static, private]

Definition at line 56 of file BUEvent.h.

Referenced by computeCrc(), and setComputeCrc().

unsigned int evf::BUEvent::evtNumber_ [private]

Definition at line 47 of file BUEvent.h.

Referenced by evtNumber(), and initialize().

unsigned int evf::BUEvent::evtSize_ [private]

Definition at line 48 of file BUEvent.h.

Referenced by evtSize(), initialize(), and writeFed().

unsigned int* evf::BUEvent::fedId_ [private]

Definition at line 51 of file BUEvent.h.

Referenced by BUEvent(), fedId(), writeFed(), and ~BUEvent().

unsigned int* evf::BUEvent::fedPos_ [private]

Definition at line 52 of file BUEvent.h.

Referenced by BUEvent(), fedAddr(), writeFed(), and ~BUEvent().

unsigned int* evf::BUEvent::fedSize_ [private]

Definition at line 53 of file BUEvent.h.

Referenced by BUEvent(), fedSize(), writeFed(), and ~BUEvent().

unsigned int evf::BUEvent::nFed_ [private]

Definition at line 50 of file BUEvent.h.

Referenced by initialize(), nFed(), writeFed(), writeFedHeader(), and writeFedTrailer().