CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/SiStripMonitorHardware/interface/SiStripFEDSpyBuffer.h

Go to the documentation of this file.
00001 #ifndef DQM_SiStripMonitorHardware_SiStripFEDSpyBuffer_H
00002 #define DQM_SiStripMonitorHardware_SiStripFEDSpyBuffer_H
00003 
00004 #include "boost/cstdint.hpp"
00005 #include <string>
00006 #include <ostream>
00007 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBufferComponents.h"
00008 
00009 namespace sistrip {
00010 
00011   //
00012   // Constants
00013   //
00014   
00015   static const uint16_t FEDCH_PER_DELAY_CHIP = 4;
00016   static const uint16_t DELAY_CHIPS_PER_FED = FEDCH_PER_FED/FEDCH_PER_DELAY_CHIP;
00017   static const uint16_t SPY_DELAY_CHIP_PAYLOAD_SIZE_IN_BYTES = 376*4;                                               // 376 32bit words
00018   static const uint16_t SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES = SPY_DELAY_CHIP_PAYLOAD_SIZE_IN_BYTES+8;               // Extra 8 bytes for counters
00019   static const uint16_t SPY_DELAYCHIP_DATA_OFFSET_IN_BITS = 44;                                                     // Offset to start of data
00020   //static const uint16_t SPY_SAMPLES_PER_CHANNEL = ( (SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES * 8) - SPY_DELAYCHIP_DATA_OFFSET_IN_BITS ) / 10 / FEDCH_PER_DELAY_CHIP;
00021   // TW Dirty hack to lose the 3 samples from the end that screw things up...
00022   static const uint16_t SPY_SAMPLES_PER_CHANNEL = 298;
00023   static const uint16_t SPY_BUFFER_SIZE_IN_BYTES = SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES * DELAY_CHIPS_PER_FED + 40;
00024   // Delaychip data + 8 bytes header for counters + 8 bytes for word with delay chip enable bits
00025   // + 16 bytes for DAQ header and trailer
00026   
00027   //
00028   // Class definitions
00029   //
00030 
00031   //class representing spy channel buffers
00032   class FEDSpyBuffer : public FEDBufferBase
00033   {
00034   public:
00035     //construct from buffer
00036     FEDSpyBuffer(const uint8_t* fedBuffer, const size_t fedBufferSize);
00037     virtual ~FEDSpyBuffer();
00038     virtual void print(std::ostream& os) const;
00039       
00040     //get the run number from the corresponding global run
00041     uint32_t globalRunNumber() const;
00042     //get the L1 ID stored in the spy header
00043     uint32_t spyHeaderL1ID() const;
00044     //get the total frame count stored in the spy header
00045     uint32_t spyHeaderTotalEventCount() const;
00046     //get the L1 ID after reading a given delay chip
00047     uint32_t delayChipL1ID(const uint8_t delayChip) const;
00048     //get the total event count after reading a given delay chip
00049     uint32_t delayChipTotalEventCount(const uint8_t delayChip) const;
00050       
00051     //checks that a delay chip is complete i.e. that it all came from the same event
00052     bool delayChipGood(const uint8_t delayChip) const;
00053     //checks that a channel is usable (i.e. that the delay chip it is on is good)
00054     virtual bool channelGood(const uint8_t internalFEDannelNum) const;
00055   private:
00056     //mapping of channel index to position in data
00057     static const uint8_t channelPositionsInData_[FEDCH_PER_DELAY_CHIP];
00058       
00059     //setup the channel objects
00060     void findChannels();
00061       
00062     const uint8_t* payloadPointer_;
00063     uint16_t payloadLength_;
00064     uint8_t versionId_;
00065   };
00066 
00067   class FEDSpyChannelUnpacker
00068   {
00069   public:
00070     explicit FEDSpyChannelUnpacker(const FEDChannel& channel);
00071     uint16_t sampleNumber() const;
00072     uint16_t adc() const;
00073     bool hasData() const;
00074     FEDSpyChannelUnpacker& operator ++ ();
00075     FEDSpyChannelUnpacker& operator ++ (int);
00076   private:
00077     const uint32_t* data_;
00078     size_t currentOffset_;
00079     uint16_t currentSample_;
00080     uint16_t valuesLeft_;
00081   };
00082 
00083   //
00084   // Inline function definitions
00085   //
00086 
00087   //FEDSpyChannelUnpacker
00088 
00089   inline FEDSpyChannelUnpacker::FEDSpyChannelUnpacker(const FEDChannel& channel)
00090     : data_(reinterpret_cast<const uint32_t*>(channel.data())),
00091       currentOffset_(channel.offset()),
00092       currentSample_(0),
00093       valuesLeft_(channel.length())
00094   {
00095   }
00096 
00097   inline uint16_t FEDSpyChannelUnpacker::sampleNumber() const
00098   {
00099     return currentSample_;
00100   }
00101 
00102   inline bool FEDSpyChannelUnpacker::hasData() const
00103   {
00104     return (valuesLeft_ != 0);
00105   }
00106 
00107   inline FEDSpyChannelUnpacker& FEDSpyChannelUnpacker::operator ++ ()
00108   {
00109     currentOffset_ += FEDCH_PER_DELAY_CHIP*10;
00110     currentSample_++;
00111     valuesLeft_--;
00112     return (*this);
00113   }
00114   
00115   inline FEDSpyChannelUnpacker& FEDSpyChannelUnpacker::operator ++ (int)
00116   {
00117     ++(*this); return *this;
00118   }
00119 
00120 }
00121 
00122 #endif //ndef DQM_SiStripMonitorHardware_SiStripFEDSpyBuffer_H