Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:31

0001 /** \file
0002  *
0003  *  \author  M. Zanetti - INFN Padova 
0004  * FRC 140906
0005  */
0006 
0007 #include <EventFilter/DTRawToDigi/plugins/DTROS8Unpacker.h>
0008 #include <CondFormats/DTObjects/interface/DTReadOutMapping.h>
0009 #include <FWCore/Utilities/interface/Exception.h>
0010 #include <DataFormats/MuonDetId/interface/DTWireId.h>
0011 
0012 #include <iostream>
0013 #include <map>
0014 
0015 using namespace std;
0016 using namespace edm;
0017 using namespace cms;
0018 
0019 void DTROS8Unpacker::interpretRawData(const unsigned int* index,
0020                                       int datasize,
0021                                       int dduID,
0022                                       edm::ESHandle<DTReadOutMapping>& mapping,
0023                                       std::unique_ptr<DTDigiCollection>& product,
0024                                       std::unique_ptr<DTLocalTriggerCollection>& product2,
0025                                       uint16_t rosList) {
0026   /// CopyAndPaste from P. Ronchese unpacker
0027   const int wordLength = 4;
0028   int numberOfWords = datasize / wordLength;
0029   int robID = 0;
0030   int rosID = 0;
0031 
0032   map<int, int> hitOrder;
0033 
0034   // Loop over the ROS8 words
0035   for (int i = 1; i < numberOfWords; i++) {
0036     // The word
0037     uint32_t word = index[i];
0038 
0039     // The word type
0040     int type = (word >> 28) & 0xF;
0041 
0042     // Event Header
0043     if (type == 15) {
0044       robID = word & 0x7;
0045       rosID = (word >> 3) & 0xFF;
0046     }
0047 
0048     // TDC Measurement
0049     else if (type >= 4 && type <= 5) {
0050       int tdcID = (word >> 24) & 0xF;
0051       int tdcChannel = (word >> 19) & 0x1F;
0052 
0053       int channelIndex = robID << 7 | tdcID << 5 | tdcChannel;
0054       hitOrder[channelIndex]++;
0055 
0056       int tdcMeasurement = word & 0x7FFFF;
0057       tdcMeasurement >>= 2;
0058 
0059       try {
0060         // Check the ddu ID in the mapping been used
0061         dduID = pset.getUntrackedParameter<int>("dduID", 730);
0062 
0063         // Map the RO channel to the DetId and wire
0064         DTWireId detId;
0065         if (!mapping->readOutToGeometry(dduID, rosID, robID, tdcID, tdcChannel, detId)) {
0066           if (pset.getUntrackedParameter<bool>("debugMode", false))
0067             cout << "[DTROS8Unpacker] " << detId << endl;
0068           int wire = detId.wire();
0069 
0070           // Produce the digi
0071           DTDigi digi(wire, tdcMeasurement, hitOrder[channelIndex] - 1);
0072 
0073           // Commit to the event
0074           product->insertDigi(detId.layerId(), digi);
0075         } else if (pset.getUntrackedParameter<bool>("debugMode", false))
0076           cout << "[DTROS8Unpacker] Missing wire!" << endl;
0077       }
0078 
0079       catch (cms::Exception& e1) {
0080         cout << "[DTUnpackingModule]: WARNING: Digi not build!" << endl;
0081         return;
0082       }
0083     }
0084   }
0085 }