Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:27

0001 /****************************************************************************
0002  *
0003  * 
0004  * Authors: 
0005  *  F.Ferro ferro@ge.infn.it
0006  *
0007  ****************************************************************************/
0008 
0009 #ifndef CondFormats_PPSObjects_CTPPSPixelFramePosition
0010 #define CondFormats_PPSObjects_CTPPSPixelFramePosition
0011 
0012 #include <iostream>
0013 #include <string>
0014 
0015 #include "CondFormats/Serialization/interface/Serializable.h"
0016 
0017 /**
0018  * Uniquely identifies the DAQ channel through which a ROC frame has been received.
0019  * 
0020  * The internal representation has the following structure:
0021  * \verbatim
0022  * |                                     32 bits raw position                                                                      |
0023  * | 11 bits  |   12 bits |  1  bit          |      6 bits                        |  2bits     |
0024  * |  empty   |  FED ID  |    FMC   0-1  |   fiber index      0-12          | ROC 0-2 |
0025  * \endverbatim
0026  *
0027  **/
0028 class CTPPSPixelFramePosition {
0029 public:
0030   static const unsigned int offsetROC = 0, maskROC = 0x3;
0031   static const unsigned int offsetChannelIdx = 2, maskChannelIdx = 0x3F;
0032   static const unsigned int offsetFMCId = 8, maskFMCId = 0x1;
0033   static const unsigned int offsetFEDId = 9, maskFEDId = 0xFFF;
0034 
0035   /// the preferred constructor
0036   CTPPSPixelFramePosition(unsigned short FEDId, unsigned short FMCId, unsigned short ChannelIdx, unsigned short ROC)
0037       : rawPosition(ROC << offsetROC | ChannelIdx << offsetChannelIdx | FMCId << FMCId | FEDId << offsetFEDId) {}
0038 
0039   /// don't use this constructor unless you have a good reason
0040   CTPPSPixelFramePosition(unsigned int pos = 0) : rawPosition(pos) {}
0041 
0042   ~CTPPSPixelFramePosition() {}
0043 
0044   /// recomended getters and setters
0045 
0046   unsigned short getFEDId() const { return (rawPosition >> offsetFEDId) & maskFEDId; }
0047 
0048   void setFEDId(unsigned short v) {
0049     v &= maskFEDId;
0050     rawPosition &= 0xFFFFFFFF - (maskFEDId << offsetFEDId);
0051     rawPosition |= (v << offsetFEDId);
0052   }
0053 
0054   unsigned short getChannelIdx() const { return (rawPosition >> offsetChannelIdx) & maskChannelIdx; }
0055 
0056   void setChannelIdx(unsigned short v) {
0057     v &= maskChannelIdx;
0058     rawPosition &= 0xFFFFFFFF - (maskChannelIdx << offsetChannelIdx);
0059     rawPosition |= (v << offsetChannelIdx);
0060   }
0061 
0062   unsigned short getROC() const { return (rawPosition >> offsetROC) & maskROC; }
0063 
0064   void setROC(unsigned short v) {
0065     v &= maskROC;
0066     rawPosition &= 0xFFFFFFFF - (maskROC << offsetROC);
0067     rawPosition |= (v << offsetROC);
0068   }
0069 
0070   unsigned short getFMCId() const { return (rawPosition >> offsetFMCId) & maskFMCId; }
0071 
0072   void setFMCId(unsigned short v) {
0073     v &= maskFMCId;
0074     rawPosition &= 0xFFFFFFFF - (maskFMCId << offsetFMCId);
0075     rawPosition |= (v << offsetFMCId);
0076   }
0077 
0078   unsigned int getRawPosition() const { return rawPosition; }
0079 
0080   bool operator<(const CTPPSPixelFramePosition &pos) const { return (rawPosition < pos.rawPosition); }
0081 
0082   bool operator==(const CTPPSPixelFramePosition &pos) const { return (rawPosition == pos.rawPosition); }
0083 
0084   /// Condensed representation of the DAQ channel.
0085   /// prints 5-digit hex number,
0086   friend std::ostream &operator<<(std::ostream &s, const CTPPSPixelFramePosition &fp);
0087 
0088   /// prints XML formatted DAQ channel to stdout
0089   void printXML();
0090 
0091   /// Sets attribute with XML name 'attribute' and value 'value'.
0092   /// Also turns on attribute presents bit in the flag parameter
0093   /// returns 0 if the attribute is known, non-zero value else
0094   unsigned char setXMLAttribute(const std::string &attribute, const std::string &value, unsigned char &flag);
0095 
0096   /// returns true if all attributes have been set
0097   static bool checkXMLAttributeFlag(unsigned char flag) { return (flag == 0xF); }
0098 
0099 protected:
0100   unsigned int rawPosition;
0101 
0102   COND_SERIALIZABLE;
0103 };
0104 
0105 #endif