/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Private Member Functions | Private Attributes
DybDaq::PackedRpcEvent Class Reference

#include <PackedRpcEvent.h>

List of all members.

Public Member Functions

 PackedRpcEvent (bool farSite)
virtual ~PackedRpcEvent ()
void initHeader (const uint32_t *header)
int rtmNeeded ()
int fecNeeded ()
int addRtmData (const uint32_t *rtmData)
int addFecData (const uint32_t *fecData, int iRtm, const bool forced)
int tryPreFecData (const uint32_t *fecData, int iRtm)
char * recordData ()
int recordSize ()
void pack ()
void reset ()
void makeFecList ()
void setNextFec ()
void setNextRtm ()
bool accumulationValid ()
void updateAccumulation (const uint32_t *rtm)

Private Member Functions

int rtmTimeDiff (const uint32_t *frag)
int fecTimeDiff (const uint32_t *frag, int iRtm)
int telescopeRtm (const uint32_t *frag)
int telescopeFec (const uint32_t *frag)
int rtmPositionStat (const uint32_t *frag)
 PackedRpcEvent ()

Private Attributes

uint32_t * m_record
uint32_t * m_rtm
uint32_t * m_fec
int m_recordSize
int m_nRtm
int m_nFec
int m_rtmNeeded
std::vector< int > m_fecList
std::vector< int >::iterator m_fecNeeded
int m_sequnceNo
int m_maxRtmCF
int m_dtFecRtm
bool m_accumulationValid
std::list< std::pair< uint32_t,
int > > * 
m_vAccumulation

Detailed Description

Definition at line 12 of file PackedRpcEvent.h.


Constructor & Destructor Documentation

PackedRpcEvent::PackedRpcEvent ( bool  farSite)

Definition at line 12 of file PackedRpcEvent.cc.

    : m_record(new uint32_t[512]),
      m_sequnceNo(0),
      m_dtFecRtm(0)
{
    m_maxRtmCF   = farSite ? 3 : 2;

    m_rtm        = m_record + 15;
    m_vAccumulation = new std::list<std::pair<uint32_t, int> >[m_maxRtmCF];

    reset();

    // data seperator record
    m_record[0] = 0x1234cccc;   //marker
    m_record[1] = 4;            //size
    m_record[2] = 0;            // * sequence number
    m_record[3] = 0;            // * event size byte
    // event header
    m_record[4]  = 0xaa1234aa;  //marker
    m_record[5]  = 0x00070000;  //version
    m_record[6]  = 0;           // * size(header/total)
    m_record[7]  = 0;           // ! source identifier
    m_record[8]  = 0;           // ! run number
    m_record[9]  = 0;           // * event number
    m_record[10] = 0;           // ! detector data type
    m_record[11] = 0;           //data status
    // RTM rom
    m_record[12] = 0xbb1234bb;  //marker
    m_record[13] = 0;           // * size(headers/total)
    m_record[14] = 0x00170500;  // ! module identifier

#ifdef RPC_ERROR_DEBUG
    m_debug = RPC_ERROR_DEBUG;
#endif
}
PackedRpcEvent::~PackedRpcEvent ( ) [virtual]

Definition at line 48 of file PackedRpcEvent.cc.

{
    delete [] m_record;
    delete [] m_vAccumulation;
}
DybDaq::PackedRpcEvent::PackedRpcEvent ( ) [private]

Member Function Documentation

void PackedRpcEvent::initHeader ( const uint32_t *  header)

Definition at line 54 of file PackedRpcEvent.cc.

{
    if ( m_record[7] == 0 ) {
        m_record[7]  = header[3];   // ! source identifier
        m_record[8]  = header[4];   // ! run number
        m_record[10] = header[6];   // ! detector data type
    }
}
int PackedRpcEvent::rtmNeeded ( )

Definition at line 63 of file PackedRpcEvent.cc.

{
    if ( m_rtmNeeded < m_maxRtmCF ) {
        return m_rtmNeeded;
    }
    return -1;
}
int PackedRpcEvent::fecNeeded ( )

Definition at line 71 of file PackedRpcEvent.cc.

{
    if ( m_fecNeeded != m_fecList.end() ) {
        return *m_fecNeeded;
    }
    return -1;
}
int PackedRpcEvent::addRtmData ( const uint32_t *  rtmData)

Definition at line 79 of file PackedRpcEvent.cc.

{
    using DybDaq::RawRecordPoolUtil::MAX_EVENT_TIME_GAP;
    using DybDaq::RawRecordPoolUtil::MAX_TELE_ARRAY_HGAP;
    using DybDaq::RawRecordPoolUtil::MAX_TELE_ARRAY_LGAP;

    int _upperLimit = MAX_EVENT_TIME_GAP;
    int _lowerLimit = -MAX_EVENT_TIME_GAP;

    int _posStat = rtmPositionStat(rtmData);
    if ( _posStat != 0 ) {
        if ( _posStat > 0 ) {
            _upperLimit = MAX_TELE_ARRAY_HGAP;
            _lowerLimit = -MAX_TELE_ARRAY_LGAP;
        }
        else {
            _upperLimit = MAX_TELE_ARRAY_LGAP;
            _lowerLimit = -MAX_TELE_ARRAY_HGAP;
        }
    }

    int _nsDiff = rtmTimeDiff(rtmData);
    if ( _nsDiff > _upperLimit ) {
        ++m_rtmNeeded;
    }
    else if ( _nsDiff >= _lowerLimit ) {
        _nsDiff = 0;
        uint32_t* pRtm = m_rtm + m_nRtm*RTM_DATA_SIZE;
        memcpy(pRtm, rtmData, RTM_DATA_SIZE*sizeof(uint32_t));
        ++m_nRtm;
    }
    else {
#ifdef RPC_ERROR_DEBUG
        if ( m_debug > 0 ) {
        std::cout << "RPC repacking: " << m_debug << " debug message left" << std::endl;
        std::cout << "zdebug Missmatched RTM data 0x" << std::hex << rtmData[0] << std::dec << std::endl;
        --m_debug;
        }
#endif
    }
    return _nsDiff;
}
int PackedRpcEvent::addFecData ( const uint32_t *  fecData,
int  iRtm,
const bool  forced 
)

Definition at line 122 of file PackedRpcEvent.cc.

{
    using DybDaq::RawRecordPoolUtil::MAX_FEC_RTM_TIME_GAP;
    using DybDaq::RawRecordPoolUtil::EXT_FEC_RTM_TIME_GAP;

    int _nsDiff = fecTimeDiff(fecData, iRtm);
    if ( m_dtFecRtm == 0 ) m_dtFecRtm = _nsDiff;
    _nsDiff -= m_dtFecRtm;

    if ( m_accumulationValid || forced ) {
        int _d_time = m_accumulationValid ? MAX_FEC_RTM_TIME_GAP : EXT_FEC_RTM_TIME_GAP;
        if ( _nsDiff >= -_d_time ) {
            if ( _nsDiff <= _d_time ) {
                _nsDiff = 0;
                uint32_t* pFec = m_fec + m_nFec*FEC_DATA_SIZE;
                memcpy(pFec, fecData, FEC_DATA_SIZE*sizeof(uint32_t));
                ++m_nFec;
            }
            //else {
            //    tryPreFecData();
            //}
            ++m_fecNeeded;
        }
        else {
#ifdef RPC_ERROR_DEBUG
            if ( m_debug > 0 ) {
            std::cout << "RPC repacking: " << m_debug << " debug message left" << std::endl;
            std::cout << "zdebug Missmatched FEC data 0x" << std::hex << fecData[0] << std::dec << "  " << _nsDiff << std::endl;
            std::cout << "m_dtFecRtm: " << m_dtFecRtm << std::endl;
            for ( int iCF = 0; iCF < 2; ++iCF ) {
                std::list<std::pair<uint32_t, int> >::iterator it = m_vAccumulation[iCF].begin();
                for ( ; it != m_vAccumulation[iCF].end(); ++it ) {
                    std::cout << iCF << "CF accumulation: 0x" << std::hex << it->first
                              << " 0x" << it->second << std::dec << std::endl;
                }
            }
            for ( int i = 0; i < m_nRtm; ++i ) {
                DybDaq::RawRecordPoolUtil::record_dump(m_rtm+i*6, 6);
            }
            DybDaq::RawRecordPoolUtil::record_dump(fecData, 4);
            --m_debug;
            }
#endif
        }
    }
    return _nsDiff;
}
int PackedRpcEvent::tryPreFecData ( const uint32_t *  fecData,
int  iRtm 
)

Definition at line 170 of file PackedRpcEvent.cc.

{
    using DybDaq::RawRecordPoolUtil::MAX_FEC_RTM_TIME_GAP;
    using DybDaq::RawRecordPoolUtil::PRETIME_WHEN_OVERLAP;

    int _nsDiff = fecTimeDiff(fecData, iRtm) - m_dtFecRtm;
    if ( _nsDiff >= PRETIME_WHEN_OVERLAP && _nsDiff <= MAX_FEC_RTM_TIME_GAP ) {
        uint32_t* pFec = m_fec + m_nFec*FEC_DATA_SIZE;
        memcpy(pFec, fecData, FEC_DATA_SIZE*sizeof(uint32_t));
        ++m_nFec;
    }
//    else {
//#ifdef RPC_ERROR_DEBUG
//      if ( m_debug > 0 ) {
//        std::cout << "RPC repacking: " << m_debug << " debug message left" << std::endl;
//        std::cout << "zdebug Lost FEC data 0x" << std::hex << *(m_fecNeeded-1) << std::dec
//                << "   " << _nsDiff << "ns" << std::endl;
//      --m_debug;
//      }
//#endif
//      return -1;
//    }
    return 0;
}
char * PackedRpcEvent::recordData ( )

Definition at line 195 of file PackedRpcEvent.cc.

{
    return (char*)m_record;
}
int PackedRpcEvent::recordSize ( )

Definition at line 200 of file PackedRpcEvent.cc.

{
    return m_recordSize;
}
void PackedRpcEvent::pack ( )

Definition at line 205 of file PackedRpcEvent.cc.

{
    --m_sequnceNo;
    int m_eventSize = m_nRtm*RTM_DATA_SIZE + m_nFec*FEC_DATA_SIZE + 14;
    int m_eventByte = m_eventSize * sizeof(uint32_t);
    m_eventSize |= 0x08000000;
    m_recordSize = m_eventByte + 4*sizeof(uint32_t);
    int  m_rtmRomSize = 0x03000000 | (m_nRtm*RTM_DATA_SIZE+3);
    int  m_fecRomSize = 0x03000000 | (m_nFec*FEC_DATA_SIZE+3);
    // data seperator record
    m_record[2]  = m_sequnceNo;    //sequence number
    m_record[3]  = m_eventByte;    //event size byte
    // event header
    m_record[6]  = m_eventSize;    //size(header/total)
    m_record[9]  = m_sequnceNo;    //event number
    // RTM rom
    m_record[13] = m_rtmRomSize;   //size(headers/total)
    // FEC rom
    *(m_fec-3)  = 0xbb1234bb;      //marker
    *(m_fec-2)  = m_fecRomSize;    //size(header/total)
    *(m_fec-1)  = 0x00170400;      // ! module identifier

    //DybDaq::RawRecordPoolUtil::record_dump(m_record, (m_recordSize/4));
}
void PackedRpcEvent::reset ( )

Definition at line 232 of file PackedRpcEvent.cc.

{
    for ( int iCF = 0; iCF < m_maxRtmCF; ++iCF ) {
        while ( !m_vAccumulation[iCF].empty() && m_rtm[1]>m_vAccumulation[iCF].front().first ) {
            m_vAccumulation[iCF].pop_front();
        }
    }

    m_fec = m_rtm + 3;

    m_recordSize = 0;
    m_nRtm = 0;
    m_nFec = 0;

    m_rtmNeeded = 0;

    m_fecList.clear();
    m_fecNeeded = m_fecList.end();
}
void PackedRpcEvent::makeFecList ( )

Definition at line 252 of file PackedRpcEvent.cc.

{
    m_fec += m_nRtm*RTM_DATA_SIZE;

    for ( int i = 0; i < m_nRtm; ++i ) {
        //_FecCfId: b(0-3)FecId, b(4-7)CfId, b(8--)iRtm
        int _RtmCfId = ((*(m_rtm+i*RTM_DATA_SIZE))>>12) & 0xF;
        int _FecCfId = (i<<8) | (_RtmCfId<<5);  //FecCFId=RtmCfId*2
        int mask = 1;
        const uint32_t _triggerMap = *(m_rtm+i*RTM_DATA_SIZE+5);
        for ( int j = 0; j < 15; ++j,mask<<=1 ) { //first ROT
            if ( (_triggerMap&mask) != 0 ) {
                m_fecList.push_back( _FecCfId | j );
            }
        }
        _FecCfId |= 0x10;
        mask <<= 1;
        for ( int j = 0; j < 12; ++j,mask<<=1 ) { //second ROT
            if ( (_triggerMap&mask) != 0 ) {
                m_fecList.push_back( _FecCfId | j );
            }
        }
        if ( (_triggerMap&(mask<<2)) != 0 ) { //telescope
            m_fecList.push_back( _FecCfId | 14 );
        }
    }

    m_fecNeeded = m_fecList.begin();
}
void PackedRpcEvent::setNextFec ( )

Definition at line 282 of file PackedRpcEvent.cc.

{
    if ( m_fecNeeded != m_fecList.end() ) ++m_fecNeeded;
}
void PackedRpcEvent::setNextRtm ( )

Definition at line 287 of file PackedRpcEvent.cc.

bool PackedRpcEvent::accumulationValid ( )

Definition at line 292 of file PackedRpcEvent.cc.

{
    return m_accumulationValid;
}
void PackedRpcEvent::updateAccumulation ( const uint32_t *  rtm)

Definition at line 297 of file PackedRpcEvent.cc.

{
    int iCF    = ((*rtm)>> 12) & 0xF;
    uint32_t second = *(rtm+1);
    if ( m_vAccumulation[iCF].empty() || second > m_vAccumulation[iCF].back().first ) {
        m_vAccumulation[iCF].push_back(
                std::make_pair<uint32_t, int>(second, *((int*)rtm+3))
                );
    }
}
int PackedRpcEvent::rtmTimeDiff ( const uint32_t *  frag) [private]

Definition at line 308 of file PackedRpcEvent.cc.

{
    int result = 0;
    if ( m_nRtm != 0 ) {
        result = (int(frag[2])+int(frag[3])) - (int(m_rtm[2])+int(m_rtm[3]));
        int _sDiff = frag[1] - m_rtm[1];
        if ( _sDiff != 0 ) {
            if ( result*_sDiff > 0 || abs(_sDiff) > 1 ) {  //very large time diff
                result = (_sDiff > 0) ? 1000000000 : -1000000000;
            }
            else {  //_sDiff == +/- 1
                result += _sDiff*2000000000;
            }
        }
    }
    return result;
}
int PackedRpcEvent::fecTimeDiff ( const uint32_t *  frag,
int  iRtm 
) [private]

Definition at line 326 of file PackedRpcEvent.cc.

{
    using DybDaq::RawRecordPoolUtil::RTM_DATA_SIZE;

    m_accumulationValid = true;

    const uint32_t* rtm = m_rtm + iRtm*RTM_DATA_SIZE;
    int iCF = ((*rtm)>>12) & 0xF;  //RtmCfId

    int result  = int(frag[2]) - int(rtm[2]);
    int _sDiff  = frag[1] - rtm[1];
    if ( _sDiff != 0 ) {
        if ( result*_sDiff > 0 || _sDiff < 0 || _sDiff > 1 ) {  //very large time diff
            result = (_sDiff > 0) ? 1000000000 : -1000000000;
        }
        else {  // _sDiff == 1
            result += 2000000000 - int(rtm[3]);  //fix time with RTM accumulation
            std::list<std::pair<uint32_t, int> >::iterator it = m_vAccumulation[iCF].begin();
            for ( ; it != m_vAccumulation[iCF].end(); ++it ) {
                if ( it->first == frag[1] ) {
                    result += it->second;  //fix time with FEC accumulation
                    break;
                }
            }
            if ( it == m_vAccumulation[iCF].end() ) { //have to wait for the accumulation data
                m_accumulationValid = false;
            }
        }
    }
    return result;
}
int PackedRpcEvent::telescopeRtm ( const uint32_t *  frag) [private]

Definition at line 358 of file PackedRpcEvent.cc.

{
    return ((frag[4]&0x40000000) != 0) ? 1 : 0;
}
int PackedRpcEvent::telescopeFec ( const uint32_t *  frag) [private]

Definition at line 363 of file PackedRpcEvent.cc.

{
    // 1: an odd FecCfId with FecId is 14
    return ( ((*frag)&0x1F00) == 0x1E00 ) ? 1 : 0;  
}
int PackedRpcEvent::rtmPositionStat ( const uint32_t *  frag) [private]

Definition at line 369 of file PackedRpcEvent.cc.

{
    // -1:Array-Telescope  1:Telescope-Array  0:OtherStat
    if ( m_nRtm != 0 ) {
        return (telescopeRtm(m_rtm) - telescopeRtm(frag));
    }
    return 0;
}

Member Data Documentation

uint32_t* DybDaq::PackedRpcEvent::m_record [private]

Definition at line 56 of file PackedRpcEvent.h.

uint32_t* DybDaq::PackedRpcEvent::m_rtm [private]

Definition at line 57 of file PackedRpcEvent.h.

uint32_t* DybDaq::PackedRpcEvent::m_fec [private]

Definition at line 58 of file PackedRpcEvent.h.

Definition at line 60 of file PackedRpcEvent.h.

Definition at line 61 of file PackedRpcEvent.h.

Definition at line 62 of file PackedRpcEvent.h.

Definition at line 64 of file PackedRpcEvent.h.

std::vector<int> DybDaq::PackedRpcEvent::m_fecList [private]

Definition at line 66 of file PackedRpcEvent.h.

std::vector<int>::iterator DybDaq::PackedRpcEvent::m_fecNeeded [private]

Definition at line 67 of file PackedRpcEvent.h.

Definition at line 69 of file PackedRpcEvent.h.

Definition at line 70 of file PackedRpcEvent.h.

Definition at line 72 of file PackedRpcEvent.h.

Definition at line 74 of file PackedRpcEvent.h.

std::list<std::pair<uint32_t, int> >* DybDaq::PackedRpcEvent::m_vAccumulation [private]

Definition at line 75 of file PackedRpcEvent.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:52:46 for RawRecordPool by doxygen 1.7.4