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