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_TotemT2FramePosition
0010 #define CondFormats_PPSObjects_TotemT2FramePosition
0011 #include "CondFormats/PPSObjects/interface/TotemFramePosition.h"
0012 
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  | T2 payload |  FED ID  | GOH ID | index within fiber |
0024  * \endverbatim
0025  *
0026  **/
0027 class TotemT2FramePosition : public TotemFramePosition {
0028 public:
0029   static const unsigned int offsetPayload = 18, maskPayload = 0x3;
0030 
0031   /// the preferred constructor
0032   TotemT2FramePosition(unsigned short SubSystemId,
0033                        unsigned short TOTFEDId,
0034                        unsigned short OptoRxId,
0035                        unsigned short GOHId,
0036                        unsigned short IdxInFiber,
0037                        unsigned short payload)
0038       : rawPosition(IdxInFiber << offsetIdxInFiber | GOHId << offsetGOHId | OptoRxId << offsetOptoRxId |
0039                     TOTFEDId << offsetTOTFEDId | SubSystemId << offsetSubSystemId | (payload + 1) << offsetPayload) {}
0040 
0041   /// don't use this constructor unless you have a good reason
0042   TotemT2FramePosition(unsigned int pos = 0) : rawPosition(pos) {}
0043 
0044   ~TotemT2FramePosition() {}
0045 
0046   /// recomended getters and setters
0047 
0048   unsigned short getFEDId() const { return (rawPosition >> offsetFEDId) & maskFEDId; }
0049   unsigned short getPayload() const { return (((rawPosition >> offsetPayload) & maskPayload) - 1); }
0050 
0051   void setFEDId(unsigned short v) {
0052     v &= maskFEDId;
0053     rawPosition &= 0xFFFFFFFF - (maskFEDId << offsetFEDId);
0054     rawPosition |= (v << offsetFEDId);
0055   }
0056   void setPayload(unsigned short v) {
0057     unsigned short av = (v + 1) & maskPayload;
0058     rawPosition &= 0xFFFFFFFF - (maskPayload << offsetPayload);
0059     rawPosition |= (av << offsetPayload);
0060   }
0061 
0062   unsigned short getGOHId() const { return (rawPosition >> offsetGOHId) & maskGOHId; }
0063 
0064   void setGOHId(unsigned short v) {
0065     v &= maskGOHId;
0066     rawPosition &= 0xFFFFFFFF - (maskGOHId << offsetGOHId);
0067     rawPosition |= (v << offsetGOHId);
0068   }
0069 
0070   unsigned short getIdxInFiber() const { return (rawPosition >> offsetIdxInFiber) & maskIdxInFiber; }
0071 
0072   void setIdxInFiber(unsigned short v) {
0073     v &= maskIdxInFiber;
0074     rawPosition &= 0xFFFFFFFF - (maskIdxInFiber << offsetIdxInFiber);
0075     rawPosition |= (v << offsetIdxInFiber);
0076   }
0077 
0078   /// the getters and setters below are deprecated
0079 
0080   /// don't use this method unless you have a good reason
0081   unsigned int getRawPosition() const { return rawPosition; }
0082 
0083   bool operator<(const TotemT2FramePosition &pos) const { return (rawPosition < pos.rawPosition); }
0084   bool operator<(const TotemFramePosition &pos) const { return (rawPosition < pos.getRawPosition()); }
0085 
0086   bool operator==(const TotemT2FramePosition &pos) const { return (rawPosition == pos.rawPosition); }
0087   bool operator==(const TotemFramePosition &pos) const { return (rawPosition == pos.getRawPosition()); }
0088 
0089   /// Condensed representation of the DAQ channel.
0090   /// prints 5-digit hex number, the digits correspond to SubSystem, TOTFED ID, OptoRx ID,
0091   /// GOH ID, index within fiber in this order
0092   friend std::ostream &operator<<(std::ostream &s, const TotemT2FramePosition &fp);
0093 
0094   /// prints XML formatted DAQ channel to stdout
0095   void printXML();
0096 
0097   /// Sets attribute with XML name 'attribute' and value 'value'.
0098   /// Also turns on attribute presents bit in the flag parameter
0099   /// returns 0 if the attribute is known, non-zero value else
0100   unsigned char setXMLAttribute(const std::string &attribute, const std::string &value, unsigned char &flag);
0101 
0102   /// returns true if all attributes have been set
0103   static bool checkXMLAttributeFlag(unsigned char flag) { return (flag == 0x3f); }
0104 
0105 protected:
0106   unsigned int rawPosition;
0107 };
0108 
0109 #endif