00001 #include "DataFormats/FEDRawData/interface/FEDRawData.h" 00002 #include "DataFormats/HcalDigi/interface/HcalLaserDigi.h" 00003 #include "RecoLocalCalo/HcalLaserReco/src/HcalLaserUnpacker.h" 00004 #include "FWCore/Utilities/interface/Exception.h" 00005 00006 HcalLaserUnpacker::HcalLaserUnpacker(){} 00007 00008 struct CombinedTDCQDCDataFormat { 00009 unsigned int cdfHeader0,cdfHeader1,cdfHeader2,cdfHeader3; 00010 unsigned int n_qdc_hits; // Count of QDC channels 00011 unsigned int n_tdc_hits; // upper/lower TDC counts 00012 unsigned short qdc_values[4]; 00013 }; 00014 00015 void HcalLaserUnpacker::unpack(const FEDRawData& raw, 00016 HcalLaserDigi& digi) const { 00017 00018 if (raw.size()<3*8) { 00019 throw cms::Exception("Missing Data") << "No data in the block"; 00020 } 00021 00022 const CombinedTDCQDCDataFormat* qdctdc=(const CombinedTDCQDCDataFormat*)raw.data(); 00023 00024 // first, we do the QADC 00025 std::vector<uint16_t> qadcvals; 00026 for (unsigned int i=0;i<qdctdc->n_qdc_hits;i++) { 00027 qadcvals.push_back(qdctdc->qdc_values[i]&0xFFF); 00028 } 00029 digi.setQADC(qadcvals); 00030 00031 // next, we do the TDC 00032 const unsigned int* hitbase=(&(qdctdc->n_tdc_hits))+1; // base is one beyond 00033 unsigned int totalhits=0; 00034 00035 hitbase+=qdctdc->n_qdc_hits/2; // two unsigned short per unsigned long 00036 totalhits=qdctdc->n_tdc_hits&0xFFFF; // mask off high bits 00037 00038 for (unsigned int i=0; i<totalhits; i++) { 00039 int channel=(hitbase[i]&0x7FC00000)>>22; // hardcode channel assignment 00040 int time=(hitbase[i]&0xFFFFF); 00041 if (channel==0 && time==0 && i==(totalhits-1)) continue; // ignore "filler" hit 00042 digi.addTDCHit(channel,time); 00043 } 00044 }