CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:38
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_, and cond::rpcobgas::time.

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 66 of file CastorUnpacker.cc.

References CastorRawCollections::castorCont, HcalHTRData::check(), HcalUnpackerReport::countSpigotFormatError(), HcalUnpackerReport::countUnmappedDigi(), FEDRawData::data(), HcalHTRData::dataPointers(), endSample_, expectedOrbitMessageTime_, HcalQIESample::fiber(), HcalQIESample::fiberAndChan(), HcalQIESample::fiberChan(), HcalHTRData::getFirmwareFlavor(), HcalHTRData::getFormatVersion(), HcalHTRData::getNPS(), HcalDCCHeader::getSourceId(), HcalDCCHeader::getSpigotCRCError(), HcalDCCHeader::getSpigotData(), HcalDCCHeader::getSpigotPresent(), HcalHTRData::getSubmodule(), HcalHTRData::isHistogramEvent(), isTPGSOI(), HcalHTRData::isUnsuppressed(), LogDebug, CastorElectronicsMap::lookup(), HcalCastorDetId::module(), DetId::null(), HcalTriggerPrimitiveSample::raw(), HcalQIESample::raw(), HcalCastorDetId::sector(), CastorElectronicsId::setHTR(), FEDRawData::size(), HcalTriggerPrimitiveSample::slb(), HcalTriggerPrimitiveSample::slbAndChan(), HcalTriggerPrimitiveSample::slbChan(), sourceIdOffset_, HcalDCCHeader::SPIGOT_COUNT, startSample_, CastorRawCollections::tpCont, CastorRawCollections::ttp, unknownIds_, HcalTTPUnpacker::unpack(), TrackValidation_HighPurity_cff::valid, HcalHTRData::wasMarkAndPassZSTP(), and HcalCastorDetId::zside().

Referenced by CastorRawToDigi::produce().

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