Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:24

0001 #include <string>
0002 #include <sstream>
0003 #include <cmath>
0004 
0005 namespace {
0006 
0007   template <typename T>
0008   inline T deltaPhiInRadians(T phi1, T phi2) {
0009     T result = phi1 - phi2;  // same convention as reco::deltaPhi()
0010     constexpr T _twopi = M_PI * 2.;
0011     result /= _twopi;
0012     result -= std::round(result);
0013     result *= _twopi;  // result in [-pi,pi]
0014     return result;
0015   }
0016 
0017   template <typename T>
0018   inline T deltaPhiInDegrees(T phi1, T phi2) {
0019     T result = phi1 - phi2;  // same convention as reco::deltaPhi()
0020     constexpr T _twopi = 360.;
0021     result /= _twopi;
0022     result -= std::round(result);
0023     result *= _twopi;  // result in [-180,180]
0024     return result;
0025   }
0026 
0027   template <typename T>
0028   T get_subword(T word, unsigned int msb, unsigned int lsb) {
0029     int len = msb - lsb + 1;
0030     len = (len < 0) ? 0 : len;
0031     return (word >> (lsb)) & ((1u << len) - 1);
0032   }
0033 
0034   template <typename T>
0035   std::string print_subaddresses(T address) {
0036     int mode_inv = (address >> (30 - 4)) & ((1 << 4) - 1);
0037     std::stringstream ss;
0038 
0039     switch (mode_inv) {
0040       case 0:
0041       case 1:
0042       case 2:
0043       case 4:
0044       case 8:
0045         // Invalid addresses
0046         ss << get_subword(address, 29, 26) << ":" << get_subword(address, 25, 0);
0047         break;
0048 
0049       case 3:
0050       case 5:
0051       case 9:
0052       case 6:
0053       case 10:
0054       case 12:
0055         // 2-station addresses
0056         ss << get_subword(address, 29, 26) << ":" << get_subword(address, 25, 21) << ":" << get_subword(address, 20, 20)
0057            << ":" << get_subword(address, 19, 19) << ":" << get_subword(address, 18, 16) << ":"
0058            << get_subword(address, 15, 13) << ":" << get_subword(address, 12, 10) << ":" << get_subword(address, 9, 9)
0059            << ":" << get_subword(address, 8, 0);
0060         break;
0061 
0062       case 7:
0063       case 11:
0064       case 13:
0065         // 3-station addresses (except 2-3-4)
0066         ss << get_subword(address, 29, 26) << ":" << get_subword(address, 25, 21) << ":" << get_subword(address, 20, 20)
0067            << ":" << get_subword(address, 19, 17) << ":" << get_subword(address, 16, 14) << ":"
0068            << get_subword(address, 13, 13) << ":" << get_subword(address, 12, 12) << ":" << get_subword(address, 11, 7)
0069            << ":" << get_subword(address, 6, 0);
0070         break;
0071 
0072       case 14:
0073         // 3-station addresses (only 2-3-4)
0074         ss << get_subword(address, 29, 26) << ":" << get_subword(address, 25, 21) << ":" << get_subword(address, 20, 18)
0075            << ":" << get_subword(address, 17, 15) << ":" << get_subword(address, 14, 14) << ":"
0076            << get_subword(address, 13, 13) << ":" << get_subword(address, 12, 7) << ":" << get_subword(address, 6, 0);
0077         break;
0078 
0079       case 15:
0080         // 4-station addresses
0081         ss << get_subword(address, 29, 26) << ":" << get_subword(address, 25, 21) << ":" << get_subword(address, 20, 20)
0082            << ":" << get_subword(address, 19, 19) << ":" << get_subword(address, 18, 18) << ":"
0083            << get_subword(address, 17, 12) << ":" << get_subword(address, 11, 7) << ":" << get_subword(address, 6, 0);
0084         break;
0085 
0086       default:
0087         break;
0088     }
0089     return ss.str();
0090   }
0091 
0092 }  // namespace