CMS 3D CMS Logo

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

evf::FUShmBuffer Class Reference

#include <FUShmBuffer.h>

List of all members.

Public Member Functions

pid_t clientPrcId (unsigned int index)
void discardDqmCell (unsigned int iCell)
void discardOrphanedRecoCell (unsigned int iCell)
void discardRawCell (FUShmRawCell *cell)
void discardRecoCell (unsigned int iCell)
FUShmDqmCelldqmCell (unsigned int iCell)
FUShmDqmCelldqmCellToRead ()
dqm::State_t dqmState (unsigned int index)
unsigned int evtNumber (unsigned int index)
pid_t evtPrcId (unsigned int index)
evt::State_t evtState (unsigned int index)
time_t evtTimeStamp (unsigned int index)
void finishReadingDqmCell (FUShmDqmCell *cell)
void finishReadingRawCell (FUShmRawCell *cell)
void finishReadingRecoCell (FUShmRecoCell *cell)
void finishWritingRawCell (FUShmRawCell *cell)
void initialize (unsigned int shmid, unsigned int semid)
void lock ()
int nbRawCellsToRead () const
int nbRawCellsToWrite () const
unsigned int nClients () const
unsigned int nDqmCells () const
unsigned int nRawCells () const
unsigned int nRecoCells () const
void printDqmState (unsigned int index)
void printEvtState (unsigned int index)
FUShmRawCellrawCell (unsigned int iCell)
FUShmRawCellrawCellToDiscard ()
FUShmRawCellrawCellToRead ()
FUShmRawCellrawCellToWrite ()
FUShmRecoCellrecoCell (unsigned int iCell)
FUShmRecoCellrecoCellToRead ()
void releaseRawCell (FUShmRawCell *cell)
bool removeClientPrcId (pid_t prcId)
void reset ()
void scheduleRawCellForDiscard (unsigned int iCell)
void scheduleRawCellForDiscardServerSide (unsigned int iCell)
void scheduleRawEmptyCellForDiscard ()
void scheduleRawEmptyCellForDiscard (FUShmRawCell *cell)
void scheduleRawEmptyCellForDiscardServerSide (FUShmRawCell *cell)
void sem_print ()
int semid () const
bool setDqmState (unsigned int index, dqm::State_t state)
bool setEvtState (unsigned int index, evt::State_t state)
int shmid () const
void unlock ()
void writeDqmEmptyEvent ()
bool writeDqmEventData (unsigned int runNumber, unsigned int evtAtUpdate, unsigned int folderId, unsigned int fuProcessId, unsigned int fuGuid, unsigned char *data, unsigned int dataSize)
bool writeErrorEventData (unsigned int runNumber, unsigned int fuProcessId, unsigned int iRawCell)
void writeRawEmptyEvent ()
void writeRawLumiSectionEvent (unsigned int)
void writeRecoEmptyEvent ()
bool writeRecoEventData (unsigned int runNumber, unsigned int evtNumber, unsigned int outModId, unsigned int fuProcessId, unsigned int fuGuid, unsigned char *data, unsigned int dataSize)
bool writeRecoInitMsg (unsigned int outModId, unsigned int fuProcessId, unsigned int fuGuid, unsigned char *data, unsigned int dataSize)
 ~FUShmBuffer ()

Static Public Member Functions

static FUShmBuffercreateShmBuffer (bool semgmentationMode, unsigned int nRawCells, unsigned int nRecoCells, unsigned int nDqmCells, unsigned int rawCellSize=0x400000, unsigned int recoCellSize=0x400000, unsigned int dqmCellSize=0x400000)
static key_t getSemKey ()
static FUShmBuffergetShmBuffer ()
static key_t getShmDescriptorKey ()
static key_t getShmKey ()
static bool releaseSharedMemory ()
static int sem_create (key_t key, int nsem)
static int sem_destroy (int semid)
static int sem_get (key_t key, int nsem)
static void * shm_attach (int shmid)
static int shm_create (key_t key, int size)
static int shm_destroy (int shmid)
static int shm_get (key_t key, int size)
static int shm_nattch (int shmid)
static unsigned int size (bool segmentationMode, unsigned int nRawCells, unsigned int nRecoCells, unsigned int nDqmCells, unsigned int rawCellSize, unsigned int recoCellSize, unsigned int dqmCellSize)

Private Member Functions

key_t dqmCellShmKey (unsigned int iCell)
 FUShmBuffer (bool segmentationMode, unsigned int nRawCells, unsigned int nRecoCells, unsigned int nDqmCells, unsigned int rawCellSize, unsigned int recoCellSize, unsigned int dqmCellSize)
int incEvtDiscard (unsigned int index)
unsigned int indexForEvtNumber (unsigned int evtNumber)
unsigned int nextDqmReadIndex ()
unsigned int nextDqmWriteIndex ()
unsigned int nextIndex (unsigned int offset, unsigned int nCells, unsigned int &iNext)
unsigned int nextRawReadIndex ()
unsigned int nextRawWriteIndex ()
unsigned int nextRecoReadIndex ()
unsigned int nextRecoWriteIndex ()
void postDqmIndexToRead (unsigned int index)
void postDqmIndexToWrite (unsigned int index)
void postDqmRead ()
void postDqmWrite ()
void postIndex (unsigned int index, unsigned int offset, unsigned int nCells, unsigned int &iLast)
void postRawDiscard ()
void postRawDiscarded ()
void postRawIndexToRead (unsigned int index)
void postRawIndexToWrite (unsigned int index)
void postRawRead ()
void postRawWrite ()
void postRecoIndexToRead (unsigned int index)
void postRecoIndexToWrite (unsigned int index)
void postRecoRead ()
void postRecoWrite ()
bool rawCellReadyForDiscard (unsigned int index)
key_t rawCellShmKey (unsigned int iCell)
key_t recoCellShmKey (unsigned int iCell)
void sem_init (int isem, int value)
void sem_post (int isem)
int sem_wait (int isem)
bool setClientPrcId (pid_t prcId)
bool setEvtDiscard (unsigned int index, unsigned int discard)
bool setEvtNumber (unsigned int index, unsigned int evtNumber)
bool setEvtPrcId (unsigned int index, pid_t prcId)
bool setEvtTimeStamp (unsigned int index, time_t timeStamp)
key_t shmKey (unsigned int iCell, unsigned int offset)
void waitDqmRead ()
void waitDqmWrite ()
void waitRawDiscard ()
void waitRawDiscarded ()
void waitRawRead ()
void waitRawWrite ()
void waitRecoRead ()
void waitRecoWrite ()

Private Attributes

unsigned int clientPrcIdOffset_
unsigned int dqmCellOffset_
unsigned int dqmCellPayloadSize_
unsigned int dqmCellTotalSize_
unsigned int dqmReadIndex_
unsigned int dqmReadLast_
unsigned int dqmReadNext_
unsigned int dqmReadOffset_
unsigned int dqmStateOffset_
unsigned int dqmWriteIndex_
unsigned int dqmWriteLast_
unsigned int dqmWriteNext_
unsigned int dqmWriteOffset_
unsigned int evtDiscardOffset_
unsigned int evtNumberOffset_
unsigned int evtPrcIdOffset_
unsigned int evtStateOffset_
unsigned int evtTimeStampOffset_
unsigned int nClients_
unsigned int nClientsMax_
unsigned int nDqmCells_
unsigned int nRawCells_
unsigned int nRecoCells_
unsigned int rawCellOffset_
unsigned int rawCellPayloadSize_
unsigned int rawCellTotalSize_
unsigned int rawDiscardIndex_
unsigned int rawReadLast_
unsigned int rawReadNext_
unsigned int rawReadOffset_
unsigned int rawWriteLast_
unsigned int rawWriteNext_
unsigned int rawWriteOffset_
unsigned int recoCellOffset_
unsigned int recoCellPayloadSize_
unsigned int recoCellTotalSize_
unsigned int recoReadIndex_
unsigned int recoReadLast_
unsigned int recoReadNext_
unsigned int recoReadOffset_
unsigned int recoWriteIndex_
unsigned int recoWriteLast_
unsigned int recoWriteNext_
unsigned int recoWriteOffset_
bool segmentationMode_
int semid_
int shmid_

Static Private Attributes

static const char * semKeyPath_
static const char * shmKeyPath_

Detailed Description

Definition at line 40 of file FUShmBuffer.h.


Constructor & Destructor Documentation

FUShmBuffer::FUShmBuffer ( bool  segmentationMode,
unsigned int  nRawCells,
unsigned int  nRecoCells,
unsigned int  nDqmCells,
unsigned int  rawCellSize,
unsigned int  recoCellSize,
unsigned int  dqmCellSize 
) [private]

Definition at line 53 of file FUShmBuffer.cc.

References clientPrcIdOffset_, dqmCellOffset_, dqmCellPayloadSize_, dqmCellTotalSize_, dqmReadOffset_, dqmStateOffset_, dqmWriteOffset_, evtDiscardOffset_, evtNumberOffset_, evtPrcIdOffset_, evtStateOffset_, evtTimeStampOffset_, i, nClientsMax_, nDqmCells_, nRawCells_, nRecoCells_, rawCellOffset_, rawCellPayloadSize_, rawCellTotalSize_, rawReadOffset_, rawWriteOffset_, recoCellOffset_, recoCellPayloadSize_, recoCellTotalSize_, recoReadOffset_, recoWriteOffset_, segmentationMode_, and size().

Referenced by createShmBuffer(), getShmBuffer(), releaseSharedMemory(), and size().

  : segmentationMode_(segmentationMode)
  , nClientsMax_(128)
  , nRawCells_(nRawCells)
  , rawCellPayloadSize_(rawCellSize)
  , nRecoCells_(nRecoCells)
  , recoCellPayloadSize_(recoCellSize)
  , nDqmCells_(nDqmCells)
  , dqmCellPayloadSize_(dqmCellSize)
{
  rawCellTotalSize_ =FUShmRawCell::size(rawCellPayloadSize_);
  recoCellTotalSize_=FUShmRecoCell::size(recoCellPayloadSize_);
  dqmCellTotalSize_ =FUShmDqmCell::size(dqmCellPayloadSize_);

  void* addr;
  
  rawWriteOffset_=sizeof(FUShmBuffer);
  addr=(void*)((unsigned long)this+rawWriteOffset_);
  new (addr) unsigned int[nRawCells_];
  
  rawReadOffset_=rawWriteOffset_+nRawCells_*sizeof(unsigned int);
  addr=(void*)((unsigned long)this+rawReadOffset_);
  new (addr) unsigned int[nRawCells_];
 
  recoWriteOffset_=rawReadOffset_+nRawCells_*sizeof(unsigned int);
  addr=(void*)((unsigned long)this+recoWriteOffset_);
  new (addr) unsigned int[nRecoCells_];

  recoReadOffset_=recoWriteOffset_+nRecoCells_*sizeof(unsigned int);
  addr=(void*)((unsigned long)this+recoReadOffset_);
  new (addr) unsigned int[nRecoCells_];

  dqmWriteOffset_=recoReadOffset_+nRecoCells_*sizeof(unsigned int);
  addr=(void*)((unsigned long)this+dqmWriteOffset_);
  new (addr) unsigned int[nDqmCells_];

  dqmReadOffset_=dqmWriteOffset_+nDqmCells_*sizeof(unsigned int);
  addr=(void*)((unsigned long)this+dqmReadOffset_);
  new (addr) unsigned int[nDqmCells_];

  evtStateOffset_=dqmReadOffset_+nDqmCells_*sizeof(unsigned int);
  addr=(void*)((unsigned long)this+evtStateOffset_);
  new (addr) evt::State_t[nRawCells_];
  
  evtDiscardOffset_=evtStateOffset_+nRawCells_*sizeof(evt::State_t);
  addr=(void*)((unsigned long)this+evtDiscardOffset_);
  new (addr) unsigned int[nRawCells_];
  
  evtNumberOffset_=evtDiscardOffset_+nRawCells_*sizeof(unsigned int);
  addr=(void*)((unsigned long)this+evtNumberOffset_);
  new (addr) unsigned int[nRawCells_];
  
  evtPrcIdOffset_=evtNumberOffset_+nRawCells_*sizeof(unsigned int);
  addr=(void*)((unsigned long)this+evtPrcIdOffset_);
  new (addr) pid_t[nRawCells_];
  
  evtTimeStampOffset_=evtPrcIdOffset_+nRawCells_*sizeof(pid_t);
  addr=(void*)((unsigned long)this+evtTimeStampOffset_);
  new (addr) time_t[nRawCells_];
  
  dqmStateOffset_=evtTimeStampOffset_+nRawCells_*sizeof(time_t);
  addr=(void*)((unsigned long)this+dqmStateOffset_);
  new (addr) dqm::State_t[nDqmCells_];
  
  clientPrcIdOffset_=dqmStateOffset_+nDqmCells_*sizeof(dqm::State_t);
  addr=(void*)((unsigned long)this+clientPrcIdOffset_);
  new (addr) pid_t[nClientsMax_];

  rawCellOffset_=dqmStateOffset_+nClientsMax_*sizeof(pid_t);
  
  if (segmentationMode_) {
    recoCellOffset_=rawCellOffset_+nRawCells_*sizeof(key_t);
    dqmCellOffset_ =recoCellOffset_+nRecoCells_*sizeof(key_t);
    addr=(void*)((unsigned long)this+rawCellOffset_);
    new (addr) key_t[nRawCells_];
    addr=(void*)((unsigned long)this+recoCellOffset_);
    new (addr) key_t[nRecoCells_];
    addr=(void*)((unsigned long)this+dqmCellOffset_);
    new (addr) key_t[nDqmCells_];
  }
  else {
    recoCellOffset_=rawCellOffset_+nRawCells_*rawCellTotalSize_;
    dqmCellOffset_ =recoCellOffset_+nRecoCells_*recoCellTotalSize_;
    for (unsigned int i=0;i<nRawCells_;i++) {
      addr=(void*)((unsigned long)this+rawCellOffset_+i*rawCellTotalSize_);
      new (addr) FUShmRawCell(rawCellSize);
    }
    for (unsigned int i=0;i<nRecoCells_;i++) {
      addr=(void*)((unsigned long)this+recoCellOffset_+i*recoCellTotalSize_);
      new (addr) FUShmRecoCell(recoCellSize);
    }
    for (unsigned int i=0;i<nDqmCells_;i++) {
      addr=(void*)((unsigned long)this+dqmCellOffset_+i*dqmCellTotalSize_);
      new (addr) FUShmDqmCell(dqmCellSize);
    }
  }
}
FUShmBuffer::~FUShmBuffer ( )

Definition at line 159 of file FUShmBuffer.cc.

{
  
}

Member Function Documentation

pid_t FUShmBuffer::clientPrcId ( unsigned int  index)

Definition at line 1389 of file FUShmBuffer.cc.

References clientPrcIdOffset_, getHLTprescales::index, and nClientsMax_.

{
  assert(index<nClientsMax_);
  pid_t *prcid=(pid_t*)((unsigned long)this+clientPrcIdOffset_);
  prcid+=index;
  return *prcid;
}
FUShmBuffer * FUShmBuffer::createShmBuffer ( bool  semgmentationMode,
unsigned int  nRawCells,
unsigned int  nRecoCells,
unsigned int  nDqmCells,
unsigned int  rawCellSize = 0x400000,
unsigned int  recoCellSize = 0x400000,
unsigned int  dqmCellSize = 0x400000 
) [static]

Definition at line 853 of file FUShmBuffer.cc.

References gather_cfg::cout, FUShmBuffer(), getSemKey(), getShmDescriptorKey(), getShmKey(), initialize(), nDqmCells(), nRawCells(), nRecoCells(), L1TEmulatorMonitor_cff::p, releaseSharedMemory(), sem_create(), semid(), shm_attach(), shm_create(), shm_nattch(), shmid(), and size().

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

{
  // if necessary, release shared memory first!
  if (FUShmBuffer::releaseSharedMemory())
    cout<<"FUShmBuffer::createShmBuffer: "
        <<"REMOVAL OF OLD SHARED MEM SEGMENTS SUCCESSFULL."
        <<endl;
  
  // create bookkeeping shared memory segment
  int  size =sizeof(unsigned int)*7;
  int  shmid=shm_create(FUShmBuffer::getShmDescriptorKey(),size);if(shmid<0)return 0;
  void*shmAddr=shm_attach(shmid); if(0==shmAddr)return 0;
  
  if(1!=shm_nattch(shmid)) {
    cout<<"FUShmBuffer::createShmBuffer() FAILED: nattch="<<shm_nattch(shmid)<<endl;
    shmdt(shmAddr);
    return 0;
  }
  
  unsigned int* p=(unsigned int*)shmAddr;
  *p++=segmentationMode;
  *p++=nRawCells;
  *p++=nRecoCells;
  *p++=nDqmCells;
  *p++=rawCellSize;
  *p++=recoCellSize;
  *p++=dqmCellSize;
  shmdt(shmAddr);
  
  // create the 'real' shared memory buffer
  size     =FUShmBuffer::size(segmentationMode,
                              nRawCells,nRecoCells,nDqmCells,
                              rawCellSize,recoCellSize,dqmCellSize);
  shmid    =shm_create(FUShmBuffer::getShmKey(),size); if (shmid<0)    return 0;
  int semid=sem_create(FUShmBuffer::getSemKey(),9);    if (semid<0)    return 0;
  shmAddr  =shm_attach(shmid);                         if (0==shmAddr) return 0;
  
  if (1!=shm_nattch(shmid)) {
    cout<<"FUShmBuffer::createShmBuffer FAILED: nattch="<<shm_nattch(shmid)<<endl;
    shmdt(shmAddr);
    return 0;
  }
  FUShmBuffer* buffer=new(shmAddr) FUShmBuffer(segmentationMode,
                                               nRawCells,nRecoCells,nDqmCells,
                                               rawCellSize,recoCellSize,dqmCellSize);
  
  cout<<"FUShmBuffer::createShmBuffer(): CREATED shared memory buffer."<<endl;
  cout<<"                                segmentationMode="<<segmentationMode<<endl;
  
  buffer->initialize(shmid,semid);
  
  return buffer;
}
void FUShmBuffer::discardDqmCell ( unsigned int  iCell)
void FUShmBuffer::discardOrphanedRecoCell ( unsigned int  iCell)
void FUShmBuffer::discardRawCell ( FUShmRawCell cell)

Definition at line 456 of file FUShmBuffer.cc.

References postRawDiscard(), and releaseRawCell().

Referenced by evf::FUShmClient::readNext().

void FUShmBuffer::discardRecoCell ( unsigned int  iCell)

Definition at line 464 of file FUShmBuffer.cc.

References evf::FUShmRecoCell::clear(), nRawCells_, postRecoIndexToWrite(), postRecoWrite(), evf::FUShmRecoCell::rawCellIndex(), recoCell(), scheduleRawCellForDiscard(), and segmentationMode_.

{
  FUShmRecoCell* cell=recoCell(iCell);
  unsigned int iRawCell=cell->rawCellIndex();
  if (iRawCell<nRawCells_) {
    //evt::State_t state=evtState(iRawCell);
    //assert(state==evt::SENT);
    scheduleRawCellForDiscard(iRawCell);
  }
  cell->clear();
  if (segmentationMode_) shmdt(cell);
  postRecoIndexToWrite(iCell);
  postRecoWrite();
}
FUShmDqmCell * FUShmBuffer::dqmCell ( unsigned int  iCell)

Definition at line 1577 of file FUShmBuffer.cc.

References gather_cfg::cout, dqmCellOffset_, dqmCellPayloadSize_, dqmCellShmKey(), dqmCellTotalSize_, nDqmCells_, query::result, segmentationMode_, shm_attach(), shm_get(), and shmid().

Referenced by discardDqmCell(), dqmCellToRead(), initialize(), writeDqmEmptyEvent(), and writeDqmEventData().

{
  FUShmDqmCell* result(0);
  
  if (iCell>=nDqmCells_) {
    cout<<"FUShmBuffer::dqmCell("<<iCell<<") ERROR: "
        <<"iCell="<<iCell<<" >= nDqmCells="<<nDqmCells_<<endl;
    return result;
  }
  
  if (segmentationMode_) {
    key_t         shmkey  =dqmCellShmKey(iCell);
    int           shmid   =shm_get(shmkey,dqmCellTotalSize_);
    void*         cellAddr=shm_attach(shmid);
    result=new (cellAddr) FUShmDqmCell(dqmCellPayloadSize_);
  }
  else {
    result=
      (FUShmDqmCell*)((unsigned long)this+dqmCellOffset_+iCell*dqmCellTotalSize_);
  }
  
  return result;
}
key_t FUShmBuffer::dqmCellShmKey ( unsigned int  iCell) [private]

Definition at line 1655 of file FUShmBuffer.cc.

References gather_cfg::cout, dqmCellOffset_, nDqmCells_, and shmKey().

Referenced by dqmCell(), and releaseSharedMemory().

{
  if (iCell>=nDqmCells_) {
    cout<<"FUShmBuffer::dqmCellShmKey() ERROR: "
        <<"iCell>=nDqmCells: "<<iCell<<">="<<nDqmCells_<<endl;
    return -1;
  }
  return shmKey(iCell,dqmCellOffset_);
}
FUShmDqmCell * FUShmBuffer::dqmCellToRead ( )

Definition at line 339 of file FUShmBuffer.cc.

References dqmCell(), dqmState(), evf::dqm::EMPTY, nextDqmReadIndex(), evf::dqm::SENDING, setDqmState(), waitDqmRead(), and evf::dqm::WRITTEN.

{
  waitDqmRead();
  unsigned int  iCell=nextDqmReadIndex();
  FUShmDqmCell* cell=dqmCell(iCell);
  dqm::State_t  state=dqmState(iCell);
  assert(state==dqm::WRITTEN||state==dqm::EMPTY);
  if (state==dqm::WRITTEN) setDqmState(iCell,dqm::SENDING);
  return cell;
}
dqm::State_t FUShmBuffer::dqmState ( unsigned int  index)

Definition at line 1349 of file FUShmBuffer.cc.

References dqmStateOffset_, getHLTprescales::index, and nDqmCells_.

Referenced by discardDqmCell(), dqmCellToRead(), finishReadingDqmCell(), printDqmState(), and writeDqmEventData().

{
  assert(index<nDqmCells_);
  dqm::State_t *pstate=(dqm::State_t*)((unsigned long)this+dqmStateOffset_);
  pstate+=index;
  return *pstate;
}
unsigned int FUShmBuffer::evtNumber ( unsigned int  index)

Definition at line 1359 of file FUShmBuffer.cc.

References evtNumberOffset_, getHLTprescales::index, and nRawCells_.

Referenced by indexForEvtNumber(), and setEvtNumber().

{
  assert(index<nRawCells_);
  unsigned int *pevt=(unsigned int*)((unsigned long)this+evtNumberOffset_);
  pevt+=index;
  return *pevt;
}
pid_t FUShmBuffer::evtPrcId ( unsigned int  index)

Definition at line 1369 of file FUShmBuffer.cc.

References evtPrcIdOffset_, getHLTprescales::index, and nRawCells_.

{
  assert(index<nRawCells_);
  pid_t *prcid=(pid_t*)((unsigned long)this+evtPrcIdOffset_);
  prcid+=index;
  return *prcid;
}
evt::State_t FUShmBuffer::evtState ( unsigned int  index)
time_t FUShmBuffer::evtTimeStamp ( unsigned int  index)

Definition at line 1379 of file FUShmBuffer.cc.

References evtTimeStampOffset_, getHLTprescales::index, and nRawCells_.

{
  assert(index<nRawCells_);
  time_t *ptstmp=(time_t*)((unsigned long)this+evtTimeStampOffset_);
  ptstmp+=index;
  return *ptstmp;
}
void FUShmBuffer::finishReadingDqmCell ( FUShmDqmCell cell)
void FUShmBuffer::finishReadingRawCell ( FUShmRawCell cell)
void FUShmBuffer::finishReadingRecoCell ( FUShmRecoCell cell)

Definition at line 397 of file FUShmBuffer.cc.

References nRawCells_, evf::FUShmRecoCell::rawCellIndex(), segmentationMode_, evf::evt::SENT, and setEvtState().

{
  unsigned int iRawCell=cell->rawCellIndex();
  if (iRawCell<nRawCells_) {
    //evt::State_t state=evtState(cell->rawCellIndex());
    //assert(state==evt::SENDING);
    setEvtState(cell->rawCellIndex(),evt::SENT);
  }
  if (segmentationMode_) shmdt(cell);
}
void FUShmBuffer::finishWritingRawCell ( FUShmRawCell cell)
key_t FUShmBuffer::getSemKey ( ) [static]

Definition at line 1093 of file FUShmBuffer.cc.

References gather_cfg::cout, query::result, SEM_KEYID, and semKeyPath_.

Referenced by createShmBuffer(), getShmBuffer(), and releaseSharedMemory().

{
  key_t result=getuid()*1000+SEM_KEYID;
  if (result==(key_t)-1) cout<<"FUShmBuffer::getSemKey: ftok() failed "
                             <<"for file "<<semKeyPath_<<"!"<<endl;
  return result;
}
FUShmBuffer * FUShmBuffer::getShmBuffer ( ) [static]

Definition at line 915 of file FUShmBuffer.cc.

References gather_cfg::cout, FUShmBuffer(), getSemKey(), getShmDescriptorKey(), getShmKey(), nDqmCells(), nRawCells(), nRecoCells(), L1TEmulatorMonitor_cff::p, sem_get(), semid(), setClientPrcId(), shm_attach(), shm_get(), shm_nattch(), shmid(), and size().

Referenced by FUShmDQMOutputService::attachToShm().

{
  // get bookkeeping shared memory segment
  int   size   =sizeof(unsigned int)*7;
  int   shmid  =shm_get(FUShmBuffer::getShmDescriptorKey(),size);if(shmid<0)return 0;
  void* shmAddr=shm_attach(shmid); if (0==shmAddr) return 0;
  
  unsigned int *p=(unsigned int*)shmAddr;
  bool          segmentationMode=*p++;
  unsigned int  nRawCells       =*p++;
  unsigned int  nRecoCells      =*p++;
  unsigned int  nDqmCells       =*p++;
  unsigned int  rawCellSize     =*p++;
  unsigned int  recoCellSize    =*p++;
  unsigned int  dqmCellSize     =*p++;
  shmdt(shmAddr);

  cout<<"FUShmBuffer::getShmBuffer():"
      <<" segmentationMode="<<segmentationMode
      <<" nRawCells="<<nRawCells
      <<" nRecoCells="<<nRecoCells
      <<" nDqmCells="<<nDqmCells
      <<" rawCellSize="<<rawCellSize
      <<" recoCellSize="<<recoCellSize
      <<" dqmCellSize="<<dqmCellSize
      <<endl;
  
  // get the 'real' shared memory buffer
  size     =FUShmBuffer::size(segmentationMode,
                              nRawCells,nRecoCells,nDqmCells,
                              rawCellSize,recoCellSize,dqmCellSize);
  shmid    =shm_get(FUShmBuffer::getShmKey(),size); if (shmid<0)    return 0;
  int semid=sem_get(FUShmBuffer::getSemKey(),9);    if (semid<0)    return 0;
  shmAddr  =shm_attach(shmid);                      if (0==shmAddr) return 0;
  
  if (0==shm_nattch(shmid)) {
    cout<<"FUShmBuffer::getShmBuffer() FAILED: nattch="<<shm_nattch(shmid)<<endl;
    return 0;
  }
  
  FUShmBuffer* buffer=new(shmAddr) FUShmBuffer(segmentationMode,
                                               nRawCells,nRecoCells,nDqmCells,
                                               rawCellSize,recoCellSize,dqmCellSize);
  
  cout<<"FUShmBuffer::getShmBuffer(): shared memory buffer RETRIEVED."<<endl;
  cout<<"                             segmentationMode="<<segmentationMode<<endl;
  
  buffer->setClientPrcId(getpid());

  return buffer;
}
key_t FUShmBuffer::getShmDescriptorKey ( ) [static]

Definition at line 1073 of file FUShmBuffer.cc.

References gather_cfg::cout, query::result, SHM_DESCRIPTOR_KEYID, and shmKeyPath_.

Referenced by createShmBuffer(), getShmBuffer(), and releaseSharedMemory().

{
  key_t result=getuid()*1000+SHM_DESCRIPTOR_KEYID;
  if (result==(key_t)-1) cout<<"FUShmBuffer::getShmDescriptorKey: failed "
                             <<"for file "<<shmKeyPath_<<"!"<<endl;
  return result;
}
key_t FUShmBuffer::getShmKey ( ) [static]

Definition at line 1083 of file FUShmBuffer.cc.

References gather_cfg::cout, query::result, SHM_KEYID, and shmKeyPath_.

Referenced by createShmBuffer(), getShmBuffer(), and releaseSharedMemory().

{
  key_t result=getuid()*1000+SHM_KEYID;
  if (result==(key_t)-1) cout<<"FUShmBuffer::getShmKey: ftok() failed "
                             <<"for file "<<shmKeyPath_<<"!"<<endl;
  return result;
}
int FUShmBuffer::incEvtDiscard ( unsigned int  index) [private]

Definition at line 1438 of file FUShmBuffer.cc.

References evtDiscardOffset_, getHLTprescales::index, lock(), nRawCells_, query::result, and unlock().

Referenced by writeRecoEventData().

{
  int result = 0;
  assert(index<nRawCells_);
  unsigned int *pcount=(unsigned int*)((unsigned long)this+evtDiscardOffset_);
  pcount+=index;
  lock();
  (*pcount)++;
  result = *pcount;
  unlock();
  return result;
}
unsigned int FUShmBuffer::indexForEvtNumber ( unsigned int  evtNumber) [private]

Definition at line 1327 of file FUShmBuffer.cc.

References evtNumber(), evtNumberOffset_, i, and nRawCells_.

Referenced by writeRecoEventData().

{
  unsigned int *pevt=(unsigned int*)((unsigned long)this+evtNumberOffset_);
  for (unsigned int i=0;i<nRawCells_;i++) {
    if ((*pevt++)==evtNumber) return i;
  }
  assert(false);
  return 0xffffffff;
}
void FUShmBuffer::initialize ( unsigned int  shmid,
unsigned int  semid 
)

Definition at line 170 of file FUShmBuffer.cc.

References dqmCell(), dqmCellOffset_, dqmCellPayloadSize_, dqmCellTotalSize_, i, evf::FUShmDqmCell::initialize(), evf::FUShmRawCell::initialize(), evf::FUShmRecoCell::initialize(), nDqmCells_, nRawCells_, nRecoCells_, rawCell(), rawCellOffset_, rawCellPayloadSize_, rawCellTotalSize_, recoCell(), recoCellOffset_, recoCellPayloadSize_, recoCellTotalSize_, reset(), segmentationMode_, semid(), semid_, shm_attach(), shm_create(), shmid(), shmid_, and shmKeyPath_.

Referenced by createShmBuffer().

{
  shmid_=shmid;
  semid_=semid;
  
  if (segmentationMode_) {
    int    shmKeyId=666;
    key_t* keyAddr =(key_t*)((unsigned long)this+rawCellOffset_);
    for (unsigned int i=0;i<nRawCells_;i++) {
      *keyAddr     =ftok(shmKeyPath_,shmKeyId++);
      int   shmid  =shm_create(*keyAddr,rawCellTotalSize_);
      void* shmAddr=shm_attach(shmid);
      new (shmAddr) FUShmRawCell(rawCellPayloadSize_);
      shmdt(shmAddr);
      ++keyAddr;
    }
    keyAddr =(key_t*)((unsigned long)this+recoCellOffset_);
    for (unsigned int i=0;i<nRecoCells_;i++) {
      *keyAddr     =ftok(shmKeyPath_,shmKeyId++);
      int   shmid  =shm_create(*keyAddr,recoCellTotalSize_);
      void* shmAddr=shm_attach(shmid);
      new (shmAddr) FUShmRecoCell(recoCellPayloadSize_);
      shmdt(shmAddr);
      ++keyAddr;
    }
    keyAddr =(key_t*)((unsigned long)this+dqmCellOffset_);
    for (unsigned int i=0;i<nDqmCells_;i++) {
      *keyAddr     =ftok(shmKeyPath_,shmKeyId++);
      int   shmid  =shm_create(*keyAddr,dqmCellTotalSize_);
      void* shmAddr=shm_attach(shmid);
      new (shmAddr) FUShmDqmCell(dqmCellPayloadSize_);
      shmdt(shmAddr);
      ++keyAddr;
    }
  }
  
  for (unsigned int i=0;i<nRawCells_;i++) {
    FUShmRawCell* cell=rawCell(i);
    cell->initialize(i);
    if (segmentationMode_) shmdt(cell);
  }
  
  for (unsigned int i=0;i<nRecoCells_;i++) {
    FUShmRecoCell* cell=recoCell(i);
    cell->initialize(i);
    if (segmentationMode_) shmdt(cell);
  }
  
  for (unsigned int i=0;i<nDqmCells_;i++) {
    FUShmDqmCell* cell=dqmCell(i);
    cell->initialize(i);
    if (segmentationMode_) shmdt(cell);
  }

  reset();
}
void evf::FUShmBuffer::lock ( void  ) [inline]
int FUShmBuffer::nbRawCellsToRead ( ) const

Definition at line 283 of file FUShmBuffer.cc.

References semid().

{
  return semctl(semid(),2,GETVAL);
}
int FUShmBuffer::nbRawCellsToWrite ( ) const

Definition at line 276 of file FUShmBuffer.cc.

References semid().

{
  return semctl(semid(),1,GETVAL);
}
unsigned int evf::FUShmBuffer::nClients ( ) const [inline]

Definition at line 70 of file FUShmBuffer.h.

References nClients_.

{ return nClients_; }
unsigned int evf::FUShmBuffer::nDqmCells ( ) const [inline]

Definition at line 66 of file FUShmBuffer.h.

References nDqmCells_.

Referenced by createShmBuffer(), getShmBuffer(), releaseSharedMemory(), and size().

{ return nDqmCells_;  }
unsigned int FUShmBuffer::nextDqmReadIndex ( ) [private]

Definition at line 1306 of file FUShmBuffer.cc.

References dqmReadNext_, dqmReadOffset_, nDqmCells_, and nextIndex().

Referenced by dqmCellToRead().

unsigned int FUShmBuffer::nextDqmWriteIndex ( ) [private]
unsigned int FUShmBuffer::nextIndex ( unsigned int  offset,
unsigned int  nCells,
unsigned int &  iNext 
) [private]

Definition at line 1213 of file FUShmBuffer.cc.

References lock(), evf::evtn::offset(), query::result, and unlock().

Referenced by nextDqmReadIndex(), nextDqmWriteIndex(), nextRawReadIndex(), nextRawWriteIndex(), nextRecoReadIndex(), and nextRecoWriteIndex().

{
  lock();
  unsigned int* pindex=(unsigned int*)((unsigned long)this+offset);
  pindex+=iNext;
  iNext=(iNext+1)%nCells;
  unsigned int result=*pindex;
  unlock();
  return result;
}
unsigned int FUShmBuffer::nextRawReadIndex ( ) [private]

Definition at line 1250 of file FUShmBuffer.cc.

References nextIndex(), nRawCells_, rawReadNext_, and rawReadOffset_.

Referenced by rawCellToRead().

unsigned int FUShmBuffer::nextRawWriteIndex ( ) [private]

Definition at line 1243 of file FUShmBuffer.cc.

References nextIndex(), nRawCells_, rawWriteNext_, and rawWriteOffset_.

Referenced by rawCellToWrite().

unsigned int FUShmBuffer::nextRecoReadIndex ( ) [private]
unsigned int FUShmBuffer::nextRecoWriteIndex ( ) [private]
unsigned int evf::FUShmBuffer::nRawCells ( ) const [inline]

Definition at line 64 of file FUShmBuffer.h.

References nRawCells_.

Referenced by createShmBuffer(), getShmBuffer(), and releaseSharedMemory().

{ return nRawCells_;  }
unsigned int evf::FUShmBuffer::nRecoCells ( ) const [inline]

Definition at line 65 of file FUShmBuffer.h.

References nRecoCells_.

Referenced by createShmBuffer(), getShmBuffer(), and releaseSharedMemory().

{ return nRecoCells_; }
void FUShmBuffer::postDqmIndexToRead ( unsigned int  index) [private]
void FUShmBuffer::postDqmIndexToWrite ( unsigned int  index) [private]
void evf::FUShmBuffer::postDqmRead ( ) [inline, private]

Definition at line 262 of file FUShmBuffer.h.

References sem_post().

Referenced by writeDqmEmptyEvent(), and writeDqmEventData().

{ sem_post(8); }
void evf::FUShmBuffer::postDqmWrite ( ) [inline, private]

Definition at line 260 of file FUShmBuffer.h.

References sem_post().

Referenced by discardDqmCell().

{ sem_post(7); }
void FUShmBuffer::postIndex ( unsigned int  index,
unsigned int  offset,
unsigned int  nCells,
unsigned int &  iLast 
) [private]

Definition at line 1228 of file FUShmBuffer.cc.

References getHLTprescales::index, lock(), evf::evtn::offset(), and unlock().

Referenced by postDqmIndexToRead(), postDqmIndexToWrite(), postRawIndexToRead(), postRawIndexToWrite(), postRecoIndexToRead(), and postRecoIndexToWrite().

{
  lock();
  unsigned int* pindex=(unsigned int*)((unsigned long)this+offset);
  pindex+=iLast;
  *pindex=index;
  iLast=(iLast+1)%nCells;
  unlock();
}
void evf::FUShmBuffer::postRawDiscard ( ) [inline, private]
void evf::FUShmBuffer::postRawDiscarded ( ) [inline, private]
void FUShmBuffer::postRawIndexToRead ( unsigned int  index) [private]
void FUShmBuffer::postRawIndexToWrite ( unsigned int  index) [private]
void evf::FUShmBuffer::postRawRead ( ) [inline, private]

Definition at line 250 of file FUShmBuffer.h.

References sem_post().

Referenced by finishWritingRawCell(), writeRawEmptyEvent(), and writeRawLumiSectionEvent().

{ sem_post(2); }
void evf::FUShmBuffer::postRawWrite ( ) [inline, private]

Definition at line 248 of file FUShmBuffer.h.

References sem_post().

Referenced by releaseRawCell().

{ sem_post(1); }
void FUShmBuffer::postRecoIndexToRead ( unsigned int  index) [private]
void FUShmBuffer::postRecoIndexToWrite ( unsigned int  index) [private]
void evf::FUShmBuffer::postRecoRead ( ) [inline, private]

Definition at line 258 of file FUShmBuffer.h.

References sem_post().

Referenced by writeErrorEventData(), writeRecoEmptyEvent(), writeRecoEventData(), and writeRecoInitMsg().

{ sem_post(6); }
void evf::FUShmBuffer::postRecoWrite ( ) [inline, private]

Definition at line 256 of file FUShmBuffer.h.

References sem_post().

Referenced by discardOrphanedRecoCell(), and discardRecoCell().

{ sem_post(5); }
void FUShmBuffer::printDqmState ( unsigned int  index)

Definition at line 845 of file FUShmBuffer.cc.

References gather_cfg::cout, and dqmState().

{
  dqm::State_t state=dqmState(index);
  cout<<"dqm evt "<<index<<" in state '"<<state<<"'."<<endl;
}
void FUShmBuffer::printEvtState ( unsigned int  index)

Definition at line 823 of file FUShmBuffer.cc.

References gather_cfg::cout, evf::evt::DISCARDING, evf::evt::EMPTY, evtState(), evf::evt::PROCESSED, evf::evt::PROCESSING, evf::evt::RAWREAD, evf::evt::RAWREADING, evf::evt::RAWWRITING, evf::evt::RAWWRITTEN, evf::evt::RECOWRITING, evf::evt::RECOWRITTEN, evf::evt::SENDING, evf::evt::SENT, and evf::evt::STOP.

Referenced by evf::FUShmServer::writeNext().

{
  evt::State_t state=evtState(index);
  std::string stateName;
  if      (state==evt::EMPTY)      stateName="EMPTY";
  else if (state==evt::STOP)       stateName="STOP";
  else if (state==evt::RAWWRITING) stateName="RAWWRITING";
  else if (state==evt::RAWWRITTEN) stateName="RAWRITTEN";
  else if (state==evt::RAWREADING) stateName="RAWREADING";
  else if (state==evt::RAWREAD)    stateName="RAWREAD";
  else if (state==evt::PROCESSING) stateName="PROCESSING";
  else if (state==evt::PROCESSED)  stateName="PROCESSED";
  else if (state==evt::RECOWRITING)stateName="RECOWRITING";
  else if (state==evt::RECOWRITTEN)stateName="RECOWRITTEN";
  else if (state==evt::SENDING)    stateName="SENDING";
  else if (state==evt::SENT)       stateName="SENT";
  else if (state==evt::DISCARDING) stateName="DISCARDING";
  cout<<"evt "<<index<<" in state '"<<stateName<<"'."<<endl;
}
FUShmRawCell * FUShmBuffer::rawCell ( unsigned int  iCell)

Definition at line 1525 of file FUShmBuffer.cc.

References gather_cfg::cout, nRawCells_, rawCellOffset_, rawCellPayloadSize_, rawCellShmKey(), rawCellTotalSize_, query::result, segmentationMode_, shm_attach(), shm_get(), and shmid().

Referenced by initialize(), rawCellToDiscard(), rawCellToRead(), rawCellToWrite(), and writeErrorEventData().

{
  FUShmRawCell* result(0);
  
  if (iCell>=nRawCells_) {
    cout<<"FUShmBuffer::rawCell("<<iCell<<") ERROR: "
        <<"iCell="<<iCell<<" >= nRawCells()="<<nRawCells_<<endl;
    return result;
  }
  
  if (segmentationMode_) {
    key_t         shmkey  =rawCellShmKey(iCell);
    int           shmid   =shm_get(shmkey,rawCellTotalSize_);
    void*         cellAddr=shm_attach(shmid);
    result=new (cellAddr) FUShmRawCell(rawCellPayloadSize_);
  }
  else {
    result=
      (FUShmRawCell*)((unsigned long)this+rawCellOffset_+iCell*rawCellTotalSize_);
  }
  
  return result;
}
bool FUShmBuffer::rawCellReadyForDiscard ( unsigned int  index) [private]

Definition at line 1603 of file FUShmBuffer.cc.

References evtDiscardOffset_, getHLTprescales::index, lock(), nRawCells_, query::result, and unlock().

Referenced by scheduleRawCellForDiscard(), scheduleRawCellForDiscardServerSide(), scheduleRawEmptyCellForDiscard(), and scheduleRawEmptyCellForDiscardServerSide().

{
  assert(index<nRawCells_);
  unsigned int *pcount=(unsigned int*)((unsigned long)this+evtDiscardOffset_);
  pcount+=index;
  lock();
  assert(*pcount>0);
  --(*pcount);
  bool result=(*pcount==0);
  unlock();
  return result;
}
key_t FUShmBuffer::rawCellShmKey ( unsigned int  iCell) [private]

Definition at line 1631 of file FUShmBuffer.cc.

References gather_cfg::cout, nRawCells_, rawCellOffset_, and shmKey().

Referenced by rawCell(), and releaseSharedMemory().

{
  if (iCell>=nRawCells_) {
    cout<<"FUShmBuffer::rawCellShmKey() ERROR: "
        <<"iCell>=nRawCells: "<<iCell<<">="<<nRawCells_<<endl;
    return -1;
  }
  return shmKey(iCell,rawCellOffset_);
}
FUShmRawCell * FUShmBuffer::rawCellToDiscard ( )
FUShmRawCell * FUShmBuffer::rawCellToRead ( )
FUShmRawCell * FUShmBuffer::rawCellToWrite ( )
FUShmRecoCell * FUShmBuffer::recoCell ( unsigned int  iCell)

Definition at line 1551 of file FUShmBuffer.cc.

References gather_cfg::cout, nRecoCells_, recoCellOffset_, recoCellPayloadSize_, recoCellShmKey(), recoCellTotalSize_, query::result, segmentationMode_, shm_attach(), shm_get(), and shmid().

Referenced by discardOrphanedRecoCell(), discardRecoCell(), initialize(), recoCellToRead(), writeErrorEventData(), writeRecoEmptyEvent(), writeRecoEventData(), and writeRecoInitMsg().

{
  FUShmRecoCell* result(0);
  
  if (iCell>=nRecoCells_) {
    cout<<"FUShmBuffer::recoCell("<<iCell<<") ERROR: "
        <<"iCell="<<iCell<<" >= nRecoCells="<<nRecoCells_<<endl;
    return result;
  }
  
  if (segmentationMode_) {
    key_t         shmkey  =recoCellShmKey(iCell);
    int           shmid   =shm_get(shmkey,recoCellTotalSize_);
    void*         cellAddr=shm_attach(shmid);
    result=new (cellAddr) FUShmRecoCell(recoCellPayloadSize_);
  }
  else {
    result=
      (FUShmRecoCell*)((unsigned long)this+recoCellOffset_+iCell*recoCellTotalSize_);
  }
  
  return result;
}
key_t FUShmBuffer::recoCellShmKey ( unsigned int  iCell) [private]

Definition at line 1643 of file FUShmBuffer.cc.

References gather_cfg::cout, nRecoCells_, recoCellOffset_, and shmKey().

Referenced by recoCell(), and releaseSharedMemory().

{
  if (iCell>=nRecoCells_) {
    cout<<"FUShmBuffer::recoCellShmKey() ERROR: "
        <<"iCell>=nRecoCells: "<<iCell<<">="<<nRecoCells_<<endl;
    return -1;
  }
  return shmKey(iCell,recoCellOffset_);
}
FUShmRecoCell * FUShmBuffer::recoCellToRead ( )

Definition at line 323 of file FUShmBuffer.cc.

References nextRecoReadIndex(), nRawCells_, evf::FUShmRecoCell::rawCellIndex(), recoCell(), evf::evt::SENDING, setEvtState(), and waitRecoRead().

{
  waitRecoRead();
  unsigned int   iCell   =nextRecoReadIndex();
  FUShmRecoCell* cell    =recoCell(iCell);
  unsigned int   iRawCell=cell->rawCellIndex();
  if (iRawCell<nRawCells_) {
    //evt::State_t   state=evtState(iRawCell);
    //assert(state==evt::RECOWRITTEN);
    setEvtState(iRawCell,evt::SENDING);
  }
  return cell;
}
void FUShmBuffer::releaseRawCell ( FUShmRawCell cell)

Definition at line 506 of file FUShmBuffer.cc.

References evf::FUShmRawCell::clear(), gather_cfg::cout, evf::evt::DISCARDING, evf::evt::EMPTY, evtState(), evf::FUShmRawCell::index(), postRawIndexToWrite(), postRawWrite(), evf::evt::RAWWRITING, segmentationMode_, setEvtDiscard(), setEvtNumber(), setEvtPrcId(), setEvtState(), setEvtTimeStamp(), evf::evt::STOP, and evf::evt::USEDLS.

Referenced by discardRawCell().

{
  evt::State_t state=evtState(cell->index());
  if(!(
     state==evt::DISCARDING
     ||state==evt::RAWWRITING
     ||state==evt::EMPTY
     ||state==evt::STOP
     //     ||state==evt::LUMISECTION
     ||state==evt::USEDLS
     )) std::cout << "=================releaseRawCell state " << state 
                  << std::endl;

  assert(
         state==evt::DISCARDING
         ||state==evt::RAWWRITING
         ||state==evt::EMPTY
         ||state==evt::STOP
         //      ||state==evt::LUMISECTION
         ||state==evt::USEDLS
         );
  setEvtState(cell->index(),evt::EMPTY);
  setEvtDiscard(cell->index(),0);
  setEvtNumber(cell->index(),0xffffffff);
  setEvtPrcId(cell->index(),0);
  setEvtTimeStamp(cell->index(),0);
  cell->clear();
  postRawIndexToWrite(cell->index());
  if (segmentationMode_) shmdt(cell);
  postRawWrite();
}
bool FUShmBuffer::releaseSharedMemory ( ) [static]

Definition at line 969 of file FUShmBuffer.cc.

References gather_cfg::cout, dqmCellShmKey(), FUShmBuffer(), getSemKey(), getShmDescriptorKey(), getShmKey(), i, nDqmCells(), nRawCells(), nRecoCells(), L1TEmulatorMonitor_cff::p, rawCellShmKey(), recoCellShmKey(), sem_destroy(), sem_get(), semid(), shm_attach(), shm_destroy(), shm_get(), shm_nattch(), shmid(), size(), and stor::utils::sleep().

Referenced by createShmBuffer(), and evf::FUResourceTable::~FUResourceTable().

{
  // get bookkeeping shared memory segment
  int   size   =sizeof(unsigned int)*7;
  int   shmidd =shm_get(FUShmBuffer::getShmDescriptorKey(),size); if(shmidd<0) return false;
  void* shmAddr=shm_attach(shmidd); if (0==shmAddr) return false;

  unsigned int*p=(unsigned int*)shmAddr;
  bool         segmentationMode=*p++;
  unsigned int nRawCells       =*p++;
  unsigned int nRecoCells      =*p++;
  unsigned int nDqmCells       =*p++;
  unsigned int rawCellSize     =*p++;
  unsigned int recoCellSize    =*p++;
  unsigned int dqmCellSize     =*p++;
  shmdt(shmAddr);

  
  // get the 'real' shared memory segment
  size     =FUShmBuffer::size(segmentationMode,
                              nRawCells,nRecoCells,nDqmCells,
                              rawCellSize,recoCellSize,dqmCellSize);
  int shmid=shm_get(FUShmBuffer::getShmKey(),size);if (shmid<0)    return false;
  int semid=sem_get(FUShmBuffer::getSemKey(),9);   if (semid<0)    return false;
  shmAddr  =shm_attach(shmid);                     if (0==shmAddr) return false; 

  int att = 0;
  for(; att <10; att++)
    {
      if(shm_nattch(shmid)>1) {
        cout << att << " FUShmBuffer::releaseSharedMemory(): nattch="<<shm_nattch(shmid)
             <<", failed attempt to release shared memory."<<endl;
	::sleep(1);
      }
      else
        break;
    }

  if(att>=10) return false;

  if (segmentationMode) {
    FUShmBuffer* buffer=
      new (shmAddr) FUShmBuffer(segmentationMode,
                                nRawCells,nRecoCells,nDqmCells,
                                rawCellSize,recoCellSize,dqmCellSize);
    int cellid;
    for (unsigned int i=0;i<nRawCells;i++) {
      cellid=shm_get(buffer->rawCellShmKey(i),FUShmRawCell::size(rawCellSize));
      if ((shm_destroy(cellid)==-1)) return false;
    }
    for (unsigned int i=0;i<nRecoCells;i++) {
      cellid=shm_get(buffer->recoCellShmKey(i),FUShmRecoCell::size(recoCellSize));
      if ((shm_destroy(cellid)==-1)) return false;
    }
    for (unsigned int i=0;i<nDqmCells;i++) {
      cellid=shm_get(buffer->dqmCellShmKey(i),FUShmDqmCell::size(dqmCellSize));
      if ((shm_destroy(cellid)==-1)) return false;
    }
  }
  shmdt(shmAddr);
  if (sem_destroy(semid)==-1)  return false;
  if (shm_destroy(shmid)==-1)  return false;
  if (shm_destroy(shmidd)==-1) return false;

  return true;
}
bool FUShmBuffer::removeClientPrcId ( pid_t  prcId)

Definition at line 1509 of file FUShmBuffer.cc.

References clientPrcIdOffset_, lock(), nClients_, and unlock().

Referenced by scheduleRawEmptyCellForDiscard(), and FUShmReader::~FUShmReader().

{
  lock();
  pid_t *prcid=(pid_t*)((unsigned long)this+clientPrcIdOffset_);
  unsigned int iClient(0);
  while (iClient<=nClients_&&(*prcid)!=prcId) { prcid++; iClient++; }
  assert(iClient!=nClients_);
  pid_t* next=prcid; next++;
  while (iClient<nClients_-1) { *prcid=*next; prcid++; next++; iClient++; }
  nClients_--;
  unlock();
  return true;
}
void FUShmBuffer::reset ( void  )

Definition at line 229 of file FUShmBuffer.cc.

References dqmReadLast_, dqmReadNext_, dqmReadOffset_, dqmWriteLast_, dqmWriteNext_, dqmWriteOffset_, evf::dqm::EMPTY, evf::evt::EMPTY, i, nClients_, nDqmCells_, nRawCells_, nRecoCells_, rawReadLast_, rawReadNext_, rawReadOffset_, rawWriteLast_, rawWriteNext_, rawWriteOffset_, recoReadLast_, recoReadNext_, recoReadOffset_, recoWriteLast_, recoWriteNext_, recoWriteOffset_, sem_init(), sem_print(), setDqmState(), setEvtDiscard(), setEvtNumber(), setEvtPrcId(), setEvtState(), and setEvtTimeStamp().

Referenced by initialize().

{
  nClients_=0;

  // setup ipc semaphores
  sem_init(0,1);          // lock (binary)
  sem_init(1,nRawCells_); // raw  write semaphore
  sem_init(2,0);          // raw  read  semaphore
  sem_init(3,1);          // binary semaphore to schedule raw event for discard
  sem_init(4,0);          // binary semaphore to discard raw event
  sem_init(5,nRecoCells_);// reco write semaphore
  sem_init(6,0);          // reco send (read) semaphore
  sem_init(7,nDqmCells_); // dqm  write semaphore
  sem_init(8,0);          // dqm  send (read) semaphore

  sem_print();

  unsigned int *iWrite,*iRead;
  
  rawWriteNext_=0; rawWriteLast_=0; rawReadNext_ =0; rawReadLast_ =0;
  iWrite=(unsigned int*)((unsigned long)this+rawWriteOffset_);
  iRead =(unsigned int*)((unsigned long)this+rawReadOffset_);
  for (unsigned int i=0;i<nRawCells_;i++) { *iWrite++=i; *iRead++ =0xffffffff; }

  recoWriteNext_=0; recoWriteLast_=0; recoReadNext_ =0; recoReadLast_ =0;
  iWrite=(unsigned int*)((unsigned long)this+recoWriteOffset_);
  iRead =(unsigned int*)((unsigned long)this+recoReadOffset_);
  for (unsigned int i=0;i<nRecoCells_;i++) { *iWrite++=i; *iRead++ =0xffffffff; }

  dqmWriteNext_=0; dqmWriteLast_=0; dqmReadNext_ =0; dqmReadLast_ =0;
  iWrite=(unsigned int*)((unsigned long)this+dqmWriteOffset_);
  iRead =(unsigned int*)((unsigned long)this+dqmReadOffset_);
  for (unsigned int i=0;i<nDqmCells_;i++) { *iWrite++=i; *iRead++ =0xffffffff; }
  
  for (unsigned int i=0;i<nRawCells_;i++) {
    setEvtState(i,evt::EMPTY);
    setEvtDiscard(i,0);
    setEvtNumber(i,0xffffffff);
    setEvtPrcId(i,0);
    setEvtTimeStamp(i,0);
  }

  for (unsigned int i=0;i<nDqmCells_;i++) setDqmState(i,dqm::EMPTY);
}
void FUShmBuffer::scheduleRawCellForDiscard ( unsigned int  iCell)
void FUShmBuffer::scheduleRawCellForDiscardServerSide ( unsigned int  iCell)
void FUShmBuffer::scheduleRawEmptyCellForDiscard ( )
void FUShmBuffer::scheduleRawEmptyCellForDiscard ( FUShmRawCell cell)

Definition at line 608 of file FUShmBuffer.cc.

References evf::FUShmRawCell::index(), postRawDiscard(), postRawDiscarded(), rawCellReadyForDiscard(), rawDiscardIndex_, removeClientPrcId(), segmentationMode_, and waitRawDiscard().

{
  waitRawDiscard();
  if (rawCellReadyForDiscard(cell->index())) {
    rawDiscardIndex_=cell->index();
    // as this function is called by the reader, the state and type should 
    // already be correct
    //    setEvtState(cell->index(),evt::STOP);
    //    cell->setEventType(evt::STOPPER);
    //    setEvtNumber(cell->index(),0xffffffff);
    //    setEvtPrcId(cell->index(),0);
    //    setEvtTimeStamp(cell->index(),0);
    removeClientPrcId(getpid());
    if (segmentationMode_) shmdt(cell);
    postRawDiscarded();
  }
  else postRawDiscard();
}
void FUShmBuffer::scheduleRawEmptyCellForDiscardServerSide ( FUShmRawCell cell)

Definition at line 628 of file FUShmBuffer.cc.

References evf::FUShmRawCell::index(), postRawDiscard(), postRawDiscarded(), rawCellReadyForDiscard(), rawDiscardIndex_, and segmentationMode_.

{
  //  waitRawDiscard();
  if (rawCellReadyForDiscard(cell->index())) {
    rawDiscardIndex_=cell->index();
    //    setEvtState(cell->index(),evt::STOP);
    //    cell->setEventType(evt::STOPPER);
    //    setEvtNumber(cell->index(),0xffffffff);
    //    setEvtPrcId(cell->index(),0);
    //    setEvtTimeStamp(cell->index(),0);
    //    removeClientPrcId(getpid());
    if (segmentationMode_) shmdt(cell);
    postRawDiscarded();
  }
  else postRawDiscard();
}
int FUShmBuffer::sem_create ( key_t  key,
int  nsem 
) [static]

Definition at line 1173 of file FUShmBuffer.cc.

References gather_cfg::cout, and semid().

Referenced by createShmBuffer().

{
  int semid=semget(key,nsem,IPC_CREAT|0666);
  if (semid<0) {
    int err=errno;
    cout<<"FUShmBuffer::sem_create(key="<<key<<",nsem="<<nsem<<") failed: "
        <<strerror(err)<<endl;
  }
  return semid;
}
int FUShmBuffer::sem_destroy ( int  semid) [static]

Definition at line 1199 of file FUShmBuffer.cc.

References gather_cfg::cout, and query::result.

Referenced by releaseSharedMemory().

{
  int result=semctl(semid,0,IPC_RMID);
  if (result==-1) cout<<"FUShmBuffer::sem_destroy(semid="<<semid<<") failed."<<endl;
  return result;
}
int FUShmBuffer::sem_get ( key_t  key,
int  nsem 
) [static]

Definition at line 1186 of file FUShmBuffer.cc.

References gather_cfg::cout, and semid().

Referenced by getShmBuffer(), and releaseSharedMemory().

{
  int semid=semget(key,nsem,0666);
  if (semid<0) {
    int err=errno;
    cout<<"FUShmBuffer::sem_get(key="<<key<<",nsem="<<nsem<<") failed: "
        <<strerror(err)<<endl;
  }
  return semid;
}
void FUShmBuffer::sem_init ( int  isem,
int  value 
) [private]

Definition at line 1667 of file FUShmBuffer.cc.

References gather_cfg::cout, and semid().

Referenced by reset().

{
  if (semctl(semid(),isem,SETVAL,value)<0) {
    cout<<"FUShmBuffer: FATAL ERROR in semaphore initialization."<<endl;
  }
}
void FUShmBuffer::sem_post ( int  isem) [private]

Definition at line 1691 of file FUShmBuffer.cc.

References gather_cfg::cout, and semid().

Referenced by postDqmRead(), postDqmWrite(), postRawDiscard(), postRawDiscarded(), postRawRead(), postRawWrite(), postRecoRead(), postRecoWrite(), and unlock().

{
  struct sembuf sops[1];
  sops[0].sem_num=isem;
  sops[0].sem_op =   1;
  sops[0].sem_flg=   0;
  if (semop(semid(),sops,1)==-1) {
    cout<<"FUShmBuffer: ERROR in semaphore operation sem_post."<<endl;
  }
}
void FUShmBuffer::sem_print ( )

Definition at line 801 of file FUShmBuffer.cc.

References gather_cfg::cout, and semid().

Referenced by FUShmReader::fillRawData(), and reset().

{
  cout<<"--> current sem values:"
      <<endl
      <<" lock="<<semctl(semid(),0,GETVAL)
      <<endl
      <<" wraw="<<semctl(semid(),1,GETVAL)
      <<" rraw="<<semctl(semid(),2,GETVAL)
      <<endl
      <<" wdsc="<<semctl(semid(),3,GETVAL)
      <<" rdsc="<<semctl(semid(),4,GETVAL)
      <<endl
      <<" wrec="<<semctl(semid(),5,GETVAL)
      <<" rrec="<<semctl(semid(),6,GETVAL)
      <<endl
      <<" wdqm="<<semctl(semid(),7,GETVAL)
      <<" rdqm="<<semctl(semid(),8,GETVAL)
      <<endl;
}
int FUShmBuffer::sem_wait ( int  isem) [private]

Definition at line 1676 of file FUShmBuffer.cc.

References gather_cfg::cout, and semid().

Referenced by lock(), waitDqmRead(), waitDqmWrite(), waitRawDiscard(), waitRawDiscarded(), waitRawRead(), waitRawWrite(), waitRecoRead(), and waitRecoWrite().

{
  struct sembuf sops[1];
  sops[0].sem_num=isem;
  sops[0].sem_op =  -1;
  sops[0].sem_flg=   0;
  if (semop(semid(),sops,1)==-1) {
    cout<<"FUShmBuffer: ERROR in semaphore operation sem_wait."<<endl;
    return -1;
  }
  return 0;
}
int evf::FUShmBuffer::semid ( ) const [inline]
bool FUShmBuffer::setClientPrcId ( pid_t  prcId) [private]

Definition at line 1492 of file FUShmBuffer.cc.

References clientPrcIdOffset_, i, lock(), nClients_, nClientsMax_, and unlock().

Referenced by getShmBuffer().

{
  lock();
  assert(nClients_<nClientsMax_);
  pid_t *prcid=(pid_t*)((unsigned long)this+clientPrcIdOffset_);
  for (unsigned int i=0;i<nClients_;i++) {
    if ((*prcid)==prcId) { unlock();  return false; }
    prcid++;
  }
  nClients_++;
  *prcid=prcId;
  unlock();
  return true;
}
bool FUShmBuffer::setDqmState ( unsigned int  index,
dqm::State_t  state 
)

Definition at line 1412 of file FUShmBuffer.cc.

References dqmStateOffset_, getHLTprescales::index, lock(), nDqmCells_, evf::utils::state, and unlock().

Referenced by discardDqmCell(), dqmCellToRead(), finishReadingDqmCell(), reset(), and writeDqmEventData().

{
  assert(index<nDqmCells_);
  dqm::State_t *pstate=(dqm::State_t*)((unsigned long)this+dqmStateOffset_);
  pstate+=index;
  lock();
  *pstate=state;
  unlock();
  return true;
}
bool FUShmBuffer::setEvtDiscard ( unsigned int  index,
unsigned int  discard 
) [private]

Definition at line 1425 of file FUShmBuffer.cc.

References evtDiscardOffset_, getHLTprescales::index, lock(), nRawCells_, and unlock().

Referenced by rawCellToWrite(), releaseRawCell(), reset(), and writeErrorEventData().

{
  assert(index<nRawCells_);
  unsigned int *pcount=(unsigned int*)((unsigned long)this+evtDiscardOffset_);
  pcount+=index;
  lock();
  *pcount=discard;
  unlock();
  return true;
}
bool FUShmBuffer::setEvtNumber ( unsigned int  index,
unsigned int  evtNumber 
) [private]

Definition at line 1453 of file FUShmBuffer.cc.

References evtNumber(), evtNumberOffset_, getHLTprescales::index, lock(), nRawCells_, and unlock().

Referenced by finishWritingRawCell(), releaseRawCell(), reset(), and scheduleRawEmptyCellForDiscard().

{
  assert(index<nRawCells_);
  unsigned int *pevt=(unsigned int*)((unsigned long)this+evtNumberOffset_);
  pevt+=index;
  lock();
  *pevt=evtNumber;
  unlock();
  return true;
}
bool FUShmBuffer::setEvtPrcId ( unsigned int  index,
pid_t  prcId 
) [private]

Definition at line 1466 of file FUShmBuffer.cc.

References evtPrcIdOffset_, getHLTprescales::index, lock(), nRawCells_, and unlock().

Referenced by rawCellToRead(), releaseRawCell(), reset(), and scheduleRawEmptyCellForDiscard().

{
  assert(index<nRawCells_);
  pid_t* prcid=(pid_t*)((unsigned long)this+evtPrcIdOffset_);
  prcid+=index;
  lock();
  *prcid=prcId;
  unlock();
  return true;
}
bool FUShmBuffer::setEvtState ( unsigned int  index,
evt::State_t  state 
)
bool FUShmBuffer::setEvtTimeStamp ( unsigned int  index,
time_t  timeStamp 
) [private]

Definition at line 1479 of file FUShmBuffer.cc.

References evtTimeStampOffset_, getHLTprescales::index, lock(), nRawCells_, stor::utils::timeStamp(), and unlock().

Referenced by finishReadingRawCell(), releaseRawCell(), reset(), and scheduleRawEmptyCellForDiscard().

{
  assert(index<nRawCells_);
  time_t *ptstmp=(time_t*)((unsigned long)this+evtTimeStampOffset_);
  ptstmp+=index;
  lock();
  *ptstmp=timeStamp;
  unlock();
  return true;
}
void * FUShmBuffer::shm_attach ( int  shmid) [static]

Definition at line 1141 of file FUShmBuffer.cc.

References gather_cfg::cout, NULL, and query::result.

Referenced by createShmBuffer(), dqmCell(), getShmBuffer(), initialize(), rawCell(), recoCell(), and releaseSharedMemory().

{
  void* result=shmat(shmid,NULL,0);
  if (0==result) {
    int err=errno;
    cout<<"FUShmBuffer::shm_attach("<<shmid<<") failed: "
        <<strerror(err)<<endl;
  }
  return result;
}
int FUShmBuffer::shm_create ( key_t  key,
int  size 
) [static]

Definition at line 1103 of file FUShmBuffer.cc.

References gather_cfg::cout, query::result, and shmid().

Referenced by createShmBuffer(), and initialize().

{
  // first check and possibly remove existing segment with same id
  int shmid=shmget(key,1,0644);//using minimal size any segment with key "key" will be connected
  if(shmid!=-1){
    // an existing segment was found, remove it
    shmid_ds shmstat;
    int result=shmctl(shmid,IPC_STAT,&shmstat);
    cout << "FUShmBuffer found segment for key 0x " << hex << key << dec
         << " created by process " << shmstat.shm_cpid << " owned by "
         << shmstat.shm_perm.uid << " permissions " 
         << hex << shmstat.shm_perm.mode << dec << endl;
    result=shmctl(shmid,IPC_RMID,&shmstat);
  }
  shmid=shmget(key,size,IPC_CREAT|0644);
  if (shmid==-1) {
    int err=errno;
    cout<<"FUShmBuffer::shm_create("<<key<<","<<size<<") failed: "
        <<strerror(err)<<endl;
  }
  return shmid;
}
int FUShmBuffer::shm_destroy ( int  shmid) [static]

Definition at line 1163 of file FUShmBuffer.cc.

References gather_cfg::cout, and query::result.

Referenced by releaseSharedMemory().

{
  shmid_ds shmstat;
  int result=shmctl(shmid,IPC_RMID,&shmstat);
  if (result==-1) cout<<"FUShmBuffer::shm_destroy(shmid="<<shmid<<") failed."<<endl;
  return result;
}
int FUShmBuffer::shm_get ( key_t  key,
int  size 
) [static]

Definition at line 1128 of file FUShmBuffer.cc.

References gather_cfg::cout, and shmid().

Referenced by dqmCell(), getShmBuffer(), rawCell(), recoCell(), and releaseSharedMemory().

{
  int shmid=shmget(key,size,0644);
  if (shmid==-1) {
    int err=errno;
    cout<<"FUShmBuffer::shm_get("<<key<<","<<size<<") failed: "
        <<strerror(err)<<endl;
  }
  return shmid;
}
int FUShmBuffer::shm_nattch ( int  shmid) [static]

Definition at line 1154 of file FUShmBuffer.cc.

Referenced by createShmBuffer(), evf::FUResourceTable::discard(), getShmBuffer(), and releaseSharedMemory().

{
  shmid_ds shmstat;
  shmctl(shmid,IPC_STAT,&shmstat);
  return shmstat.shm_nattch;
}
int evf::FUShmBuffer::shmid ( ) const [inline]
key_t FUShmBuffer::shmKey ( unsigned int  iCell,
unsigned int  offset 
) [private]

Definition at line 1618 of file FUShmBuffer.cc.

References gather_cfg::cout, i, evf::evtn::offset(), and segmentationMode_.

Referenced by dqmCellShmKey(), rawCellShmKey(), and recoCellShmKey().

{
  if (!segmentationMode_) {
    cout<<"FUShmBuffer::shmKey() ERROR: only valid in segmentationMode!"<<endl;
    return -1;
  }
  key_t* addr=(key_t*)((unsigned long)this+offset);
  for (unsigned int i=0;i<iCell;i++) ++addr;
  return *addr;
}
unsigned int FUShmBuffer::size ( bool  segmentationMode,
unsigned int  nRawCells,
unsigned int  nRecoCells,
unsigned int  nDqmCells,
unsigned int  rawCellSize,
unsigned int  recoCellSize,
unsigned int  dqmCellSize 
) [static]

Definition at line 1038 of file FUShmBuffer.cc.

References FUShmBuffer(), nDqmCells(), evf::evtn::offset(), and query::result.

Referenced by createShmBuffer(), FUShmBuffer(), getShmBuffer(), and releaseSharedMemory().

{
  unsigned int offset=
    sizeof(FUShmBuffer)+
    sizeof(unsigned int)*4*nRawCells+
    sizeof(evt::State_t)*nRawCells+
    sizeof(dqm::State_t)*nDqmCells;
  
  unsigned int rawCellTotalSize=FUShmRawCell::size(rawCellSize);
  unsigned int recoCellTotalSize=FUShmRecoCell::size(recoCellSize);
  unsigned int dqmCellTotalSize=FUShmDqmCell::size(dqmCellSize);
  
  unsigned int realSize =
    (segmentationMode) ?
    offset
    +sizeof(key_t)*(nRawCells+nRecoCells+nDqmCells)
    :
    offset
    +rawCellTotalSize*nRawCells
    +recoCellTotalSize*nRecoCells
    +dqmCellTotalSize*nDqmCells;

  unsigned int result=realSize/0x10*0x10 + (realSize%0x10>0)*0x10;
  
  return result;
}
void evf::FUShmBuffer::unlock ( void  ) [inline]
void evf::FUShmBuffer::waitDqmRead ( ) [inline, private]

Definition at line 261 of file FUShmBuffer.h.

References sem_wait().

Referenced by dqmCellToRead().

{ sem_wait(8); }
void evf::FUShmBuffer::waitDqmWrite ( ) [inline, private]

Definition at line 259 of file FUShmBuffer.h.

References sem_wait().

Referenced by writeDqmEmptyEvent(), and writeDqmEventData().

{ sem_wait(7); }
void evf::FUShmBuffer::waitRawDiscard ( ) [inline, private]
void evf::FUShmBuffer::waitRawDiscarded ( ) [inline, private]

Definition at line 253 of file FUShmBuffer.h.

References sem_wait().

Referenced by rawCellToDiscard().

{ sem_wait(4); }
void evf::FUShmBuffer::waitRawRead ( ) [inline, private]

Definition at line 249 of file FUShmBuffer.h.

References sem_wait().

Referenced by rawCellToRead().

{ sem_wait(2); }
void evf::FUShmBuffer::waitRawWrite ( ) [inline, private]

Definition at line 247 of file FUShmBuffer.h.

References sem_wait().

Referenced by rawCellToWrite().

{ sem_wait(1); }
void evf::FUShmBuffer::waitRecoRead ( ) [inline, private]

Definition at line 257 of file FUShmBuffer.h.

References sem_wait().

Referenced by recoCellToRead().

{ sem_wait(6); }
void evf::FUShmBuffer::waitRecoWrite ( ) [inline, private]

Definition at line 255 of file FUShmBuffer.h.

References sem_wait().

Referenced by writeErrorEventData(), writeRecoEmptyEvent(), writeRecoEventData(), and writeRecoInitMsg().

{ sem_wait(5); }
void FUShmBuffer::writeDqmEmptyEvent ( )
bool FUShmBuffer::writeDqmEventData ( unsigned int  runNumber,
unsigned int  evtAtUpdate,
unsigned int  folderId,
unsigned int  fuProcessId,
unsigned int  fuGuid,
unsigned char *  data,
unsigned int  dataSize 
)

Definition at line 772 of file FUShmBuffer.cc.

References gather_cfg::cout, dqmCell(), dqmCellPayloadSize_, dqmState(), evf::dqm::EMPTY, nextDqmWriteIndex(), postDqmIndexToRead(), postDqmRead(), segmentationMode_, setDqmState(), waitDqmWrite(), evf::FUShmDqmCell::writeData(), evf::dqm::WRITING, and evf::dqm::WRITTEN.

Referenced by FUShmDQMOutputService::writeShmDQMData().

{
  if (dataSize>dqmCellPayloadSize_) {
    cout<<"FUShmBuffer::writeDqmEventData() ERROR: buffer overflow."<<endl;
    return false;
  }
  
  waitDqmWrite();
  unsigned int  iCell=nextDqmWriteIndex();
  FUShmDqmCell* cell=dqmCell(iCell);
  dqm::State_t state=dqmState(iCell);
  assert(state==dqm::EMPTY);
  setDqmState(iCell,dqm::WRITING);
  cell->writeData(runNumber,evtAtUpdate,folderId,fuProcessId,fuGuid,data,dataSize);
  setDqmState(iCell,dqm::WRITTEN);
  postDqmIndexToRead(iCell);
  if (segmentationMode_) shmdt(cell);
  postDqmRead();
  return true;
}
bool FUShmBuffer::writeErrorEventData ( unsigned int  runNumber,
unsigned int  fuProcessId,
unsigned int  iRawCell 
)

Definition at line 702 of file FUShmBuffer.cc.

References runTheMatrix::data, evf::FUShmRawCell::eventSize(), evf::FUShmRawCell::evtNumber(), evf::FUShmRawCell::fedAddr(), evf::FUShmRawCell::fedSize(), evf::evtn::getlbn(), i, FEDNumbering::MINTriggerGTPFEDID, nextRecoWriteIndex(), evf::FUShmRawCell::payloadAddr(), pos, postRecoIndexToRead(), postRecoRead(), runTheMatrix_dev::raw, rawCell(), dt_dqm_sourceclient_common_cff::reco, recoCell(), evf::evt::RECOWRITING, evf::evt::RECOWRITTEN, segmentationMode_, setEvtDiscard(), setEvtState(), waitRecoWrite(), and evf::FUShmRecoCell::writeErrorEvent().

Referenced by FUShmReader::~FUShmReader().

{
  FUShmRawCell *raw=rawCell(iRawCell);

  unsigned int   dataSize=sizeof(uint32_t)*(4+1024)+raw->eventSize();
  unsigned char *data    =new unsigned char[dataSize];
  uint32_t      *pos     =(uint32_t*)data;
  // 06-Oct-2008, KAB - added a version number for the error event format.
  //
  // Version 1 had no version number, so the run number appeared in the
  // first value.  So, a reasonable test for version 1 is whether the
  // first value is larger than some relatively small cutoff (say 32).
  // Version 2 added the lumi block number.
  //
  *pos++=(uint32_t)2;  // protocol version number
  *pos++=(uint32_t)runNumber;
  *pos++=(uint32_t)evf::evtn::getlbn(raw->fedAddr(FEDNumbering::MINTriggerGTPFEDID)) + 1;
  *pos++=(uint32_t)raw->evtNumber();
  for (unsigned int i=0;i<1024;i++) *pos++ = (uint32_t)raw->fedSize(i);
  memcpy(pos,raw->payloadAddr(),raw->eventSize());
  
  // DEBUG
  /*
    if (1) {
    stringstream ss;
    ss<<"/tmp/run"<<runNumber<<"_evt"<<raw->evtNumber()<<".err";
    ofstream fout;
    fout.open(ss.str().c_str(),ios::out|ios::binary);
    if (!fout.write((char*)data,dataSize))
    cout<<"Failed to write error event to "<<ss.str()<<endl;
    fout.close();
    
    stringstream ss2;
    ss2<<"/tmp/run"<<runNumber<<"_evt"<<raw->evtNumber()<<".info";
    ofstream fout2;
    fout2.open(ss2.str().c_str());
    fout2<<"dataSize = "<<dataSize<<endl;
    fout2<<"runNumber = "<<runNumber<<endl;
    fout2<<"evtNumber = "<<raw->evtNumber()<<endl;
    fout2<<"eventSize = "<<raw->eventSize()<<endl;
    unsigned int totalSize(0);
    for (unsigned int i=0;i<1024;i++) {
    unsigned int fedSize = raw->fedSize(i);
    totalSize += fedSize;
    if (fedSize>0) fout2<<i<<": "<<fedSize<<endl;
    }
    fout2<<"totalSize = "<<totalSize<<endl;
    fout2.close();
    }
  */// END DEBUG
  
  waitRecoWrite();
  unsigned int   iRecoCell=nextRecoWriteIndex();
  FUShmRecoCell* reco     =recoCell(iRecoCell);
  setEvtState(iRawCell,evt::RECOWRITING);
  setEvtDiscard(iRawCell,1);
  reco->writeErrorEvent(iRawCell,runNumber,raw->evtNumber(),fuProcessId,
                        data,dataSize);
  delete [] data;
  setEvtState(iRawCell,evt::RECOWRITTEN);
  postRecoIndexToRead(iRecoCell);
  if (segmentationMode_) { shmdt(raw); shmdt(reco); }
  postRecoRead();
  return true;
}
void FUShmBuffer::writeRawEmptyEvent ( )
void FUShmBuffer::writeRawLumiSectionEvent ( unsigned int  ls)
void FUShmBuffer::writeRecoEmptyEvent ( )
bool FUShmBuffer::writeRecoEventData ( unsigned int  runNumber,
unsigned int  evtNumber,
unsigned int  outModId,
unsigned int  fuProcessId,
unsigned int  fuGuid,
unsigned char *  data,
unsigned int  dataSize 
)

Definition at line 670 of file FUShmBuffer.cc.

References gather_cfg::cout, incEvtDiscard(), indexForEvtNumber(), nextRecoWriteIndex(), postRecoIndexToRead(), postRecoRead(), recoCell(), recoCellPayloadSize_, evf::evt::RECOWRITING, evf::evt::RECOWRITTEN, segmentationMode_, setEvtState(), waitRecoWrite(), and evf::FUShmRecoCell::writeEventData().

Referenced by edm::FUShmOutputModule::doOutputEvent().

{
  if (dataSize>recoCellPayloadSize_) {
    cout<<"FUShmBuffer::writeRecoEventData() ERROR: buffer overflow."<<endl;
    return false;
  }
  
  waitRecoWrite();
  unsigned int   iCell=nextRecoWriteIndex();
  FUShmRecoCell* cell =recoCell(iCell);
  unsigned int rawCellIndex=indexForEvtNumber(evtNumber);
  //evt::State_t state=evtState(rawCellIndex);
  //assert(state==evt::PROCESSING||state==evt::RECOWRITING||state==evt::SENT);
  setEvtState(rawCellIndex,evt::RECOWRITING);
  incEvtDiscard(rawCellIndex);
  cell->writeEventData(rawCellIndex,runNumber,evtNumber,outModId,
                       fuProcessId,fuGuid,data,dataSize);
  setEvtState(rawCellIndex,evt::RECOWRITTEN);
  postRecoIndexToRead(iCell);
  if (segmentationMode_) shmdt(cell);
  postRecoRead();
  return true;
}
bool FUShmBuffer::writeRecoInitMsg ( unsigned int  outModId,
unsigned int  fuProcessId,
unsigned int  fuGuid,
unsigned char *  data,
unsigned int  dataSize 
)

Definition at line 647 of file FUShmBuffer.cc.

References gather_cfg::cout, nextRecoWriteIndex(), postRecoIndexToRead(), postRecoRead(), recoCell(), recoCellPayloadSize_, segmentationMode_, waitRecoWrite(), and evf::FUShmRecoCell::writeInitMsg().

Referenced by edm::FUShmOutputModule::doOutputHeader().

{
  if (dataSize>recoCellPayloadSize_) {
    cout<<"FUShmBuffer::writeRecoInitMsg() ERROR: buffer overflow."<<endl;
    return false;
  }
  
  waitRecoWrite();
  unsigned int   iCell=nextRecoWriteIndex();
  FUShmRecoCell* cell =recoCell(iCell);
  cell->writeInitMsg(outModId,fuProcessId,fuGuid,data,dataSize);
  postRecoIndexToRead(iCell);
  if (segmentationMode_) shmdt(cell);
  postRecoRead();
  return true;
}

Member Data Documentation

unsigned int evf::FUShmBuffer::clientPrcIdOffset_ [private]

Definition at line 304 of file FUShmBuffer.h.

Referenced by clientPrcId(), FUShmBuffer(), removeClientPrcId(), and setClientPrcId().

unsigned int evf::FUShmBuffer::dqmCellOffset_ [private]

Definition at line 323 of file FUShmBuffer.h.

Referenced by dqmCell(), dqmCellShmKey(), FUShmBuffer(), and initialize().

unsigned int evf::FUShmBuffer::dqmCellPayloadSize_ [private]

Definition at line 321 of file FUShmBuffer.h.

Referenced by dqmCell(), FUShmBuffer(), initialize(), and writeDqmEventData().

unsigned int evf::FUShmBuffer::dqmCellTotalSize_ [private]

Definition at line 322 of file FUShmBuffer.h.

Referenced by dqmCell(), FUShmBuffer(), and initialize().

unsigned int evf::FUShmBuffer::dqmReadIndex_ [private]

Definition at line 319 of file FUShmBuffer.h.

unsigned int evf::FUShmBuffer::dqmReadLast_ [private]

Definition at line 292 of file FUShmBuffer.h.

Referenced by postDqmIndexToRead(), and reset().

unsigned int evf::FUShmBuffer::dqmReadNext_ [private]

Definition at line 291 of file FUShmBuffer.h.

Referenced by nextDqmReadIndex(), and reset().

unsigned int evf::FUShmBuffer::dqmReadOffset_ [private]

Definition at line 293 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), nextDqmReadIndex(), postDqmIndexToRead(), and reset().

unsigned int evf::FUShmBuffer::dqmStateOffset_ [private]

Definition at line 300 of file FUShmBuffer.h.

Referenced by dqmState(), FUShmBuffer(), and setDqmState().

unsigned int evf::FUShmBuffer::dqmWriteIndex_ [private]

Definition at line 318 of file FUShmBuffer.h.

unsigned int evf::FUShmBuffer::dqmWriteLast_ [private]

Definition at line 289 of file FUShmBuffer.h.

Referenced by postDqmIndexToWrite(), and reset().

unsigned int evf::FUShmBuffer::dqmWriteNext_ [private]

Definition at line 288 of file FUShmBuffer.h.

Referenced by nextDqmWriteIndex(), and reset().

unsigned int evf::FUShmBuffer::dqmWriteOffset_ [private]

Definition at line 290 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), nextDqmWriteIndex(), postDqmIndexToWrite(), and reset().

unsigned int evf::FUShmBuffer::evtDiscardOffset_ [private]

Definition at line 296 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), incEvtDiscard(), rawCellReadyForDiscard(), and setEvtDiscard().

unsigned int evf::FUShmBuffer::evtNumberOffset_ [private]

Definition at line 297 of file FUShmBuffer.h.

Referenced by evtNumber(), FUShmBuffer(), indexForEvtNumber(), and setEvtNumber().

unsigned int evf::FUShmBuffer::evtPrcIdOffset_ [private]

Definition at line 298 of file FUShmBuffer.h.

Referenced by evtPrcId(), FUShmBuffer(), and setEvtPrcId().

unsigned int evf::FUShmBuffer::evtStateOffset_ [private]

Definition at line 295 of file FUShmBuffer.h.

Referenced by evtState(), FUShmBuffer(), and setEvtState().

unsigned int evf::FUShmBuffer::evtTimeStampOffset_ [private]

Definition at line 299 of file FUShmBuffer.h.

Referenced by evtTimeStamp(), FUShmBuffer(), and setEvtTimeStamp().

unsigned int evf::FUShmBuffer::nClients_ [private]

Definition at line 302 of file FUShmBuffer.h.

Referenced by nClients(), removeClientPrcId(), reset(), and setClientPrcId().

unsigned int evf::FUShmBuffer::nClientsMax_ [private]

Definition at line 303 of file FUShmBuffer.h.

Referenced by clientPrcId(), FUShmBuffer(), and setClientPrcId().

unsigned int evf::FUShmBuffer::nDqmCells_ [private]
unsigned int evf::FUShmBuffer::nRawCells_ [private]
unsigned int evf::FUShmBuffer::nRecoCells_ [private]
unsigned int evf::FUShmBuffer::rawCellOffset_ [private]

Definition at line 309 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), initialize(), rawCell(), and rawCellShmKey().

unsigned int evf::FUShmBuffer::rawCellPayloadSize_ [private]

Definition at line 307 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), initialize(), and rawCell().

unsigned int evf::FUShmBuffer::rawCellTotalSize_ [private]

Definition at line 308 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), initialize(), and rawCell().

unsigned int evf::FUShmBuffer::rawDiscardIndex_ [private]
unsigned int evf::FUShmBuffer::rawReadLast_ [private]

Definition at line 277 of file FUShmBuffer.h.

Referenced by postRawIndexToRead(), and reset().

unsigned int evf::FUShmBuffer::rawReadNext_ [private]

Definition at line 276 of file FUShmBuffer.h.

Referenced by nextRawReadIndex(), and reset().

unsigned int evf::FUShmBuffer::rawReadOffset_ [private]

Definition at line 278 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), nextRawReadIndex(), postRawIndexToRead(), and reset().

unsigned int evf::FUShmBuffer::rawWriteLast_ [private]

Definition at line 274 of file FUShmBuffer.h.

Referenced by postRawIndexToWrite(), and reset().

unsigned int evf::FUShmBuffer::rawWriteNext_ [private]

Definition at line 273 of file FUShmBuffer.h.

Referenced by nextRawWriteIndex(), and reset().

unsigned int evf::FUShmBuffer::rawWriteOffset_ [private]

Definition at line 275 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), nextRawWriteIndex(), postRawIndexToWrite(), and reset().

unsigned int evf::FUShmBuffer::recoCellOffset_ [private]

Definition at line 316 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), initialize(), recoCell(), and recoCellShmKey().

unsigned int evf::FUShmBuffer::recoCellTotalSize_ [private]

Definition at line 315 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), initialize(), and recoCell().

unsigned int evf::FUShmBuffer::recoReadIndex_ [private]

Definition at line 312 of file FUShmBuffer.h.

unsigned int evf::FUShmBuffer::recoReadLast_ [private]

Definition at line 285 of file FUShmBuffer.h.

Referenced by postRecoIndexToRead(), and reset().

unsigned int evf::FUShmBuffer::recoReadNext_ [private]

Definition at line 284 of file FUShmBuffer.h.

Referenced by nextRecoReadIndex(), and reset().

unsigned int evf::FUShmBuffer::recoReadOffset_ [private]

Definition at line 286 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), nextRecoReadIndex(), postRecoIndexToRead(), and reset().

unsigned int evf::FUShmBuffer::recoWriteIndex_ [private]

Definition at line 311 of file FUShmBuffer.h.

unsigned int evf::FUShmBuffer::recoWriteLast_ [private]

Definition at line 282 of file FUShmBuffer.h.

Referenced by postRecoIndexToWrite(), and reset().

unsigned int evf::FUShmBuffer::recoWriteNext_ [private]

Definition at line 281 of file FUShmBuffer.h.

Referenced by nextRecoWriteIndex(), and reset().

unsigned int evf::FUShmBuffer::recoWriteOffset_ [private]

Definition at line 283 of file FUShmBuffer.h.

Referenced by FUShmBuffer(), nextRecoWriteIndex(), postRecoIndexToWrite(), and reset().

int evf::FUShmBuffer::semid_ [private]

Definition at line 271 of file FUShmBuffer.h.

Referenced by initialize(), and semid().

const char * FUShmBuffer::semKeyPath_ [static, private]
Initial value:
  (getenv("FUSEM_KEYFILE") == NULL ? "/dev/null" : getenv("FUSEM_KEYFILE"))

Definition at line 326 of file FUShmBuffer.h.

Referenced by getSemKey().

int evf::FUShmBuffer::shmid_ [private]

Definition at line 270 of file FUShmBuffer.h.

Referenced by initialize(), and shmid().

const char * FUShmBuffer::shmKeyPath_ [static, private]
Initial value:
  (getenv("FUSHM_KEYFILE") == NULL ? "/dev/null" : getenv("FUSHM_KEYFILE"))

Definition at line 325 of file FUShmBuffer.h.

Referenced by getShmDescriptorKey(), getShmKey(), and initialize().