CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

DTROS25Unpacker Class Reference

#include <DTROS25Unpacker.h>

Inheritance diagram for DTROS25Unpacker:
DTUnpacker

List of all members.

Public Member Functions

 DTROS25Unpacker (const edm::ParameterSet &ps)
 Constructor.
const std::vector< DTROS25Data > & getROSsControlData () const
virtual void interpretRawData (const unsigned int *index, int datasize, int dduID, edm::ESHandle< DTReadOutMapping > &mapping, std::auto_ptr< DTDigiCollection > &product, std::auto_ptr< DTLocalTriggerCollection > &product2, uint16_t rosList=0)
virtual ~DTROS25Unpacker ()
 Destructor.

Private Member Functions

int swap (int x)

Private Attributes

std::vector< DTROS25DatacontrolDataFromAllROS
DTDataMonitorInterfacedataMonitor
bool debug
int hardcodedDDUID
 to analyze older data..
bool localDAQ
 if reading data locally, words, being assembled as 32-bits, do not need to be swapped
bool performDataIntegrityMonitor
 perform DQM on ROS data
bool readDDUIDfromDDU
 since June 2007, local DAQ, provides FED number
bool readingDDU
 if data are read from ROS directly, no information on the ROS Id is present
bool writeSC
 make the local SC spy data persistent

Detailed Description

The unpacker for DTs' ROS25: final version of Read Out Sector board with 25 channels.

Date:
2007/09/04 08:07:26
Revision:
1.4
Author:
M. Zanetti INFN Padova FRC 060906

Definition at line 21 of file DTROS25Unpacker.h.


Constructor & Destructor Documentation

DTROS25Unpacker::DTROS25Unpacker ( const edm::ParameterSet ps)

Constructor.

Definition at line 33 of file DTROS25Unpacker.cc.

References debug, edm::ParameterSet::getUntrackedParameter(), edm::Service< T >::isAvailable(), and cmsCodeRules::cppFunctionSkipper::operator.

                                                          {
  

  localDAQ = ps.getUntrackedParameter<bool>("localDAQ",false);
  readingDDU = ps.getUntrackedParameter<bool>("readingDDU",true);

  readDDUIDfromDDU = ps.getUntrackedParameter<bool>("readDDUIDfromDDU",true);
  hardcodedDDUID = ps.getUntrackedParameter<int>("dduID",770);

  writeSC = ps.getUntrackedParameter<bool>("writeSC",false);
  performDataIntegrityMonitor = ps.getUntrackedParameter<bool>("performDataIntegrityMonitor",false);
  debug = ps.getUntrackedParameter<bool>("debug",false);

  // enable DQM if Service is available
  if(performDataIntegrityMonitor) {
    if (edm::Service<DTDataMonitorInterface>().isAvailable()) {
      dataMonitor = edm::Service<DTDataMonitorInterface>().operator->(); 
    } else {
      LogWarning("DTRawToDigi|DTROS25Unpacker") << 
        "[DTROS25Unpacker] WARNING! Data Integrity Monitoring requested but no DTDataMonitorInterface Service available" << endl;
      performDataIntegrityMonitor = false;
    }
  }

}
DTROS25Unpacker::~DTROS25Unpacker ( ) [virtual]

Destructor.

Definition at line 60 of file DTROS25Unpacker.cc.

{}

Member Function Documentation

const std::vector<DTROS25Data>& DTROS25Unpacker::getROSsControlData ( ) const [inline]

Definition at line 39 of file DTROS25Unpacker.h.

References controlDataFromAllROS.

Referenced by DTDDUUnpacker::interpretRawData().

                                                                   {
    return controlDataFromAllROS;
  }
void DTROS25Unpacker::interpretRawData ( const unsigned int *  index,
int  datasize,
int  dduID,
edm::ESHandle< DTReadOutMapping > &  mapping,
std::auto_ptr< DTDigiCollection > &  product,
std::auto_ptr< DTLocalTriggerCollection > &  product2,
uint16_t  rosList = 0 
) [virtual]

Unpacking method. index is the pointer to the beginning of the buffer. datasize is the size of the buffer in bytes

Implements DTUnpacker.

Definition at line 63 of file DTROS25Unpacker.cc.

References DTROS25Data::addROBHeader(), DTROS25Data::addROBTrailer(), DTROS25Data::addROSDebug(), DTROS25Data::addROSError(), DTROS25Data::addROSHeader(), DTROS25Data::addROSTrailer(), DTROS25Data::addSCData(), DTROS25Data::addSCHeader(), DTROS25Data::addSCPrivHeader(), DTROS25Data::addSCPrivSubHeader(), DTROS25Data::addSCTrailer(), DTROS25Data::addTDCData(), DTROS25Data::addTDCError(), DTROBHeaderWord::bunchID(), DTROS25Data::clean(), gather_cfg::cout, debug, DTROSDebugWord::debugMessage(), DTROSDebugWord::debugType(), DTROSErrorWord::errorType(), DTROBHeaderWord::eventID(), DTLocalTriggerHeaderWord::eventID(), DTROBTrailerWord::eventID(), DTROSTrailerWord::EventWordCount(), DTLocalTriggerDataWord::getBits(), DTROChainCoding::getCode(), DTROSWordType::GroupHeader, DTROSWordType::GroupTrailer, DTLocalTriggerDataWord::hasTrigger(), DTWireId::layerId(), DTLocalTriggerSectorCollectorSubHeaderWord::LocalBunchCounter(), DTLocalTriggerSectorCollectorHeaderWord::NumberOf16bitWords(), funct::pow(), DTLocalTrigger::print(), DTTDCErrorNotifier::print(), DTROSErrorWord::robID(), DTROBTrailerWord::robID(), DTROBHeaderWord::robID(), DTROSWordType::ROSDebug, DTROSWordType::ROSError, DTROSWordType::ROSHeader, DTROSWordType::ROSTrailer, DTROSWordType::SCData, DTLocalTriggerDataWord::SCData(), DTROSWordType::SCHeader, DTROSWordType::SCTrailer, DTROS25Data::setROSId(), std::swap(), DTTDCMeasurementWord::tdcChannel(), DTROSWordType::TDCDebug, DTROSWordType::TDCError, DTTDCMeasurementWord::tdcID(), DTROSWordType::TDCMeasurement, DTTDCMeasurementWord::tdcTime(), DTLocalTriggerDataWord::trackQuality(), DTLocalTriggerSectorCollectorSubHeaderWord::TriggerDelay(), DTROSHeaderWord::TTCEventCounter(), DTROSWordType::type(), DTWireId::wire(), DTROBTrailerWord::wordCount(), and DTLocalTriggerTrailerWord::wordCount().

Referenced by DTDDUUnpacker::interpretRawData().

                                                         {


  int dduID;
  if (readDDUIDfromDDU) dduID = dduIDfromDDU;
  else dduID = hardcodedDDUID;

  const int wordLength = 4;
  int numberOfWords = datasize / wordLength;
  
  int rosID = 0;
  DTROS25Data controlData(rosID);
  controlDataFromAllROS.clear();
  
  int wordCounter = 0;
  uint32_t word = index[swap(wordCounter)];

  map<uint32_t,int> hitOrder;


  /******************************************************
  / The the loop is performed with "do-while" statements
  / because the ORDER of the words in the event data
  / is assumed to be fixed. Eventual changes into the
  / structure should be considered as data corruption
  *******************************************************/
  
  // Loop on ROSs
  while (wordCounter < numberOfWords) {

    controlData.clean();
    
    rosID++; // to be mapped;

    if ( readingDDU ) {
      // matching the ROS number with the enabled DDU channel
      if ( rosID <= 12 && !((rosList & int(pow(2., (rosID-1) )) ) >> (rosID-1) ) ) continue;
      if (debug) cout<<"[DTROS25Unpacker]: ros list: "<<rosList <<" ROS ID "<<rosID<<endl;
    }

    // FRC prepare info for DTLocalTrigger: wheel and sector corresponding to this ROS

    int SCwheel=-3;
    int SCsector=0;
    int dum1, dum2, dum3, dum4;

    if (writeSC && ! mapping->readOutToGeometry(dduID, rosID, 1, 1, 1,
                                                SCwheel, dum1, SCsector, dum2, dum3, dum4) ) {
      if (debug) cout <<" found SCwheel: "<<SCwheel<<" and SCsector: "<<SCsector<<endl;
    }
    else {
      if (writeSC && debug) cout <<" WARNING failed to find WHEEL and SECTOR for ROS "<<rosID<<" !"<<endl;
    }


    // ROS Header;
    if (DTROSWordType(word).type() == DTROSWordType::ROSHeader) {
      DTROSHeaderWord rosHeaderWord(word);

      if (debug) cout<<"[DTROS25Unpacker]: ROSHeader "<<rosHeaderWord.TTCEventCounter()<<endl;

      // container for words to be sent to DQM
      controlData.setROSId(rosID);
      controlData.addROSHeader(rosHeaderWord);
      

      // Loop on ROBs
      do {
        wordCounter++; word = index[swap(wordCounter)];

        // Eventual ROS Error: occurs when some errors are found in a ROB
        if (DTROSWordType(word).type() == DTROSWordType::ROSError) {
          DTROSErrorWord dtROSErrorWord(word);
          controlData.addROSError(dtROSErrorWord);
          if (debug) cout<<"[DTROS25Unpacker]: ROSError, Error type "<<dtROSErrorWord.errorType()
                         <<" robID "<<dtROSErrorWord.robID()<<endl;
        }

        // Eventual ROS Debugging;
        else if (DTROSWordType(word).type() == DTROSWordType::ROSDebug) {
          DTROSDebugWord rosDebugWord(word);
          controlData.addROSDebug(rosDebugWord);
          if (debug) cout<<"[DTROS25Unpacker]: ROSDebug, type "<<rosDebugWord.debugType()
                         <<"  message "<<rosDebugWord.debugMessage()<<endl;
        }

        // Check ROB header
        else if (DTROSWordType(word).type() == DTROSWordType::GroupHeader) {

          DTROBHeaderWord robHeaderWord(word);
          int eventID = robHeaderWord.eventID(); // from the TDCs
          int bunchID = robHeaderWord.bunchID(); // from the TDCs
          int robID = robHeaderWord.robID(); // to be mapped

          DTROBHeader robHeader(robID,robHeaderWord);  // IJ
          controlData.addROBHeader(robHeader);    // IJ

          if (debug) cout<<"[DTROS25Unpacker] ROB: ID "<<robID
                         <<" Event ID "<<eventID
                         <<" BXID "<<bunchID<<endl;

          // Loop on TDCs data (headers and trailers are not there)
          do {
            wordCounter++; word = index[swap(wordCounter)];

            // Eventual TDC Error
            if ( DTROSWordType(word).type() == DTROSWordType::TDCError) {
              DTTDCErrorWord dtTDCErrorWord(word);
              DTTDCError tdcError(robID,dtTDCErrorWord);
              controlData.addTDCError(tdcError);

              DTTDCErrorNotifier dtTDCError(dtTDCErrorWord);
              if (debug) dtTDCError.print();
            }

            // Eventual TDC Debug
            else if ( DTROSWordType(word).type() == DTROSWordType::TDCDebug) {
              if (debug) cout<<"TDC Debugging"<<endl;
            }
            
            // The TDC information
            else if (DTROSWordType(word).type() == DTROSWordType::TDCMeasurement) {

              DTTDCMeasurementWord tdcMeasurementWord(word);
              DTTDCData tdcData(robID,tdcMeasurementWord);
              controlData.addTDCData(tdcData);

              int tdcID = tdcMeasurementWord.tdcID();
              int tdcChannel = tdcMeasurementWord.tdcChannel();

              if (debug) cout<<"[DTROS25Unpacker] TDC: ID "<<tdcID
                             <<" Channel "<< tdcChannel
                             <<" Time "<<tdcMeasurementWord.tdcTime()<<endl;

              DTROChainCoding channelIndex(dduID, rosID, robID, tdcID, tdcChannel);

              hitOrder[channelIndex.getCode()]++;

              if (debug) {
                cout<<"[DTROS25Unpacker] ROAddress: DDU "<< dduID
                    <<", ROS "<< rosID
                    <<", ROB "<< robID
                    <<", TDC "<< tdcID
                    <<", Channel "<< tdcChannel<<endl;
              }

              // FRC if not already done for this ROS, find wheel and sector for SC data
              if (writeSC && (SCsector < 1 || SCwheel < -2) ) {

                if (debug) cout <<" second try to find SCwheel and SCsector "<<endl;
                if ( ! mapping->readOutToGeometry(dduID, rosID, robID, tdcID, tdcChannel,
                                                  SCwheel, dum1, SCsector, dum2, dum3, dum4) ) {
                  if (debug) cout<<" ROS "<<rosID<<" SC wheel "<<SCwheel<<" SC sector "<<SCsector<<endl;
                }
                else {
                  if (debug) cout<<" WARNING !! ROS "<<rosID<<" failed again to map for SC!! "<<endl;
                }
              }


              // Map the RO channel to the DetId and wire
              DTWireId detId;
              // if ( ! mapping->readOutToGeometry(dduID, rosID, robID, tdcID, tdcChannel, detId)) {
              int wheelId, stationId, sectorId, slId,layerId, cellId; 
              if ( ! mapping->readOutToGeometry(dduID, rosID, robID, tdcID, tdcChannel, 
                                                wheelId, stationId, sectorId, slId, layerId, cellId)) {

                // skip the digi if the detId is invalid 
                if (sectorId==0 || stationId == 0) continue;
                else detId = DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId); 

                if (debug) cout<<"[DTROS25Unpacker] "<<detId<<endl;
                int wire = detId.wire();

                // Produce the digi
                DTDigi digi( wire, tdcMeasurementWord.tdcTime(), hitOrder[channelIndex.getCode()]-1);

                // Commit to the event
                detectorProduct->insertDigi(detId.layerId(),digi);
              }
              else {
                LogWarning ("DTRawToDigi|DTROS25Unpacker") <<"Unable to map the RO channel: DDU "<<dduID
                                          <<" ROS "<<rosID<<" ROB "<<robID<<" TDC "<<tdcID<<" TDC ch. "<<tdcChannel;
                if (debug) cout<<"[DTROS25Unpacker] ***ERROR***  Missing wire: DDU "<<dduID
                               <<" ROS "<<rosID<<" ROB "<<robID<<" TDC "<<tdcID<<" TDC ch. "<<tdcChannel<<endl;
              }

            } // TDC information

          } while ( DTROSWordType(word).type() != DTROSWordType::GroupTrailer &&
                    DTROSWordType(word).type() != DTROSWordType::ROSError); // loop on TDC's?

          // Check ROB Trailer (condition already verified)
          if (DTROSWordType(word).type() == DTROSWordType::GroupTrailer) {
            DTROBTrailerWord robTrailerWord(word);
            controlData.addROBTrailer(robTrailerWord);
            if (debug) cout<<"[DTROS25Unpacker]: ROBTrailer, robID  "<<robTrailerWord.robID()
                           <<" eventID  "<<robTrailerWord.eventID()
                           <<" wordCount  "<<robTrailerWord.wordCount()<<endl;
          }
        } // ROB header

        // Check the eventual Sector Collector Header
        else if (DTROSWordType(word).type() == DTROSWordType::SCHeader) {
          DTLocalTriggerHeaderWord scHeaderWord(word);
          if (debug) cout<<"[DTROS25Unpacker]: SC header  eventID " << scHeaderWord.eventID()<<endl;

          // RT added : first word following SCHeader is a SC private header
          wordCounter++; word = index[swap(wordCounter)];

          if(DTROSWordType(word).type() == DTROSWordType::SCData) {
            DTLocalTriggerSectorCollectorHeaderWord scPrivateHeaderWord(word);
            
            if(performDataIntegrityMonitor) {
              controlData.addSCPrivHeader(scPrivateHeaderWord);
            }

            int numofscword = scPrivateHeaderWord.NumberOf16bitWords();
            int leftword = numofscword;

            if(debug) cout<<"                   SC PrivateHeader (number of words + subheader = "
                          << scPrivateHeaderWord.NumberOf16bitWords() << ")" <<endl;

            // if no SC data -> no loop ;
            // otherwise subtract 1 word (subheader) and countdown for bx assignment
            if(numofscword > 0){

              int bx_received = (numofscword - 1) / 2;
              if(debug)  cout<<"                   SC number of bx read-out: " << bx_received << endl;

              wordCounter++; word = index[swap(wordCounter)];
              if (DTROSWordType(word).type() == DTROSWordType::SCData) {
                //second word following SCHeader is a SC private SUB-header
                leftword--;

                DTLocalTriggerSectorCollectorSubHeaderWord scPrivateSubHeaderWord(word);
                // read the event BX in the SC header (will be stored in SC digis)
                int scEventBX = scPrivateSubHeaderWord.LocalBunchCounter();
                if(debug) cout <<"                   SC trigger delay = "
                                << scPrivateSubHeaderWord.TriggerDelay() << endl
                                <<"                   SC bunch counter = "
                                << scEventBX << endl;
                
                controlData.addSCPrivSubHeader(scPrivateSubHeaderWord);

                // actual loop on SC time slots
                int stationGroup=0;
                do {
                  wordCounter++; word = index[swap(wordCounter)];
                  int SCstation=0;

                  if (DTROSWordType(word).type() == DTROSWordType::SCData) {
                    leftword--;
                    //RT: bx are sent from SC in reverse order starting from the one
                    //which stopped the spy buffer
                    int bx_counter = int(round( (leftword + 1)/ 2.));

                    if(debug){
                      if(bx_counter < 0 || leftword < 0)
                        cout<<"[DTROS25Unpacker]: SC data more than expected; negative bx counter reached! "<<endl;
                    }
                    
                    DTLocalTriggerDataWord scDataWord(word);

                    // DTSectorCollectorData scData(scDataWord, int(round(bx_counter/2.))); M.Z.
                    DTSectorCollectorData scData(scDataWord,bx_counter);
                    controlData.addSCData(scData);

                    if (debug) {
                      //cout<<"[DTROS25Unpacker]: SCData bits "<<scDataWord.SCData()<<endl;
                      //cout << " word in esadecimale: " << hex << word << dec << endl;
                      if (scDataWord.hasTrigger(0))
                        cout<<" at BX "<< bx_counter //round(bx_counter/2.)
                            <<" lower part has trigger! with track quality "
                            << scDataWord.trackQuality(0)<<endl;
                      if (scDataWord.hasTrigger(1))
                        cout<<" at BX "<< bx_counter //round(bx_counter/2.)
                            <<" upper part has trigger! with track quality "
                            << scDataWord.trackQuality(1)<<endl;
                    }

                    if (writeSC && SCwheel >= -2  && SCsector >=1 ) {

                      // FRC: start constructing persistent SC objects:
                      // first identify the station (data come in 2 triggers per word: MB1+MB2, MB3+MB4)
                      if ( scDataWord.hasTrigger(0) || (scDataWord.getBits(0) & 0x30) ) {
                        if ( stationGroup%2 == 0) SCstation = 1;
                        else                      SCstation = 3;

                        // construct localtrigger for first station of this "group" ...
                        DTLocalTrigger localtrigger(scEventBX, bx_counter,(scDataWord.SCData()) & 0xFF);
                        // ... and commit it to the event
                        DTChamberId chamberId (SCwheel,SCstation,SCsector);
                        triggerProduct->insertDigi(chamberId,localtrigger);
                        if (debug) { 
                          cout<<"Add SC digi to the collection, for chamber: " << chamberId
                              <<endl;
                          localtrigger.print(); }
                      }
                      if ( scDataWord.hasTrigger(1) || (scDataWord.getBits(1) & 0x30) ) {
                        if ( stationGroup%2 == 0) SCstation = 2;
                        else                      SCstation = 4;

                        // construct localtrigger for second station of this "group" ...
                        DTLocalTrigger localtrigger(scEventBX, bx_counter,(scDataWord.SCData()) >> 8);
                        // ... and commit it to the event
                        DTChamberId chamberId (SCwheel,SCstation,SCsector);
                        triggerProduct->insertDigi(chamberId,localtrigger);
                        if(debug) { 
                          cout<<"Add SC digi to the collection, for chamber: " << chamberId
                              <<endl;
                          localtrigger.print();
                        }
                      }
                      
                      stationGroup++;
                    } // if writeSC
                  } // if SC data
                } while ( DTROSWordType(word).type() != DTROSWordType::SCTrailer );

              } // end SC subheader
            } // end if SC send more than only its own header!
          } //  end if first data following SCheader is not SCData

          if (DTROSWordType(word).type() == DTROSWordType::SCTrailer) {
            DTLocalTriggerTrailerWord scTrailerWord(word);
            // add infos for data integrity monitoring
            controlData.addSCHeader(scHeaderWord);
            controlData.addSCTrailer(scTrailerWord);

            if (debug) cout<<"                   SC Trailer, # of words: "
                           << scTrailerWord.wordCount() <<endl;
          }
        }

      } while ( DTROSWordType(word).type() != DTROSWordType::ROSTrailer ); // loop on ROBS

      // check ROS Trailer (condition already verified)
      if (DTROSWordType(word).type() == DTROSWordType::ROSTrailer){
        DTROSTrailerWord rosTrailerWord(word);
        controlData.addROSTrailer(rosTrailerWord);
        if (debug) cout<<"[DTROS25Unpacker]: ROSTrailer "<<rosTrailerWord.EventWordCount()<<endl;
      }
      
      // Perform dqm if requested:
      // DQM IS PERFORMED FOR EACH ROS SEPARATELY
      if (performDataIntegrityMonitor) {
        dataMonitor->processROS25(controlData, dduID, rosID);
        // fill the vector with ROS's control data
        controlDataFromAllROS.push_back(controlData);
      }

    }

    else if (index[swap(wordCounter)] == 0) {
      // in the case of odd number of words of a given ROS the header of
      // the next one is postponed by 4 bytes word set to 0.
      // rosID needs to be step back by 1 unit
      if (debug) cout<<"[DTROS25Unpacker]: odd number of ROS words"<<endl;
      rosID--;
    } // if ROS header
    
    else {
      cout<<"[DTROS25Unpacker]: ERROR! First word is not a ROS Header"<<endl;
    }
    
    // (needed if there are more than 1 ROS)
    wordCounter++; word = index[swap(wordCounter)];

  } // loop on ROS!

}
int DTROS25Unpacker::swap ( int  x) [private]

Definition at line 442 of file DTROS25Unpacker.cc.

References n, and query::result.

                               {

  int result=n;

  if ( !localDAQ ) {
    if (n%2==0) result = (n+1);
    if (n%2==1) result = (n-1);
  }
  
  return result;
}

Member Data Documentation

Definition at line 68 of file DTROS25Unpacker.h.

Referenced by getROSsControlData().

Definition at line 66 of file DTROS25Unpacker.h.

bool DTROS25Unpacker::debug [private]

Definition at line 64 of file DTROS25Unpacker.h.

to analyze older data..

Definition at line 56 of file DTROS25Unpacker.h.

bool DTROS25Unpacker::localDAQ [private]

if reading data locally, words, being assembled as 32-bits, do not need to be swapped

Definition at line 48 of file DTROS25Unpacker.h.

perform DQM on ROS data

Definition at line 62 of file DTROS25Unpacker.h.

since June 2007, local DAQ, provides FED number

Definition at line 54 of file DTROS25Unpacker.h.

if data are read from ROS directly, no information on the ROS Id is present

Definition at line 51 of file DTROS25Unpacker.h.

bool DTROS25Unpacker::writeSC [private]

make the local SC spy data persistent

Definition at line 59 of file DTROS25Unpacker.h.