Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:47:22

0001 /****************************************************************************
0002 *
0003 * This is a part of the TOTEM offline software.
0004 * Authors: 
0005 *   Jan Kašpar (jan.kaspar@gmail.com) 
0006 *
0007 ****************************************************************************/
0008 
0009 #ifndef CondFormats_PPSObjects_TotemFramePosition
0010 #define CondFormats_PPSObjects_TotemFramePosition
0011 
0012 #include <iostream>
0013 #include <string>
0014 
0015 /**
0016  * Uniquely identifies the DAQ channel through which a VFAT frame has been received.
0017  * 
0018  * The internal representation has the following structure:
0019  * \verbatim
0020  * |                   32 bits raw position                    |
0021  * | 12 bits | 2 bits |  10 bits | 4 bits |       4 bits       |
0022  * |  empty  | empty  |  FED ID  | GOH ID | index within fiber |
0023  * \endverbatim
0024  *
0025  * In the old (TOTEM only) scheme, the FED ID was further split
0026  * \verbatim
0027  * |  3 bits   |  5 bits   |  2 bits   |
0028  * | SubSystem | TOTFED ID | OptoRx ID |
0029  * \endverbatim
0030  * IMPORTANT: This splitting is only supported for backward compatibility and should not be used anymore.
0031  **/
0032 class TotemFramePosition {
0033 public:
0034   static const unsigned int offsetIdxInFiber = 0, maskIdxInFiber = 0xF;
0035   static const unsigned int offsetGOHId = 4, maskGOHId = 0xF;
0036   static const unsigned int offsetFEDId = 8, maskFEDId = 0x3FF;
0037 
0038   static const unsigned int offsetOptoRxId = 8, maskOptoRxId = 0x3;
0039   static const unsigned int offsetTOTFEDId = 10, maskTOTFEDId = 0x1F;
0040   static const unsigned int offsetSubSystemId = 15, maskSubSystemId = 0x7;
0041 
0042   /// the preferred constructor
0043   TotemFramePosition(unsigned short SubSystemId,
0044                      unsigned short TOTFEDId,
0045                      unsigned short OptoRxId,
0046                      unsigned short GOHId,
0047                      unsigned short IdxInFiber)
0048       : rawPosition(IdxInFiber << offsetIdxInFiber | GOHId << offsetGOHId | OptoRxId << offsetOptoRxId |
0049                     TOTFEDId << offsetTOTFEDId | SubSystemId << offsetSubSystemId) {}
0050 
0051   /// don't use this constructor unless you have a good reason
0052   TotemFramePosition(unsigned int pos = 0) : rawPosition(pos) {}
0053 
0054   ~TotemFramePosition() {}
0055 
0056   /// recomended getters and setters
0057 
0058   unsigned short getFEDId() const { return (rawPosition >> offsetFEDId) & maskFEDId; }
0059 
0060   void setFEDId(unsigned short v) {
0061     v &= maskFEDId;
0062     rawPosition &= 0xFFFFFFFF - (maskFEDId << offsetFEDId);
0063     rawPosition |= (v << offsetFEDId);
0064   }
0065 
0066   unsigned short getGOHId() const { return (rawPosition >> offsetGOHId) & maskGOHId; }
0067 
0068   void setGOHId(unsigned short v) {
0069     v &= maskGOHId;
0070     rawPosition &= 0xFFFFFFFF - (maskGOHId << offsetGOHId);
0071     rawPosition |= (v << offsetGOHId);
0072   }
0073 
0074   unsigned short getIdxInFiber() const { return (rawPosition >> offsetIdxInFiber) & maskIdxInFiber; }
0075 
0076   void setIdxInFiber(unsigned short v) {
0077     v &= maskIdxInFiber;
0078     rawPosition &= 0xFFFFFFFF - (maskIdxInFiber << offsetIdxInFiber);
0079     rawPosition |= (v << offsetIdxInFiber);
0080   }
0081 
0082   /// the getters and setters below are deprecated
0083 
0084   unsigned short getSubSystemId() const { return (rawPosition >> offsetSubSystemId) & maskSubSystemId; }
0085 
0086   void setSubSystemId(unsigned short v) {
0087     v &= maskSubSystemId;
0088     rawPosition &= 0xFFFFFFFF - (maskSubSystemId << offsetSubSystemId);
0089     rawPosition |= (v << offsetSubSystemId);
0090   }
0091 
0092   unsigned short getTOTFEDId() const { return (rawPosition >> offsetTOTFEDId) & maskTOTFEDId; }
0093 
0094   void setTOTFEDId(unsigned short v) {
0095     v &= maskTOTFEDId;
0096     rawPosition &= 0xFFFFFFFF - (maskTOTFEDId << offsetTOTFEDId);
0097     rawPosition |= (v << offsetTOTFEDId);
0098   }
0099 
0100   unsigned short getOptoRxId() const { return (rawPosition >> offsetOptoRxId) & maskOptoRxId; }
0101 
0102   void setOptoRxId(unsigned short v) {
0103     v &= maskOptoRxId;
0104     rawPosition &= 0xFFFFFFFF - (maskOptoRxId << offsetOptoRxId);
0105     rawPosition |= (v << offsetOptoRxId);
0106   }
0107 
0108   /// don't use this method unless you have a good reason
0109   unsigned int getRawPosition() const { return rawPosition; }
0110 
0111   bool operator<(const TotemFramePosition &pos) const { return (rawPosition < pos.rawPosition); }
0112 
0113   bool operator==(const TotemFramePosition &pos) const { return (rawPosition == pos.rawPosition); }
0114 
0115   /// Condensed representation of the DAQ channel.
0116   /// prints 5-digit hex number, the digits correspond to SubSystem, TOTFED ID, OptoRx ID,
0117   /// GOH ID, index within fiber in this order
0118   friend std::ostream &operator<<(std::ostream &s, const TotemFramePosition &fp);
0119 
0120   /// prints XML formatted DAQ channel to stdout
0121   void printXML();
0122 
0123   /// Sets attribute with XML name 'attribute' and value 'value'.
0124   /// Also turns on attribute presents bit in the flag parameter
0125   /// returns 0 if the attribute is known, non-zero value else
0126   unsigned char setXMLAttribute(const std::string &attribute, const std::string &value, unsigned char &flag);
0127 
0128   /// returns true if all attributes have been set
0129   static bool checkXMLAttributeFlag(unsigned char flag) { return (flag == 0x1f); }
0130 
0131 protected:
0132   unsigned int rawPosition;
0133 };
0134 
0135 #endif