Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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