CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

L1GTDigiToRaw Class Reference

#include <L1GTDigiToRaw.h>

Inheritance diagram for L1GTDigiToRaw:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 L1GTDigiToRaw (const edm::ParameterSet &)
 constructor(s)
virtual ~L1GTDigiToRaw ()
 destructor

Private Member Functions

virtual void beginJob ()
 beginning of job stuff
virtual void endJob ()
 end of job stuff
unsigned int flipPtQ (unsigned int)
void packFDL (const edm::EventSetup &, unsigned char *, L1GtFdlWord &)
 pack FDL blocks for various bunch crosses
unsigned int packGMT (L1MuGMTReadoutRecord const &, unsigned char *)
 pack a GMT record
unsigned int packGmtCollection (unsigned char *ptrGt, L1MuGMTReadoutCollection const *digis)
 pack the GMT collection using packGMT (GMT record packing)
void packGTFE (const edm::EventSetup &, unsigned char *, L1GtfeWord &, cms_uint16_t activeBoardsGtValue)
void packHeader (unsigned char *, edm::Event &)
 block packers -------------
void packPSB (const edm::EventSetup &, unsigned char *, L1GtPsbWord &)
void packTrailer (unsigned char *, unsigned char *, int)
 pack trailer word
virtual void produce (edm::Event &, const edm::EventSetup &)
 loop over events

Private Attributes

cms_uint16_t m_activeBoardsMaskGt
 mask for active boards
int m_daqGtFedId
edm::InputTag m_daqGtInputTag
 input tag for GT DAQ record
bool m_isDebugEnabled
int m_maxBxInEvent
int m_minBxInEvent
edm::InputTag m_muGmtInputTag
 input tag for GMT record
int m_totalBxInEvent
 total Bx's in the event, obtained from GTFE block
int m_verbosity
 verbosity level

Detailed Description

Description: generate raw data from digis.

Implementation: <TODO: enter implementation details>

Author:
: Vasile Mihai Ghete - HEPHY Vienna - GT
: Ivan Mikulec - HEPHY Vienna - GMT

$Date$ $Revision$

Definition at line 45 of file L1GTDigiToRaw.h.


Constructor & Destructor Documentation

L1GTDigiToRaw::L1GTDigiToRaw ( const edm::ParameterSet pSet) [explicit]

constructor(s)

Definition at line 62 of file L1GTDigiToRaw.cc.

References LogDebug, m_activeBoardsMaskGt, m_daqGtFedId, m_daqGtInputTag, m_isDebugEnabled, m_muGmtInputTag, and m_verbosity.

                                                        :

    m_daqGtFedId(pSet.getUntrackedParameter<int> (
            "DaqGtFedId", FEDNumbering::MAXTriggerGTPFEDID)),
    m_daqGtInputTag(pSet.getParameter<edm::InputTag> ("DaqGtInputTag")),
    m_muGmtInputTag(pSet.getParameter<edm::InputTag> ("MuGmtInputTag")),
    m_activeBoardsMaskGt(pSet.getParameter<unsigned int> ("ActiveBoardsMask")),
    m_totalBxInEvent(0),
    m_minBxInEvent(0), m_maxBxInEvent(),
    m_verbosity(pSet.getUntrackedParameter<int> ("Verbosity", 0)),
    m_isDebugEnabled(edm::isDebugEnabled())

{

    if (m_verbosity && m_isDebugEnabled) {
        LogDebug("L1GTDigiToRaw")
                << "\nFED Id for DAQ GT record: " << m_daqGtFedId << " \n"
                << "\nInput tag for DAQ GT record: " << m_daqGtInputTag << " \n"
                << "\nInput tag for GMT record: " << m_muGmtInputTag << " \n"
                << "\nMask for active boards (hex format): " << std::hex
                << std::setw(sizeof(m_activeBoardsMaskGt) * 2) << std::setfill('0')
                << m_activeBoardsMaskGt
                << std::dec << std::setfill(' ') << " \n"
                << std::endl;
    }

    //
    produces<FEDRawDataCollection> ();

}
L1GTDigiToRaw::~L1GTDigiToRaw ( ) [virtual]

destructor

Definition at line 94 of file L1GTDigiToRaw.cc.

{

    // empty now

}

Member Function Documentation

void L1GTDigiToRaw::beginJob ( void  ) [private, virtual]

beginning of job stuff

Reimplemented from edm::EDProducer.

Definition at line 104 of file L1GTDigiToRaw.cc.

{

    // empty now

}
void L1GTDigiToRaw::endJob ( void  ) [private, virtual]

end of job stuff

Reimplemented from edm::EDProducer.

Definition at line 887 of file L1GTDigiToRaw.cc.

{

    // empty now
}
unsigned int L1GTDigiToRaw::flipPtQ ( unsigned int  w) [private]

Definition at line 853 of file L1GTDigiToRaw.cc.

{
    return ( (w&0xffff00ff) | ((~w)&0x0000ff00) );
}
void L1GTDigiToRaw::packFDL ( const edm::EventSetup evSetup,
unsigned char *  ptrGt,
L1GtFdlWord fdlBlock 
) [private]

pack FDL blocks for various bunch crosses

Definition at line 612 of file L1GTDigiToRaw.cc.

References L1GtFdlWord::getSize(), LogDebug, LogTrace, m_isDebugEnabled, m_verbosity, L1GtFdlWord::setBoardIdWord64(), L1GtFdlWord::setBxInEventWord64(), L1GtFdlWord::setBxNrWord64(), L1GtFdlWord::setEventNrWord64(), L1GtFdlWord::setFinalORWord64(), L1GtFdlWord::setGtDecisionWordAWord64(), L1GtFdlWord::setGtDecisionWordBWord64(), L1GtFdlWord::setGtDecisionWordExtendedWord64(), L1GtFdlWord::setGtPrescaleFactorIndexAlgoWord64(), L1GtFdlWord::setGtPrescaleFactorIndexTechWord64(), L1GtFdlWord::setGtTechnicalTriggerWordWord64(), L1GtFdlWord::setLocalBxNrWord64(), L1GtFdlWord::setLumiSegmentNrWord64(), L1GtFdlWord::setNoAlgoWord64(), L1GtFdlWord::setOrbitNrWord64(), L1GtFdlWord::setPhysicsDeclaredWord64(), and L1GlobalTriggerReadoutSetup::UnitLength.

Referenced by produce().

                                                                                   {

    if (m_verbosity && m_isDebugEnabled) {

        LogDebug("L1GTDigiToRaw") << "\nPacking FDL \n" << std::endl;
    }

    int uLength = L1GlobalTriggerReadoutSetup::UnitLength;

    // initialize the required number of word64
    int nrWord64 = fdlBlock.getSize() / uLength;
    std::vector<cms_uint64_t> tmpWord64;
    tmpWord64.resize(nrWord64);

    for (int iWord = 0; iWord < nrWord64; ++iWord) {
        tmpWord64[iWord] = 0x0000000000000000ULL;
    }

    // fill the values in the words
    for (int iWord = 0; iWord < nrWord64; ++iWord) {

        fdlBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
        fdlBlock.setBxInEventWord64(tmpWord64[iWord], iWord);
        fdlBlock.setBxNrWord64(tmpWord64[iWord], iWord);
        fdlBlock.setEventNrWord64(tmpWord64[iWord], iWord);

        fdlBlock.setGtTechnicalTriggerWordWord64(tmpWord64[iWord], iWord);

        fdlBlock.setGtDecisionWordAWord64(tmpWord64[iWord], iWord);
        fdlBlock.setGtDecisionWordBWord64(tmpWord64[iWord], iWord);

        fdlBlock.setGtDecisionWordExtendedWord64(tmpWord64[iWord], iWord);

        fdlBlock.setPhysicsDeclaredWord64(tmpWord64[iWord], iWord);
        fdlBlock.setGtPrescaleFactorIndexTechWord64(tmpWord64[iWord], iWord);
        fdlBlock.setGtPrescaleFactorIndexAlgoWord64(tmpWord64[iWord], iWord);
        fdlBlock.setNoAlgoWord64(tmpWord64[iWord], iWord);
        fdlBlock.setFinalORWord64(tmpWord64[iWord], iWord);

        fdlBlock.setOrbitNrWord64(tmpWord64[iWord], iWord);
        fdlBlock.setLumiSegmentNrWord64(tmpWord64[iWord], iWord);
        fdlBlock.setLocalBxNrWord64(tmpWord64[iWord], iWord);

    }

    // put the words in the FED record

    cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*> (const_cast<unsigned char*> (ptrGt));

    for (int iWord = 0; iWord < nrWord64; ++iWord) {

        *pw++ = tmpWord64[iWord];

        if (m_verbosity && m_isDebugEnabled) {

            LogTrace("L1GTDigiToRaw")
                    << std::setw(4) << iWord << "  "
                    << std::hex << std::setfill('0') << std::setw(16) << tmpWord64[iWord] << std::dec
                    << std::setfill(' ')
                    << std::endl;
        }
    }

}
unsigned L1GTDigiToRaw::packGMT ( L1MuGMTReadoutRecord const &  gmtrr,
unsigned char *  chp 
) [private]

pack a GMT record

Definition at line 757 of file L1GTDigiToRaw.cc.

References L1MuGMTReadoutRecord::getBCERR(), L1MuGMTReadoutRecord::getBrlRPCCands(), L1MuGMTReadoutRecord::getBxInEvent(), L1MuGMTReadoutRecord::getBxNr(), L1MuGMTReadoutRecord::getCSCCands(), L1MuGMTReadoutRecord::getDTBXCands(), L1MuGMTReadoutRecord::getEvNr(), L1MuGMTReadoutRecord::getFwdRPCCands(), L1MuGMTReadoutRecord::getGMTBrlCands(), L1MuGMTReadoutRecord::getGMTCands(), L1MuGMTReadoutRecord::getGMTFwdCands(), i, AlCaHLTBitMon_ParallelJobs::p, createTree::pp, and w().

Referenced by packGmtCollection().

{

    const unsigned SIZE=136;
    const unsigned boardId=0xdd12;
    memset(chp,0,SIZE);

    unsigned* p = (unsigned*) chp;

    // event number + bcerr
    *p++ = (gmtrr.getEvNr()&0xffffff) | ((gmtrr.getBCERR()&0xff)<<24);
    // bx number, bx in event, length(?), board-id(?)
    *p++ = (gmtrr.getBxNr()&0xfff) | ((gmtrr.getBxInEvent()&0xf)<<12) | (boardId<<16);

    std::vector<L1MuRegionalCand> vrc;
    std::vector<L1MuRegionalCand>::const_iterator irc;
    unsigned* pp = p;

    vrc = gmtrr.getDTBXCands();
    pp = p;
    for(irc=vrc.begin(); irc!=vrc.end(); irc++) {
        *pp++ = (*irc).getDataWord();
    }
    p+=4;

    vrc = gmtrr.getBrlRPCCands();
    pp = p;
    for(irc=vrc.begin(); irc!=vrc.end(); irc++) {
        *pp++ = (*irc).getDataWord();
    }
    p+=4;

    vrc = gmtrr.getCSCCands();
    pp = p;
    for(irc=vrc.begin(); irc!=vrc.end(); irc++) {
        *pp++ = (*irc).getDataWord();
    }
    p+=4;

    vrc = gmtrr.getFwdRPCCands();
    pp = p;
    for(irc=vrc.begin(); irc!=vrc.end(); irc++) {
        *pp++ = (*irc).getDataWord();
    }
    p+=4;

    // the regional candidates are written to the record with inverted Pt and qual bits
    pp = p-16;
    for(int i=0; i<16; i++) {
        unsigned w = *pp;
        *pp++ = (w&0xffff00ff) | ((~w)&0x0000ff00);
    }

    std::vector<L1MuGMTExtendedCand> vgc;
    std::vector<L1MuGMTExtendedCand>::const_iterator igc;

    vgc = gmtrr.getGMTBrlCands();
    pp = p;
    for(igc=vgc.begin(); igc!=vgc.end(); igc++) {
        *pp++ = (*igc).getDataWord();
    }
    p+=4;

    vgc = gmtrr.getGMTFwdCands();
    pp = p;
    for(igc=vgc.begin(); igc!=vgc.end(); igc++) {
        *pp++ = (*igc).getDataWord();
    }
    p+=4;

    vgc = gmtrr.getGMTCands();
    pp = p;
    for(igc=vgc.begin(); igc!=vgc.end(); igc++) {
        *pp++ = (*igc).getDataWord();
    }
    p+=4;

    unsigned char* chpp;

    vgc = gmtrr.getGMTBrlCands();
    chpp = (unsigned char*) p;
    for(igc=vgc.begin(); igc!=vgc.end(); igc++) {
        *chpp++ = (*igc).rank();
    }
    p++;

    vgc = gmtrr.getGMTFwdCands();
    chpp = (unsigned char*) p;
    for(igc=vgc.begin(); igc!=vgc.end(); igc++) {
        *chpp++ = (*igc).rank();
    }
    p++;

    return SIZE;
}
unsigned int L1GTDigiToRaw::packGmtCollection ( unsigned char *  ptrGt,
L1MuGMTReadoutCollection const *  digis 
) [private]

pack the GMT collection using packGMT (GMT record packing)

Definition at line 733 of file L1GTDigiToRaw.cc.

References L1MuGMTReadoutCollection::getRecord(), LogDebug, m_isDebugEnabled, m_maxBxInEvent, m_minBxInEvent, m_totalBxInEvent, m_verbosity, and packGMT().

Referenced by produce().

{

    if (m_verbosity && m_isDebugEnabled) {
        LogDebug("L1GTDigiToRaw") << "\nPacking GMT collection \n" << std::endl;
    }

    unsigned gmtsize = 0;

    // loop range: int m_totalBxInEvent is normally even (L1A-1, L1A, L1A+1, with L1A = 0)
    for (int iBxInEvent = m_minBxInEvent; iBxInEvent <= m_maxBxInEvent;
            ++iBxInEvent) {
        L1MuGMTReadoutRecord const& gmtrr = digis->getRecord(iBxInEvent);
        gmtsize = packGMT(gmtrr, ptrGt);
        ptrGt += gmtsize;
    }

    return m_totalBxInEvent*gmtsize;

}
void L1GTDigiToRaw::packGTFE ( const edm::EventSetup evSetup,
unsigned char *  ptrGt,
L1GtfeWord gtfeBlock,
cms_uint16_t  activeBoardsGtValue 
) [private]

pack the GTFE block gives the number of bunch crosses in the event, as well as the active boards records for inactive boards are not written in the GT DAQ record

Definition at line 558 of file L1GTDigiToRaw.cc.

References L1GtfeWord::getSize(), LogDebug, LogTrace, m_isDebugEnabled, m_verbosity, L1GtfeWord::setActiveBoardsWord64(), L1GtfeWord::setAltNrBxBoardWord64(), L1GtfeWord::setBoardIdWord64(), L1GtfeWord::setBxNrWord64(), L1GtfeWord::setRecordLength1Word64(), L1GtfeWord::setRecordLengthWord64(), L1GtfeWord::setSetupVersionWord64(), L1GtfeWord::setTotalTriggerNrWord64(), and L1GlobalTriggerReadoutSetup::UnitLength.

Referenced by produce().

                                          {

    if (m_verbosity && m_isDebugEnabled) {
        LogDebug("L1GTDigiToRaw") << "\nPacking GTFE \n" << std::endl;
    }

    int uLength = L1GlobalTriggerReadoutSetup::UnitLength;

    // initialize the required number of word64
    int nrWord64 = gtfeBlock.getSize() / uLength;
    std::vector<cms_uint64_t> tmpWord64;
    tmpWord64.resize(nrWord64);

    for (int iWord = 0; iWord < nrWord64; ++iWord) {
        tmpWord64[iWord] = 0x0000000000000000ULL;
    }

    // fill the values in the words
    for (int iWord = 0; iWord < nrWord64; ++iWord) {

        gtfeBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
        gtfeBlock.setRecordLength1Word64(tmpWord64[iWord], iWord);
        gtfeBlock.setRecordLengthWord64(tmpWord64[iWord], iWord);
        gtfeBlock.setBxNrWord64(tmpWord64[iWord], iWord);
        gtfeBlock.setSetupVersionWord64(tmpWord64[iWord], iWord);
        gtfeBlock.setActiveBoardsWord64(tmpWord64[iWord], iWord, activeBoardsGtValue);
        gtfeBlock.setAltNrBxBoardWord64(tmpWord64[iWord], iWord);
        gtfeBlock.setTotalTriggerNrWord64(tmpWord64[iWord], iWord);

    }

    // put the words in the FED record

    cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*> (const_cast<unsigned char*> (ptrGt));

    for (int iWord = 0; iWord < nrWord64; ++iWord) {

        *pw++ = tmpWord64[iWord];

        if (m_verbosity && m_isDebugEnabled) {
            LogTrace("L1GTDigiToRaw")
                    << std::setw(4) << iWord << "  "
                    << std::hex << std::setfill('0') << std::setw(16) << tmpWord64[iWord] << std::dec
                    << std::setfill(' ')
                    << std::endl;
        }
    }

}
void L1GTDigiToRaw::packHeader ( unsigned char *  ptrGt,
edm::Event iEvent 
) [private]

block packers -------------

pack header

Definition at line 516 of file L1GTDigiToRaw.cc.

References edm::EventBase::bunchCrossing(), edm::EventID::event(), edm::EventBase::id(), LogDebug, m_daqGtFedId, m_isDebugEnabled, m_verbosity, and FEDHeader::set().

Referenced by produce().

                                                                     {
    // TODO FIXME where from to get all numbers?

    // Event Trigger type identifier
    int triggerTypeVal = 0;

    // Level-1 event number generated by the TTC system
    int lvl1IdVal = iEvent.id().event();

    // The bunch crossing number
    int bxCross = iEvent.bunchCrossing();
    cms_uint16_t bxCrossHw = 0;
    if ( ( bxCross & 0xFFF ) == bxCross) {
        bxCrossHw = static_cast<cms_uint16_t> (bxCross);
    } else {
        bxCrossHw = 0; // Bx number too large, set to 0!
        if (m_verbosity && m_isDebugEnabled) {
            LogDebug("L1GTDigiToRaw") << "\nBunch cross number [hex] = " << std::hex << bxCross
                    << "\n  larger than 12 bits. Set to 0! \n" << std::dec << std::endl;
        }
    }
    int bxIdVal = bxCrossHw;

    // Identifier of the FED
    int sourceIdVal = m_daqGtFedId;

    // Version identifier of the FED data format
    int versionVal = 0;

    // 0 -> the current header word is the last one.
    // 1-> other header words can follow
    // (always 1 for ECAL)
    bool moreHeadersVal = false;

    FEDHeader gtFEDHeader(ptrGt);

    gtFEDHeader.set(
            ptrGt, triggerTypeVal, lvl1IdVal, bxIdVal, sourceIdVal, versionVal, moreHeadersVal);

}
void L1GTDigiToRaw::packPSB ( const edm::EventSetup evSetup,
unsigned char *  ptrGt,
L1GtPsbWord psbBlock 
) [private]

pack PSB blocks packing is done in PSB class format

Definition at line 679 of file L1GTDigiToRaw.cc.

References L1GtPsbWord::getSize(), LogDebug, LogTrace, m_isDebugEnabled, m_verbosity, L1GtPsbWord::setADataWord64(), L1GtPsbWord::setBDataWord64(), L1GtPsbWord::setBoardIdWord64(), L1GtPsbWord::setBxInEventWord64(), L1GtPsbWord::setBxNrWord64(), L1GtPsbWord::setEventNrWord64(), L1GtPsbWord::setLocalBxNrWord64(), and L1GlobalTriggerReadoutSetup::UnitLength.

Referenced by produce().

                                                                                   {
    if (m_verbosity && m_isDebugEnabled) {

        LogDebug("L1GTDigiToRaw") << "\nPacking PSB \n" << std::endl;
    }

    int uLength = L1GlobalTriggerReadoutSetup::UnitLength;

    // initialize the required number of word64
    int nrWord64 = psbBlock.getSize() / uLength;
    std::vector<cms_uint64_t> tmpWord64;
    tmpWord64.resize(nrWord64);

    for (int iWord = 0; iWord < nrWord64; ++iWord) {
        tmpWord64[iWord] = 0x0000000000000000ULL;
    }

    // fill the values in the words
    for (int iWord = 0; iWord < nrWord64; ++iWord) {

        psbBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
        psbBlock.setBxInEventWord64(tmpWord64[iWord], iWord);
        psbBlock.setBxNrWord64(tmpWord64[iWord], iWord);
        psbBlock.setEventNrWord64(tmpWord64[iWord], iWord);

        psbBlock.setADataWord64(tmpWord64[iWord], iWord);
        psbBlock.setBDataWord64(tmpWord64[iWord], iWord);

        psbBlock.setLocalBxNrWord64(tmpWord64[iWord], iWord);

    }

    // put the words in the FED record

    cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*> (const_cast<unsigned char*> (ptrGt));

    for (int iWord = 0; iWord < nrWord64; ++iWord) {

        *pw++ = tmpWord64[iWord];

        if (m_verbosity && m_isDebugEnabled) {

            LogTrace("L1GTDigiToRaw")
                    << std::setw(4) << iWord << "  "
                    << std::hex << std::setfill('0') << std::setw(16) << tmpWord64[iWord] << std::dec
                    << std::setfill(' ')
                    << std::endl;
        }
    }

}
void L1GTDigiToRaw::packTrailer ( unsigned char *  ptrGt,
unsigned char *  ptrGtBegin,
int  dataSize 
) [private]

pack trailer word

Definition at line 859 of file L1GTDigiToRaw.cc.

References evf::compute_crc(), and FEDTrailer::set().

Referenced by produce().

                                                                                             {

    // TODO FIXME where from to get all numbers?

    // The length of the event fragment counted in 64-bit words including header and trailer
    int lengthVal = dataSize / 8;

    // Cyclic Redundancy Code of the event fragment including header and trailer
    int crcVal = evf::compute_crc(ptrGtBegin, dataSize);

    // Event fragment status information
    int evtStatusVal = 0;

    // Current value of the Trigger Throttling System bits.
    int ttsBitsVal = 0;

    // 0 -> the current trailer word is the last one.
    // 1-> other trailer words can follow
    // (always 0 for ECAL)
    bool moreTrailersVal = false;

    FEDTrailer gtFEDTrailer(ptrGt);
    gtFEDTrailer.set(ptrGt, lengthVal, crcVal, evtStatusVal, ttsBitsVal, moreTrailersVal);

}
void L1GTDigiToRaw::produce ( edm::Event iEvent,
const edm::EventSetup evSetup 
) [private, virtual]

loop over events

Implements edm::EDProducer.

Definition at line 113 of file L1GTDigiToRaw.cc.

References L1GtfeWord::activeBoards(), L1GtfeWord::altNrBxBoard(), FEDRawData::data(), FDL, edm::EventSetup::get(), edm::Event::getByLabel(), L1GtPsbWord::getSize(), L1TcsWord::getSize(), L1GtfeWord::getSize(), L1GtFdlWord::getSize(), GMT, GTFE, edm::HandleBase::isValid(), LogDebug, LogTrace, m_activeBoardsMaskGt, m_daqGtFedId, m_daqGtInputTag, m_isDebugEnabled, m_maxBxInEvent, m_minBxInEvent, m_muGmtInputTag, m_totalBxInEvent, m_verbosity, packFDL(), packGmtCollection(), packGTFE(), packHeader(), packPSB(), packTrailer(), L1GtFdlWord::print(), L1GtfeWord::print(), L1GtPsbWord::print(), edm::Handle< T >::product(), PSB, edm::Event::put(), L1GtfeWord::recordLength(), L1GtfeWord::recordLength1(), FEDRawData::resize(), FEDRawData::size(), TCS, and TIM.

{

    // define new FEDRawDataCollection
    // it contains ALL FEDs in an event
    std::auto_ptr<FEDRawDataCollection> allFedRawData(new FEDRawDataCollection);

    FEDRawData& gtRawData = allFedRawData->FEDData(m_daqGtFedId);

    // get records from EventSetup

    //  board maps
    edm::ESHandle< L1GtBoardMaps > l1GtBM;
    evSetup.get< L1GtBoardMapsRcd >().get( l1GtBM );

    const std::vector<L1GtBoard> boardMaps = l1GtBM->gtBoardMaps();
    int boardMapsSize = boardMaps.size();

    typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;

    // create an ordered vector for the GT DAQ record
    // header (pos 0 in record) and trailer (last position in record)
    // not included, as they are not in board list
    std::vector<L1GtBoard> gtRecordMap;
    gtRecordMap.reserve(boardMapsSize);

    for (int iPos = 0; iPos < boardMapsSize; ++iPos) {
        for (CItBoardMaps itBoard = boardMaps.begin(); itBoard
                != boardMaps.end(); ++itBoard) {

            if (itBoard->gtPositionDaqRecord() == iPos) {
                gtRecordMap.push_back(*itBoard);
                break;
            }

        }
    }


    // get L1GlobalTriggerReadoutRecord
    edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecord;
    iEvent.getByLabel(m_daqGtInputTag, gtReadoutRecord);

    if (!gtReadoutRecord.isValid()) {
        if (m_verbosity) {
            edm::LogWarning("L1GTDigiToRaw")
                    << "\nWarning: L1GlobalTriggerReadoutRecord with input tag " << m_daqGtInputTag
                    << "\nrequested in configuration, but not found in the event."
                    << "\nQuit packing this event" << std::endl;
        }

        // put the raw data in the event
        iEvent.put(allFedRawData);

        return;
    }

    if (m_verbosity && m_isDebugEnabled) {
        std::ostringstream myCoutStream;
        gtReadoutRecord->print(myCoutStream);
        LogTrace("L1GTDigiToRaw")
                << "\n The following L1 GT DAQ readout record will be packed.\n"
                << " Some boards could be disabled before packing,"
                << " see detailed board packing.\n" << myCoutStream.str() << "\n"
                << std::endl;
    }

    // get GTFE block
    L1GtfeWord gtfeBlock = gtReadoutRecord->gtfeWord();

    // get the number of Bx in the event for alternative 0 and alternative 1
    cms_uint16_t recordLength0 = gtfeBlock.recordLength();
    cms_uint16_t recordLength1 = gtfeBlock.recordLength1();


    // get list of active boards from the GTFE payload
    // and mask some boards, if required
    // boards not active are not written to the record

    cms_uint16_t activeBoardsGtInitial = gtfeBlock.activeBoards();
    cms_uint16_t altNrBxBoardInitial = gtfeBlock.altNrBxBoard();

    // mask some boards, if needed

    cms_uint16_t activeBoardsGt = activeBoardsGtInitial & m_activeBoardsMaskGt;

    if (m_verbosity && m_isDebugEnabled) {
        LogDebug("L1GTDigiToRaw")
                << "\nActive boards before masking(hex format): " << std::hex
                << std::setw(sizeof ( activeBoardsGtInitial ) * 2) << std::setfill('0')
                << activeBoardsGtInitial << std::dec << std::setfill(' ')
                << "Active boards after masking(hex format):  " << std::hex
                << std::setw(sizeof ( activeBoardsGt ) * 2) << std::setfill('0') << activeBoardsGt
                << std::dec << std::setfill(' ') << " \n"
                << std::endl;
    }

    // get the size of the record

    unsigned int gtDataSize = 0;

    unsigned int headerSize = 8;
    gtDataSize += headerSize;

    for (CItBoardMaps
            itBoard = boardMaps.begin();
            itBoard != boardMaps.end(); ++itBoard) {

        if (itBoard->gtBoardType() == GTFE) {
            gtDataSize += gtfeBlock.getSize();
            continue;
        }


        int iActiveBit = itBoard->gtBitDaqActiveBoards();
        bool activeBoardToPack = false;

        int altNrBxBoardVal = -1;

        if (iActiveBit >= 0) {
            activeBoardToPack = activeBoardsGt & (1 << iActiveBit);

            altNrBxBoardVal = (altNrBxBoardInitial & ( 1 << iActiveBit )) >> iActiveBit;

            if (altNrBxBoardVal == 1) {
                m_totalBxInEvent = recordLength1;
            } else if (altNrBxBoardVal == 0) {
                m_totalBxInEvent = recordLength0;
            } else {
                if (m_verbosity) {
                    edm::LogWarning("L1GTDigiToRaw")
                    << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal
                    << " for board " << std::hex << ( itBoard->gtBoardId() ) << std::dec
                    << "\n  iActiveBit =            " << iActiveBit
                    << "\n  altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<  std::dec
                    << "\n  activeBoardsGt =      0x" << std::hex << activeBoardsGt <<  std::dec
                    << "\n  activeBoardToPack =   " << activeBoardToPack
                    << "\n Set altNrBxBoardVal tentatively to "
                    << recordLength0 << "\n Job may crash or produce wrong results!\n\n"
                    << std::endl;
                }

                m_totalBxInEvent = recordLength0;
            }


        } else {
            // board not in the ActiveBoards for the record
            continue;
        }

        if (activeBoardToPack) {

            switch (itBoard->gtBoardType()) {
                case GTFE: {
                        // size already added;
                    }

                    break;
                case FDL: {
                        L1GtFdlWord fdlBlock;
                        gtDataSize += m_totalBxInEvent*fdlBlock.getSize();
                    }

                    break;
                case PSB: {
                        L1GtPsbWord psbBlock;
                        gtDataSize += m_totalBxInEvent*psbBlock.getSize();
                    }

                    break;
                case GMT: {
                        // 17*64/8 TODO FIXME ask Ivan for a getSize() function for GMT record
                        unsigned int gmtRecordSize = 136;
                        unsigned int gmtCollSize = m_totalBxInEvent*gmtRecordSize;
                        gtDataSize += gmtCollSize;
                    }

                    break;
                case TCS: {
                        L1TcsWord tcsBlock;
                        gtDataSize += tcsBlock.getSize();
                    }

                    break;
                case TIM: {
                        // not considered
                    }

                    break;
                default: {
                        // do nothing, all blocks are given in GtBoardType enum
                    }

                    break;
            }
        }

    }


    unsigned int trailerSize = 8;
    gtDataSize += trailerSize;


    // resize, GT raw data record has variable length,
    // depending on active boards (read in GTFE)
    gtRawData.resize(gtDataSize);


    // ptrGt: pointer to the beginning of GT record in the raw data

    unsigned char* ptrGt = gtRawData.data();
    unsigned char* ptrGtBegin = gtRawData.data();

    if (m_verbosity && m_isDebugEnabled) {
        LogDebug("L1GTDigiToRaw") << "\n Size of raw data: " << gtRawData.size() << "\n"
                << std::endl;
    }

    // ------- pack boards -------

    // pack header
    packHeader(ptrGt, iEvent);
    ptrGt += headerSize; // advance with header size

    // loop over other blocks in the raw record, if they are active

    for (CItBoardMaps
            itBoard = gtRecordMap.begin();
            itBoard != gtRecordMap.end(); ++itBoard) {

        if (itBoard->gtBoardType() == GTFE) {

            packGTFE(evSetup, ptrGt, gtfeBlock, activeBoardsGt);

            if (m_verbosity && m_isDebugEnabled) {

                std::ostringstream myCoutStream;
                gtfeBlock.print(myCoutStream);
                LogTrace("L1GTDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
            }

            ptrGt += gtfeBlock.getSize(); // advance with GTFE block size

            continue;
        }


        // pack modules other than GTFE if they are active

        int iActiveBit = itBoard->gtBitDaqActiveBoards();
        bool activeBoardToPack = false;

        int altNrBxBoardVal = -1;

        if (iActiveBit >= 0) {
            activeBoardToPack = activeBoardsGt & (1 << iActiveBit);

            altNrBxBoardVal = (altNrBxBoardInitial & ( 1 << iActiveBit )) >> iActiveBit;

            if (altNrBxBoardVal == 1) {
                m_totalBxInEvent = recordLength1;
            } else if (altNrBxBoardVal == 0) {
                m_totalBxInEvent = recordLength0;
            } else {
                if (m_verbosity) {
                    edm::LogWarning("L1GTDigiToRaw")
                    << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal
                    << " for board " << std::hex << ( itBoard->gtBoardId() ) << std::dec
                    << "\n  iActiveBit =            " << iActiveBit
                    << "\n  altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial <<  std::dec
                    << "\n  activeBoardsGt =      0x" << std::hex << activeBoardsGt <<  std::dec
                    << "\n  activeBoardToPack =   " << activeBoardToPack
                    << "\n Set altNrBxBoardVal tentatively to "
                    << recordLength0 << "\n Job may crash or produce wrong results!\n\n"
                    << std::endl;
                }

                m_totalBxInEvent = recordLength0;
            }

            m_minBxInEvent = (m_totalBxInEvent + 1)/2 - m_totalBxInEvent;
            m_maxBxInEvent = (m_totalBxInEvent + 1)/2 - 1;


        } else {
            // board not in the ActiveBoards for the record
            continue;
        }

        if (activeBoardToPack) {

            if (m_verbosity && m_isDebugEnabled) {
                LogDebug("L1GTDigiToRaw")
                        << "\nBoard " << std::hex << "0x" << ( itBoard->gtBoardId() ) << std::dec
                        << "\n  Number of bunch crosses in the record: " << m_totalBxInEvent
                        << " = " << "[" << m_minBxInEvent << ", " << m_maxBxInEvent
                        << "] BX\n"
                        << std::endl;
            }

            // active board, pack it
            switch (itBoard->gtBoardType()) {

                case FDL: {

                    for (int iBxInEvent = m_minBxInEvent; iBxInEvent <= m_maxBxInEvent; ++iBxInEvent) {

                        L1GtFdlWord fdlBlock = gtReadoutRecord->gtFdlWord(iBxInEvent);
                        packFDL(evSetup, ptrGt, fdlBlock);

                        if (m_verbosity && m_isDebugEnabled) {

                            std::ostringstream myCoutStream;
                            fdlBlock.print(myCoutStream);
                            LogTrace("L1GTDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
                        }

                        ptrGt += fdlBlock.getSize(); // advance with FDL block size
                    }

                }
                    break;
                case PSB: {

                    if (m_verbosity && m_isDebugEnabled) {
                        LogDebug("L1GTDigiToRaw") << "\nBoard of type " << itBoard->gtBoardName()
                                << " with index " << itBoard->gtBoardIndex() << " and boardId "
                                << std::hex << itBoard->gtBoardId() << std::dec << "\n"
                                << std::endl;
                    }

                    for (int iBxInEvent = m_minBxInEvent; iBxInEvent <= m_maxBxInEvent; ++iBxInEvent) {

                        L1GtPsbWord psbBlock = gtReadoutRecord->gtPsbWord(
                                itBoard->gtBoardId(), iBxInEvent);

                        packPSB(evSetup, ptrGt, psbBlock);

                        if (m_verbosity && m_isDebugEnabled) {

                            std::ostringstream myCoutStream;
                            psbBlock.print(myCoutStream);
                            LogTrace("L1GTDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
                        }

                        ptrGt += psbBlock.getSize(); // advance with PSB block size
                    }

                }
                    break;
                case GMT: {

                    // get GMT record TODO separate GMT record or via RefProd from GT record
                    edm::Handle<L1MuGMTReadoutCollection> gmtrc_handle;
                    iEvent.getByLabel(m_muGmtInputTag, gmtrc_handle);
                    if (!gmtrc_handle.isValid()) {
                        if (m_verbosity) {
                            edm::LogWarning("L1GTDigiToRaw")
                                    << "\nWarning: L1MuGMTReadoutCollection with input tag "
                                    << m_muGmtInputTag
                                    << "\nrequested in configuration, but not found in the event."
                                    << "\nQuit packing this event" << std::endl;
                        }

                        std::auto_ptr<FEDRawDataCollection> allFedRawData(new FEDRawDataCollection);

                        // put the raw data in the event
                        iEvent.put(allFedRawData);

                        return;
                    }

                    L1MuGMTReadoutCollection const* gmtrc = gmtrc_handle.product();

                    // pack the GMT record

                    unsigned int gmtCollSize = 0;
                    gmtCollSize = packGmtCollection(ptrGt, gmtrc);
                    ptrGt += gmtCollSize; // advance with GMT collection size

                }
                    break;
                default: {

                    // do nothing, all blocks are given in GtBoardType enum
                    break;
                }
            }

        }
    }

    // pack trailer
    packTrailer(ptrGt, ptrGtBegin, gtDataSize);

    // put the raw data in the event
    iEvent.put(allFedRawData);
}

Member Data Documentation

mask for active boards

Definition at line 110 of file L1GTDigiToRaw.h.

Referenced by L1GTDigiToRaw(), and produce().

FED Id for GT DAQ record default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc

Definition at line 101 of file L1GTDigiToRaw.h.

Referenced by L1GTDigiToRaw(), packHeader(), and produce().

input tag for GT DAQ record

Definition at line 104 of file L1GTDigiToRaw.h.

Referenced by L1GTDigiToRaw(), and produce().

max Bx's in the event, computed after m_totalBxInEvent is obtained from GTFE block assume symmetrical number of BX around L1Accept

Definition at line 121 of file L1GTDigiToRaw.h.

Referenced by packGmtCollection(), and produce().

min Bx's in the event, computed after m_totalBxInEvent is obtained from GTFE block assume symmetrical number of BX around L1Accept

Definition at line 117 of file L1GTDigiToRaw.h.

Referenced by packGmtCollection(), and produce().

input tag for GMT record

Definition at line 107 of file L1GTDigiToRaw.h.

Referenced by L1GTDigiToRaw(), and produce().

total Bx's in the event, obtained from GTFE block

Definition at line 113 of file L1GTDigiToRaw.h.

Referenced by packGmtCollection(), and produce().

verbosity level

Definition at line 126 of file L1GTDigiToRaw.h.

Referenced by L1GTDigiToRaw(), packFDL(), packGmtCollection(), packGTFE(), packHeader(), packPSB(), and produce().