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)
int incEvtDiscard (unsigned int index, bool lockShm=true)
void initialize (unsigned int shmid, unsigned int semid)
void lock ()
int nbRawCellsToRead () const
unsigned 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 (bool)
void scheduleRawCellForDiscard (unsigned int iCell)
void scheduleRawCellForDiscardServerSide (unsigned int iCell)
bool scheduleRawEmptyCellForDiscard (FUShmRawCell *cell, bool &pidstatus)
void scheduleRawEmptyCellForDiscard ()
void scheduleRawEmptyCellForDiscardServerSide (FUShmRawCell *cell)
void sem_print ()
std::string sem_print_s ()
int semid () const
bool setDqmState (unsigned int index, dqm::State_t state)
bool setEvtDiscard (unsigned int index, unsigned int discard, bool checkValue=false, bool lockShm=true)
bool setEvtPrcId (unsigned int index, pid_t prcId)
bool setEvtState (unsigned int index, evt::State_t state, bool lockShm=true)
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, bool checkValue)
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, unsigned int nExpectedEPs)
 ~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)
unsigned int indexForEvtNumber (unsigned int evtNumber)
unsigned int indexForEvtPrcId (pid_t 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 setEvtNumber (unsigned int index, unsigned int evtNumber)
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 ()
int 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 41 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_ = clientPrcIdOffset_ + 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 152 of file FUShmBuffer.cc.

                          {

}

Member Function Documentation

pid_t FUShmBuffer::clientPrcId ( unsigned int  index)

Definition at line 1444 of file FUShmBuffer.cc.

References clientPrcIdOffset_, getHLTprescales::index, and nClientsMax_.

                                                 {
        if (!(index < nClientsMax_)) {
          stringstream details;
          details << "index<nClientsMax_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        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 917 of file FUShmBuffer.cc.

References gather_cfg::cout, FUShmBuffer(), getSemKey(), getShmDescriptorKey(), getShmKey(), initialize(), nDqmCells(), nRawCells(), nRecoCells(), AlCaHLTBitMon_ParallelJobs::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)

Definition at line 527 of file FUShmBuffer.cc.

References evf::FUShmDqmCell::clear(), evf::dqm::DISCARDING, dqmCell(), dqmState(), evf::dqm::EMPTY, postDqmIndexToWrite(), postDqmWrite(), segmentationMode_, evf::dqm::SENT, and setDqmState().

                                                   {
        dqm::State_t state = dqmState(iCell);
        if(!(state == dqm::EMPTY || state == dqm::SENT)) {
          stringstream details;
          details << "state==dqm::EMPTY||state==dqm::SENT assertion failed! Actual state is "
                  << state << ", iCell = " << iCell;
          XCEPT_ASSERT(false, evf::Exception,details.str());
        }
        setDqmState(iCell, dqm::DISCARDING);
        FUShmDqmCell* cell = dqmCell(iCell);
        cell->clear();
        if (segmentationMode_)
                shmdt(cell);
        setDqmState(iCell, dqm::EMPTY);
        postDqmIndexToWrite(iCell);
        postDqmWrite();
}
void FUShmBuffer::discardOrphanedRecoCell ( unsigned int  iCell)
void FUShmBuffer::discardRawCell ( FUShmRawCell cell)

Definition at line 495 of file FUShmBuffer.cc.

References postRawDiscard(), and releaseRawCell().

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

void FUShmBuffer::discardRecoCell ( unsigned int  iCell)

Definition at line 501 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);
                //XCEPT_ASSERT(state==evt::SENT, evf::Exception, "state==evt::SENT assertion failed!");
                scheduleRawCellForDiscard(iRawCell);
        }
        cell->clear();
        if (segmentationMode_)
                shmdt(cell);
        postRecoIndexToWrite(iCell);
        postRecoWrite();
}
FUShmDqmCell * FUShmBuffer::dqmCell ( unsigned int  iCell)

Definition at line 1678 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(), reset(), 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 1758 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 354 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);
        
        if(!(state == dqm::WRITTEN || state == dqm::EMPTY)) {
          stringstream details;
          details << "state==dqm::WRITTEN || state==dqm::EMPTY assertion failed! Actual state is "
                  << state << ", iCell = " << iCell;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }

        if (state == dqm::WRITTEN)
                setDqmState(iCell, dqm::SENDING);
        return cell;
}
dqm::State_t FUShmBuffer::dqmState ( unsigned int  index)

Definition at line 1394 of file FUShmBuffer.cc.

References dqmStateOffset_, getHLTprescales::index, and nDqmCells_.

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

                                                   {
        if (!(index < nDqmCells_)) {
          stringstream details;
          details << "index<nDqmCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        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 1407 of file FUShmBuffer.cc.

References evtNumberOffset_, getHLTprescales::index, and nRawCells_.

Referenced by indexForEvtNumber(), and setEvtNumber().

                                                      {
        if (!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        unsigned int *pevt = (unsigned int*) ((unsigned long) this
                        + evtNumberOffset_);
        pevt += index;
        return *pevt;
}
pid_t FUShmBuffer::evtPrcId ( unsigned int  index)

Definition at line 1420 of file FUShmBuffer.cc.

References evtPrcIdOffset_, getHLTprescales::index, and nRawCells_.

                                              {
        if (!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        pid_t *prcid = (pid_t*) ((unsigned long) this + evtPrcIdOffset_);
        prcid += index;
        return *prcid;
}
evt::State_t FUShmBuffer::evtState ( unsigned int  index)

Definition at line 1381 of file FUShmBuffer.cc.

References evtStateOffset_, getHLTprescales::index, and nRawCells_.

Referenced by FUShmReader::fillRawData(), finishReadingRawCell(), finishWritingRawCell(), printEvtState(), rawCellToDiscard(), rawCellToRead(), rawCellToWrite(), releaseRawCell(), scheduleRawCellForDiscard(), scheduleRawCellForDiscardServerSide(), writeRawEmptyEvent(), and writeRawLumiSectionEvent().

                                                   {
        if (!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        evt::State_t *pstate = (evt::State_t*) ((unsigned long) this
                        + evtStateOffset_);
        pstate += index;
        return *pstate;
}
time_t FUShmBuffer::evtTimeStamp ( unsigned int  index)

Definition at line 1432 of file FUShmBuffer.cc.

References evtTimeStampOffset_, getHLTprescales::index, and nRawCells_.

                                                   {
        if (!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        time_t *ptstmp = (time_t*) ((unsigned long) this + evtTimeStampOffset_);
        ptstmp += index;
        return *ptstmp;
}
void FUShmBuffer::finishReadingDqmCell ( FUShmDqmCell cell)

Definition at line 438 of file FUShmBuffer.cc.

References dqmState(), evf::dqm::EMPTY, evf::FUShmDqmCell::index(), segmentationMode_, evf::dqm::SENDING, evf::evt::SENT, and setDqmState().

                                                         {
        dqm::State_t state = dqmState(cell->index());
        if(!(state == dqm::SENDING || state == dqm::EMPTY)) {
        stringstream details;
        details << "state==dqm::SENDING||state==dqm::EMPTY assertion failed! Actual state is "
                << state << ", index = " << cell->index();
          XCEPT_ASSERT(false, evf::Exception, details.str());

        }
        if (state == dqm::SENDING)
                setDqmState(cell->index(), dqm::SENT);
        if (segmentationMode_)
                shmdt(cell);
}
void FUShmBuffer::finishReadingRawCell ( FUShmRawCell cell)

Definition at line 410 of file FUShmBuffer.cc.

References evtState(), evf::FUShmRawCell::index(), evf::evt::PROCESSING, evf::evt::RAWREAD, evf::evt::RAWREADING, segmentationMode_, setEvtState(), setEvtTimeStamp(), and cond::rpcobgas::time.

Referenced by FUShmReader::fillRawData(), and evf::FUShmClient::readNext().

                                                         {
        evt::State_t state = evtState(cell->index());
        if(!(state == evt::RAWREADING)) {
          stringstream details;
          details << "state==evt::RAWREADING assertion failed! Actual state is "
                  << state << ", index = " << cell->index();
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        setEvtState(cell->index(), evt::RAWREAD);
        setEvtState(cell->index(), evt::PROCESSING);
        setEvtTimeStamp(cell->index(), time(0));
        if (segmentationMode_)
                shmdt(cell);
}
void FUShmBuffer::finishReadingRecoCell ( FUShmRecoCell cell)

Definition at line 426 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());
                //XCEPT_ASSERT(state==evt::SENDING, evf::Exception, "state==evt::SENDING assertion failed!");
                setEvtState(cell->rawCellIndex(), evt::SENT);
        }
        if (segmentationMode_)
                shmdt(cell);
}
void FUShmBuffer::finishWritingRawCell ( FUShmRawCell cell)

Definition at line 393 of file FUShmBuffer.cc.

References evf::FUShmRawCell::evtNumber(), evtState(), evf::FUShmRawCell::index(), postRawIndexToRead(), postRawRead(), evf::evt::RAWWRITING, evf::evt::RAWWRITTEN, segmentationMode_, setEvtNumber(), and setEvtState().

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

                                                         {
        evt::State_t state = evtState(cell->index());
        if(!(state == evt::RAWWRITING)) {
          stringstream details;
          details << "state==evt::RAWWRITING assertion failed! Actual state is "
          << state << ", index = " << cell->index();
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        setEvtState(cell->index(), evt::RAWWRITTEN);
        setEvtNumber(cell->index(), cell->evtNumber());
        postRawIndexToRead(cell->index());
        if (segmentationMode_)
                shmdt(cell);
        postRawRead();
}
key_t FUShmBuffer::getSemKey ( ) [static]

Definition at line 1169 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 986 of file FUShmBuffer.cc.

References gather_cfg::cout, FUShmBuffer(), getSemKey(), getShmDescriptorKey(), getShmKey(), nDqmCells(), nRawCells(), nRecoCells(), AlCaHLTBitMon_ParallelJobs::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. PID:" << getpid()
                        << endl;
        cout << "                             segmentationMode="
                        << segmentationMode << endl;

        buffer->setClientPrcId(getpid());

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

Definition at line 1151 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 1160 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,
bool  lockShm = true 
)

Definition at line 1512 of file FUShmBuffer.cc.

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

Referenced by writeRecoEventData().

                                                               {
        int result = 0;
        if(!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          //unlock here as it will skip external unlock
          if (!lockShm) unlock();
          XCEPT_ASSERT(false,evf::Exception,details.str());
        }
        unsigned int *pcount = (unsigned int*) ((unsigned long) this
                        + evtDiscardOffset_);
        pcount += index;
        if (lockShm) lock();
        (*pcount)++;
        result = *pcount;
        if (lockShm) unlock();
        return result;
}
unsigned int FUShmBuffer::indexForEvtNumber ( unsigned int  evtNumber) [private]

Definition at line 1358 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;
        }
        XCEPT_ASSERT(false, evf::Exception, "This point should not be reached!");
        return 0xffffffff;
}
unsigned int FUShmBuffer::indexForEvtPrcId ( pid_t  evtNumber) [private]

Definition at line 1370 of file FUShmBuffer.cc.

References evtPrcIdOffset_, i, and nRawCells_.

                                                      {
        pid_t *pevt = (pid_t*) ((unsigned long) this + evtPrcIdOffset_);
        for (unsigned int i = 0; i < nRawCells_; i++) {
                if ((*pevt++) == prcid)
                        return i;
        }
        XCEPT_ASSERT(false, evf::Exception, "This point should not be reached!");
        return 0xffffffff;
}
void FUShmBuffer::initialize ( unsigned int  shmid,
unsigned int  semid 
)

Definition at line 162 of file FUShmBuffer.cc.

References dqmCellOffset_, dqmCellPayloadSize_, dqmCellTotalSize_, i, nDqmCells_, nRawCells_, nRecoCells_, rawCellOffset_, rawCellPayloadSize_, rawCellTotalSize_, 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;
                }
        }

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

Definition at line 293 of file FUShmBuffer.cc.

References semid().

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

Definition at line 288 of file FUShmBuffer.cc.

References semid().

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

Definition at line 71 of file FUShmBuffer.h.

References nClients_.

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

Definition at line 67 of file FUShmBuffer.h.

References nDqmCells_.

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

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

Definition at line 1343 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 1275 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 1303 of file FUShmBuffer.cc.

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

Referenced by rawCellToRead().

unsigned int FUShmBuffer::nextRawWriteIndex ( ) [private]

Definition at line 1298 of file FUShmBuffer.cc.

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

Referenced by rawCellToWrite().

unsigned int FUShmBuffer::nextRecoReadIndex ( ) [private]

Definition at line 1323 of file FUShmBuffer.cc.

References nextIndex(), nRecoCells_, recoReadNext_, and recoReadOffset_.

Referenced by recoCellToRead().

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

Definition at line 65 of file FUShmBuffer.h.

References nRawCells_.

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

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

Definition at line 66 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 267 of file FUShmBuffer.h.

References sem_post().

Referenced by writeDqmEmptyEvent(), and writeDqmEventData().

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

Definition at line 265 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 1287 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 255 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 253 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 263 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 261 of file FUShmBuffer.h.

References sem_post().

Referenced by discardOrphanedRecoCell(), and discardRecoCell().

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

Definition at line 911 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 878 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 1632 of file FUShmBuffer.cc.

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

Referenced by rawCellToDiscard(), rawCellToRead(), rawCellToWrite(), reset(), 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 1701 of file FUShmBuffer.cc.

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

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

                                                           {
        if(!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        unsigned int *pcount = (unsigned int*) ((unsigned long) this
                        + evtDiscardOffset_);
        pcount += index;
        lock();
        if(!(*pcount > 0)) {
          stringstream details;
          details << "*pcount>0 assertion failed! Value at pcount is " << *pcount << " for cell index " << index;
          unlock();
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        --(*pcount);
        bool result = (*pcount == 0);
        unlock();
        return result;
}
key_t FUShmBuffer::rawCellShmKey ( unsigned int  iCell) [private]

Definition at line 1737 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 ( )

Definition at line 373 of file FUShmBuffer.cc.

References evf::evt::DISCARDING, evf::evt::EMPTY, evtState(), evf::FUShmRawCell::index(), evf::evt::PROCESSED, rawCell(), rawDiscardIndex_, evf::evt::SENT, setEvtState(), evf::evt::STOP, evf::evt::USEDLS, and waitRawDiscarded().

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

                                            {
        waitRawDiscarded();
        FUShmRawCell* cell = rawCell(rawDiscardIndex_);
        evt::State_t state = evtState(cell->index());
        if(!(state == evt::PROCESSED || state == evt::SENT || 
             state == evt::EMPTY || state == evt::STOP ||
             state == evt::USEDLS)) {
          stringstream details;
          details << "state==evt::PROCESSED || state==evt::SENT || "
                  << "state==evt::EMPTY || state==evt::STOP || "
                  << "state==evt::USEDLS assertion failed! Actual state is "
                  << state << ", index = " << cell->index();
          XCEPT_ASSERT(false,evf::Exception,details.str());
        }
        if (state != evt::EMPTY && state != evt::USEDLS && state != evt::STOP)
                setEvtState(cell->index(), evt::DISCARDING);
        return cell;
}
FUShmRawCell * FUShmBuffer::rawCellToRead ( )

Definition at line 317 of file FUShmBuffer.cc.

References evf::evt::EMPTY, evtState(), evf::evt::LUMISECTION, nextRawReadIndex(), rawCell(), evf::evt::RAWREADING, evf::evt::RAWWRITTEN, setEvtPrcId(), setEvtState(), evf::evt::STOP, and waitRawRead().

Referenced by FUShmReader::fillRawData(), and evf::FUShmClient::readNext().

                                         {
        waitRawRead();
        unsigned int iCell = nextRawReadIndex();
        FUShmRawCell* cell = rawCell(iCell);
        evt::State_t state = evtState(iCell);
        if(!(state == evt::RAWWRITTEN || state == evt::EMPTY || 
             state == evt::STOP || state == evt::LUMISECTION))
        {
          stringstream details;
          details
                << "state==evt::RAWWRITTEN ||state==evt::EMPTY ||state==evt::STOP"
                << "||state==evt::LUMISECTION assertion failed! Actual state is "
                << state << ", iCell = " << iCell;
          XCEPT_ASSERT(false,evf::Exception, details.str());
        }
        if (state == evt::RAWWRITTEN) {
                setEvtPrcId(iCell, getpid());
                setEvtState(iCell, evt::RAWREADING);
        }
        return cell;
}
FUShmRawCell * FUShmBuffer::rawCellToWrite ( )

Definition at line 298 of file FUShmBuffer.cc.

References evf::evt::EMPTY, evtState(), lock(), nextRawWriteIndex(), rawCell(), evf::evt::RAWWRITING, setEvtDiscard(), setEvtState(), unlock(), and waitRawWrite().

Referenced by scheduleRawEmptyCellForDiscard(), evf::FUShmServer::writeNext(), writeRawEmptyEvent(), and writeRawLumiSectionEvent().

                                          {
        if (waitRawWrite() != 0)
                return 0;
        unsigned int iCell = nextRawWriteIndex();
        FUShmRawCell* cell = rawCell(iCell);
        evt::State_t state = evtState(iCell);
        if(!(state == evt::EMPTY)) {
          stringstream details;
          details << "state==evt::EMPTY assertion failed! Actual state is " << state << ", iCell = " << iCell;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        lock();
        setEvtState(iCell, evt::RAWWRITING,false);
        setEvtDiscard(iCell, 1,false,false);
        unlock();
        return cell;
}
FUShmRecoCell * FUShmBuffer::recoCell ( unsigned int  iCell)

Definition at line 1655 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(), recoCellToRead(), reset(), 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 1747 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 340 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);
                //XCEPT_ASSERT(state==evt::RECOWRITTEN, evf::Exception, "state==evt::RECOWRITTEN assertion failed!");
                setEvtState(iRawCell, evt::SENDING);
        }
        return cell;
}
void FUShmBuffer::releaseRawCell ( FUShmRawCell cell)

Definition at line 546 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;
          stringstream details;
          details << "state==evt::DISCARDING||state==evt::RAWWRITING||"
                  << "state==evt::EMPTY||state==evt::STOP||state==evt::USEDLS"
                  << " assertion failed! Actual state is " << state << ", index = " << cell->index();
          XCEPT_ASSERT( false, evf::Exception, details.str());
        }
        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 1045 of file FUShmBuffer.cc.

References gather_cfg::cout, dqmCellShmKey(), FUShmBuffer(), getSemKey(), getShmDescriptorKey(), getShmKey(), i, nDqmCells(), nRawCells(), nRecoCells(), AlCaHLTBitMon_ParallelJobs::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 1602 of file FUShmBuffer.cc.

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

Referenced by scheduleRawEmptyCellForDiscard(), edm::FUShmOutputModule::unregisterFromShm(), and FUShmReader::~FUShmReader().

                                               {
        lock();
        pid_t *prcid = (pid_t*) ((unsigned long) this + clientPrcIdOffset_);
        unsigned int iClient(0);
        while (iClient < nClients_ && (*prcid) != prcId) {
                prcid++;
                iClient++;
        }
        if (iClient==nClients_) {
                unlock();
                return false;
        }
        //stringstream details;
        //details << "iClient!=nClients_ assertion failed! Actual iClient is "
        //              << iClient;
        //XCEPT_ASSERT(iClient != nClients_, evf::Exception, details.str());
        pid_t* next = prcid;
        next++;
        while (iClient < nClients_ - 1) {
                *prcid = *next;
                prcid++;
                next++;
                iClient++;
        }
        nClients_--;
        unlock();
        return true;
}
void FUShmBuffer::reset ( bool  shm_detach)

Definition at line 201 of file FUShmBuffer.cc.

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

Referenced by initialize().

                                       {
        nClients_ = 0;


        for (unsigned int i = 0; i < nRawCells_; i++) {
                FUShmRawCell* cell = rawCell(i);
                cell->initialize(i);
                if (segmentationMode_ && shm_detach)
                        shmdt(cell);
        }

        for (unsigned int i = 0; i < nRecoCells_; i++) {
                FUShmRecoCell* cell = recoCell(i);
                cell->initialize(i);
                if (segmentationMode_ && shm_detach)
                        shmdt(cell);
        }

        for (unsigned int i = 0; i < nDqmCells_; i++) {
                FUShmDqmCell* cell = dqmCell(i);
                cell->initialize(i);
                if (segmentationMode_ && shm_detach)
                        shmdt(cell);
        }


        // 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)

Definition at line 454 of file FUShmBuffer.cc.

References evf::evt::EMPTY, evtState(), evf::evt::LUMISECTION, postRawDiscard(), postRawDiscarded(), evf::evt::PROCESSED, evf::evt::PROCESSING, rawCellReadyForDiscard(), rawDiscardIndex_, evf::evt::RECOWRITTEN, evf::evt::SENT, setEvtState(), evf::evt::STOP, evf::evt::USEDLS, and waitRawDiscard().

Referenced by discardRecoCell(), FUShmReader::fillRawData(), and evf::FUShmClient::readNext().

                                                              {
        waitRawDiscard();
        if (rawCellReadyForDiscard(iCell)) {
                rawDiscardIndex_ = iCell;
                evt::State_t state = evtState(iCell);
                if(!(state == evt::PROCESSING || state == evt::SENT ||
                     state == evt::EMPTY || state == evt::STOP ||
                     state == evt::LUMISECTION || state == evt::RECOWRITTEN)) {
                  stringstream details;
                  details << "state==evt::PROCESSING||state==evt::SENT||state==evt::EMPTY||"
                          <<"state==evt::STOP||state==evt::LUMISECTION||state==evt::RECOWRITTEN assertion failed! Actual state is "
                          << state << ", iCell = " << iCell;
                  XCEPT_ASSERT( false,evf::Exception,details.str()); 
                }
                if (state == evt::PROCESSING)
                        setEvtState(iCell, evt::PROCESSED);
                if (state == evt::LUMISECTION)
                        setEvtState(iCell, evt::USEDLS);
                postRawDiscarded();
        } else
                postRawDiscard();
}
void FUShmBuffer::scheduleRawCellForDiscardServerSide ( unsigned int  iCell)
void FUShmBuffer::scheduleRawEmptyCellForDiscard ( )
bool FUShmBuffer::scheduleRawEmptyCellForDiscard ( FUShmRawCell cell,
bool &  pidstatus 
)

Definition at line 652 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);
                pidstatus = removeClientPrcId(getpid());
                if (segmentationMode_)
                        shmdt(cell);
                postRawDiscarded();
                return true;
        } else {
                postRawDiscard();
                return false;
        }
}
void FUShmBuffer::scheduleRawEmptyCellForDiscardServerSide ( FUShmRawCell cell)

Definition at line 675 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 1240 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 1262 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 1251 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 1768 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 1788 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 852 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;
}
std::string FUShmBuffer::sem_print_s ( )

Definition at line 863 of file FUShmBuffer.cc.

References semid().

                                   {
        ostringstream ostr;
        ostr    << "--> 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;
        return ostr.str();

}
int FUShmBuffer::sem_wait ( int  isem) [private]

Definition at line 1775 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 1578 of file FUShmBuffer.cc.

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

Referenced by getShmBuffer().

                                            {
        lock();
        if(!(nClients_ < nClientsMax_)) {
          stringstream details;
          details << "nClients_<nClientsMax_ assertion failed! Actual nClients is "
                  << nClients_ << " and nClientsMax is " << nClientsMax_;
          unlock();
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        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 1474 of file FUShmBuffer.cc.

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

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

                                                                  {
        if(!(index < nDqmCells_)) {
          stringstream details;
          details << "index<nDqmCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        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,
bool  checkValue = false,
bool  lockShm = true 
)

Definition at line 1490 of file FUShmBuffer.cc.

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

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

                                                                                                       {
        if(!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          //unlock here as it will skip external unlock
          if (!lockShm) unlock();
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        unsigned int *pcount = (unsigned int*) ((unsigned long) this
                        + evtDiscardOffset_);
        pcount += index;
        if (lockShm) lock();
        if (checkValue) {
                if (*pcount < discard)
                        *pcount = discard;
        } else
                *pcount = discard;
        if (lockShm) unlock();
        return true;
}
bool FUShmBuffer::setEvtNumber ( unsigned int  index,
unsigned int  evtNumber 
) [private]

Definition at line 1532 of file FUShmBuffer.cc.

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

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

                                                                         {
        if(!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        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 
)

Definition at line 1548 of file FUShmBuffer.cc.

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

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

                                                             {
        if(!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        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  lockShm = true 
)

Definition at line 1456 of file FUShmBuffer.cc.

References evtStateOffset_, getHLTprescales::index, lock(), nRawCells_, evf::utils::state, and unlock().

Referenced by finishReadingRawCell(), finishReadingRecoCell(), finishWritingRawCell(), rawCellToDiscard(), rawCellToRead(), rawCellToWrite(), recoCellToRead(), releaseRawCell(), reset(), scheduleRawCellForDiscard(), scheduleRawCellForDiscardServerSide(), scheduleRawEmptyCellForDiscard(), writeErrorEventData(), writeRawEmptyEvent(), writeRawLumiSectionEvent(), and writeRecoEventData().

                                                                                {
        if(!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          //unlock here as it will skip external unlock
          if (!lockShm) unlock();
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        evt::State_t *pstate = (evt::State_t*) ((unsigned long) this
                        + evtStateOffset_);
        pstate += index;
        if (lockShm) lock();
        *pstate = state;
        if (lockShm) unlock();
        return true;
}
bool FUShmBuffer::setEvtTimeStamp ( unsigned int  index,
time_t  timeStamp 
) [private]

Definition at line 1563 of file FUShmBuffer.cc.

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

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

                                                                      {
        if(!(index < nRawCells_)) {
          stringstream details;
          details << "index<nRawCells_ assertion failed! Actual index is " << index;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        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 1212 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 1178 of file FUShmBuffer.cc.

References gather_cfg::cout, 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;
                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;
                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 1230 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 1201 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 1223 of file FUShmBuffer.cc.

Referenced by createShmBuffer(), evf::FUResourceTable::discardNoReschedule(), 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 1724 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 1128 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 266 of file FUShmBuffer.h.

References sem_wait().

Referenced by dqmCellToRead().

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

Definition at line 264 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 258 of file FUShmBuffer.h.

References sem_wait().

Referenced by rawCellToDiscard().

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

Definition at line 254 of file FUShmBuffer.h.

References sem_wait().

Referenced by rawCellToRead().

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

Definition at line 252 of file FUShmBuffer.h.

References sem_wait().

Referenced by rawCellToWrite().

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

Definition at line 262 of file FUShmBuffer.h.

References sem_wait().

Referenced by recoCellToRead().

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

Definition at line 260 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 820 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);
        if (!(state == dqm::EMPTY)) {
          stringstream details;
          details << "state==dqm::EMPTY assertion failed! Actual state is " << state
                  << ", iCell = " << iCell;
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        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,
bool  checkValue 
)

Definition at line 746 of file FUShmBuffer.cc.

References AlCaHLTBitMon_QueryRunRegistry::data, evf::FUShmRawCell::eventSize(), evf::FUShmRawCell::evtNumber(), evf::FUShmRawCell::fedAddr(), evf::FUShmRawCell::fedSize(), evf::evtn::getlbn(), i, lock(), FEDNumbering::MINTriggerGTPFEDID, nextRecoWriteIndex(), evf::FUShmRawCell::payloadAddr(), pos, postRecoIndexToRead(), postRecoRead(), rawCell(), dt_dqm_sourceclient_common_cff::reco, recoCell(), evf::evt::RECOWRITING, evf::evt::RECOWRITTEN, segmentationMode_, setEvtDiscard(), setEvtState(), unlock(), 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);
        lock();
        setEvtState(iRawCell, evt::RECOWRITING,false);
        setEvtDiscard(iRawCell, 1, true,false);
        unlock();
        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 ( )

Definition at line 572 of file FUShmBuffer.cc.

References evtState(), evf::FUShmRawCell::index(), postRawIndexToRead(), postRawRead(), rawCellToWrite(), evf::evt::RAWWRITING, segmentationMode_, evf::FUShmRawCell::setEventTypeStopper(), setEvtState(), and evf::evt::STOP.

                                     {
        FUShmRawCell* cell = rawCellToWrite();
        if (cell == 0)
                return;
        evt::State_t state = evtState(cell->index());
        if(!(state == evt::RAWWRITING)) {
          stringstream details;
          details << "state==evt::RAWWRITING assertion failed! Actual state is "
                  << state << ", index = " << cell->index();
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        setEvtState(cell->index(), evt::STOP);
        cell->setEventTypeStopper();
        postRawIndexToRead(cell->index());
        if (segmentationMode_)
                shmdt(cell);
        postRawRead();
}
void FUShmBuffer::writeRawLumiSectionEvent ( unsigned int  ls)

Definition at line 592 of file FUShmBuffer.cc.

References evtState(), evf::FUShmRawCell::index(), evf::evt::LUMISECTION, postRawIndexToRead(), postRawRead(), rawCellToWrite(), evf::evt::RAWWRITING, segmentationMode_, evf::FUShmRawCell::setEventTypeEol(), setEvtNumber(), setEvtState(), and evf::FUShmRawCell::setLumiSection().

                                                          {
        FUShmRawCell* cell = rawCellToWrite();
        if (cell == 0)
                return;
        cell->setLumiSection(ls);
        evt::State_t state = evtState(cell->index());
        if (!(state == evt::RAWWRITING)) {
          stringstream details;
          details << "state==evt::RAWWRITING assertion failed! Actual state is "
                  << state << ", index = " << cell->index();
          XCEPT_ASSERT(false, evf::Exception, details.str());
        }
        setEvtNumber(cell->index(),0xfffffffe);
        setEvtState(cell->index(), evt::LUMISECTION);
        cell->setEventTypeEol();
        postRawIndexToRead(cell->index());
        if (segmentationMode_)
                shmdt(cell);
        postRawRead();
}
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 714 of file FUShmBuffer.cc.

References gather_cfg::cout, incEvtDiscard(), indexForEvtNumber(), lock(), nextRecoWriteIndex(), postRecoIndexToRead(), postRecoRead(), recoCell(), recoCellPayloadSize_, evf::evt::RECOWRITING, evf::evt::RECOWRITTEN, segmentationMode_, setEvtState(), unlock(), 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 rawCellIndex = indexForEvtNumber(evtNumber);
        unsigned int iCell = nextRecoWriteIndex();
        FUShmRecoCell* cell = recoCell(iCell);
        //evt::State_t state=evtState(rawCellIndex);
        //XCEPT_ASSERT(state==evt::PROCESSING||state==evt::RECOWRITING||state==evt::SENT,
        //evf::Exception, "state==evt::PROCESSING||state==evt::RECOWRITING||state==evt::SENT assertion failed!");
        lock();
        setEvtState(rawCellIndex, evt::RECOWRITING,false);
        incEvtDiscard(rawCellIndex,false);
        unlock();
        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,
unsigned int  nExpectedEPs 
)

Definition at line 693 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,nExpectedEPs);
        postRecoIndexToRead(iCell);
        if (segmentationMode_)
                shmdt(cell);
        postRecoRead();
        return true;
}

Member Data Documentation

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

Definition at line 309 of file FUShmBuffer.h.

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

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

Definition at line 328 of file FUShmBuffer.h.

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

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

Definition at line 326 of file FUShmBuffer.h.

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

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

Definition at line 327 of file FUShmBuffer.h.

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

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

Definition at line 324 of file FUShmBuffer.h.

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

Definition at line 297 of file FUShmBuffer.h.

Referenced by postDqmIndexToRead(), and reset().

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

Definition at line 296 of file FUShmBuffer.h.

Referenced by nextDqmReadIndex(), and reset().

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

Definition at line 298 of file FUShmBuffer.h.

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

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

Definition at line 305 of file FUShmBuffer.h.

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

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

Definition at line 323 of file FUShmBuffer.h.

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

Definition at line 294 of file FUShmBuffer.h.

Referenced by postDqmIndexToWrite(), and reset().

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

Definition at line 293 of file FUShmBuffer.h.

Referenced by nextDqmWriteIndex(), and reset().

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

Definition at line 295 of file FUShmBuffer.h.

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

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

Definition at line 301 of file FUShmBuffer.h.

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

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

Definition at line 302 of file FUShmBuffer.h.

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

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

Definition at line 303 of file FUShmBuffer.h.

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

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

Definition at line 300 of file FUShmBuffer.h.

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

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

Definition at line 304 of file FUShmBuffer.h.

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

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

Definition at line 307 of file FUShmBuffer.h.

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

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

Definition at line 308 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 314 of file FUShmBuffer.h.

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

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

Definition at line 312 of file FUShmBuffer.h.

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

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

Definition at line 313 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 282 of file FUShmBuffer.h.

Referenced by postRawIndexToRead(), and reset().

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

Definition at line 281 of file FUShmBuffer.h.

Referenced by nextRawReadIndex(), and reset().

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

Definition at line 283 of file FUShmBuffer.h.

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

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

Definition at line 279 of file FUShmBuffer.h.

Referenced by postRawIndexToWrite(), and reset().

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

Definition at line 278 of file FUShmBuffer.h.

Referenced by nextRawWriteIndex(), and reset().

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

Definition at line 280 of file FUShmBuffer.h.

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

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

Definition at line 321 of file FUShmBuffer.h.

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

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

Definition at line 320 of file FUShmBuffer.h.

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

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

Definition at line 317 of file FUShmBuffer.h.

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

Definition at line 290 of file FUShmBuffer.h.

Referenced by postRecoIndexToRead(), and reset().

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

Definition at line 289 of file FUShmBuffer.h.

Referenced by nextRecoReadIndex(), and reset().

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

Definition at line 291 of file FUShmBuffer.h.

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

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

Definition at line 316 of file FUShmBuffer.h.

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

Definition at line 287 of file FUShmBuffer.h.

Referenced by postRecoIndexToWrite(), and reset().

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

Definition at line 286 of file FUShmBuffer.h.

Referenced by nextRecoWriteIndex(), and reset().

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

Definition at line 288 of file FUShmBuffer.h.

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

int evf::FUShmBuffer::semid_ [private]

Definition at line 276 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 331 of file FUShmBuffer.h.

Referenced by getSemKey().

int evf::FUShmBuffer::shmid_ [private]

Definition at line 275 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 330 of file FUShmBuffer.h.

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