CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripFEDBuffer.h
Go to the documentation of this file.
1 #ifndef EventFilter_SiStripRawToDigi_SiStripFEDBuffer_H
2 #define EventFilter_SiStripRawToDigi_SiStripFEDBuffer_H
3 
4 #include "boost/cstdint.hpp"
5 #include <string>
6 #include <vector>
7 #include <memory>
8 #include <ostream>
9 #include <cstring>
11 
13 
14 namespace sistrip {
15 
16  //
17  // Class definitions
18  //
19 
20  //class representing standard (non-spy channel) FED buffers
21  class FEDBuffer final : public FEDBufferBase
22  {
23  public:
24  //construct from buffer
25  //if allowBadBuffer is set to true then exceptions will not be thrown if the channel lengths do not make sense or the event format is not recognized
26  FEDBuffer(const uint8_t* fedBuffer, const size_t fedBufferSize, const bool allowBadBuffer = false);
27  virtual ~FEDBuffer();
28  virtual void print(std::ostream& os) const;
29  const FEDFEHeader* feHeader() const;
30  //check that a FE unit is enabled, has a good majority address and, if in full debug mode, that it is present
31  bool feGood(const uint8_t internalFEUnitNum) const;
32  bool feGoodWithoutAPVEmulatorCheck(const uint8_t internalFEUnitNum) const;
33  //check that a FE unit is present in the data.
34  //The high order byte of the FEDStatus register in the tracker special header is used in APV error mode.
35  //The FE length from the full debug header is used in full debug mode.
36  bool fePresent(uint8_t internalFEUnitNum) const;
37  //check that a channel is present in data, found, on a good FE unit and has no errors flagged in status bits
38  virtual bool channelGood(const uint8_t internalFEDannelNum, const bool doAPVeCheck=true) const;
39 
40  //functions to check buffer. All return true if there is no problem.
41  //minimum checks to do before using buffer
42  virtual bool doChecks(bool doCRC=true) const;
43 
44  //additional checks to check for corrupt buffers
45  //check channel lengths fit inside to buffer length
46  bool checkChannelLengths() const;
47  //check that channel lengths add up to buffer length (this does the previous check as well)
49  //check channel packet codes match readout mode
50  bool checkChannelPacketCodes() const;
51  //check FE unit lengths in FULL DEBUG header match the lengths of their channels
52  bool checkFEUnitLengths() const;
53  //check FE unit APV addresses in FULL DEBUG header are equal to the APVe address if the majority was good
54  bool checkFEUnitAPVAddresses() const;
55  //do all corrupt buffer checks
56  virtual bool doCorruptBufferChecks() const;
57 
58  //check that there are no errors in channel, APV or FEUnit status bits
59  //these are done by channelGood(). Channels with bad status bits may be disabled so bad status bits do not usually indicate an error
60  bool checkStatusBits(const uint8_t internalFEDChannelNum) const;
61  bool checkStatusBits(const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const;
62  //same but for all channels on enabled FE units
63  bool checkAllChannelStatusBits() const;
64 
65  //check that all FE unit payloads are present
66  bool checkFEPayloadsPresent() const;
67 
68  //print a summary of all checks
69  virtual std::string checkSummary() const;
70  private:
71  uint8_t nFEUnitsPresent() const;
72  void findChannels();
73  uint8_t getCorrectPacketCode() const;
74  uint16_t calculateFEUnitLength(const uint8_t internalFEUnitNumber) const;
75  std::auto_ptr<FEDFEHeader> feHeader_;
76  const uint8_t* payloadPointer_;
77  uint16_t payloadLength_;
78  uint8_t validChannels_;
80  };
81 
82  //class for unpacking data from ZS FED channels
84  {
85  public:
90  uint8_t sampleNumber() const;
91  uint8_t adc() const;
92  uint16_t adcPreMix() const;
93  bool hasData() const;
96  private:
97  //pointer to beginning of FED or FE data, offset of start of channel payload in data and length of channel payload
98  FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength, const size_t offsetIncrement=1);
99  void readNewClusterInfo();
100  static void throwBadChannelLength(const uint16_t length);
101  void throwBadClusterLength();
102  static void throwUnorderedData(const uint8_t currentStrip, const uint8_t firstStripOfNewCluster);
103  const uint8_t* data_;
106  uint8_t currentStrip_;
110  };
111 
112  //class for unpacking data from raw FED channels
114  {
115  public:
116  static FEDRawChannelUnpacker scopeModeUnpacker(const FEDChannel& channel) { return FEDRawChannelUnpacker(channel); }
118  static FEDRawChannelUnpacker procRawModeUnpacker(const FEDChannel& channel) { return FEDRawChannelUnpacker(channel); }
119  explicit FEDRawChannelUnpacker(const FEDChannel& channel);
120  uint8_t sampleNumber() const;
121  uint16_t adc() const;
122  bool hasData() const;
125  private:
126  static void throwBadChannelLength(const uint16_t length);
127  const uint8_t* data_;
129  uint8_t currentStrip_;
130  uint16_t valuesLeft_;
131  };
132 
133  //
134  // Inline function definitions
135  //
136 
137  //FEDBuffer
138 
139  inline const FEDFEHeader* FEDBuffer::feHeader() const
140  {
141  return feHeader_.get();
142  }
143 
144  inline bool FEDBuffer::feGood(const uint8_t internalFEUnitNum) const
145  {
146  return ( !majorityAddressErrorForFEUnit(internalFEUnitNum) && !feOverflow(internalFEUnitNum) && fePresent(internalFEUnitNum) );
147  }
148 
149  inline bool FEDBuffer::feGoodWithoutAPVEmulatorCheck(const uint8_t internalFEUnitNum) const
150  {
151  return ( !feOverflow(internalFEUnitNum) && fePresent(internalFEUnitNum) );
152  }
153 
154  inline bool FEDBuffer::fePresent(uint8_t internalFEUnitNum) const
155  {
156  return fePresent_[internalFEUnitNum];
157  }
158 
159  inline bool FEDBuffer::checkStatusBits(const uint8_t internalFEDChannelNum) const
160  {
161  return feHeader_->checkChannelStatusBits(internalFEDChannelNum);
162  }
163 
164  inline bool FEDBuffer::checkStatusBits(const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const
165  {
166  return checkStatusBits(internalFEDChannelNum(internalFEUnitNum,internalChannelNum));
167  }
168 
169  //FEDRawChannelUnpacker
170 
172  : data_(channel.data()),
173  currentOffset_(channel.offset()+3),
174  currentStrip_(0),
175  valuesLeft_((channel.length()-3)/2)
176  {
177  if ((channel.length()-3)%2) throwBadChannelLength(channel.length());
178  }
179 
180  inline uint8_t FEDRawChannelUnpacker::sampleNumber() const
181  {
182  return currentStrip_;
183  }
184 
185  inline uint16_t FEDRawChannelUnpacker::adc() const
186  {
187  return ( data_[currentOffset_^7] + ((data_[(currentOffset_+1)^7]&0x03)<<8) );
188  }
189 
190  inline bool FEDRawChannelUnpacker::hasData() const
191  {
192  return valuesLeft_;
193  }
194 
196  {
197  currentOffset_ += 2;
198  currentStrip_++;
199  valuesLeft_--;
200  return (*this);
201  }
202 
204  {
205  ++(*this); return *this;
206  }
207 
208  //FEDZSChannelUnpacker
209 
211  : data_(NULL),
212  offsetIncrement_(1),
213  valuesLeftInCluster_(0),
214  channelPayloadOffset_(0),
215  channelPayloadLength_(0)
216  { }
217 
218  inline FEDZSChannelUnpacker::FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength, const size_t offsetIncrement)
219  : data_(payload),
220  currentOffset_(channelPayloadOffset),
221  offsetIncrement_(offsetIncrement),
222  currentStrip_(0),
223  valuesLeftInCluster_(0),
224  channelPayloadOffset_(channelPayloadOffset),
225  channelPayloadLength_(channelPayloadLength)
226  {
228  }
229 
231  {
232  uint16_t length = channel.length();
233  if (length & 0xF000) throwBadChannelLength(length);
234  FEDZSChannelUnpacker result(channel.data(),channel.offset()+7,length-7);
235  return result;
236  }
237 
239  {
240  uint16_t length = channel.length();
241  if (length & 0xF000) throwBadChannelLength(length);
242  FEDZSChannelUnpacker result(channel.data(),channel.offset()+2,length-2);
243  return result;
244  }
245 
247  {
248  //CAMM - to modify more ?
249  uint16_t length = channel.length();
250  if (length & 0xF000) throwBadChannelLength(length);
251  FEDZSChannelUnpacker result(channel.data(),channel.offset()+7,length-7,2);
252  return result;
253  }
254 
255  inline uint8_t FEDZSChannelUnpacker::sampleNumber() const
256  {
257  return currentStrip_;
258  }
259 
260  inline uint8_t FEDZSChannelUnpacker::adc() const
261  {
262  return data_[currentOffset_^7];
263  }
264 
265  inline uint16_t FEDZSChannelUnpacker::adcPreMix() const
266  {
267  return ( data_[currentOffset_^7] + ((data_[(currentOffset_+1)^7]&0x03)<<8) );
268  }
269 
270  inline bool FEDZSChannelUnpacker::hasData() const
271  {
273  }
274 
276  {
277  if (valuesLeftInCluster_) {
278  currentStrip_++;
281  } else {
283  if (hasData()) {
284  const uint8_t oldStrip = currentStrip_;
286  if ( !(currentStrip_ > oldStrip) ) throwUnorderedData(oldStrip,currentStrip_);
287  }
288  }
289  return (*this);
290  }
291 
293  {
294  ++(*this); return *this;
295  }
296 
298  {
301  }
302 
303 }
304 
305 #endif //ndef EventFilter_SiStripRawToDigi_SiStripFEDBuffer_H
static FEDRawChannelUnpacker procRawModeUnpacker(const FEDChannel &channel)
std::auto_ptr< FEDFEHeader > feHeader_
bool checkFEUnitLengths() const
static FEDZSChannelUnpacker zeroSuppressedModeUnpacker(const FEDChannel &channel)
bool checkStatusBits(const uint8_t internalFEDChannelNum) const
static void throwBadChannelLength(const uint16_t length)
FEDBuffer(const uint8_t *fedBuffer, const size_t fedBufferSize, const bool allowBadBuffer=false)
virtual bool doCorruptBufferChecks() const
virtual void print(std::ostream &os) const
bool checkFEPayloadsPresent() const
static FEDZSChannelUnpacker preMixRawModeUnpacker(const FEDChannel &channel)
static FEDRawChannelUnpacker scopeModeUnpacker(const FEDChannel &channel)
static FEDRawChannelUnpacker virginRawModeUnpacker(const FEDChannel &channel)
FEDRawChannelUnpacker(const FEDChannel &channel)
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
#define NULL
Definition: scimark2.h:8
static void throwUnorderedData(const uint8_t currentStrip, const uint8_t firstStripOfNewCluster)
const FEDFEHeader * feHeader() const
virtual bool channelGood(const uint8_t internalFEDannelNum, const bool doAPVeCheck=true) const
bool feGoodWithoutAPVEmulatorCheck(const uint8_t internalFEUnitNum) const
bool fePresent_[FEUNITS_PER_FED]
const uint8_t * payloadPointer_
bool fePresent(uint8_t internalFEUnitNum) const
bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const
static const uint16_t FEUNITS_PER_FED
tuple result
Definition: query.py:137
virtual std::string checkSummary() const
unsigned int offset(bool)
FEDRawChannelUnpacker & operator++()
bool checkChannelPacketCodes() const
FEDZSChannelUnpacker & operator++()
static FEDZSChannelUnpacker zeroSuppressedLiteModeUnpacker(const FEDChannel &channel)
uint8_t nFEUnitsPresent() const
bool checkFEUnitAPVAddresses() const
const uint8_t * data() const
uint8_t getCorrectPacketCode() const
bool checkChannelLengthsMatchBufferLength() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool checkAllChannelStatusBits() const
static void throwBadChannelLength(const uint16_t length)
uint16_t calculateFEUnitLength(const uint8_t internalFEUnitNumber) const
bool checkChannelLengths() const
bool feGood(const uint8_t internalFEUnitNum) const
bool feOverflow(const uint8_t internalFEUnitNum) const