Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:20:07

0001 #include "InttMapping.h"
0002 #include "InttFelixMap.h"
0003 
0004 #include <ffarawobjects/InttRawHit.h>
0005 
0006 #include <format>
0007 
0008 /// Struct methods
0009 InttNameSpace::RawData_s& InttNameSpace::RawData_s::operator++()
0010 {
0011   if (++channel < 128)
0012   {
0013     return *this;
0014   }
0015   channel = 0;
0016 
0017   if (++chip < 26)
0018   {
0019     return *this;
0020   }
0021   chip = 0;
0022 
0023   if (++felix_channel < 14)
0024   {
0025     return *this;
0026   }
0027   felix_channel = 0;
0028 
0029   ++felix_server;
0030   return *this;
0031 }
0032 
0033 bool InttNameSpace::operator<(RawData_s const& lhs, RawData_s const& rhs)
0034 {
0035   if (lhs.felix_server != rhs.felix_server)
0036   {
0037     return lhs.felix_server < rhs.felix_server;
0038   }
0039   if (lhs.felix_channel != rhs.felix_channel)
0040   {
0041     return lhs.felix_channel < rhs.felix_channel;
0042   }
0043   if (lhs.chip != rhs.chip)
0044   {
0045     return lhs.chip < rhs.chip;
0046   }
0047   if (lhs.channel != rhs.channel)
0048   {
0049     return lhs.channel < rhs.channel;
0050   }
0051   return false;
0052 }
0053 
0054 std::ostream& InttNameSpace::operator<<(std::ostream& out, RawData_s const& rawdata)
0055 {
0056   return out << std::format(
0057              "RawData_s {{ .felix_server = {}, .felix_channel = {:2}, .chip = {:2}, .channel = {:3} }}",
0058              rawdata.felix_server, rawdata.felix_channel, rawdata.chip, rawdata.channel);
0059 }
0060 
0061 InttNameSpace::Online_s& InttNameSpace::Online_s::operator++()
0062 {
0063   if (++chn < 128)
0064   {
0065     return *this;
0066   }
0067   chn = 0;
0068 
0069   if (++chp < 26)
0070   {
0071     return *this;
0072   }
0073   chp = 0;
0074 
0075   if (++arm < 2)
0076   {
0077     return *this;
0078   }
0079   arm = 0;
0080 
0081   if (++ldr < (lyr < 5 ? 12 : 16))
0082   {
0083     return *this;
0084   }
0085   ldr = 0;
0086 
0087   ++lyr;
0088   return *this;
0089 }
0090 
0091 bool InttNameSpace::operator<(Online_s const& lhs, Online_s const& rhs)
0092 {
0093   if (lhs.lyr != rhs.lyr)
0094   {
0095     return lhs.lyr < rhs.lyr;
0096   }
0097   if (lhs.ldr != rhs.ldr)
0098   {
0099     return lhs.ldr < rhs.ldr;
0100   }
0101   if (lhs.arm != rhs.arm)
0102   {
0103     return lhs.arm < rhs.arm;
0104   }
0105   if (lhs.chp != rhs.chp)
0106   {
0107     return lhs.chp < rhs.chp;
0108   }
0109   if (lhs.chn != rhs.chn)
0110   {
0111     return lhs.chn < rhs.chn;
0112   }
0113   return false;
0114 }
0115 
0116 std::ostream& InttNameSpace::operator<<(std::ostream& out, Online_s const& online)
0117 {
0118   return out << std::format(
0119              "Online_s {{ .lyr = {}, .ldr = {:2}, .arm = {:2}, .chp = {:2}, .chn = {:3} }}",
0120              online.lyr, online.ldr, online.arm, online.chp, online.chn);
0121 }
0122 
0123 InttNameSpace::Offline_s& InttNameSpace::Offline_s::operator++()
0124 {
0125   if (++strip_x < 256)
0126   {
0127     return *this;
0128   }
0129   strip_x = 0;
0130 
0131   if (++strip_y < (ladder_z % 2 ? 5 : 8))
0132   {
0133     return *this;
0134   }
0135   strip_y = 0;
0136 
0137   if (++ladder_z < 4)
0138   {
0139     return *this;
0140   }
0141   ladder_z = 0;
0142 
0143   if (++ladder_phi < (layer < 2 ? 12 : 16))
0144   {
0145     return *this;
0146   }
0147   ladder_phi = 0;
0148 
0149   ++layer;
0150   return *this;
0151 }
0152 
0153 bool InttNameSpace::operator<(Offline_s const& lhs, Offline_s const& rhs)
0154 {
0155   if (lhs.layer != rhs.layer)
0156   {
0157     return lhs.layer < rhs.layer;
0158   }
0159   if (lhs.ladder_phi != rhs.ladder_phi)
0160   {
0161     return lhs.ladder_phi < rhs.ladder_phi;
0162   }
0163   if (lhs.ladder_z != rhs.ladder_z)
0164   {
0165     return lhs.ladder_z < rhs.ladder_z;
0166   }
0167   if (lhs.strip_x != rhs.strip_x)
0168   {
0169     return lhs.strip_x < rhs.strip_x;
0170   }
0171   if (lhs.strip_y != rhs.strip_y)
0172   {
0173     return lhs.strip_y < rhs.strip_y;
0174   }
0175   return false;
0176 }
0177 
0178 std::ostream& InttNameSpace::operator<<(std::ostream& out, Offline_s const& offline)
0179 {
0180   return out << std::format(
0181              "Offline_s {{ .layer = {}, .ladder_phi = {:2}, .ladder_z = {:2}, .strip_x = {:2}, .strip_y = {:3} }}",
0182              offline.layer, offline.ladder_phi, offline.ladder_z, offline.strip_x, offline.strip_y);
0183 }
0184 
0185 /// Namespace-scope methods
0186 InttNameSpace::RawData_s InttNameSpace::RawFromHit(InttRawHit* hit)
0187 {
0188   return {
0189       .felix_server = hit->get_packetid() - 3001,
0190       .felix_channel = hit->get_fee(),
0191       .chip = (hit->get_chip_id() + 25) % 26,
0192       .channel = hit->get_channel_id(),
0193   };
0194 }
0195 
0196 InttNameSpace::Online_s InttNameSpace::ToOnline(Offline_s const& offline)
0197 {
0198   Online_s online;
0199   int n_ldr = offline.layer < 5 ? 12 : 16;
0200 
0201   online.lyr = offline.layer - 3;
0202   // online.ldr = (7 * n_ldr / 4 - offline.ladder_phi + (offline.layer % 2 ? n_ldr - 1 : 0)) % n_ldr;
0203   online.ldr = (7 * n_ldr / 4 - offline.ladder_phi) % n_ldr;
0204 
0205   online.arm = offline.ladder_z / 2;
0206   switch (offline.ladder_z)
0207   {
0208   case 1:
0209     online.chp = offline.strip_y + 13 * (offline.strip_x < 128);
0210     break;
0211 
0212   case 0:
0213     online.chp = offline.strip_y + 13 * (offline.strip_x < 128) + 5;
0214     break;
0215 
0216   case 2:
0217     online.chp = 12 - offline.strip_y + 13 * !(offline.strip_x < 128);
0218     break;
0219 
0220   case 3:
0221     online.chp = 4 - offline.strip_y + 13 * !(offline.strip_x < 128);
0222     break;
0223 
0224   default:
0225     break;
0226   }
0227 
0228   online.chn = (offline.strip_x < 128) ? offline.strip_x : 255 - offline.strip_x;
0229 
0230   return online;
0231 }
0232 
0233 InttNameSpace::Offline_s InttNameSpace::ToOffline(Online_s const& online)
0234 {
0235   Offline_s offline;
0236   int n_ldr = online.lyr < 2 ? 12 : 16;
0237 
0238   offline.layer = online.lyr + 3;
0239   // offline.ladder_phi = (7 * n_ldr / 4 - online.ldr + (online.lyr % 2 ? 0 : n_ldr - 1)) % n_ldr;
0240   offline.ladder_phi = (7 * n_ldr / 4 - online.ldr) % n_ldr;
0241 
0242   offline.ladder_z = 2 * online.arm + (online.chp % 13 < 5);
0243   switch (offline.ladder_z)
0244   {
0245   case 1:
0246     offline.strip_y = online.chp % 13;
0247     break;
0248 
0249   case 0:
0250     offline.strip_y = online.chp % 13 - 5;
0251     break;
0252 
0253   case 2:
0254     offline.strip_y = 12 - (online.chp % 13);
0255     break;
0256 
0257   case 3:
0258     offline.strip_y = 4 - (online.chp % 13);
0259     break;
0260 
0261   default:
0262     break;
0263   }
0264 
0265   offline.strip_x = (online.arm == (online.chp / 13)) ? 255 - online.chn : online.chn;
0266 
0267   return offline;
0268 }
0269 
0270 InttNameSpace::RawData_s InttNameSpace::ToRawData(Online_s const& online)
0271 {
0272   RawData_s rawdata;
0273 
0274   InttFelix::OnlineToRawData(online, rawdata);
0275   rawdata.chip = online.chp;
0276   rawdata.channel = online.chn;
0277 
0278   return rawdata;
0279 }
0280 
0281 InttNameSpace::Online_s InttNameSpace::ToOnline(RawData_s const& rawdata)
0282 {
0283   Online_s online;
0284 
0285   InttFelix::RawDataToOnline(rawdata, online);
0286   online.chp = rawdata.chip;
0287   online.chn = rawdata.channel;
0288 
0289   return online;
0290 }