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 
12 namespace sistrip {
13 
14  //
15  // Class definitions
16  //
17 
18  //class representing standard (non-spy channel) FED buffers
19  class FEDBuffer : public FEDBufferBase
20  {
21  public:
22  //construct from buffer
23  //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
24  FEDBuffer(const uint8_t* fedBuffer, const size_t fedBufferSize, const bool allowBadBuffer = false);
25  virtual ~FEDBuffer();
26  virtual void print(std::ostream& os) const;
27  const FEDFEHeader* feHeader() const;
28  //check that a FE unit is enabled, has a good majority address and, if in full debug mode, that it is present
29  bool feGood(const uint8_t internalFEUnitNum) const;
30  //check that a FE unit is present in the data.
31  //The high order byte of the FEDStatus register in the tracker special header is used in APV error mode.
32  //The FE length from the full debug header is used in full debug mode.
33  bool fePresent(uint8_t internalFEUnitNum) const;
34  //check that a channel is present in data, found, on a good FE unit and has no errors flagged in status bits
35  virtual bool channelGood(const uint8_t internalFEDannelNum) const;
36 
37  //functions to check buffer. All return true if there is no problem.
38  //minimum checks to do before using buffer
39  virtual bool doChecks() const;
40 
41  //additional checks to check for corrupt buffers
42  //check channel lengths fit inside to buffer length
43  bool checkChannelLengths() const;
44  //check that channel lengths add up to buffer length (this does the previous check as well)
46  //check channel packet codes match readout mode
47  bool checkChannelPacketCodes() const;
48  //check FE unit lengths in FULL DEBUG header match the lengths of their channels
49  bool checkFEUnitLengths() const;
50  //check FE unit APV addresses in FULL DEBUG header are equal to the APVe address if the majority was good
51  bool checkFEUnitAPVAddresses() const;
52  //do all corrupt buffer checks
53  virtual bool doCorruptBufferChecks() const;
54 
55  //check that there are no errors in channel, APV or FEUnit status bits
56  //these are done by channelGood(). Channels with bad status bits may be disabled so bad status bits do not usually indicate an error
57  bool checkStatusBits(const uint8_t internalFEDChannelNum) const;
58  bool checkStatusBits(const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const;
59  //same but for all channels on enabled FE units
60  bool checkAllChannelStatusBits() const;
61 
62  //check that all FE unit payloads are present
63  bool checkFEPayloadsPresent() const;
64 
65  //print a summary of all checks
66  virtual std::string checkSummary() const;
67  private:
68  uint8_t nFEUnitsPresent() const;
69  void findChannels();
70  uint8_t getCorrectPacketCode() const;
71  uint16_t calculateFEUnitLength(const uint8_t internalFEUnitNumber) const;
72  std::auto_ptr<FEDFEHeader> feHeader_;
73  const uint8_t* payloadPointer_;
74  uint16_t payloadLength_;
75  uint8_t validChannels_;
77  };
78 
79  //class for unpacking data from ZS FED channels
81  {
82  public:
86  uint8_t sampleNumber() const;
87  uint8_t adc() const;
88  bool hasData() const;
91  private:
92  //pointer to begining of FED or FE data, offset of start of channel payload in data and length of channel payload
93  FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength);
94  void readNewClusterInfo();
95  static void throwBadChannelLength(const uint16_t length);
96  void throwBadClusterLength();
97  static void throwUnorderedData(const uint8_t currentStrip, const uint8_t firstStripOfNewCluster);
98  const uint8_t* data_;
100  uint8_t currentStrip_;
104  };
105 
106  //class for unpacking data from raw FED channels
108  {
109  public:
110  static FEDRawChannelUnpacker scopeModeUnpacker(const FEDChannel& channel) { return FEDRawChannelUnpacker(channel); }
112  static FEDRawChannelUnpacker procRawModeUnpacker(const FEDChannel& channel) { return FEDRawChannelUnpacker(channel); }
113  explicit FEDRawChannelUnpacker(const FEDChannel& channel);
114  uint8_t sampleNumber() const;
115  uint16_t adc() const;
116  bool hasData() const;
119  private:
120  static void throwBadChannelLength(const uint16_t length);
121  const uint8_t* data_;
123  uint8_t currentStrip_;
124  uint16_t valuesLeft_;
125  };
126 
127  //
128  // Inline function definitions
129  //
130 
131  //FEDBuffer
132 
133  inline const FEDFEHeader* FEDBuffer::feHeader() const
134  {
135  return feHeader_.get();
136  }
137 
138  inline bool FEDBuffer::feGood(const uint8_t internalFEUnitNum) const
139  {
140  return ( !majorityAddressErrorForFEUnit(internalFEUnitNum) && !feOverflow(internalFEUnitNum) && fePresent(internalFEUnitNum) );
141  }
142 
143  inline bool FEDBuffer::fePresent(uint8_t internalFEUnitNum) const
144  {
145  return fePresent_[internalFEUnitNum];
146  }
147 
148  inline bool FEDBuffer::checkStatusBits(const uint8_t internalFEDChannelNum) const
149  {
150  return feHeader_->checkChannelStatusBits(internalFEDChannelNum);
151  }
152 
153  inline bool FEDBuffer::checkStatusBits(const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const
154  {
155  return checkStatusBits(internalFEDChannelNum(internalFEUnitNum,internalChannelNum));
156  }
157 
158  //FEDRawChannelUnpacker
159 
161  : data_(channel.data()),
162  currentOffset_(channel.offset()+3),
163  currentStrip_(0),
164  valuesLeft_((channel.length()-3)/2)
165  {
166  if ((channel.length()-3)%2) throwBadChannelLength(channel.length());
167  }
168 
169  inline uint8_t FEDRawChannelUnpacker::sampleNumber() const
170  {
171  return currentStrip_;
172  }
173 
174  inline uint16_t FEDRawChannelUnpacker::adc() const
175  {
176  return ( data_[currentOffset_^7] + ((data_[(currentOffset_+1)^7]&0x03)<<8) );
177  }
178 
179  inline bool FEDRawChannelUnpacker::hasData() const
180  {
181  return valuesLeft_;
182  }
183 
185  {
186  currentOffset_ += 2;
187  currentStrip_++;
188  valuesLeft_--;
189  return (*this);
190  }
191 
193  {
194  ++(*this); return *this;
195  }
196 
197  //FEDZSChannelUnpacker
198 
200  : data_(NULL),
201  valuesLeftInCluster_(0),
202  channelPayloadOffset_(0),
203  channelPayloadLength_(0)
204  { }
205 
206  inline FEDZSChannelUnpacker::FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength)
207  : data_(payload),
208  currentOffset_(channelPayloadOffset),
209  currentStrip_(0),
210  valuesLeftInCluster_(0),
211  channelPayloadOffset_(channelPayloadOffset),
212  channelPayloadLength_(channelPayloadLength)
213  {
215  }
216 
218  {
219  uint16_t length = channel.length();
220  if (length & 0xF000) throwBadChannelLength(length);
221  FEDZSChannelUnpacker result(channel.data(),channel.offset()+7,length-7);
222  return result;
223  }
224 
226  {
227  uint16_t length = channel.length();
228  if (length & 0xF000) throwBadChannelLength(length);
229  FEDZSChannelUnpacker result(channel.data(),channel.offset()+2,length-2);
230  return result;
231  }
232 
233  inline uint8_t FEDZSChannelUnpacker::sampleNumber() const
234  {
235  return currentStrip_;
236  }
237 
238  inline uint8_t FEDZSChannelUnpacker::adc() const
239  {
240  return data_[currentOffset_^7];
241  }
242 
243  inline bool FEDZSChannelUnpacker::hasData() const
244  {
246  }
247 
249  {
250  if (valuesLeftInCluster_) {
251  currentStrip_++;
252  currentOffset_++;
254  } else {
255  currentOffset_++;
256  if (hasData()) {
257  const uint8_t oldStrip = currentStrip_;
259  if ( !(currentStrip_ > oldStrip) ) throwUnorderedData(oldStrip,currentStrip_);
260  }
261  }
262  return (*this);
263  }
264 
266  {
267  ++(*this); return *this;
268  }
269 
271  {
274  }
275 
276 }
277 
278 #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)
virtual bool doChecks() const
const FEDFEHeader * feHeader() 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 bool channelGood(const uint8_t internalFEDannelNum) const
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
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