Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:46

0001 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0002 #include "DataFormats/HcalDigi/interface/HcalLaserDigi.h"
0003 #include "RecoLocalCalo/HcalLaserReco/src/HcalLaserUnpacker.h"
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 #include <ostream>
0006 
0007 HcalLaserUnpacker::HcalLaserUnpacker() {}
0008 
0009 struct CombinedTDCQDCDataFormat {
0010   unsigned int cdfHeader0, cdfHeader1, cdfHeader2, cdfHeader3;
0011   unsigned int n_qdc_hits;  // Count of QDC channels
0012   unsigned int n_tdc_hits;  // upper/lower TDC counts
0013   unsigned short qdc_values[4];
0014 };
0015 
0016 void HcalLaserUnpacker::unpack(const FEDRawData& raw, HcalLaserDigi& digi) const {
0017   if (raw.size() < 3 * 8) {
0018     throw cms::Exception("Missing Data") << "No data in the block";
0019   }
0020 
0021   const CombinedTDCQDCDataFormat* qdctdc = (const CombinedTDCQDCDataFormat*)raw.data();
0022 
0023   // first, we do the QADC
0024   std::vector<uint16_t> qadcvals;
0025   for (unsigned int i = 0; i < qdctdc->n_qdc_hits; i++) {
0026     qadcvals.push_back(qdctdc->qdc_values[i] & 0xFFF);
0027   }
0028   digi.setQADC(qadcvals);
0029 
0030   // next, we do the TDC
0031   const unsigned int* hitbase = (&(qdctdc->n_tdc_hits)) + 1;  // base is one beyond
0032   unsigned int totalhits = 0;
0033 
0034   hitbase += qdctdc->n_qdc_hits / 2;        // two unsigned short per unsigned long
0035   totalhits = qdctdc->n_tdc_hits & 0xFFFF;  // mask off high bits
0036 
0037   for (unsigned int i = 0; i < totalhits; i++) {
0038     int channel = (hitbase[i] & 0x7FC00000) >> 22;  // hardcode channel assignment
0039     int time = (hitbase[i] & 0xFFFFF);
0040     if (channel == 0 && time == 0 && i == (totalhits - 1))
0041       continue;  // ignore "filler" hit
0042     digi.addTDCHit(channel, time);
0043   }
0044 }