CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
ZdcUnpacker Class Reference

#include <ZdcUnpacker.h>

Public Member Functions

void setExpectedOrbitMessageTime (int time)
 
void unpack (const FEDRawData &raw, const CastorElectronicsMap &emap, CastorRawCollections &conts, HcalUnpackerReport &report, bool silent=false)
 For histograms, no begin and end. More...
 
void unpackOld (const FEDRawData &raw, const HcalElectronicsMap &emap, CastorRawCollections &conts, HcalUnpackerReport &report, bool silent=false)
 
 ZdcUnpacker (int sourceIdOffset, int beg, int end)
 for normal data More...
 

Private Attributes

int endSample_
 last sample from fed raw data to copy (if present) More...
 
int expectedOrbitMessageTime_
 Expected orbit bunch time (needed to evaluate time differences) More...
 
int mode_
 
int sourceIdOffset_
 number to subtract from the source id to get the dcc id More...
 
int startSample_
 first sample from fed raw data to copy More...
 
std::set< HcalElectronicsIdunknownIds_
 
std::set< HcalElectronicsIdunknownIdsTrig_
 Recorded to limit number of times a log message is generated. More...
 

Detailed Description

Definition at line 17 of file ZdcUnpacker.h.

Constructor & Destructor Documentation

ZdcUnpacker::ZdcUnpacker ( int  sourceIdOffset,
int  beg,
int  end 
)

for normal data

Definition at line 84 of file ZdcUnpacker.cc.

References end, endSample_, ZDCDataFrame::MAXSAMPLES, and startSample_.

84  : sourceIdOffset_(sourceIdOffset) , expectedOrbitMessageTime_(-1)
85 {
86  if ( beg >= 0 && beg <= ZDCDataFrame::MAXSAMPLES -1 ) {
87  startSample_ = beg;
88  } else {
89  startSample_ = 0;
90  }
91  if ( end >= 0 && end <= ZDCDataFrame::MAXSAMPLES -1 && end >= beg ) {
92  endSample_ = end;
93  } else {
95  }
96 }
int startSample_
first sample from fed raw data to copy
Definition: ZdcUnpacker.h:29
static const int MAXSAMPLES
Definition: ZDCDataFrame.h:54
int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
Definition: ZdcUnpacker.h:31
#define end
Definition: vmac.h:39
int sourceIdOffset_
number to subtract from the source id to get the dcc id
Definition: ZdcUnpacker.h:28
int endSample_
last sample from fed raw data to copy (if present)
Definition: ZdcUnpacker.h:30

Member Function Documentation

void ZdcUnpacker::setExpectedOrbitMessageTime ( int  time)
inline

Definition at line 22 of file ZdcUnpacker.h.

References expectedOrbitMessageTime_, edmIntegrityCheck::report, protons_cff::time, unpack(), and unpackOld().

int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
Definition: ZdcUnpacker.h:31
void ZdcUnpacker::unpack ( const FEDRawData raw,
const CastorElectronicsMap emap,
CastorRawCollections conts,
HcalUnpackerReport report,
bool  silent = false 
)

For histograms, no begin and end.

Definition at line 98 of file ZdcUnpacker.cc.

References DetId::Calo, HcalHTRData::check(), HcalUnpackerReport::countSpigotFormatError(), HcalUnpackerReport::countUnmappedDigi(), FEDRawData::data(), HcalHTRData::dataPointers(), DetId::det(), runTauDisplay::eid, endSample_, expectedOrbitMessageTime_, HcalHTRData::getFirmwareFlavor(), HcalHTRData::getNPS(), HcalDCCHeader::getSourceId(), HcalDCCHeader::getSpigotCRCError(), HcalDCCHeader::getSpigotData(), HcalDCCHeader::getSpigotPresent(), HcalHTRData::getSubmodule(), HcalHTRData::is_channel_header(), HcalHTRData::isHistogramEvent(), LogDebug, DetId::null(), HcalElectronicsId::setHTR(), FEDRawData::size(), sourceIdOffset_, HcalDCCHeader::SPIGOT_COUNT, startSample_, HcalZDCDetId::SubdetectorId, DetId::subdetId(), CastorRawCollections::ttp, HcalTTPUnpacker::unpack(), HcalHTRData::unpack_per_channel_header(), and CastorRawCollections::zdcCont.

Referenced by CastorRawToDigi::produce(), and setExpectedOrbitMessageTime().

99  {
100 
101  if (raw.size()<16) {
102  if (!silent) edm::LogWarning("Invalid Data") << "Empty/invalid DCC data, size = " << raw.size();
103  return;
104  }
105 
106  // get the DCC header
107  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
108  int dccid=dccHeader->getSourceId()-sourceIdOffset_;
109 
110  // walk through the HTR data...
111  HcalHTRData htr;
112  const unsigned short* daq_first, *daq_last, *tp_first, *tp_last;
113  std::map<HcalElectronicsId,DetId> myEMap;
114 
115 
117  //PZDC
119  eid.setHTR(18, 8, 1);
120  myEMap[eid]=DetId(0x54000051);//PZDC EM1
121 
122  eid = HcalElectronicsId(1, 1, 0, 3);
123  eid.setHTR(18, 8, 1);
124  myEMap[eid]=DetId(0x54000052);//PZDC EM2
125 
126  eid = HcalElectronicsId(2, 1, 0, 3);
127  eid.setHTR(18, 8, 1);
128  myEMap[eid]=DetId(0x54000053);//PZDC EM3
129 
130  eid = HcalElectronicsId(0, 2, 0, 3);
131  eid.setHTR(18, 8, 1);
132  myEMap[eid]=DetId(0x54000061);//PZDC HAD1
133 
134  eid = HcalElectronicsId(1, 2, 0, 3);
135  eid.setHTR(18, 8, 1);
136  myEMap[eid]=DetId(0x54000054);//PZDC EM4
137 
138  eid = HcalElectronicsId(2, 2, 0, 3);
139  eid.setHTR(18, 8, 1);
140  myEMap[eid]=DetId(0x54000055);//PZDC EM5
141 
142  eid = HcalElectronicsId(0, 3, 0, 3);
143  eid.setHTR(18, 8, 1);
144  myEMap[eid]=DetId(0x54000062);//PZDC HAD2
145 
146  eid = HcalElectronicsId(1, 3, 0, 3);
147  eid.setHTR(18, 8, 1);
148  myEMap[eid]=DetId(0x54000063);//PZDC HAD3
149 
150  eid = HcalElectronicsId(2, 3, 0, 3);
151  eid.setHTR(18, 8, 1);
152  myEMap[eid]=DetId(0x54000064);//PZDC HAD4
153 
154  //NZDC
155  eid = HcalElectronicsId(0,1,1,3);
156  eid.setHTR(18, 8, 0);
157  myEMap[eid]=DetId(0x54000011);//NZDC EM1
158 
159  eid = HcalElectronicsId(1,1,1,3);
160  eid.setHTR(18, 8, 0);
161  myEMap[eid]=DetId(0x54000012);//NZDC EM2
162 
163  eid = HcalElectronicsId(2,1,1,3);
164  eid.setHTR(18, 8, 0);
165  myEMap[eid]=DetId(0x54000013);//NZDC EM3
166 
167  eid = HcalElectronicsId(0,2,1,3);
168  eid.setHTR(18, 8, 0);
169  myEMap[eid]=DetId(0x54000015);//NZDC EM5
170 
171  eid = HcalElectronicsId(1,2,1,3);
172  eid.setHTR(18, 8, 0);
173  myEMap[eid]=DetId(0x54000021);//NZDC HAD1
174 
175  eid = HcalElectronicsId(2,2,1,3);
176  eid.setHTR(18, 8, 0);
177  myEMap[eid]=DetId(0x54000014);//NZDC EM4
178 
179  eid = HcalElectronicsId(0,3,1,3);
180  eid.setHTR(18, 8, 0);
181  myEMap[eid]=DetId(0x54000022);//NZDC HAD2
182 
183  eid = HcalElectronicsId(1,3,1,3);
184  eid.setHTR(18, 8, 0);
185  myEMap[eid]=DetId(0x54000023);//NZDC HAD3
186 
187  eid = HcalElectronicsId(2,3,1,3);
188  eid.setHTR(18, 8, 0);
189  myEMap[eid]=DetId(0x54000024);//NZDC HAD4
190 
191  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
192  {
193  if (!dccHeader->getSpigotPresent(spigot)) continue;
194  int retval=dccHeader->getSpigotData(spigot,htr,raw.size());
195  if (retval!=0) {
196  if (retval==-1) {
197  if (!silent) edm::LogWarning("Invalid Data") << "Invalid HTR data (data beyond payload size) observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
198  report.countSpigotFormatError();
199  }
200  continue;
201  }
202  // check
203  if (dccHeader->getSpigotCRCError(spigot)) {
204  if (!silent)
205  edm::LogWarning("Invalid Data") << "CRC Error on HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
206  report.countSpigotFormatError();
207  continue;
208  }
209  if (!htr.check()) {
210  if (!silent)
211  edm::LogWarning("Invalid Data") << "Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
212  report.countSpigotFormatError();
213  continue;
214  }
215  if (htr.isHistogramEvent()) {
216  if (!silent)
217  edm::LogWarning("Invalid Data") << "Histogram data passed to non-histogram unpacker on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
218  continue;
219 
220  }
221  if ((htr.getFirmwareFlavor()&0xE0)==0x80) { // some kind of TTP data
222  if (colls.ttp!=nullptr) {
223  HcalTTPUnpacker ttpUnpack;
224  colls.ttp->push_back(HcalTTPDigi());
225  ttpUnpack.unpack(htr,colls.ttp->back());
226  } else {
227  LogDebug("ZdcUnpackerHcalTechTrigProcessor") << "Skipping data on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << " which is from the TechTrigProcessor (use separate unpacker!)";
228  }
229  continue;
230  }
231  if (htr.getFirmwareFlavor()>=0x80) {
232  if (!silent) edm::LogWarning("ZdcUnpacker") << "Skipping data on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << " which is of unknown flavor " << htr.getFirmwareFlavor();
233  continue;
234  }
235  // calculate "real" number of presamples
236  int nps=htr.getNPS()-startSample_;
237 
238  // get pointers
239  htr.dataPointers(&daq_first,&daq_last,&tp_first,&tp_last);
240  unsigned int smid=htr.getSubmodule();
241  int htr_tb=smid&0x1;
242  int htr_slot=(smid>>1)&0x1F;
243  int htr_cr=(smid>>6)&0x1F;
244 
245 
246  const unsigned short* ptr_header=daq_first;
247  const unsigned short* ptr_end=daq_last+1;
248  int flavor, error_flags, capid0, channelid;
249 
250  while (ptr_header!=ptr_end) {
251  if (*ptr_header==0xFFFF) { // impossible filler word
252  ptr_header++;
253  continue;
254  }
255  // unpack the header word
256  bool isheader=HcalHTRData::unpack_per_channel_header(*ptr_header,flavor,error_flags,capid0,channelid);
257  if (!isheader) {
258  ptr_header++;
259  continue;
260  }
261  int fiberchan=channelid&0x3;
262  int fiber=((channelid>>2)&0x7)+1;
263 
264  // lookup the right channel
265  HcalElectronicsId eid(fiberchan,fiber,spigot,dccid);
266  eid.setHTR(htr_cr,htr_slot,htr_tb);
267  auto it = myEMap.find(eid);
268  DetId did;
269  if (it != myEMap.end())
270  {
271  did = it->second;
272  }
273 
274  if (!did.null()) {
275  if (did.det()==DetId::Calo && did.subdetId()==HcalZDCDetId::SubdetectorId) {
276  colls.zdcCont->push_back(ZDCDataFrame(HcalZDCDetId(did)));
277  ptr_header=ZdcUnpacker_impl::unpack_compact<ZDCDataFrame>(ptr_header, ptr_end, colls.zdcCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
278  }
279  } else {
280  report.countUnmappedDigi(eid);
281  for (ptr_header++;
282  ptr_header!=ptr_end && !HcalHTRData::is_channel_header(*ptr_header);
283  ptr_header++);
284  }
285 
286  }
287  }//end of loop over spigots
288 }
#define LogDebug(id)
constexpr void setHTR(int crate, int slot, int tb)
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:62
constexpr bool null() const
is this a null id ?
Definition: DetId.h:52
bool getSpigotCRCError(unsigned int nspigot) const
Read the "CRC-Mismatch" bit for this spigot.
int startSample_
first sample from fed raw data to copy
Definition: ZdcUnpacker.h:29
static bool unpack_per_channel_header(unsigned short, int &flav, int &error_flags, int &capid0, int &channelid)
Unpack a per-channel header word (compact format)
Definition: HcalHTRData.cc:434
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
static bool is_channel_header(unsigned short value)
check top bit to see if this is a compact format channel header word
Definition: HcalHTRData.h:90
int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
Definition: ZdcUnpacker.h:31
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
bool getSpigotPresent(unsigned int nspigot) const
Read the "PRESENT" bit for this spigot.
int sourceIdOffset_
number to subtract from the source id to get the dcc id
Definition: ZdcUnpacker.h:28
int getSourceId() const
Definition: HcalDCCHeader.h:32
Definition: DetId.h:18
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
void dataPointers(const unsigned short **daq_first, const unsigned short **daq_last, const unsigned short **tp_first, const unsigned short **tp_last) const
Obtain the starting and ending pointers for external unpacking of the data.
Definition: HcalHTRData.cc:154
bool unpack(const HcalHTRData &data, HcalTTPDigi &digi)
int getNPS() const
Get the number of presamples in daq data.
Definition: HcalHTRData.cc:401
int endSample_
last sample from fed raw data to copy (if present)
Definition: ZdcUnpacker.h:30
int getFirmwareFlavor() const
Get the HTR firmware flavor.
Definition: HcalHTRData.cc:410
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
unsigned int getSubmodule() const
Get the HTR submodule number.
Definition: HcalHTRData.cc:332
Readout chain identification for Hcal.
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:386
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39
void ZdcUnpacker::unpackOld ( const FEDRawData raw,
const HcalElectronicsMap emap,
CastorRawCollections conts,
HcalUnpackerReport report,
bool  silent = false 
)

Member Data Documentation

int ZdcUnpacker::endSample_
private

last sample from fed raw data to copy (if present)

Definition at line 30 of file ZdcUnpacker.h.

Referenced by unpack(), and ZdcUnpacker().

int ZdcUnpacker::expectedOrbitMessageTime_
private

Expected orbit bunch time (needed to evaluate time differences)

Definition at line 31 of file ZdcUnpacker.h.

Referenced by setExpectedOrbitMessageTime(), and unpack().

int ZdcUnpacker::mode_
private

Definition at line 33 of file ZdcUnpacker.h.

int ZdcUnpacker::sourceIdOffset_
private

number to subtract from the source id to get the dcc id

Definition at line 28 of file ZdcUnpacker.h.

Referenced by unpack().

int ZdcUnpacker::startSample_
private

first sample from fed raw data to copy

Definition at line 29 of file ZdcUnpacker.h.

Referenced by unpack(), and ZdcUnpacker().

std::set<HcalElectronicsId> ZdcUnpacker::unknownIds_
private

Definition at line 32 of file ZdcUnpacker.h.

std::set<HcalElectronicsId> ZdcUnpacker::unknownIdsTrig_
private

Recorded to limit number of times a log message is generated.

Definition at line 32 of file ZdcUnpacker.h.