/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 | Static Public Member Functions | Private Member Functions | Private Attributes
ROsFecReadoutTool Class Reference

#include <ROsFecReadoutTool.h>

Inheritance diagram for ROsFecReadoutTool:
Inheritance graph
[legend]
Collaboration diagram for ROsFecReadoutTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ROsFecReadoutTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~ROsFecReadoutTool ()
virtual StatusCode mutate (DayaBay::SimReadoutHeader *roHeader, std::vector< DayaBay::ReadoutTriggerDataPkg * > &trigDataPkg, const DayaBay::ElecHeader &elecHeader)
 Modify the event.
virtual StatusCode initialize ()
virtual StatusCode finalize ()

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Retrieve interface ID.

Private Member Functions

virtual StatusCode makeReadouts (DayaBay::SimReadoutHeader *roHeader, std::vector< DayaBay::ReadoutTriggerDataPkg * > &trigDataPkg, const DayaBay::ElecHeader &elecHeader)
DayaBay::ReadoutRpcCratereadoutCrate (const DayaBay::ReadoutRpcTriggerDataFrame *tdf, const DayaBay::ElecFecCrate *cr, Context context)
DayaBay::ReadoutFecBoardreadoutBoard (const DayaBay::ReadoutRpcTriggerDataFrame *tdf, const DayaBay::ElecFecBoard *brd, Context context)

Private Attributes

std::vector< std::string > m_detectorsToProcess
std::set< DayaBay::Detectorm_detectors
 Names of detectors to be processed by this tool.
std::map
< DayaBay::ElecChannelId,
TimeStamp
m_lastRead
 Detectors to be processed by this tool.
int m_refuseTime
 Map of trigger times to the board IDs. For Board muting.
int m_readoutWindow
 Time in clk cycles for which FEC will not accept readout query after issuing one.
int m_readoutWindowPosition
 So called readout window implemented in FEC. Number of clk cycles to OR the signal in each channel.

Detailed Description

Definition at line 34 of file ROsFecReadoutTool.h.


Constructor & Destructor Documentation

ROsFecReadoutTool::ROsFecReadoutTool ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 18 of file ROsFecReadoutTool.cc.

    : GaudiTool(type,name,parent)
{
  declareInterface< IROsReadoutTool >(this) ;
  // for now add all but RPC's as default.
  m_detectorsToProcess.push_back("DayaBayRPC");
  m_detectorsToProcess.push_back("LingAoRPC");
  m_detectorsToProcess.push_back("FarRPC");

  declareProperty("detectorsToProcess",m_detectorsToProcess,
                  "List of detectors to process with this tool");
  declareProperty("refuseTime",m_refuseTime = 8,
                  "Time in clk cycles for which FEC will refuse readout");
  declareProperty("readoutWindow",m_readoutWindow = 16,
                  "Number of clk cycles to OR the signal in each channel when reading out.");
  declareProperty("readoutWindowPosition",m_readoutWindowPosition = 8,
                  "Number of clk cycles to OR the signal in each channel when reading out.");
}
ROsFecReadoutTool::~ROsFecReadoutTool ( ) [virtual]

Definition at line 39 of file ROsFecReadoutTool.cc.

{}

Member Function Documentation

StatusCode ROsFecReadoutTool::mutate ( DayaBay::SimReadoutHeader roHeader,
std::vector< DayaBay::ReadoutTriggerDataPkg * > &  trigDataPkg,
const DayaBay::ElecHeader elecHeader 
) [virtual]

Modify the event.

Implements IROsReadoutTool.

Definition at line 151 of file ROsFecReadoutTool.cc.

{
    debug() << "mutate(): start mutating the ReadoutHeader" << endreq;
    StatusCode sc = makeReadouts(roHeader, trigDataPkg, elecHeader);
    if (sc.isFailure()) {
        return StatusCode::FAILURE;
    } else
        return StatusCode::SUCCESS;
}
StatusCode ROsFecReadoutTool::initialize ( ) [virtual]

Definition at line 41 of file ROsFecReadoutTool.cc.

{
    std::vector<std::string>::iterator it;
    for(it=m_detectorsToProcess.begin();it!=m_detectorsToProcess.end();++it){
        short int detId = DayaBay::Detector::siteDetPackedFromString(*it);
        DayaBay::Detector det(detId);
        m_detectors.insert(det);
    }

    return StatusCode::SUCCESS;
}
StatusCode ROsFecReadoutTool::finalize ( ) [virtual]

Definition at line 53 of file ROsFecReadoutTool.cc.

{
  return StatusCode::SUCCESS;
}
StatusCode ROsFecReadoutTool::makeReadouts ( DayaBay::SimReadoutHeader roHeader,
std::vector< DayaBay::ReadoutTriggerDataPkg * > &  trigDataPkg,
const DayaBay::ElecHeader elecHeader 
) [private, virtual]

Introduce the readout and trigger data package to one another.

Definition at line 58 of file ROsFecReadoutTool.cc.

{
    debug() << "running makeReadouts() in ROsFecReadoutTool" << endreq;

    DayaBay::SimReadoutHeader::SimReadoutContainer& outputReadouts
        = roHeader->readouts();

    Context context = roHeader->context();
    //Get Crate Map
    const DayaBay::ElecCrateHeader *ech = elecHeader.crateHeader();
    const DayaBay::ElecCrateHeader::CrateMap crMap = ech->crates();
    DayaBay::ElecCrateHeader::CrateMap::const_iterator crIt;

    std::vector<DayaBay::ReadoutTriggerDataPkg*>::iterator pkgIt;

    //Loop over All trigger data packages
    for(pkgIt = trigDataPkg.begin(); pkgIt != trigDataPkg.end(); ++pkgIt) {
        DayaBay::Detector det((*pkgIt)->detector());
        if(m_detectors.find(det) != m_detectors.end()){
            if((*pkgIt)->frames().size()==0){
                fatal() << "makeReadouts(): Trying to process a trigger for " << det.detName()
                    << " But Package Has No Frames" << endreq;
                return StatusCode::FAILURE;
            }

            crIt = crMap.find(det);
            const DayaBay::ElecFecCrate *crate;
            if(crIt == crMap.end()){
                fatal() << "makeReadouts(): Trying to process a trigger for " << det.detName()
                    << " But no crate exists." << endreq;
                return StatusCode::FAILURE;
            } else {
                crate = dynamic_cast<const DayaBay::ElecFecCrate*>(crIt->second);
                if (!crate) { // is not fec crate?
                    fatal() << "makeReadouts(): We are supposed to process FEC crate, but did not get it."
                        << endreq;
                    return StatusCode::FAILURE;
                }
                debug() << "makeReadouts(): Processing a trigger for " << det.detName()
                    << " found crate at " << crate << endreq;
            }

            if(crate != 0){ // if the crate exists read it out.
                debug()<<"Reading out 1 trigger with: "
                    <<((*pkgIt)->frames().size())-1
                    <<" masked triggers."<<endreq;
                if (msgLevel(MSG::VERBOSE)) { // Print out list of boards in the ElecCrate
                  verbose()<<"makeReadouts(): ElecFecCrate: {"<<crate->detector()<<", boards: {";
                  DayaBay::ElecFecCrate::FecBoardMap::const_iterator brdIt, brdDone = crate->fecBoards().end();
                  for (brdIt = crate->fecBoards().begin(); brdIt != brdDone; brdIt++) {
                    verbose()<<brdIt->first<<", ";
                  }
                  verbose()<<'\x08'<<'\x08'<<"}"<<endreq;
                }

                const DayaBay::ReadoutRpcTriggerDataFrame *tdf = (*pkgIt)->frames().at(0)->asRpcFrame();

                DayaBay::ReadoutRpcCrate *cr = readoutCrate(tdf,crate,context);
                if (!cr) { // could not create readout crate
                    error()<<"makeReadouts(): Cannot create readout crate."<<endreq;
                    return StatusCode::FAILURE;
                }
                outputReadouts.push_back(new DayaBay::SimReadout(cr,
                    roHeader));

                (*pkgIt)->setReadout(cr);
                cr->setTriggerDataPkg(*pkgIt);
                if (msgLevel(MSG::VERBOSE)) {
                    verbose() << "makeReadouts(): Set readout's trigger data package:\n" << (**pkgIt) << endreq;
                }
            }
        }else{
            if (msgLevel(MSG::VERBOSE)) {
                verbose() << "Found Trigger For " << det.detName()
                        << "but this tool is not supposed "
                        << "to process that detector type "
                        << "check properties to configure."
                        << endreq;
            }
        }
    }

    if (msgLevel(MSG::VERBOSE)) {
        verbose() << "makeReadouts(): ReadoutHeader: " << (*roHeader) <<endreq;
    }

  return StatusCode::SUCCESS;
}
DayaBay::ReadoutRpcCrate * ROsFecReadoutTool::readoutCrate ( const DayaBay::ReadoutRpcTriggerDataFrame tdf,
const DayaBay::ElecFecCrate cr,
Context  context 
) [private]

Definition at line 163 of file ROsFecReadoutTool.cc.

{
    TimeStamp triggerTime(tdf->triggerTime());

    DayaBay::ReadoutRpcCrate *out_readout
            = new DayaBay::ReadoutRpcCrate(cr->detector(),0, triggerTime, tdf->triggerType());
    DayaBay::ReadoutRpcCrate::FecReadouts ro_brdMap;

    const DayaBay::ElecFecCrate::FecBoardMap& brdMap = cr->fecBoards();
    const std::map< DayaBay::FecChannelId, DayaBay::Trigger::TriggerType_t >
                    &trigBoards = tdf->outTriggers();
    std::map< DayaBay::FecChannelId, DayaBay::Trigger::TriggerType_t >::const_iterator brdIt;

    debug()<<"readoutCrate(): Start looping over "<<trigBoards.size()<<" boards in triggered boards."<<endreq;
    for(brdIt = trigBoards.begin(); brdIt != trigBoards.end() ; ++brdIt){
        DayaBay::FecChannelId brdId = brdIt->first;
        DayaBay::ElecFecCrate::FecBoardMap::const_iterator elecBrdIt = brdMap.find(brdId);
        if (elecBrdIt == brdMap.end()) { // did not find the board in the elec crate
          error()<<"readoutCrate(): triggered board, "<<brdId<<"/"<<brdIt->first<<", is not in the current elec crate."<<endreq;
            return 0;
        }
        DayaBay::ReadoutFecBoard *ro_brd = readoutBoard(tdf, &(elecBrdIt->second), context);

        if (ro_brd == 0) continue;         // test to see if channel has readout
        ro_brd->setReadout(out_readout);
        ro_brdMap[brdId] = *ro_brd;   // copy the value by it's address to the map
        ro_brd->setReadout(0);             // reset Readout, to avoid double deletion
        delete ro_brd;                     // delete unnecessary copy
    }

    out_readout->setFecReadouts(ro_brdMap);
    return out_readout;
}
DayaBay::ReadoutFecBoard * ROsFecReadoutTool::readoutBoard ( const DayaBay::ReadoutRpcTriggerDataFrame tdf,
const DayaBay::ElecFecBoard brd,
Context  context 
) [private]

Check whether the board is muted or not

Fill hit map based on the trigger clock, readout window, and set the trigger time for muting.

Definition at line 198 of file ROsFecReadoutTool.cc.

{
    int cycle = tdf->cycle();
    TimeStamp trigTime = tdf->triggerTime();
    // FIXME: check if the trigTime and clock cycle correspond to the simulated window in elec sim.
    const DayaBay::ElecFecBoard::ChannelMap& channels = brd->channels();
    DayaBay::ReadoutFecBoard::FecHitmap hm = 0;
    DayaBay::FecChannelId brdId = brd->boardId();

    std::map<DayaBay::ElecChannelId, TimeStamp>::iterator muteIt = m_lastRead.find(brdId);
    if (muteIt != m_lastRead.end()) {
        // triggers should be time ordered, so it should never happen
        // that current trigger time would be further in past compared to the last readout
        TimeStamp lastRoT = muteIt->second;
        lastRoT.Add((double) m_refuseTime / (double) DayaBay::BaseFrequencyHz);
        if (lastRoT > trigTime) { // FEC still muted
            return 0;
        }
    }

    // loop over channels of this board
    DayaBay::ElecFecBoard::ChannelMap::const_iterator chIt, chDone = channels.end();
    debug()<<"readoutBoard(): Start looping over "<<channels.size()<<" channels in elec board "<<brdId<<endreq;
    for ( chIt = channels.begin(); chIt != chDone; chIt++) {
        // FIXME: check where the cycle is with respect to the simulation window/mainly beginning
        //  put into higher level!

        const DayaBay::DigitalSignal& hits = chIt->second.hits();
        if (msgLevel(MSG::VERBOSE)) {
          verbose()<<"Prepare to start looping over "<<hits.size()<<" cycles in the "
                 <<chIt->first<<" channel's digital signal"<<endreq;
        }
        // loop over clock cycles in the board and prepare hitmap;
        // only in specified readout window
        DayaBay::DigitalSignal::const_iterator hitIt, hitDone = hits.end();
        int iteration = 0;
        hitIt = hits.begin();
        //unsigned int setbit = 0x1<<(chIt->first.connector()); // Convention: connector starts at 0
        unsigned int setbit = chIt->first.fecHit();
        if ( cycle - m_readoutWindowPosition > 0 ) {
            hitIt = hitIt + cycle - m_readoutWindowPosition;
        }
        for ( ;
              hitIt < hitDone && iteration <= m_readoutWindow;
              hitIt++, iteration++) {
            if (*hitIt) {
                hm |= setbit; // fill into the hit map
                break;
            }
        }
        if (hitIt == hitDone && iteration < m_readoutWindow) { // trigger issued very close to the end of sim window
            // FIXME: Put this to the top level - before dealing with boards!
            //  deal with short simulation window; warning is enough?
        }
    }
    if (msgLevel(MSG::VERBOSE)) {
        verbose()<<"ReadoutBoard(): board: "<<brdId<<", hitmap = 0x"<<std::hex << hm << std::dec<<endreq;
    }

    // the FEC is not muted, let's create its readout
    DayaBay::ReadoutFecBoard *ro_brd = new DayaBay::ReadoutFecBoard(brd->boardId(),0);
    // check if it is in input triggers and what flag it is given
    // FIXME: do it properly, based on the data in readout window, the trigger flags may have changed
    std::map< DayaBay::FecChannelId,DayaBay::Trigger::TriggerType_t >::const_iterator
        inTrigIt = tdf->inTriggers().find(brdId);
    if ( inTrigIt != tdf->inTriggers().end() ) { // the boared has local trigger
        if (inTrigIt->second == DayaBay::Trigger::kRPC3of4) { // the trigger is 3 of 4
            ro_brd->setFlag3of4(true);
        }
        ro_brd->setFlag2of4(true);
    }
    // fill the hitmap
    ro_brd->setHitMap(hm);

    // Save last readout time
    m_lastRead[brdId] = trigTime;

    return ro_brd;
}
const InterfaceID & IROsReadoutTool::interfaceID ( ) [static, inherited]

Retrieve interface ID.

Definition at line 8 of file IROsReadoutTool.cc.

{ 
    return IID_IROsReadoutTool; 
}

Member Data Documentation

std::vector<std::string> ROsFecReadoutTool::m_detectorsToProcess [private]

Definition at line 60 of file ROsFecReadoutTool.h.

Names of detectors to be processed by this tool.

Definition at line 61 of file ROsFecReadoutTool.h.

Detectors to be processed by this tool.

Definition at line 62 of file ROsFecReadoutTool.h.

Map of trigger times to the board IDs. For Board muting.

Definition at line 63 of file ROsFecReadoutTool.h.

Time in clk cycles for which FEC will not accept readout query after issuing one.

Definition at line 64 of file ROsFecReadoutTool.h.

So called readout window implemented in FEC. Number of clk cycles to OR the signal in each channel.

Definition at line 65 of file ROsFecReadoutTool.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 10:17:06 for ReadoutSim by doxygen 1.7.4