CMS 3D CMS Logo

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

#include <CastorUnpacker.h>

Public Member Functions

 CastorUnpacker (int sourceIdOffset, int beg, int end)
 for normal data More...
 
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...
 

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 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< CastorElectronicsIdunknownIds_
 
std::set< CastorElectronicsIdunknownIdsTrig_
 Recorded to limit number of times a log message is generated. More...
 

Detailed Description

Definition at line 15 of file CastorUnpacker.h.

Constructor & Destructor Documentation

◆ CastorUnpacker()

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

for normal data

Definition at line 57 of file CastorUnpacker.cc.

References mps_fire::end, endSample_, CastorDataFrame::MAXSAMPLES, and startSample_.

58  : sourceIdOffset_(sourceIdOffset), expectedOrbitMessageTime_(-1) {
59  if (beg >= 0 && beg <= CastorDataFrame::MAXSAMPLES - 1) {
60  startSample_ = beg;
61  } else {
62  startSample_ = 0;
63  }
64  if (end >= 0 && end <= CastorDataFrame::MAXSAMPLES - 1 && end >= beg) {
65  endSample_ = end;
66  } else {
68  }
69 }
int sourceIdOffset_
number to subtract from the source id to get the dcc id
int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
static const int MAXSAMPLES
int startSample_
first sample from fed raw data to copy
int endSample_
last sample from fed raw data to copy (if present)

Member Function Documentation

◆ setExpectedOrbitMessageTime()

void CastorUnpacker::setExpectedOrbitMessageTime ( int  time)
inline

Definition at line 19 of file CastorUnpacker.h.

References expectedOrbitMessageTime_, and protons_cff::time.

Referenced by CastorRawToDigi::beginRun(), and CastorRawToDigi::CastorRawToDigi().

int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)

◆ unpack()

void CastorUnpacker::unpack ( const FEDRawData raw,
const CastorElectronicsMap emap,
CastorRawCollections conts,
HcalUnpackerReport report,
bool  silent = false 
)

For histograms, no begin and end.

work through the samples

work through the samples

Definition at line 75 of file CastorUnpacker.cc.

References CastorRawCollections::castorCont, HcalHTRData::check(), FEDRawData::data(), HcalHTRData::dataPointers(), runTauDisplay::eid, endSample_, expectedOrbitMessageTime_, HcalQIESample::fiber(), HcalQIESample::fiberAndChan(), HcalQIESample::fiberChan(), HcalHTRData::getFirmwareFlavor(), HcalHTRData::getFormatVersion(), HcalHTRData::getNPS(), HcalDCCHeader::getSourceId(), HcalDCCHeader::getSpigotCRCError(), HcalDCCHeader::getSpigotData(), HcalDCCHeader::getSpigotPresent(), HcalHTRData::getSubmodule(), triggerObjects_cff::id, globals_cff::id1, HcalHTRData::isHistogramEvent(), isTPGSOI(), HcalHTRData::isUnsuppressed(), LogDebug, CastorElectronicsMap::lookup(), DetId::null(), HcalTriggerPrimitiveSample::raw(), HcalQIESample::raw(), edmIntegrityCheck::report, CastorRawToDigi_cfi::silent, FEDRawData::size(), slb(), slbAndChan(), slbChan(), sourceIdOffset_, HcalDCCHeader::SPIGOT_COUNT, startSample_, CastorRawCollections::tpCont, CastorRawCollections::ttp, unknownIds_, HcalTTPUnpacker::unpack(), validateGeometry_cfg::valid, and HcalHTRData::wasMarkAndPassZSTP().

Referenced by CastorRawToDigi::produce().

79  {
80  if (raw.size() < 16) {
81  if (!silent)
82  edm::LogWarning("Invalid Data") << "Empty/invalid DCC data, size = " << raw.size();
83  return;
84  }
85 
86  // get the DCC header
87  const HcalDCCHeader* dccHeader = (const HcalDCCHeader*)(raw.data());
88  int dccid = dccHeader->getSourceId() - sourceIdOffset_;
89 
90  // check the summary status
91 
92  // walk through the HTR data...
93  HcalHTRData htr;
94  const unsigned short *daq_first, *daq_last, *tp_first, *tp_last;
95  const HcalQIESample *qie_begin, *qie_end, *qie_work;
96  const HcalTriggerPrimitiveSample *tp_begin, *tp_end, *tp_work;
97  for (int spigot = 0; spigot < HcalDCCHeader::SPIGOT_COUNT; spigot++) {
98  if (!dccHeader->getSpigotPresent(spigot))
99  continue;
100 
101  int retval = dccHeader->getSpigotData(spigot, htr, raw.size());
102  if (retval != 0) {
103  if (retval == -1) {
104  if (!silent)
105  edm::LogWarning("Invalid Data") << "Invalid HTR data (data beyond payload size) observed on spigot " << spigot
106  << " of DCC with source id " << dccHeader->getSourceId();
107  report.countSpigotFormatError();
108  }
109  continue;
110  }
111  // check
112  if (dccHeader->getSpigotCRCError(spigot)) {
113  if (!silent)
114  edm::LogWarning("Invalid Data") << "CRC Error on HTR data observed on spigot " << spigot
115  << " of DCC with source id " << dccHeader->getSourceId();
116  report.countSpigotFormatError();
117  continue;
118  }
119  if (!htr.check()) {
120  if (!silent)
121  edm::LogWarning("Invalid Data") << "Invalid HTR data observed on spigot " << spigot << " of DCC with source id "
122  << dccHeader->getSourceId();
123  report.countSpigotFormatError();
124  continue;
125  }
126  if (htr.isHistogramEvent()) {
127  if (!silent)
128  edm::LogWarning("Invalid Data") << "Histogram data passed to non-histogram unpacker on spigot " << spigot
129  << " of DCC with source id " << dccHeader->getSourceId();
130  continue;
131  }
132  if ((htr.getFirmwareFlavor() & 0xE0) == 0x80) { // some kind of TTP data
133  if (colls.ttp != nullptr) {
134  HcalTTPUnpacker ttpUnpack;
135  colls.ttp->push_back(HcalTTPDigi());
136  ttpUnpack.unpack(htr, colls.ttp->back());
137  } else {
138  LogDebug("CastorUnpackerHcalTechTrigProcessor")
139  << "Skipping data on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId()
140  << " which is from the TechTrigProcessor (use separate unpacker!)";
141  }
142  continue;
143  }
144  if (htr.getFirmwareFlavor() >= 0x80) {
145  if (!silent)
146  edm::LogWarning("CastorUnpacker")
147  << "Skipping data on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId()
148  << " which is of unknown flavor " << htr.getFirmwareFlavor();
149  continue;
150  }
151  // calculate "real" number of presamples
152  int nps = htr.getNPS() - startSample_;
153 
154  // get pointers
155  htr.dataPointers(&daq_first, &daq_last, &tp_first, &tp_last);
156  unsigned int smid = htr.getSubmodule();
157  int htr_tb = smid & 0x1;
158  int htr_slot = (smid >> 1) & 0x1F;
159  int htr_cr = (smid >> 6) & 0x1F;
160 
161  tp_begin = (const HcalTriggerPrimitiveSample*)tp_first;
162  tp_end = (const HcalTriggerPrimitiveSample*)(tp_last + 1); // one beyond last..
163 
165  int currFiberChan = 0x3F; // invalid fiber+channel...
166  int ncurr = 0;
167  bool valid = false;
169  bool tpgSOIbitInUse = htr.getFormatVersion() >= 3; // version 3 and later
170  // bool isHOtpg=htr.getFormatVersion()>=3 && htr.getFirmwareFlavor()==0; // HO is flavor zero
171  int npre = 0;
172  /*
173  Unpack the trigger primitives
174  */
175  // lookup the right channel
176  bool dotp = true;
177  CastorElectronicsId eid(0, 1, spigot, dccid);
178  eid.setHTR(htr_cr, htr_slot, htr_tb);
179  DetId did = emap.lookup(eid);
180  if (did.null())
181  dotp = false;
182  HcalCastorDetId id1(did);
183  HcalCastorDetId id((id1.zside() == 0), id1.sector(), 1);
184  if (id1.module() > 12)
185  dotp = false;
186  if (dotp) {
187  // std::cout << " tp_first="<< tp_first << " tp_last="<< tp_last<< " tb="<<htr_tb<<" slot="<<htr_slot<<" crate="<<htr_cr<<" dccid="<< dccid<< std::endl;
188  // regular TPs (not HO)
189  for (tp_work = tp_begin; tp_work != tp_end; tp_work++) {
190  // std::cout << "raw=0x"<<std::hex<< tp_work->raw()<<std::dec <<std::endl;
191  if (tp_work->raw() == 0xFFFF)
192  continue; // filler word
193  if (slbAndChan(*tp_work) != currFiberChan) { // start new set
194  npre = 0;
195  currFiberChan = slbAndChan(*tp_work);
196 
197  // std::cout<< " NEW SET "<<std::endl;
198  //HcalElectronicsId eid(tp_work->slbChan(),tp_work->slb(),spigot,dccid,htr_cr,htr_slot,htr_tb);
199  //DetId did=emap.lookupTrigger(eid);
200  //if (did.null()) {
201  //report.countUnmappedTPDigi(eid);
202  //if (unknownIdsTrig_.find(eid)==unknownIdsTrig_.end()) {
203  //if (!silent) edm::LogWarning("HCAL") << "HcalUnpacker: No trigger primitive match found for electronics id :" << eid;
204  //unknownIdsTrig_.insert(eid);
205  //}
206  //valid=false;
207  //continue;
208  //} else if (did==HcalTrigTowerDetId::Undefined ||
209  //(did.det()==DetId::Hcal && did.subdetId()==0)) {
211  //valid=false;
212  //continue;
213  //}
214 
215  colls.tpCont->push_back(CastorTriggerPrimitiveDigi(id));
216  // set the various bits
217  if (!tpgSOIbitInUse)
218  colls.tpCont->back().setPresamples(nps);
219  colls.tpCont->back().setZSInfo(htr.isUnsuppressed(),
220  htr.wasMarkAndPassZSTP(slb(*tp_work), slbChan(*tp_work)));
221 
222  // no hits recorded for current
223  ncurr = 0;
224  valid = true;
225  }
226  // add the word (if within settings or recent firmware [recent firmware ignores startSample/endSample])
227  if (valid && ((tpgSOIbitInUse && ncurr < 10) || (ncurr >= startSample_ && ncurr <= endSample_))) {
228  colls.tpCont->back().setSample(colls.tpCont->back().size(), *tp_work);
229  colls.tpCont->back().setSize(colls.tpCont->back().size() + 1);
230  }
231  // set presamples,if SOI
232  if (valid && tpgSOIbitInUse && isTPGSOI(*tp_work)) {
233  colls.tpCont->back().setPresamples(ncurr);
234  }
235  ncurr++;
236  npre++;
237  }
238  }
239 
241  qie_begin = (const HcalQIESample*)daq_first;
242  qie_end = (const HcalQIESample*)(daq_last + 1); // one beyond last..
243 
245 
246  for (qie_work = qie_begin; qie_work != qie_end;) {
247  if (qie_work->raw() == 0xFFFF) {
248  qie_work++;
249  continue; // filler word
250  }
251 
252  // lookup the right channel
253  CastorElectronicsId eid(qie_work->fiberChan(), qie_work->fiber(), spigot, dccid);
254  eid.setHTR(htr_cr, htr_slot, htr_tb);
255  DetId did = emap.lookup(eid);
256 
257  if (!did.null()) {
258  colls.castorCont->push_back(CastorDataFrame(HcalCastorDetId(did)));
259  qie_work = CastorUnpacker_impl::unpack<CastorDataFrame>(qie_work,
260  qie_end,
261  colls.castorCont->back(),
262  nps,
263  eid,
264  startSample_,
265  endSample_,
267  htr);
268  } else {
269  report.countUnmappedDigi();
270  if (unknownIds_.find(eid) == unknownIds_.end()) {
271  if (!silent)
272  edm::LogWarning("CASTOR") << "CastorUnpacker: No match found for electronics id :" << eid;
273  unknownIds_.insert(eid);
274  }
275  for (int fiberC = qie_work->fiberAndChan(); qie_work != qie_end && qie_work->fiberAndChan() == fiberC;
276  qie_work++)
277  ;
278  }
279  }
280  }
281 }
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:409
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
static int slb(const HcalTriggerPrimitiveSample &theSample)
constexpr int fiberChan() const
get the fiber channel number
Definition: HcalQIESample.h:55
static bool isTPGSOI(const HcalTriggerPrimitiveSample &s)
int getNPS() const
Get the number of presamples in daq data.
Definition: HcalHTRData.cc:426
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
static int slbChan(const HcalTriggerPrimitiveSample &theSample)
int getFirmwareFlavor() const
Get the HTR firmware flavor.
Definition: HcalHTRData.cc:433
std::set< CastorElectronicsId > unknownIds_
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:161
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
uint16_t raw() const
get the raw word
static int slbAndChan(const HcalTriggerPrimitiveSample &theSample)
int getSourceId() const
Definition: HcalDCCHeader.h:32
int getFormatVersion() const
Get the version number of this event.
Definition: HcalHTRData.h:36
bool wasMarkAndPassZSTP(int slb, int slbchan) const
Was this channel passed as part of Mark&Pass ZS?
Definition: HcalHTRData.cc:389
Definition: DetId.h:17
int sourceIdOffset_
number to subtract from the source id to get the dcc id
constexpr uint16_t raw() const
get the raw word
Definition: HcalQIESample.h:41
int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
bool getSpigotCRCError(unsigned int nspigot) const
Read the "CRC-Mismatch" bit for this spigot.
constexpr int fiber() const
get the fiber number
Definition: HcalQIESample.h:53
bool unpack(const HcalHTRData &data, HcalTTPDigi &digi)
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
bool getSpigotPresent(unsigned int nspigot) const
Read the "PRESENT" bit for this spigot.
Readout chain identification for Castor Bits for the readout chain : some names need change! [31:26] ...
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
unsigned int getSubmodule() const
Get the HTR submodule number.
Definition: HcalHTRData.cc:355
Log< level::Warning, false > LogWarning
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:63
int startSample_
first sample from fed raw data to copy
#define LogDebug(id)
int endSample_
last sample from fed raw data to copy (if present)
bool isUnsuppressed() const
Is this event an unsuppresed event?
Definition: HcalHTRData.cc:378

Member Data Documentation

◆ endSample_

int CastorUnpacker::endSample_
private

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

Definition at line 31 of file CastorUnpacker.h.

Referenced by CastorUnpacker(), and unpack().

◆ expectedOrbitMessageTime_

int CastorUnpacker::expectedOrbitMessageTime_
private

Expected orbit bunch time (needed to evaluate time differences)

Definition at line 32 of file CastorUnpacker.h.

Referenced by setExpectedOrbitMessageTime(), and unpack().

◆ sourceIdOffset_

int CastorUnpacker::sourceIdOffset_
private

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

Definition at line 29 of file CastorUnpacker.h.

Referenced by unpack().

◆ startSample_

int CastorUnpacker::startSample_
private

first sample from fed raw data to copy

Definition at line 30 of file CastorUnpacker.h.

Referenced by CastorUnpacker(), and unpack().

◆ unknownIds_

std::set<CastorElectronicsId> CastorUnpacker::unknownIds_
private

Definition at line 33 of file CastorUnpacker.h.

Referenced by unpack().

◆ unknownIdsTrig_

std::set<CastorElectronicsId> CastorUnpacker::unknownIdsTrig_
private

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

Definition at line 33 of file CastorUnpacker.h.