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 ( int  sourceIdOffset,
int  beg,
int  end 
)

for normal data

Definition at line 51 of file CastorUnpacker.cc.

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

51  : sourceIdOffset_(sourceIdOffset) , expectedOrbitMessageTime_(-1)
52 {
53  if ( beg >= 0 && beg <= CastorDataFrame::MAXSAMPLES -1 ) {
54  startSample_ = beg;
55  } else {
56  startSample_ = 0;
57  }
58  if ( end >= 0 && end <= CastorDataFrame::MAXSAMPLES -1 && end >= beg ) {
59  endSample_ = end;
60  } else {
62  }
63 }
#define end
Definition: vmac.h:39
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

void CastorUnpacker::setExpectedOrbitMessageTime ( int  time)
inline

Definition at line 20 of file CastorUnpacker.h.

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

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

int expectedOrbitMessageTime_
Expected orbit bunch time (needed to evaluate time differences)
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 71 of file CastorUnpacker.cc.

References CastorRawCollections::castorCont, HcalHTRData::check(), HcalUnpackerReport::countSpigotFormatError(), HcalUnpackerReport::countUnmappedDigi(), 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(), HcalCastorDetId::module(), DetId::null(), HcalTriggerPrimitiveSample::raw(), HcalQIESample::raw(), HcalCastorDetId::sector(), CastorElectronicsId::setHTR(), FEDRawData::size(), slb(), slbAndChan(), slbChan(), sourceIdOffset_, HcalDCCHeader::SPIGOT_COUNT, startSample_, CastorRawCollections::tpCont, CastorRawCollections::ttp, unknownIds_, HcalTTPUnpacker::unpack(), HcalHTRData::wasMarkAndPassZSTP(), and HcalCastorDetId::zside().

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

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

Member Data Documentation

int CastorUnpacker::endSample_
private

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

Definition at line 27 of file CastorUnpacker.h.

Referenced by CastorUnpacker(), and unpack().

int CastorUnpacker::expectedOrbitMessageTime_
private

Expected orbit bunch time (needed to evaluate time differences)

Definition at line 28 of file CastorUnpacker.h.

Referenced by setExpectedOrbitMessageTime(), and unpack().

int CastorUnpacker::sourceIdOffset_
private

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

Definition at line 25 of file CastorUnpacker.h.

Referenced by unpack().

int CastorUnpacker::startSample_
private

first sample from fed raw data to copy

Definition at line 26 of file CastorUnpacker.h.

Referenced by CastorUnpacker(), and unpack().

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

Definition at line 29 of file CastorUnpacker.h.

Referenced by unpack().

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

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

Definition at line 29 of file CastorUnpacker.h.