File indexing completed on 2024-04-06 12:21:42
0001
0002
0003
0004
0005
0006
0007 #include "../interface/SourceCardRouting.h" //hh"
0008
0009
0010 #include <iomanip>
0011 #include <iostream>
0012 #include <sstream>
0013 using namespace std;
0014
0015
0016
0017 SourceCardRouting::SourceCardRouting() {
0018
0019 }
0020
0021 SourceCardRouting::~SourceCardRouting() {
0022
0023 }
0024
0025
0026
0027
0028
0029
0030 void SourceCardRouting::EMUtoSFP(unsigned short (&eIsoRank)[4],
0031 unsigned short (&eIsoCardId)[4],
0032 unsigned short (&eIsoRegionId)[4],
0033 unsigned short (&eNonIsoRank)[4],
0034 unsigned short (&eNonIsoCardId)[4],
0035 unsigned short (&eNonIsoRegionId)[4],
0036 unsigned short (&MIPbits)[7][2],
0037 unsigned short (&Qbits)[7][2],
0038 unsigned short (&SFP)[2][4]) const {
0039 SFP[0][0] = 0;
0040 SFP[1][0] = 0x8000;
0041
0042 for (int i = 0; i < 7; i++) {
0043 for (int j = 0; j < 2; j++) {
0044 SFP[0][0] = SFP[0][0] | ((MIPbits[i][j] & 0x01) << ((2 * i) + j));
0045 SFP[1][0] = SFP[1][0] | ((Qbits[i][j] & 0x01) << ((2 * i) + j));
0046 }
0047 }
0048
0049 SFP[0][1] = (eIsoRank[0] & 0x3f) | ((eIsoRegionId[0] & 0x01) << 6) | ((eIsoCardId[0] & 0x07) << 7) |
0050 ((eIsoRank[1] & 0x7) << 10);
0051 SFP[1][1] = 0x8000 | (eIsoRank[2] & 0x3f) | ((eIsoRegionId[2] & 0x01) << 6) | ((eIsoCardId[2] & 0x07) << 7) |
0052 ((eIsoRank[3] & 0x7) << 10);
0053 SFP[0][2] = (eNonIsoRank[0] & 0x3f) | ((eNonIsoRegionId[0] & 0x01) << 6) | ((eNonIsoCardId[0] & 0x07) << 7) |
0054 ((eIsoRank[1] & 0x38) << 7) | ((eIsoRegionId[1] & 0x01) << 13);
0055 SFP[1][2] = 0x8000 | (eNonIsoRank[2] & 0x3f) | ((eNonIsoRegionId[2] & 0x01) << 6) | ((eNonIsoCardId[2] & 0x07) << 7) |
0056 ((eIsoRank[3] & 0x38) << 7) | ((eIsoRegionId[3] & 0x01) << 13);
0057 SFP[0][3] = (eNonIsoRank[1] & 0x3f) | ((eNonIsoRegionId[1] & 0x01) << 6) | ((eNonIsoCardId[1] & 0x07) << 7) |
0058 ((eIsoCardId[1] & 0x07) << 10);
0059 SFP[1][3] = 0x8000 | (eNonIsoRank[3] & 0x3f) | ((eNonIsoRegionId[3] & 0x01) << 6) | ((eNonIsoCardId[3] & 0x07) << 7) |
0060 ((eIsoCardId[3] & 0x07) << 10);
0061 }
0062
0063
0064
0065
0066
0067
0068 void SourceCardRouting::SFPtoEMU(unsigned short (&eIsoRank)[4],
0069 unsigned short (&eIsoCardId)[4],
0070 unsigned short (&eIsoRegionId)[4],
0071 unsigned short (&eNonIsoRank)[4],
0072 unsigned short (&eNonIsoCardId)[4],
0073 unsigned short (&eNonIsoRegionId)[4],
0074 unsigned short (&MIPbits)[7][2],
0075 unsigned short (&Qbits)[7][2],
0076 unsigned short (&SFP)[2][4]) const {
0077 for (int i = 0; i < 7; i++) {
0078 for (int j = 0; j < 2; j++) {
0079 MIPbits[i][j] = (SFP[0][0] >> ((2 * i) + j)) & 0x1;
0080 Qbits[i][j] = (SFP[1][0] >> ((2 * i) + j)) & 0x1;
0081 }
0082 }
0083
0084 eIsoRank[0] = SFP[0][1] & 0x3f;
0085 eIsoRank[1] = ((SFP[0][1] >> 10) & 0x7) | ((SFP[0][2] >> 7) & 0x38);
0086 eIsoRank[2] = SFP[1][1] & 0x3f;
0087 eIsoRank[3] = ((SFP[1][1] >> 10) & 0x7) | ((SFP[1][2] >> 7) & 0x38);
0088
0089 eNonIsoRank[0] = SFP[0][2] & 0x3f;
0090 eNonIsoRank[1] = SFP[0][3] & 0x3f;
0091 eNonIsoRank[2] = SFP[1][2] & 0x3f;
0092 eNonIsoRank[3] = SFP[1][3] & 0x3f;
0093
0094 eIsoRegionId[0] = (SFP[0][1] >> 6) & 0x1;
0095 eIsoRegionId[1] = (SFP[0][2] >> 13) & 0x1;
0096 eIsoRegionId[2] = (SFP[1][1] >> 6) & 0x1;
0097 eIsoRegionId[3] = (SFP[1][2] >> 13) & 0x1;
0098
0099 eNonIsoRegionId[0] = (SFP[0][2] >> 6) & 0x1;
0100 eNonIsoRegionId[1] = (SFP[0][3] >> 6) & 0x1;
0101 eNonIsoRegionId[2] = (SFP[1][2] >> 6) & 0x1;
0102 eNonIsoRegionId[3] = (SFP[1][3] >> 6) & 0x1;
0103
0104 eIsoCardId[0] = (SFP[0][1] >> 7) & 0x7;
0105 eIsoCardId[1] = (SFP[0][3] >> 10) & 0x7;
0106 eIsoCardId[2] = (SFP[1][1] >> 7) & 0x7;
0107 eIsoCardId[3] = (SFP[1][3] >> 10) & 0x7;
0108
0109 eNonIsoCardId[0] = (SFP[0][2] >> 7) & 0x7;
0110 eNonIsoCardId[1] = (SFP[0][3] >> 7) & 0x7;
0111 eNonIsoCardId[2] = (SFP[1][2] >> 7) & 0x7;
0112 eNonIsoCardId[3] = (SFP[1][3] >> 7) & 0x7;
0113 }
0114
0115
0116
0117
0118
0119
0120 void SourceCardRouting::RC56HFtoSFP(unsigned short (&RC)[7][2],
0121 unsigned short (&RCof)[7][2],
0122 unsigned short (&RCtau)[7][2],
0123 unsigned short (&HF)[4][2],
0124 unsigned short (&HFQ)[4][2],
0125 unsigned short (&SFP)[2][4]) const {
0126 SFP[0][0] = (RC[5][0] & 0x3ff) | ((RCof[5][0] & 0x1) << 10) | ((RCtau[5][0] & 0x1) << 11) |
0127 ((HFQ[0][0] & 0x1) << 12) | ((HFQ[1][0] & 0x01) << 13) | ((HF[0][0] & 0x01) << 14);
0128 SFP[1][0] = 0x8000 | (RC[5][1] & 0x3ff) | ((RCof[5][1] & 0x1) << 10) | ((RCtau[5][1] & 0x1) << 11) |
0129 ((HFQ[2][0] & 0x1) << 12) | ((HFQ[3][0] & 0x01) << 13) | ((HF[2][0] & 0x01) << 14);
0130 SFP[0][1] = (RC[6][0] & 0x3ff) | ((RCof[6][0] & 0x1) << 10) | ((RCtau[6][0] & 0x1) << 11) |
0131 ((HFQ[0][1] & 0x1) << 12) | ((HFQ[1][1] & 0x01) << 13) | ((HF[0][1] & 0x01) << 14);
0132 SFP[1][1] = 0x8000 | (RC[6][1] & 0x3ff) | ((RCof[6][1] & 0x1) << 10) | ((RCtau[6][1] & 0x1) << 11) |
0133 ((HFQ[2][1] & 0x1) << 12) | ((HFQ[3][1] & 0x01) << 13) | ((HF[2][1] & 0x01) << 14);
0134 SFP[0][2] = ((HF[0][0] >> 1) & 0x7f) | ((HF[1][0] & 0xff) << 7);
0135 SFP[1][2] = 0x8000 | ((HF[2][0] >> 1) & 0x7f) | ((HF[3][0] & 0xff) << 7);
0136 SFP[0][3] = ((HF[0][1] >> 1) & 0x7f) | ((HF[1][1] & 0xff) << 7);
0137 SFP[1][3] = 0x8000 | ((HF[2][1] >> 1) & 0x7f) | ((HF[3][1] & 0xff) << 7);
0138 }
0139
0140
0141
0142
0143
0144
0145 void SourceCardRouting::SFPtoRC56HF(unsigned short (&RC)[7][2],
0146 unsigned short (&RCof)[7][2],
0147 unsigned short (&RCtau)[7][2],
0148 unsigned short (&HF)[4][2],
0149 unsigned short (&HFQ)[4][2],
0150 unsigned short (&SFP)[2][4]) const {
0151 RC[5][0] = SFP[0][0] & 0x3ff;
0152 RC[5][1] = SFP[1][0] & 0x3ff;
0153 RC[6][0] = SFP[0][1] & 0x3ff;
0154 RC[6][1] = SFP[1][1] & 0x3ff;
0155
0156 RCof[5][0] = (SFP[0][0] >> 10) & 0x1;
0157 RCof[5][1] = (SFP[1][0] >> 10) & 0x1;
0158 RCof[6][0] = (SFP[0][1] >> 10) & 0x1;
0159 RCof[6][1] = (SFP[1][1] >> 10) & 0x1;
0160
0161 RCtau[5][0] = (SFP[0][0] >> 11) & 0x1;
0162 RCtau[5][1] = (SFP[1][0] >> 11) & 0x1;
0163 RCtau[6][0] = (SFP[0][1] >> 11) & 0x1;
0164 RCtau[6][1] = (SFP[1][1] >> 11) & 0x1;
0165
0166 HFQ[0][0] = (SFP[0][0] >> 12) & 0x1;
0167 HFQ[1][0] = (SFP[0][0] >> 13) & 0x1;
0168 HFQ[2][0] = (SFP[1][0] >> 12) & 0x1;
0169 HFQ[3][0] = (SFP[1][0] >> 13) & 0x1;
0170
0171 HFQ[0][1] = (SFP[0][1] >> 12) & 0x1;
0172 HFQ[1][1] = (SFP[0][1] >> 13) & 0x1;
0173 HFQ[2][1] = (SFP[1][1] >> 12) & 0x1;
0174 HFQ[3][1] = (SFP[1][1] >> 13) & 0x1;
0175
0176 HF[0][0] = ((SFP[0][2] & 0x7f) << 1) | ((SFP[0][0] >> 14) & 0x01);
0177 HF[1][0] = (SFP[0][2] >> 7) & 0xff;
0178 HF[2][0] = ((SFP[1][2] & 0x7f) << 1) | ((SFP[1][0] >> 14) & 0x01);
0179 HF[3][0] = (SFP[1][2] >> 7) & 0xff;
0180
0181 HF[0][1] = ((SFP[0][3] & 0x7f) << 1) | ((SFP[0][1] >> 14) & 0x01);
0182 HF[1][1] = (SFP[0][3] >> 7) & 0xff;
0183 HF[2][1] = ((SFP[1][3] & 0x7f) << 1) | ((SFP[1][1] >> 14) & 0x01);
0184 HF[3][1] = (SFP[1][3] >> 7) & 0xff;
0185 }
0186
0187
0188
0189
0190
0191 void SourceCardRouting::RC012toSFP(unsigned short (&RC)[7][2],
0192 unsigned short (&RCof)[7][2],
0193 unsigned short (&RCtau)[7][2],
0194 unsigned short (&SFP)[2][4]) const {
0195 SFP[0][0] = (RC[0][0] & 0x3ff) | ((RCof[0][0] & 0x1) << 10) | ((RCtau[0][0] & 0x1) << 11) | ((RC[2][0] & 0x7) << 12);
0196 SFP[1][0] =
0197 0x8000 | (RC[0][1] & 0x3ff) | ((RCof[0][1] & 0x1) << 10) | ((RCtau[0][1] & 0x1) << 11) | ((RC[2][1] & 0x7) << 12);
0198
0199 SFP[0][1] = (RC[1][0] & 0x3ff) | ((RCof[1][0] & 0x1) << 10) | ((RCtau[1][0] & 0x1) << 11) | ((RC[2][0] & 0x38) << 9);
0200 SFP[1][1] =
0201 0x8000 | (RC[1][1] & 0x3ff) | ((RCof[1][1] & 0x1) << 10) | ((RCtau[1][1] & 0x1) << 11) | ((RC[2][1] & 0x38) << 9);
0202
0203 SFP[0][2] = (RC[0][0] & 0x3ff) | ((RCof[0][0] & 0x1) << 10) | ((RCtau[0][0] & 0x1) << 11);
0204 SFP[1][2] = 0x8000 | (RC[0][1] & 0x3ff) | ((RCof[0][1] & 0x1) << 10) | ((RCtau[0][1] & 0x1) << 11);
0205
0206 SFP[0][3] = (RC[1][0] & 0x3ff) | ((RCof[1][0] & 0x1) << 10) | ((RCtau[1][0] & 0x1) << 11);
0207 SFP[1][3] = 0x8000 | (RC[1][1] & 0x3ff) | ((RCof[1][1] & 0x1) << 10) | ((RCtau[1][1] & 0x1) << 11);
0208 }
0209
0210
0211
0212
0213
0214 void SourceCardRouting::SFPtoRC012(unsigned short (&RC)[7][2],
0215 unsigned short (&RCof)[7][2],
0216 unsigned short (&RCtau)[7][2],
0217 unsigned short (&SFP)[2][4]) const {
0218 RC[0][0] = SFP[0][0] & 0x3ff;
0219 RC[0][1] = SFP[1][0] & 0x3ff;
0220 RC[1][0] = SFP[0][1] & 0x3ff;
0221 RC[1][1] = SFP[1][1] & 0x3ff;
0222 RC[2][0] = (RC[2][0] & 0x3c0) | ((SFP[0][0] & 0x7000) >> 12) | ((SFP[0][1] & 0x7000) >> 9);
0223 RC[2][1] = (RC[2][1] & 0x3c0) | ((SFP[1][0] & 0x7000) >> 12) | ((SFP[1][1] & 0x7000) >> 9);
0224
0225 RCof[0][0] = (SFP[0][0] >> 10) & 0x1;
0226 RCof[0][1] = (SFP[1][0] >> 10) & 0x1;
0227 RCof[1][0] = (SFP[0][1] >> 10) & 0x1;
0228 RCof[1][1] = (SFP[1][1] >> 10) & 0x1;
0229
0230 RCtau[0][0] = (SFP[0][0] >> 11) & 0x1;
0231 RCtau[0][1] = (SFP[1][0] >> 11) & 0x1;
0232 RCtau[1][0] = (SFP[0][1] >> 11) & 0x1;
0233 RCtau[1][1] = (SFP[1][1] >> 11) & 0x1;
0234 }
0235
0236
0237
0238
0239
0240 void SourceCardRouting::RC234toSFP(unsigned short (&RC)[7][2],
0241 unsigned short (&RCof)[7][2],
0242 unsigned short (&RCtau)[7][2],
0243 unsigned short (&sisterRC)[7][2],
0244 unsigned short (&sisterRCof)[7][2],
0245 unsigned short (&sisterRCtau)[7][2],
0246 unsigned short (&SFP)[2][4]) const {
0247 SFP[0][0] = (RC[3][0] & 0x3ff) | ((RCof[3][0] & 0x1) << 10) | ((RCtau[3][0] & 0x1) << 11) | ((RC[2][0] & 0x1c0) << 6);
0248 SFP[1][0] = 0x8000 | (RC[3][1] & 0x3ff) | ((RCof[3][1] & 0x1) << 10) | ((RCtau[3][1] & 0x1) << 11) |
0249 ((RC[2][1] & 0x1c0) << 6);
0250
0251 SFP[0][1] = (RC[4][0] & 0x3ff) | ((RCof[4][0] & 0x1) << 10) | ((RCtau[4][0] & 0x1) << 11) |
0252 ((RC[2][0] & 0x200) << 3) | ((RCof[2][0] & 0x1) << 13) | ((RCtau[2][0] & 0x1) << 14);
0253 SFP[1][1] = 0x8000 | (RC[4][1] & 0x3ff) | ((RCof[4][1] & 0x1) << 10) | ((RCtau[4][1] & 0x1) << 11) |
0254 ((RC[2][1] & 0x200) << 3) | ((RCof[2][1] & 0x1) << 13) | ((RCtau[2][1] & 0x1) << 14);
0255
0256 SFP[0][2] = (sisterRC[3][0] & 0x3ff) | ((sisterRCof[3][0] & 0x1) << 10) | ((sisterRCtau[3][0] & 0x1) << 11) |
0257 ((sisterRC[2][0] & 0x1c0) << 6);
0258 SFP[1][2] = 0x8000 | (sisterRC[3][1] & 0x3ff) | ((sisterRCof[3][1] & 0x1) << 10) | ((sisterRCtau[3][1] & 0x1) << 11) |
0259 ((sisterRC[2][1] & 0x1c0) << 6);
0260
0261 SFP[0][3] = (sisterRC[4][0] & 0x3ff) | ((sisterRCof[4][0] & 0x1) << 10) | ((sisterRCtau[4][0] & 0x1) << 11) |
0262 ((sisterRC[2][0] & 0x200) << 3) | ((sisterRCof[2][0] & 0x1) << 13) | ((sisterRCtau[2][0] & 0x1) << 14);
0263 SFP[1][3] = 0x8000 | (sisterRC[4][1] & 0x3ff) | ((sisterRCof[4][1] & 0x1) << 10) | ((sisterRCtau[4][1] & 0x1) << 11) |
0264 ((sisterRC[2][1] & 0x200) << 3) | ((sisterRCof[2][1] & 0x1) << 13) | ((sisterRCtau[2][1] & 0x1) << 14);
0265 }
0266
0267
0268
0269
0270
0271 void SourceCardRouting::SFPtoRC234(unsigned short (&RC)[7][2],
0272 unsigned short (&RCof)[7][2],
0273 unsigned short (&RCtau)[7][2],
0274 unsigned short (&sisterRC)[7][2],
0275 unsigned short (&sisterRCof)[7][2],
0276 unsigned short (&sisterRCtau)[7][2],
0277 unsigned short (&SFP)[2][4]) const {
0278 RC[2][0] = (RC[2][0] & 0x3f) | ((SFP[0][0] & 0x7000) >> 6) | ((SFP[0][1] & 0x1000) >> 3);
0279 RC[3][0] = SFP[0][0] & 0x3ff;
0280 RC[4][0] = SFP[0][1] & 0x3ff;
0281 RC[2][1] = (RC[2][1] & 0x3f) | ((SFP[1][0] & 0x7000) >> 6) | ((SFP[1][1] & 0x1000) >> 3);
0282 RC[3][1] = SFP[1][0] & 0x3ff;
0283 RC[4][1] = SFP[1][1] & 0x3ff;
0284
0285 RCof[2][0] = (SFP[0][1] >> 13) & 0x1;
0286 RCof[3][0] = (SFP[0][0] >> 10) & 0x1;
0287 RCof[4][0] = (SFP[0][1] >> 10) & 0x1;
0288 RCof[2][1] = (SFP[1][1] >> 13) & 0x1;
0289 RCof[3][1] = (SFP[1][0] >> 10) & 0x1;
0290 RCof[4][1] = (SFP[1][1] >> 10) & 0x1;
0291
0292 RCtau[2][0] = (SFP[0][1] >> 14) & 0x1;
0293 RCtau[3][0] = (SFP[0][0] >> 11) & 0x1;
0294 RCtau[4][0] = (SFP[0][1] >> 11) & 0x1;
0295 RCtau[2][1] = (SFP[1][1] >> 14) & 0x1;
0296 RCtau[3][1] = (SFP[1][0] >> 11) & 0x1;
0297 RCtau[4][1] = (SFP[1][1] >> 11) & 0x1;
0298
0299 sisterRC[2][0] = (sisterRC[2][0] & ~0x3C0) | ((SFP[0][2] & 0x7000) >> 6) | ((SFP[0][3] & 0x1000) >> 3);
0300 sisterRC[3][0] = SFP[0][2] & 0x3ff;
0301 sisterRC[4][0] = SFP[0][3] & 0x3ff;
0302 sisterRC[2][1] = (sisterRC[2][1] & ~0x3C0) | ((SFP[1][2] & 0x7000) >> 6) | ((SFP[1][3] & 0x1000) >> 3);
0303 sisterRC[3][1] = SFP[1][2] & 0x3ff;
0304 sisterRC[4][1] = SFP[1][3] & 0x3ff;
0305
0306 sisterRCof[2][0] = (SFP[0][3] >> 13) & 0x1;
0307 sisterRCof[3][0] = (SFP[0][2] >> 10) & 0x1;
0308 sisterRCof[4][0] = (SFP[0][3] >> 10) & 0x1;
0309 sisterRCof[2][1] = (SFP[1][3] >> 13) & 0x1;
0310 sisterRCof[3][1] = (SFP[1][2] >> 10) & 0x1;
0311 sisterRCof[4][1] = (SFP[1][3] >> 10) & 0x1;
0312
0313 sisterRCtau[2][0] = (SFP[0][3] >> 14) & 0x1;
0314 sisterRCtau[3][0] = (SFP[0][2] >> 11) & 0x1;
0315 sisterRCtau[4][0] = (SFP[0][3] >> 11) & 0x1;
0316 sisterRCtau[2][1] = (SFP[1][3] >> 14) & 0x1;
0317 sisterRCtau[3][1] = (SFP[1][2] >> 11) & 0x1;
0318 sisterRCtau[4][1] = (SFP[1][3] >> 11) & 0x1;
0319 }
0320
0321
0322
0323
0324
0325
0326 void SourceCardRouting::SFPtoVHDCI(int RoutingMode, unsigned short (&SFP)[2][4], unsigned long (&VHDCI)[2][2]) const {
0327 unsigned short sfp_reverse[2][4] = {{0}};
0328
0329 for (int i = 0; i < 2; i++) {
0330 for (int j = 0; j < 4; j++) {
0331 for (int k = 0; k < 16; k++) {
0332 sfp_reverse[i][j] = sfp_reverse[i][j] | (((SFP[i][j] >> k) & 0x01) << (15 - k));
0333 }
0334
0335 }
0336 }
0337
0338 switch (RoutingMode) {
0339 case 0:
0340 VHDCI[0][0] = (SFP[0][1] & 0x3ff) | ((SFP[0][1] & 0x1c00) << 1) | ((SFP[0][2] & 0x3c00) << 4) |
0341 ((SFP[0][3] & 0x1c00) << 8) | ((SFP[0][0] & 0xff) << 22);
0342 VHDCI[0][1] = (SFP[1][1] & 0x3ff) | ((SFP[1][1] & 0x1c00) << 1) | ((SFP[1][2] & 0x3c00) << 4) |
0343 ((SFP[1][3] & 0x1c00) << 8) | ((SFP[1][0] & 0xff) << 22);
0344 VHDCI[1][0] = (SFP[0][2] & 0x3ff) | ((SFP[0][3] & 0x3ff) << 11) | ((SFP[0][0] & 0x3f00) << 14);
0345 VHDCI[1][1] = (SFP[1][2] & 0x3ff) | ((SFP[1][3] & 0x3ff) << 11) | ((SFP[1][0] & 0x3f00) << 14);
0346 break;
0347 case 1:
0348 VHDCI[0][0] = (SFP[0][0] & 0xfff) | ((SFP[0][1] & 0x7) << 12) | ((SFP[0][2] & 0x80) << 10) |
0349 ((SFP[0][0] & 0x4000) << 4) | ((sfp_reverse[0][1] & 0xc) << 17) |
0350 ((sfp_reverse[0][0] & 0xc) << 19) | ((sfp_reverse[0][1] & 0x1ff0) << 19);
0351 VHDCI[0][1] = (SFP[1][0] & 0xfff) | ((SFP[1][1] & 0x7) << 12) | ((SFP[1][2] & 0x80) << 10) |
0352 ((SFP[1][0] & 0x4000) << 4) | ((sfp_reverse[1][1] & 0xc) << 17) |
0353 ((sfp_reverse[1][0] & 0xc) << 19) | ((sfp_reverse[1][1] & 0x1ff0) << 19);
0354
0355 VHDCI[1][0] = (SFP[0][1] & 0x4000) | ((SFP[0][3] & 0x80) << 24);
0356 VHDCI[1][1] = (SFP[1][1] & 0x4000) | ((SFP[1][3] & 0x80) << 24);
0357
0358 for (int i = 0; i < 7; i++) {
0359 VHDCI[1][0] = VHDCI[1][0] | (((SFP[0][2] >> i) & 0x1) << (2 * i)) |
0360 (((SFP[0][2] >> (i + 8)) & 0x1) << ((2 * i) + 1)) |
0361 (((sfp_reverse[0][3] >> (i + 1)) & 0x1) << ((2 * i) + 17)) |
0362 (((sfp_reverse[0][3] >> (i + 9)) & 0x1) << ((2 * i) + 18));
0363 VHDCI[1][1] = VHDCI[1][1] | (((SFP[1][2] >> i) & 0x1) << (2 * i)) |
0364 (((SFP[1][2] >> (i + 8)) & 0x1) << ((2 * i) + 1)) |
0365 (((sfp_reverse[1][3] >> (i + 1)) & 0x1) << ((2 * i) + 17)) |
0366 (((sfp_reverse[1][3] >> (i + 9)) & 0x1) << ((2 * i) + 18));
0367 }
0368 break;
0369 case 2:
0370 VHDCI[0][0] = (SFP[0][0] & 0xfff) | ((SFP[0][1] & 0x7) << 12) | ((sfp_reverse[0][1] & 0xe) << 16) |
0371 ((sfp_reverse[0][0] & 0xe) << 19) | ((sfp_reverse[0][1] & 0x1ff0) << 19);
0372 VHDCI[0][1] = (SFP[1][0] & 0xfff) | ((SFP[1][1] & 0x7) << 12) | ((sfp_reverse[1][1] & 0xe) << 16) |
0373 ((sfp_reverse[1][0] & 0xe) << 19) | ((sfp_reverse[1][1] & 0x1ff0) << 19);
0374 VHDCI[1][0] = 0;
0375 VHDCI[1][1] = 0;
0376 break;
0377 case 3:
0378 VHDCI[0][0] = ((SFP[0][0] >> 12) & 0x7) | ((SFP[0][1] >> 9) & 0x38) | ((SFP[0][0] & 0x1ff) << 6) |
0379 ((sfp_reverse[0][1] & 0xfff0) << 13) | ((sfp_reverse[0][0] & 0x70) << 25);
0380 VHDCI[0][1] = ((SFP[1][0] >> 12) & 0x7) | ((SFP[1][1] >> 9) & 0x38) | ((SFP[1][0] & 0x1ff) << 6) |
0381 ((sfp_reverse[1][1] & 0xfff0) << 13) | ((sfp_reverse[1][0] & 0x70) << 25);
0382
0383 VHDCI[1][0] = ((SFP[0][2] >> 12) & 0x7) | ((SFP[0][3] >> 9) & 0x38) | ((SFP[0][2] & 0x1ff) << 6) |
0384 ((sfp_reverse[0][3] & 0xfff0) << 13) | ((sfp_reverse[0][2] & 0x70) << 25);
0385 VHDCI[1][1] = ((SFP[1][2] >> 12) & 0x7) | ((SFP[1][3] >> 9) & 0x38) | ((SFP[1][2] & 0x1ff) << 6) |
0386 ((sfp_reverse[1][3] & 0xfff0) << 13) | ((sfp_reverse[1][2] & 0x70) << 25);
0387 break;
0388 default:
0389 VHDCI[0][0] = 0;
0390 VHDCI[0][1] = 0;
0391 VHDCI[1][0] = 0;
0392 VHDCI[1][1] = 0;
0393 }
0394 }
0395
0396
0397
0398
0399 void SourceCardRouting::VHDCItoSFP(int RoutingMode, unsigned short (&SFP)[2][4], unsigned long (&VHDCI)[2][2]) const {
0400 unsigned short VHDCI_reverse[2][4] = {{0}};
0401
0402 for (int i = 0; i < 2; i++) {
0403 for (int j = 0; j < 2; j++) {
0404 for (int k = 0; k < 32; k++) {
0405 VHDCI_reverse[i][j] = VHDCI_reverse[i][j] | (((VHDCI[i][j] >> k) & 0x01) << (31 - k));
0406 }
0407 }
0408 }
0409
0410 switch (RoutingMode) {
0411 case 0:
0412 SFP[0][0] = ((VHDCI[0][0] >> 22) & 0xff) | ((VHDCI[1][0] >> 14) & 0x3f00);
0413 SFP[1][0] = 0x8000 | ((VHDCI[0][1] >> 22) & 0xff) | ((VHDCI[1][1] >> 14) & 0x3f00);
0414 SFP[0][1] = (VHDCI[0][0] & 0x3ff) | ((VHDCI[0][0] >> 1) & 0x1c00);
0415 SFP[1][1] = 0x8000 | (VHDCI[0][1] & 0x3ff) | ((VHDCI[0][1] >> 1) & 0x1c00);
0416 SFP[0][2] = (VHDCI[1][0] & 0x3ff) | ((VHDCI[0][0] >> 4) & 0x3c00);
0417 SFP[1][2] = 0x8000 | (VHDCI[1][1] & 0x3ff) | ((VHDCI[0][1] >> 4) & 0x3c00);
0418 SFP[0][3] = ((VHDCI[1][0] >> 11) & 0x3ff) | ((VHDCI[0][0] >> 8) & 0x1c00);
0419 SFP[1][3] = 0x8000 | ((VHDCI[1][1] >> 11) & 0x3ff) | ((VHDCI[0][1] >> 8) & 0x1c00);
0420 break;
0421 case 1:
0422 SFP[0][0] = (VHDCI[0][0] & 0xfff) | ((VHDCI_reverse[0][0] & 0x600) << 3) | ((VHDCI_reverse[0][0] & 0x2000) << 1);
0423 SFP[1][0] =
0424 0x8000 | (VHDCI[0][1] & 0xfff) | ((VHDCI_reverse[0][1] & 0x600) << 3) | ((VHDCI_reverse[0][1] & 0x2000) << 1);
0425 SFP[0][1] = ((VHDCI[0][0] & 0x7000) >> 12) | ((VHDCI_reverse[0][0] & 0x1ff) << 3) |
0426 ((VHDCI_reverse[0][0] & 0x1800) << 1) | (VHDCI[1][0] & 0x4000);
0427 SFP[1][1] = 0x8000 | ((VHDCI[0][1] & 0x7000) >> 12) | ((VHDCI_reverse[0][1] & 0x1ff) << 3) |
0428 ((VHDCI_reverse[0][1] & 0x1800) << 1) | (VHDCI[1][1] & 0x4000);
0429
0430 SFP[0][2] = ((VHDCI[0][0] & 0x20000) >> 10);
0431 SFP[1][2] = 0x8000 | ((VHDCI[0][1] & 0x20000) >> 10);
0432 SFP[0][3] = ((VHDCI[1][0] & 0x20000) >> 3);
0433 SFP[1][3] = 0x8000 | ((VHDCI[1][1] & 0x20000) >> 3);
0434 for (int i = 0; i < 7; i++) {
0435 SFP[0][2] =
0436 SFP[0][2] | (((VHDCI[1][0] >> (2 * i)) & 0x1) << i) | (((VHDCI[1][0] >> ((2 * i) + 1)) & 0x1) << (i + 8));
0437 SFP[1][2] =
0438 SFP[1][2] | (((VHDCI[1][1] >> (2 * i)) & 0x1) << i) | (((VHDCI[1][1] >> ((2 * i) + 1)) & 0x1) << (i + 8));
0439 SFP[0][3] = SFP[0][3] | (((VHDCI_reverse[1][0] >> ((2 * i) + 1)) & 0x1) << i) |
0440 (((VHDCI_reverse[1][0] >> (2 * i)) & 0x1) << (i + 7));
0441 SFP[1][3] = SFP[1][3] | (((VHDCI_reverse[1][1] >> ((2 * i) + 1)) & 0x1) << i) |
0442 (((VHDCI_reverse[1][1] >> (2 * i)) & 0x1) << (i + 7));
0443 }
0444 break;
0445 case 2:
0446 SFP[0][0] = (VHDCI[0][0] & 0xfff) | ((VHDCI_reverse[0][0] & 0xe00) << 3);
0447 SFP[1][0] = 0x8000 | (VHDCI[0][1] & 0xfff) | ((VHDCI_reverse[0][1] & 0xe00) << 3);
0448 SFP[0][1] =
0449 ((VHDCI[0][0] & 0x7000) >> 12) | ((VHDCI_reverse[0][0] & 0x1ff) << 3) | (VHDCI_reverse[0][0] & 0x7000);
0450 SFP[1][1] = 0x8000 | ((VHDCI[0][1] & 0x7000) >> 12) | ((VHDCI_reverse[0][1] & 0x1ff) << 3) |
0451 (VHDCI_reverse[0][1] & 0x7000);
0452 SFP[0][2] = (VHDCI[0][0] & 0xfff);
0453 SFP[1][2] = 0x8000 | (VHDCI[0][1] & 0xfff);
0454 SFP[0][3] = ((VHDCI[0][0] & 0x7000) >> 12) | ((VHDCI_reverse[0][0] & 0x1ff) << 3);
0455 SFP[1][3] = 0x8000 | ((VHDCI[0][1] & 0x7000) >> 12) | ((VHDCI_reverse[0][1] & 0x1ff) << 3);
0456 break;
0457 case 3:
0458 SFP[0][0] = ((VHDCI[0][0] & 0x7fc0) >> 6) | ((VHDCI_reverse[0][0] & 0x7) << 9) | ((VHDCI[0][0] & 0x7) << 12);
0459 SFP[1][0] =
0460 0x8000 | ((VHDCI[0][1] & 0x7fc0) >> 6) | ((VHDCI_reverse[0][1] & 0x7) << 9) | ((VHDCI[0][1] & 0x7) << 12);
0461 SFP[0][1] = ((VHDCI_reverse[0][0] & 0x7ff8) >> 3) | ((VHDCI[0][0] & 0x38) << 9);
0462 SFP[1][1] = 0x8000 | ((VHDCI_reverse[0][1] & 0x7ff8) >> 3) | ((VHDCI[0][1] & 0x38) << 9);
0463 SFP[0][2] = ((VHDCI[1][0] & 0x7fc0) >> 6) | ((VHDCI_reverse[1][0] & 0x7) << 9) | ((VHDCI[1][0] & 0x7) << 12);
0464 SFP[1][2] =
0465 0x8000 | ((VHDCI[1][1] & 0x7fc0) >> 6) | ((VHDCI_reverse[1][1] & 0x7) << 9) | ((VHDCI[1][1] & 0x7) << 12);
0466 SFP[0][3] = ((VHDCI_reverse[1][0] & 0x7ff8) >> 3) | ((VHDCI[1][0] & 0x38) << 9);
0467 SFP[1][3] = 0x8000 | ((VHDCI_reverse[1][1] & 0x7ff8) >> 3) | ((VHDCI[1][1] & 0x38) << 9);
0468 break;
0469 default:
0470 SFP[0][0] = 0;
0471 SFP[1][0] = 0x8000;
0472 SFP[0][1] = 0;
0473 SFP[1][1] = 0x8000;
0474 SFP[0][2] = 0;
0475 SFP[1][2] = 0x8000;
0476 SFP[0][3] = 0;
0477 SFP[1][3] = 0x8000;
0478 }
0479 }
0480
0481
0482
0483
0484
0485
0486
0487 void SourceCardRouting::EMUtoVHDCI(unsigned short (&eIsoRank)[4],
0488 unsigned short (&eIsoCardId)[4],
0489 unsigned short (&eIsoRegionId)[4],
0490 unsigned short (&eNonIsoRank)[4],
0491 unsigned short (&eNonIsoCardId)[4],
0492 unsigned short (&eNonIsoRegionId)[4],
0493 unsigned short (&MIPbits)[7][2],
0494 unsigned short (&Qbits)[7][2],
0495 unsigned long (&VHDCI)[2][2]) const {
0496 unsigned short SFP[2][4] = {{0}};
0497 EMUtoSFP(eIsoRank, eIsoCardId, eIsoRegionId, eNonIsoRank, eNonIsoCardId, eNonIsoRegionId, MIPbits, Qbits, SFP);
0498 SFPtoVHDCI(0, SFP, VHDCI);
0499 }
0500
0501
0502
0503
0504
0505
0506 void SourceCardRouting::VHDCItoEMU(unsigned short (&eIsoRank)[4],
0507 unsigned short (&eIsoCardId)[4],
0508 unsigned short (&eIsoRegionId)[4],
0509 unsigned short (&eNonIsoRank)[4],
0510 unsigned short (&eNonIsoCardId)[4],
0511 unsigned short (&eNonIsoRegionId)[4],
0512 unsigned short (&MIPbits)[7][2],
0513 unsigned short (&Qbits)[7][2],
0514 unsigned long (&VHDCI)[2][2]) const {
0515 unsigned short SFP[2][4] = {{0}};
0516 VHDCItoSFP(0, SFP, VHDCI);
0517 SFPtoEMU(eIsoRank, eIsoCardId, eIsoRegionId, eNonIsoRank, eNonIsoCardId, eNonIsoRegionId, MIPbits, Qbits, SFP);
0518 }
0519
0520
0521
0522
0523
0524
0525 void SourceCardRouting::RC56HFtoVHDCI(unsigned short (&RC)[7][2],
0526 unsigned short (&RCof)[7][2],
0527 unsigned short (&RCtau)[7][2],
0528 unsigned short (&HF)[4][2],
0529 unsigned short (&HFQ)[4][2],
0530 unsigned long (&VHDCI)[2][2]) const {
0531 unsigned short SFP[2][4] = {{0}};
0532 RC56HFtoSFP(RC, RCof, RCtau, HF, HFQ, SFP);
0533 SFPtoVHDCI(1, SFP, VHDCI);
0534 }
0535
0536
0537
0538
0539
0540
0541 void SourceCardRouting::VHDCItoRC56HF(unsigned short (&RC)[7][2],
0542 unsigned short (&RCof)[7][2],
0543 unsigned short (&RCtau)[7][2],
0544 unsigned short (&HF)[4][2],
0545 unsigned short (&HFQ)[4][2],
0546 unsigned long (&VHDCI)[2][2]) const {
0547 unsigned short SFP[2][4] = {{0}};
0548 VHDCItoSFP(1, SFP, VHDCI);
0549 SFPtoRC56HF(RC, RCof, RCtau, HF, HFQ, SFP);
0550 }
0551
0552
0553
0554
0555
0556 void SourceCardRouting::RC012toVHDCI(unsigned short (&RC)[7][2],
0557 unsigned short (&RCof)[7][2],
0558 unsigned short (&RCtau)[7][2],
0559 unsigned long (&VHDCI)[2][2]) const {
0560 unsigned short SFP[2][4] = {{0}};
0561 RC012toSFP(RC, RCof, RCtau, SFP);
0562 SFPtoVHDCI(2, SFP, VHDCI);
0563 }
0564
0565
0566
0567
0568
0569 void SourceCardRouting::VHDCItoRC012(unsigned short (&RC)[7][2],
0570 unsigned short (&RCof)[7][2],
0571 unsigned short (&RCtau)[7][2],
0572 unsigned long (&VHDCI)[2][2]) const {
0573 unsigned short SFP[2][4] = {{0}};
0574 VHDCItoSFP(2, SFP, VHDCI);
0575 SFPtoRC012(RC, RCof, RCtau, SFP);
0576 }
0577
0578
0579
0580
0581
0582 void SourceCardRouting::RC234toVHDCI(unsigned short (&RC)[7][2],
0583 unsigned short (&RCof)[7][2],
0584 unsigned short (&RCtau)[7][2],
0585 unsigned short (&sisterRC)[7][2],
0586 unsigned short (&sisterRCof)[7][2],
0587 unsigned short (&sisterRCtau)[7][2],
0588 unsigned long (&VHDCI)[2][2]) const {
0589 unsigned short SFP[2][4] = {{0}};
0590 RC234toSFP(RC, RCof, RCtau, sisterRC, sisterRCof, sisterRCtau, SFP);
0591 SFPtoVHDCI(3, SFP, VHDCI);
0592 }
0593
0594
0595
0596
0597
0598 void SourceCardRouting::VHDCItoRC234(unsigned short (&RC)[7][2],
0599 unsigned short (&RCof)[7][2],
0600 unsigned short (&RCtau)[7][2],
0601 unsigned short (&sisterRC)[7][2],
0602 unsigned short (&sisterRCof)[7][2],
0603 unsigned short (&sisterRCtau)[7][2],
0604 unsigned long (&VHDCI)[2][2]) const {
0605 unsigned short SFP[2][4] = {{0}};
0606 VHDCItoSFP(3, SFP, VHDCI);
0607 SFPtoRC234(RC, RCof, RCtau, sisterRC, sisterRCof, sisterRCtau, SFP);
0608 }
0609
0610
0611
0612
0613
0614
0615 void SourceCardRouting::EMUtoSTRING(unsigned short &logicalCardID,
0616 unsigned short &eventNumber,
0617 unsigned short (&eIsoRank)[4],
0618 unsigned short (&eIsoCardId)[4],
0619 unsigned short (&eIsoRegionId)[4],
0620 unsigned short (&eNonIsoRank)[4],
0621 unsigned short (&eNonIsoCardId)[4],
0622 unsigned short (&eNonIsoRegionId)[4],
0623 unsigned short (&MIPbits)[7][2],
0624 unsigned short (&Qbits)[7][2],
0625 std::string &dataString) const {
0626 unsigned long VHDCI[2][2] = {{0}};
0627 EMUtoVHDCI(eIsoRank, eIsoCardId, eIsoRegionId, eNonIsoRank, eNonIsoCardId, eNonIsoRegionId, MIPbits, Qbits, VHDCI);
0628 VHDCItoSTRING(logicalCardID, eventNumber, dataString, VHDCI);
0629 }
0630
0631
0632
0633
0634
0635 void SourceCardRouting::RC56HFtoSTRING(unsigned short &logicalCardID,
0636 unsigned short &eventNumber,
0637 unsigned short (&RC)[7][2],
0638 unsigned short (&RCof)[7][2],
0639 unsigned short (&RCtau)[7][2],
0640 unsigned short (&HF)[4][2],
0641 unsigned short (&HFQ)[4][2],
0642 std::string &dataString) const {
0643 unsigned long VHDCI[2][2] = {{0}};
0644 RC56HFtoVHDCI(RC, RCof, RCtau, HF, HFQ, VHDCI);
0645 VHDCItoSTRING(logicalCardID, eventNumber, dataString, VHDCI);
0646 }
0647
0648
0649
0650
0651 void SourceCardRouting::RC012toSTRING(unsigned short &logicalCardID,
0652 unsigned short &eventNumber,
0653 unsigned short (&RC)[7][2],
0654 unsigned short (&RCof)[7][2],
0655 unsigned short (&RCtau)[7][2],
0656 std::string &dataString) const {
0657 unsigned long VHDCI[2][2] = {{0}};
0658 RC012toVHDCI(RC, RCof, RCtau, VHDCI);
0659 VHDCItoSTRING(logicalCardID, eventNumber, dataString, VHDCI);
0660 }
0661
0662
0663
0664
0665 void SourceCardRouting::RC234toSTRING(unsigned short &logicalCardID,
0666 unsigned short &eventNumber,
0667 unsigned short (&RC)[7][2],
0668 unsigned short (&RCof)[7][2],
0669 unsigned short (&RCtau)[7][2],
0670 unsigned short (&sisterRC)[7][2],
0671 unsigned short (&sisterRCof)[7][2],
0672 unsigned short (&sisterRCtau)[7][2],
0673 std::string &dataString) const {
0674 unsigned long VHDCI[2][2] = {{0}};
0675 RC234toVHDCI(RC, RCof, RCtau, sisterRC, sisterRCof, sisterRCtau, VHDCI);
0676 VHDCItoSTRING(logicalCardID, eventNumber, dataString, VHDCI);
0677 }
0678
0679
0680
0681
0682 void SourceCardRouting::SFPtoSTRING(unsigned short &logicalCardID,
0683 unsigned short &eventNumber,
0684 int RoutingMode,
0685 unsigned short (&SFP)[2][4],
0686 std::string &dataString) const {
0687 unsigned long VHDCI[2][2] = {{0}};
0688 SFPtoVHDCI(RoutingMode, SFP, VHDCI);
0689 VHDCItoSTRING(logicalCardID, eventNumber, dataString, VHDCI);
0690 }
0691
0692
0693
0694
0695 void SourceCardRouting::STRINGtoVHDCI(unsigned short &logicalCardID,
0696 unsigned short &eventNumber,
0697 std::string &dataString,
0698 unsigned long (&VHDCI)[2][2]) const {
0699 stringstream temp;
0700
0701 if (!dataString.empty()) {
0702 temp << dataString << std::endl;
0703 temp >> dec >> eventNumber;
0704 temp >> dec >> logicalCardID;
0705 temp >> hex >> VHDCI[0][0];
0706 temp >> hex >> VHDCI[0][1];
0707 temp >> hex >> VHDCI[1][0];
0708 temp >> hex >> VHDCI[1][1];
0709 } else {
0710 eventNumber = 65535;
0711 logicalCardID = 65535;
0712 VHDCI[0][0] = 0;
0713 VHDCI[0][1] = 0;
0714 VHDCI[1][0] = 0;
0715 VHDCI[1][1] = 0;
0716 }
0717 }
0718
0719
0720
0721 void SourceCardRouting::VHDCItoSTRING(unsigned short &logicalCardID,
0722 unsigned short &eventNumber,
0723 std::string &dataString,
0724 unsigned long (&VHDCI)[2][2]) const {
0725 stringstream temp;
0726
0727 temp << dec << eventNumber << '\t';
0728 temp << dec << logicalCardID << '\t';
0729 temp << hex << setw(8) << setfill('0') << VHDCI[0][0] << '\t';
0730 temp << hex << setw(8) << setfill('0') << VHDCI[0][1] << '\t';
0731 temp << hex << setw(8) << setfill('0') << VHDCI[1][0] << '\t';
0732 temp << hex << setw(8) << setfill('0') << VHDCI[1][1] << std::endl;
0733 dataString = temp.str();
0734 }
0735
0736
0737
0738
0739 void SourceCardRouting::LogicalCardIDtoRoutingMode(unsigned short &logicalCardID,
0740 int &RoutingMode,
0741 int &RCTCrateNumber) const {
0742 RCTCrateNumber = (logicalCardID >> 3);
0743 if ((logicalCardID & 0x4) != 0)
0744 RCTCrateNumber += 9;
0745 RoutingMode = (logicalCardID & 0x3);
0746 }
0747
0748
0749
0750 void SourceCardRouting::RoutingModetoLogicalCardID(unsigned short &logicalCardID,
0751 int &RoutingMode,
0752 int &RCTCrateNumber) const {
0753 logicalCardID = ((RCTCrateNumber % 9) << 3) | (RCTCrateNumber > 8 ? 0x4 : 0x0) | (RoutingMode & 0x3);
0754 }
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833
0834
0835
0836
0837
0838
0839
0840
0841
0842
0843
0844
0845
0846
0847
0848
0849
0850
0851
0852
0853
0854
0855
0856
0857
0858
0859
0860
0861
0862
0863
0864
0865
0866
0867
0868
0869
0870
0871
0872
0873
0874
0875
0876
0877
0878
0879
0880
0881
0882
0883