Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:51:49

0001 #ifndef PHYSICAL_UNIT_H
0002 #define PHYSICAL_UNIT_H
0003 
0004 /**
0005  * @file PhysicalUnit.h
0006  * @author: Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date 20 January 2016
0008  * @version 1.0
0009  */
0010 
0011 #include <string>
0012 
0013 #include "UnitCategory.h"
0014 
0015 namespace ElemUtils {
0016 class Packet;
0017 } /* namespace ElemUtils */
0018 
0019 namespace PARTONS {
0020 
0021 /**
0022  * @class PhysicalUnit
0023  *
0024  * @brief Definition of units.
0025  */
0026 class PhysicalUnit {
0027 
0028 public:
0029 
0030     /**
0031      * Enum types.
0032      */
0033     enum Type {
0034 
0035         //undefined
0036         UNDEFINED = 0,  ///< undefined
0037 
0038         //none
0039         NONE = 1,       ///< none
0040 
0041         //energy, momentum or mass
0042         EV = 2,         ///< eV
0043         KEV = 3,        ///< keV
0044         MEV = 4,        ///< MeV
0045         GEV = 5,        ///< GeV
0046         TEV = 6,        ///< TeV
0047 
0048         //energy, momentum or mass squared
0049         EV2 = 7,         ///< eV^2
0050         KEV2 = 8,        ///< keV^2
0051         MEV2 = 9,        ///< MeV^2
0052         GEV2 = 10,       ///< GeV^2
0053         TEV2 = 11,       ///< TeV^2
0054 
0055         //distance or time
0056         EVm1 = 12,       ///< eV^-1
0057         KEVm1 = 13,      ///< keV^-1
0058         MEVm1 = 14,      ///< MeV^-1
0059         GEVm1 = 15,      ///< GeV^-1
0060         TEVm1 = 16,      ///< TeV^-1
0061 
0062         FM = 17,         ///< fm
0063         PM = 18,         ///< pm
0064         NM = 19,         ///< nm
0065         UM = 20,         ///< um
0066         MM = 21,         ///< mm
0067         M = 22,          ///< m
0068 
0069         FS = 23,         ///< fs
0070         PS = 24,         ///< ps
0071         NS = 25,         ///< ns
0072         US = 26,         ///< us
0073         MS = 27,         ///< ms
0074         S = 28,          ///< s
0075 
0076         //cross-section
0077         GEVm2 = 29,      ///< GeV^-2
0078 
0079         FM2 = 30,        ///< fm^2
0080 
0081         FB = 31,         ///< fb
0082         PB = 32,         ///< pb
0083         NB = 33,         ///< nb
0084         UB = 34,         ///< ub
0085         MB = 35,         ///< mb
0086         B = 36,          ///< b
0087 
0088         //angle
0089         DEG = 37,        ///< degree
0090         RAD = 38,        ///< radian
0091         MRAD = 39        ///< mradian
0092     };
0093 
0094     /**
0095      * Default constructor.
0096      */
0097     PhysicalUnit();
0098 
0099     /**
0100      * Assignment constructor.
0101      * @param type Type to be assigned.
0102      */
0103     PhysicalUnit(Type type);
0104 
0105     /**
0106      * Assignment constructor.
0107      * @param type Type to be assigned.
0108      */
0109     PhysicalUnit(const std::string& type);
0110 
0111     /**
0112      * Copy constructor.
0113      * @param other Object to be copied.
0114      */
0115     PhysicalUnit(const PhysicalUnit &other);
0116 
0117     /**
0118      * Automatic cast to enum.
0119      */
0120     operator Type() const;
0121 
0122     /**
0123      * Get string representing class content.
0124      */
0125     std::string toString() const;
0126 
0127     /**
0128      * Get short string representing PhysicalUnit::m_type.
0129      */
0130     std::string getShortName();
0131 
0132     /**
0133      * Serialize into given Packet.
0134      * @param packet Target Packet.
0135      */
0136     void serialize(ElemUtils::Packet &packet) const;
0137 
0138     /**
0139      * Retrieve data from given Packet.
0140      * @param packet Input Packet.
0141      */
0142     void unserialize(ElemUtils::Packet &packet);
0143 
0144     /**
0145      * Get unit category.
0146      */
0147     UnitCategory::Type getUnitCategory() const;
0148 
0149     /**
0150      * Get conversion factor.
0151      */
0152     double getConversionFactor() const;
0153 
0154     //********************************************************
0155     //*** SETTERS AND GETTERS ********************************
0156     //********************************************************
0157 
0158     /**
0159      * Get PhysicalUnit::m_type.
0160      */
0161     PhysicalUnit::Type getType() const;
0162 
0163     /**
0164      * Set PhysicalUnit::m_type.
0165      */
0166     void setType(Type type);
0167 
0168 private:
0169 
0170     /**
0171      * Type.
0172      */
0173     PhysicalUnit::Type m_type;
0174 };
0175 
0176 /**
0177  * Stream operator to serialize class into Packet. See also PhysicalUnit::serialize().
0178  */
0179 ElemUtils::Packet& operator <<(ElemUtils::Packet& packet,
0180         PhysicalUnit& physicalUnit);
0181 
0182 /**
0183  * Stream operator to retrieve class from Packet. See also PhysicalUnit::unserialize().
0184  */
0185 ElemUtils::Packet& operator >>(ElemUtils::Packet& packet,
0186         PhysicalUnit& physicalUnit);
0187 
0188 } /* namespace PARTONS */
0189 
0190 #endif /* PHYSICAL_UNIT_H */