Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:40

0001 #include "InttMapping.h"
0002 #include "InttFelixMap.h"
0003 
0004 #include <ffarawobjects/InttRawHit.h>
0005 #include <boost/format.hpp>
0006 
0007 /// Struct methods
0008 InttNameSpace::RawData_s& InttNameSpace::RawData_s::operator++()
0009 {
0010   if (++channel < 128) return *this;
0011   channel = 0;
0012 
0013   if (++chip < 26) return *this;
0014   chip = 0;
0015 
0016   if (++felix_channel < 14) return *this;
0017   felix_channel = 0;
0018 
0019   ++felix_server;
0020   return *this;
0021 }
0022 
0023 bool InttNameSpace::operator<(RawData_s const& lhs, RawData_s const& rhs)
0024 {
0025   if (lhs.felix_server != rhs.felix_server) return lhs.felix_server < rhs.felix_server;
0026   if (lhs.felix_channel != rhs.felix_channel) return lhs.felix_channel < rhs.felix_channel;
0027   if (lhs.chip != rhs.chip) return lhs.chip < rhs.chip;
0028   if (lhs.channel != rhs.channel) return lhs.channel < rhs.channel;
0029   return false;
0030 }
0031 
0032 std::ostream& InttNameSpace::operator<<(std::ostream& out, RawData_s const& rawdata)
0033 {
0034   return out << (boost::format (
0035     "RawData_s { .felix_server = %1d, .felix_channel = %2d, .chip = %2d, .channel = %3d }")
0036      % rawdata.felix_server % rawdata.felix_channel % rawdata.chip % rawdata.channel).str();
0037 }
0038 
0039 InttNameSpace::Online_s& InttNameSpace::Online_s::operator++()
0040 {
0041   if (++chn < 128) return *this;
0042   chn = 0;
0043 
0044   if (++chp < 26) return *this;
0045   chp = 0;
0046 
0047   if (++arm < 2) return *this;
0048   arm = 0;
0049 
0050   if (++ldr < (lyr < 5 ? 12 : 16)) return *this;
0051   ldr = 0;
0052 
0053   ++lyr;
0054   return *this;
0055 }
0056 
0057 bool InttNameSpace::operator<(Online_s const& lhs, Online_s const& rhs)
0058 {
0059   if (lhs.lyr != rhs.lyr) return lhs.lyr < rhs.lyr;
0060   if (lhs.ldr != rhs.ldr) return lhs.ldr < rhs.ldr;
0061   if (lhs.arm != rhs.arm) return lhs.arm < rhs.arm;
0062   if (lhs.chp != rhs.chp) return lhs.chp < rhs.chp;
0063   if (lhs.chn != rhs.chn) return lhs.chn < rhs.chn;
0064   return false;
0065 }
0066 
0067 std::ostream& InttNameSpace::operator<<(std::ostream& out, Online_s const& online)
0068 {
0069   return out << (boost::format (
0070     "Online_s { .lyr = %1d, .ldr = %2d, .arm = %2d, .chp = %2d, .chn = %3d }")
0071      % online.lyr % online.ldr % online.arm % online.chp % online.chn).str();
0072 }
0073 
0074 InttNameSpace::Offline_s& InttNameSpace::Offline_s::operator++()
0075 {
0076   if (++strip_x < 256) return *this;
0077   strip_x = 0;
0078 
0079   if (++strip_y < (ladder_z % 2 ? 5 : 8)) return *this;
0080   strip_y = 0;
0081 
0082   if (++ladder_z < 4) return *this;
0083   ladder_z = 0;
0084   
0085   if (++ladder_phi < (layer < 2 ? 12 : 16)) return *this;
0086   ladder_phi = 0;
0087 
0088   ++layer;
0089   return *this;
0090 }
0091 
0092 bool InttNameSpace::operator<(Offline_s const& lhs, Offline_s const& rhs)
0093 {
0094   if (lhs.layer != rhs.layer) return lhs.layer < rhs.layer;
0095   if (lhs.ladder_phi != rhs.ladder_phi) return lhs.ladder_phi < rhs.ladder_phi;
0096   if (lhs.ladder_z != rhs.ladder_z) return lhs.ladder_z < rhs.ladder_z;
0097   if (lhs.strip_x != rhs.strip_x) return lhs.strip_x < rhs.strip_x;
0098   if (lhs.strip_y != rhs.strip_y) return lhs.strip_y < rhs.strip_y;
0099   return false;
0100 }
0101 
0102 std::ostream& InttNameSpace::operator<<(std::ostream& out, Offline_s const& offline)
0103 {
0104   return out << (boost::format (
0105     "Offline_s { .layer = %1d, .ladder_phi = %2d, .ladder_z = %2d, .strip_x = %2d, .strip_y = %3d }")
0106     % offline.layer % offline.ladder_phi % offline.ladder_z % offline.strip_x % offline.strip_y).str();
0107 }
0108 
0109 /// Namespace-scope methods
0110 InttNameSpace::RawData_s InttNameSpace::RawFromHit(InttRawHit* hit)
0111 {
0112   return {
0113     .felix_server = hit->get_packetid() - 3001,
0114     .felix_channel = hit->get_fee(),
0115     .chip = (hit->get_chip_id() + 25) % 26,
0116     .channel = hit->get_channel_id(),
0117   };
0118 }
0119 
0120 InttNameSpace::Online_s InttNameSpace::ToOnline(Offline_s const& offline)
0121 {
0122   Online_s online;
0123   int n_ldr = offline.layer < 5 ? 12 : 16;
0124 
0125   online.lyr = offline.layer - 3;
0126   // online.ldr = (7 * n_ldr / 4 - offline.ladder_phi + (offline.layer % 2 ? n_ldr - 1 : 0)) % n_ldr;
0127   online.ldr = (7 * n_ldr / 4 - offline.ladder_phi) % n_ldr;
0128 
0129   online.arm = offline.ladder_z / 2;
0130   switch (offline.ladder_z)
0131   {
0132   case 1:
0133     online.chp = offline.strip_y + 13 * (offline.strip_x < 128);
0134     break;
0135 
0136   case 0:
0137     online.chp = offline.strip_y + 13 * (offline.strip_x < 128) + 5;
0138     break;
0139 
0140   case 2:
0141     online.chp = 12 - offline.strip_y + 13 * !(offline.strip_x < 128);
0142     break;
0143 
0144   case 3:
0145     online.chp = 4 - offline.strip_y + 13 * !(offline.strip_x < 128);
0146     break;
0147 
0148   default:
0149     break;
0150   }
0151 
0152   online.chn = (offline.strip_x < 128) ? offline.strip_x : 255 - offline.strip_x;
0153 
0154   return online;
0155 }
0156 
0157 InttNameSpace::Offline_s InttNameSpace::ToOffline(Online_s const& online)
0158 {
0159   Offline_s offline;
0160   int n_ldr = online.lyr < 2 ? 12 : 16;
0161 
0162   offline.layer = online.lyr + 3;
0163   // offline.ladder_phi = (7 * n_ldr / 4 - online.ldr + (online.lyr % 2 ? 0 : n_ldr - 1)) % n_ldr;
0164   offline.ladder_phi = (7 * n_ldr / 4 - online.ldr) % n_ldr;
0165 
0166   offline.ladder_z = 2 * online.arm + (online.chp % 13 < 5);
0167   switch (offline.ladder_z)
0168   {
0169   case 1:
0170     offline.strip_y = online.chp % 13;
0171     break;
0172 
0173   case 0:
0174     offline.strip_y = online.chp % 13 - 5;
0175     break;
0176 
0177   case 2:
0178     offline.strip_y = 12 - (online.chp % 13);
0179     break;
0180 
0181   case 3:
0182     offline.strip_y = 4 - (online.chp % 13);
0183     break;
0184 
0185   default:
0186     break;
0187   }
0188 
0189   offline.strip_x = (online.arm == (online.chp / 13)) ? 255 - online.chn : online.chn;
0190 
0191   return offline;
0192 }
0193 
0194 InttNameSpace::RawData_s InttNameSpace::ToRawData(Online_s const& online)
0195 {
0196   RawData_s rawdata;
0197 
0198   InttFelix::OnlineToRawData(online, rawdata);
0199   rawdata.chip = online.chp;
0200   rawdata.channel = online.chn;
0201 
0202   return rawdata;
0203 }
0204 
0205 InttNameSpace::Online_s InttNameSpace::ToOnline(RawData_s const& rawdata)
0206 {
0207   Online_s online;
0208 
0209   InttFelix::RawDataToOnline(rawdata, online);
0210   online.chp = rawdata.chip;
0211   online.chn = rawdata.channel;
0212 
0213   return online;
0214 }