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:37
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 71 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(), slb(), slbAndChan(), slbChan(), sourceIdOffset_, HcalDCCHeader::SPIGOT_COUNT, startSample_, CastorRawCollections::tpCont, CastorRawCollections::ttp, unknownIds_, HcalTTPUnpacker::unpack(), HcalHTRData::wasMarkAndPassZSTP(), and HcalCastorDetId::zside().

Referenced by CastorRawToDigi::produce().

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!=0) {
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=(HcalTriggerPrimitiveSample*)tp_first;
145  tp_end=(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=(HcalQIESample*)daq_first;
220  qie_end=(HcalQIESample*)(daq_last+1); // one beyond last..
221 
223  currFiberChan=0x3F; // invalid fiber+channel...
224  ncurr=0;
225  valid=false;
226 
227  for (qie_work=qie_begin; qie_work!=qie_end; ) {
228  if (qie_work->raw()==0xFFFF) {
229  qie_work++;
230  continue; // filler word
231  }
232  // always at the beginning ...
233  currFiberChan=qie_work->fiberAndChan();
234 
235  // lookup the right channel
236  CastorElectronicsId eid(qie_work->fiberChan(),qie_work->fiber(),spigot,dccid);
237  eid.setHTR(htr_cr,htr_slot,htr_tb);
238  DetId did=emap.lookup(eid);
239 
240  if (!did.null()) {
241  colls.castorCont->push_back(CastorDataFrame(HcalCastorDetId(did)));
242  qie_work=CastorUnpacker_impl::unpack<CastorDataFrame>(qie_work, qie_end, colls.castorCont->back(), nps, eid, startSample_, endSample_, expectedOrbitMessageTime_, htr);
243  } else {
244  report.countUnmappedDigi();
245  if (unknownIds_.find(eid)==unknownIds_.end()) {
246  if (!silent)
247  edm::LogWarning("CASTOR") << "CastorUnpacker: No match found for electronics id :" << eid;
248  unknownIds_.insert(eid);
249  }
250  for (int fiberC=qie_work->fiberAndChan();
251  qie_work!=qie_end && qie_work->fiberAndChan()==fiberC;
252  qie_work++);
253  }
254  }
255  }
256 }
#define LogDebug(id)
uint16_t raw() const
get the raw word
Definition: HcalQIESample.h:20
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)
int fiberAndChan() const
get the id channel
Definition: HcalQIESample.h:36
int fiberChan() const
get the fiber channel number
Definition: HcalQIESample.h:34
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)
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:353
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
int fiber() const
get the fiber number
Definition: HcalQIESample.h:32
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; 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:153
bool unpack(const HcalHTRData &data, HcalTTPDigi &digi)
bool null() const
is this a null id ?
Definition: DetId.h:45
int getNPS() const
Get the number of presamples in daq data.
Definition: HcalHTRData.cc:400
int getFirmwareFlavor() const
Get the HTR firmware flavor.
Definition: HcalHTRData.cc:409
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
bool wasMarkAndPassZSTP(int slb, int slbchan) const
Was this channel passed as part of Mark&amp;Pass ZS?
Definition: HcalHTRData.cc:364
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
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:331
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:385
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.