File indexing completed on 2025-08-05 08:16:07
0001 #include "CaloPacketv1.h"
0002
0003 #include <phool/phool.h>
0004
0005 #include <Event/packetConstants.h>
0006
0007 #include <TSystem.h>
0008
0009 #include <iomanip>
0010
0011 CaloPacketv1::CaloPacketv1()
0012 {
0013 femclock.fill(0);
0014 femevt.fill(0);
0015 femslot.fill(0);
0016 femstatus.fill(CaloPacket::NOTSET);
0017 checksumlsb.fill(0);
0018 checksummsb.fill(0);
0019 calcchecksumlsb.fill(0);
0020 calcchecksummsb.fill(0);
0021
0022 isZeroSuppressed.fill(false);
0023 pre.fill(0);
0024 post.fill(0);
0025 for (auto &row : samples)
0026 {
0027 row.fill(0);
0028 }
0029 }
0030
0031 void CaloPacketv1::Reset()
0032 {
0033 OfflinePacketv1::Reset();
0034 PacketEvtSequence = 0;
0035 NrChannels = 0;
0036 NrSamples = 0;
0037 NrModules = 0;
0038 event_checksum = 0;
0039 odd_checksum = 0;
0040 calc_event_checksum = 0;
0041 calc_odd_checksum = 0;
0042 module_address = 0;
0043 detid = 0;
0044
0045 femclock.fill(0);
0046 femevt.fill(0);
0047 femslot.fill(0);
0048 femstatus.fill(CaloPacket::NOTSET);
0049 checksumlsb.fill(0);
0050 checksummsb.fill(0);
0051 calcchecksumlsb.fill(0);
0052 calcchecksummsb.fill(0);
0053
0054 isZeroSuppressed.fill(false);
0055 pre.fill(0);
0056 post.fill(0);
0057 for (auto &row : samples)
0058 {
0059 row.fill(0);
0060 }
0061 return;
0062 }
0063
0064 int CaloPacketv1::iValue(const int n, const std::string &what) const
0065 {
0066 if (what == "CLOCK")
0067 {
0068 return getBCO();
0069 }
0070
0071 if (what == "EVTNR")
0072 {
0073 return getPacketEvtSequence();
0074 }
0075
0076 if (what == "SAMPLES")
0077 {
0078 return getNrSamples();
0079 }
0080
0081 if (what == "NRMODULES")
0082 {
0083 return getNrModules();
0084 }
0085
0086 if (what == "CHANNELS")
0087 {
0088 return getNrChannels();
0089 }
0090
0091 if (what == "DETID")
0092 {
0093 return getDetId();
0094 }
0095
0096 if (what == "PRE")
0097 {
0098 return getPre(n);
0099 }
0100
0101 if (what == "POST")
0102 {
0103 return getPost(n);
0104 }
0105
0106 if (what == "SUPPRESSED")
0107 {
0108 return getSuppressed(n);
0109 }
0110
0111 if (what == "MODULEADDRESS")
0112 {
0113 return getModuleAddress();
0114 }
0115
0116 if (what == "FEMSLOT")
0117 {
0118 if (n < 0 || n >= getNrModules())
0119 {
0120 return 0;
0121 }
0122 return femslot.at(n);
0123 }
0124
0125 if (what == "FEMEVTNR")
0126 {
0127 if (n < 0 || n >= getNrModules())
0128 {
0129 return 0;
0130 }
0131 return femevt.at(n);
0132 }
0133
0134 if (what == "FEMCLOCK")
0135 {
0136 if (n < 0 || n >= getNrModules())
0137 {
0138 return 0;
0139 }
0140 return femclock.at(n);
0141 }
0142
0143 if (what == "EVENCHECKSUM")
0144 {
0145 return getEvenChecksum();
0146 }
0147
0148 if (what == "ODDCHECKSUM")
0149 {
0150 return getOddChecksum();
0151 }
0152
0153 if (what == "CALCEVENCHECKSUM")
0154 {
0155 return getCalcEvenChecksum();
0156 }
0157
0158 if (what == "CALCODDCHECKSUM")
0159 {
0160 return getCalcOddChecksum();
0161 }
0162
0163 if (what == "CHECKSUMLSB")
0164 {
0165 if (n < 0 || n >= getNrModules())
0166 {
0167 return 0;
0168 }
0169 return getChecksumLsb(n);
0170 }
0171
0172 if (what == "CALCCHECKSUMLSB")
0173 {
0174 if (n < 0 || n >= getNrModules())
0175 {
0176 return 0;
0177 }
0178 return getCalcChecksumLsb(n);
0179 }
0180
0181 if (what == "CALCCHECKSUMMSB")
0182 {
0183 if (n < 0 || n >= getNrModules())
0184 {
0185 return 0;
0186 }
0187 return getCalcChecksumMsb(n);
0188 }
0189
0190 if (what == "CHECKSUMMSB")
0191 {
0192 if (n < 0 || n >= getNrModules())
0193 {
0194 return 0;
0195 }
0196 return getChecksumMsb(n);
0197 }
0198
0199 if (what == "EVENCHECKSUMOK")
0200 {
0201 if (getCalcEvenChecksum() < 0)
0202 {
0203 return -1;
0204 }
0205 if (getCalcEvenChecksum() == getEvenChecksum())
0206 {
0207 return 1;
0208 }
0209 return 0;
0210 }
0211
0212 if (what == "ODDCHECKSUMOK")
0213 {
0214 if (getCalcOddChecksum() < 0)
0215 {
0216 return -1;
0217 }
0218 if (getCalcOddChecksum() == getOddChecksum())
0219 {
0220 return 1;
0221 }
0222 return 0;
0223 }
0224
0225 if (what == "CHECKSUMOK")
0226 {
0227 if (getCalcOddChecksum() < 0 || getCalcEvenChecksum())
0228 {
0229 return -1;
0230 }
0231 if (getCalcEvenChecksum() == getEvenChecksum() &&
0232 getCalcOddChecksum() == getOddChecksum())
0233 {
0234 return 1;
0235 }
0236 return 0;
0237 }
0238
0239 std::cout << "invalid selection " << what << std::endl;
0240 return std::numeric_limits<int>::min();
0241 }
0242
0243 int CaloPacketv1::iValue(const int channel, const int sample) const
0244 {
0245 return samples.at(channel).at(sample);
0246 }
0247
0248 void CaloPacketv1::identify(std::ostream &os) const
0249 {
0250 os << "CaloPacketv1: " << std::endl;
0251 OfflinePacketv1::identify(os);
0252 os << "Pkt Event no: " << getPacketEvtSequence() << std::endl;
0253 os << "FEM Event no: " << std::hex;
0254 for (const auto clk : femevt)
0255 {
0256 std::cout << clk << " ";
0257 }
0258 std::cout << std::dec << std::endl;
0259 os << "FEM clk: " << std::hex;
0260 for (const auto clk : femclock)
0261 {
0262 std::cout << clk << " ";
0263 }
0264 std::cout << std::dec << std::endl;
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274 }
0275
0276 void CaloPacketv1::dump(std::ostream &os) const
0277 {
0278 switch (getHitFormat())
0279 {
0280 case IDDIGITIZERV3_12S:
0281 case IDDIGITIZERV3_16S:
0282 case IDDIGITIZER_31S:
0283 dump_iddigitizer(os);
0284 break;
0285 default:
0286 std::cout << PHWHERE << "unknown hit format: "
0287 << getHitFormat() << std::endl;
0288 gSystem->Exit(1);
0289 }
0290 return;
0291 }
0292
0293 void CaloPacketv1::dump_iddigitizer(std::ostream &os) const
0294 {
0295 int _nchannels = iValue(0, "CHANNELS");
0296 int _nsamples = iValue(0, "SAMPLES");
0297 os << "Evt Nr: " << iValue(0, "EVTNR") << std::endl;
0298 os << "Clock: " << iValue(0, "CLOCK") << std::endl;
0299 os << "Nr Modules: " << iValue(0, "NRMODULES") << std::endl;
0300 os << "Channels: " << iValue(0, "CHANNELS") << std::endl;
0301 os << "Samples: " << iValue(0, "SAMPLES") << std::endl;
0302 os << "Mod. Addr: " << std::hex << "0x" << iValue(0, "MODULEADDRESS") << std::dec << std::endl;
0303
0304 os << "FEM Slot: ";
0305 for (int i = 0; i < iValue(0, "NRMODULES"); i++)
0306 {
0307 os << std::setw(8) << iValue(i, "FEMSLOT");
0308 }
0309 os << std::endl;
0310
0311 os << "FEM Evt nr: ";
0312 for (int i = 0; i < iValue(0, "NRMODULES"); i++)
0313 {
0314 os << std::setw(8) << iValue(i, "FEMEVTNR");
0315 }
0316 os << std::endl;
0317
0318 os << "FEM Clock: ";
0319 for (int i = 0; i < iValue(0, "NRMODULES"); i++)
0320 {
0321 os << std::setw(8) << iValue(i, "FEMCLOCK");
0322 }
0323 os << std::endl;
0324
0325 char oldFill = os.fill('0');
0326
0327 os << "FEM Checksum LSB: ";
0328 for (int i = 0; i < iValue(0, "NRMODULES"); i++)
0329 {
0330 os << "0x" << std::hex << std::setw(4) << iValue(i, "CHECKSUMLSB") << " " << std::dec;
0331 }
0332 os << std::endl;
0333
0334 os << "FEM Checksum MSB: ";
0335 for (int i = 0; i < iValue(0, "NRMODULES"); i++)
0336 {
0337 os << "0x" << std::hex << std::setw(4) << iValue(i, "CHECKSUMMSB") << " " << std::dec;
0338 }
0339 os << std::endl;
0340
0341 os.fill(oldFill);
0342 os << std::endl;
0343
0344 for (int c = 0; c < _nchannels; c++)
0345 {
0346 if (iValue(c, "SUPPRESSED"))
0347 {
0348 os << std::setw(4) << c << " |-";
0349 }
0350 else
0351 {
0352 os << std::setw(4) << c << " | ";
0353 }
0354
0355 os << std::hex;
0356
0357 os << std::setw(6) << iValue(c, "PRE");
0358 os << std::setw(6) << iValue(c, "POST") << " | ";
0359
0360 if (!iValue(c, "SUPPRESSED"))
0361 {
0362 for (int s = 0; s < _nsamples; s++)
0363 {
0364 os << std::setw(6) << iValue(s, c);
0365 }
0366 }
0367 os << std::dec << std::endl;
0368 }
0369 }