test
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:
89  uint8_t sampleNumber() const;
90  uint8_t adc() const;
91  bool hasData() const;
94  private:
95  //pointer to begining of FED or FE data, offset of start of channel payload in data and length of channel payload
96  FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength);
97  void readNewClusterInfo();
98  static void throwBadChannelLength(const uint16_t length);
99  void throwBadClusterLength();
100  static void throwUnorderedData(const uint8_t currentStrip, const uint8_t firstStripOfNewCluster);
101  const uint8_t* data_;
103  uint8_t currentStrip_;
107  };
108 
109  //class for unpacking data from raw FED channels
111  {
112  public:
113  static FEDRawChannelUnpacker scopeModeUnpacker(const FEDChannel& channel) { return FEDRawChannelUnpacker(channel); }
115  static FEDRawChannelUnpacker procRawModeUnpacker(const FEDChannel& channel) { return FEDRawChannelUnpacker(channel); }
116  explicit FEDRawChannelUnpacker(const FEDChannel& channel);
117  uint8_t sampleNumber() const;
118  uint16_t adc() const;
119  bool hasData() const;
122  private:
123  static void throwBadChannelLength(const uint16_t length);
124  const uint8_t* data_;
126  uint8_t currentStrip_;
127  uint16_t valuesLeft_;
128  };
129 
130  //
131  // Inline function definitions
132  //
133 
134  //FEDBuffer
135 
136  inline const FEDFEHeader* FEDBuffer::feHeader() const
137  {
138  return feHeader_.get();
139  }
140 
141  inline bool FEDBuffer::feGood(const uint8_t internalFEUnitNum) const
142  {
143  return ( !majorityAddressErrorForFEUnit(internalFEUnitNum) && !feOverflow(internalFEUnitNum) && fePresent(internalFEUnitNum) );
144  }
145 
146  inline bool FEDBuffer::feGoodWithoutAPVEmulatorCheck(const uint8_t internalFEUnitNum) const
147  {
148  return ( !feOverflow(internalFEUnitNum) && fePresent(internalFEUnitNum) );
149  }
150 
151  inline bool FEDBuffer::fePresent(uint8_t internalFEUnitNum) const
152  {
153  return fePresent_[internalFEUnitNum];
154  }
155 
156  inline bool FEDBuffer::checkStatusBits(const uint8_t internalFEDChannelNum) const
157  {
158  return feHeader_->checkChannelStatusBits(internalFEDChannelNum);
159  }
160 
161  inline bool FEDBuffer::checkStatusBits(const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const
162  {
163  return checkStatusBits(internalFEDChannelNum(internalFEUnitNum,internalChannelNum));
164  }
165 
166  //FEDRawChannelUnpacker
167 
169  : data_(channel.data()),
170  currentOffset_(channel.offset()+3),
171  currentStrip_(0),
172  valuesLeft_((channel.length()-3)/2)
173  {
174  if ((channel.length()-3)%2) throwBadChannelLength(channel.length());
175  }
176 
177  inline uint8_t FEDRawChannelUnpacker::sampleNumber() const
178  {
179  return currentStrip_;
180  }
181 
182  inline uint16_t FEDRawChannelUnpacker::adc() const
183  {
184  return ( data_[currentOffset_^7] + ((data_[(currentOffset_+1)^7]&0x03)<<8) );
185  }
186 
187  inline bool FEDRawChannelUnpacker::hasData() const
188  {
189  return valuesLeft_;
190  }
191 
193  {
194  currentOffset_ += 2;
195  currentStrip_++;
196  valuesLeft_--;
197  return (*this);
198  }
199 
201  {
202  ++(*this); return *this;
203  }
204 
205  //FEDZSChannelUnpacker
206 
208  : data_(NULL),
209  valuesLeftInCluster_(0),
210  channelPayloadOffset_(0),
211  channelPayloadLength_(0)
212  { }
213 
214  inline FEDZSChannelUnpacker::FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength)
215  : data_(payload),
216  currentOffset_(channelPayloadOffset),
217  currentStrip_(0),
218  valuesLeftInCluster_(0),
219  channelPayloadOffset_(channelPayloadOffset),
220  channelPayloadLength_(channelPayloadLength)
221  {
223  }
224 
226  {
227  uint16_t length = channel.length();
228  if (length & 0xF000) throwBadChannelLength(length);
229  FEDZSChannelUnpacker result(channel.data(),channel.offset()+7,length-7);
230  return result;
231  }
232 
234  {
235  uint16_t length = channel.length();
236  if (length & 0xF000) throwBadChannelLength(length);
237  FEDZSChannelUnpacker result(channel.data(),channel.offset()+2,length-2);
238  return result;
239  }
240 
241  inline uint8_t FEDZSChannelUnpacker::sampleNumber() const
242  {
243  return currentStrip_;
244  }
245 
246  inline uint8_t FEDZSChannelUnpacker::adc() const
247  {
248  return data_[currentOffset_^7];
249  }
250 
251  inline bool FEDZSChannelUnpacker::hasData() const
252  {
254  }
255 
257  {
258  if (valuesLeftInCluster_) {
259  currentStrip_++;
260  currentOffset_++;
262  } else {
263  currentOffset_++;
264  if (hasData()) {
265  const uint8_t oldStrip = currentStrip_;
267  if ( !(currentStrip_ > oldStrip) ) throwUnorderedData(oldStrip,currentStrip_);
268  }
269  }
270  return (*this);
271  }
272 
274  {
275  ++(*this); return *this;
276  }
277 
279  {
282  }
283 
284 }
285 
286 #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 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