File indexing completed on 2025-08-03 08:20:36
0001 #include "oncsSub_idgl1v1.h"
0002
0003 #include <string.h>
0004
0005 using namespace std;
0006
0007 #define NR_GL1PSCALERS (12)
0008
0009 oncsSub_idgl1v1::oncsSub_idgl1v1(subevtdata_ptr data)
0010 :oncsSubevent_w4 (data)
0011 {
0012
0013 BCO = 0;
0014 packet_nr = 0;
0015 tag = 0;
0016
0017 memset (scalers, 0, sizeof(scalers) );
0018 memset (gl1p_scalers, 0, sizeof(gl1p_scalers) );
0019 is_decoded = 0;
0020 GTM_AllBusyVector = 0;
0021 GTM_BusyVector = 0;
0022 _broken = 0;
0023 _newformat = 0;
0024
0025 }
0026
0027 int oncsSub_idgl1v1::decode ()
0028 {
0029 if (is_decoded) return 0;
0030 is_decoded = 1;
0031
0032
0033 if ( SubeventHdr->sub_length < 504 )
0034 {
0035 _broken = 1;
0036 return 1;
0037 }
0038
0039 if ( getHitFormat() == IDGL1V2)
0040 {
0041 _newformat = 1;
0042 }
0043
0044 unsigned short *buffer = ( unsigned short *) &SubeventHdr->data;
0045
0046
0047
0048
0049 packet_nr = ( buffer[1] << 16) | buffer[2];
0050
0051
0052
0053
0054
0055 int i = 3;
0056 BCO = 0;
0057 for ( int j = 0; j < 3; j++)
0058 {
0059 BCO |= buffer[i+j];
0060 BCO<<=16;
0061 }
0062 BCO |= buffer[i+3];
0063
0064
0065
0066 BunchNumber = 0;
0067 i = 7;
0068 for ( int j = 0; j < 3; j++)
0069 {
0070 BunchNumber |= buffer[i+j];
0071 BunchNumber<<=16;
0072 }
0073 BunchNumber |= buffer[i+3];
0074 BunchNumber &= 0x7f;
0075
0076
0077
0078
0079 if ( _newformat)
0080 {
0081
0082 GTM_AllBusyVector = buffer[12];
0083 GTM_BusyVector = buffer[14];
0084
0085 }
0086 else
0087 {
0088
0089 GTM_AllBusyVector = 0;
0090
0091 GTM_BusyVector = buffer[13];
0092 GTM_BusyVector <<= 16;
0093 GTM_BusyVector |= buffer[14];
0094 }
0095
0096
0097 TriggerInput = 0;
0098 TriggerVector = 0;
0099 ScaledVector = 0;
0100
0101
0102 i = 15;
0103 for ( int j = 0; j < 3; j++)
0104 {
0105 TriggerInput |= buffer[i+j];
0106 TriggerInput<<=16;
0107 }
0108 TriggerInput |= buffer[i+3];
0109
0110
0111 i = 19;
0112 for ( int j = 0; j < 3; j++)
0113 {
0114 TriggerVector |= buffer[i+j];
0115 TriggerVector<<=16;
0116 }
0117 TriggerVector |= buffer[i+3];
0118
0119
0120
0121
0122
0123 i = 23;
0124 for ( int j = 0; j < 3; j++)
0125 {
0126 ScaledVector |= buffer[i+j];
0127 ScaledVector <<=16;
0128 }
0129 ScaledVector |= buffer[i+3];
0130
0131 int index = 0;
0132 unsigned long long s;
0133
0134 for ( i = 27 ; i < 27+3*4*64; i+=4)
0135 {
0136 s = 0;
0137 for ( int j = 0; j < 3; j++)
0138 {
0139 s |= buffer[i+j];
0140 s<<=16;
0141 }
0142 s |= buffer[i+3];
0143
0144
0145
0146 scalers[index++] = s;
0147
0148 }
0149
0150
0151 index = 0;
0152 for ( i = 27+3*4*64; i < 27+3*4*64 + 3*2*NR_GL1PSCALERS; i+=2)
0153 {
0154 s = 0;
0155 s = buffer[i];
0156 s<<=16;
0157 s |= buffer[i+1];
0158
0159
0160
0161 gl1p_scalers[index++] = s;
0162
0163 }
0164
0165 return 0;
0166 }
0167
0168 int oncsSub_idgl1v1::iValue(const int i)
0169 {
0170 decode();
0171 if ( _broken) return 0;
0172 if ( i == 0) return packet_nr;
0173 if ( i == 1) return tag;
0174 return 0;
0175 }
0176
0177 long long oncsSub_idgl1v1::lValue(const int i, const int k)
0178 {
0179 decode();
0180 if ( _broken) return 0;
0181 if ( i < 0 || i >=64 || k < 0 || k >2) return 0;
0182 return scalers[3*i + k];
0183 }
0184
0185 long long oncsSub_idgl1v1::lValue(const int i, const char *what)
0186 {
0187 decode();
0188 if ( _broken) return 0;
0189
0190 if ( strcmp(what,"BCO") == 0)
0191 {
0192 return BCO;
0193 }
0194
0195 if ( strcmp(what,"TriggerVector") == 0)
0196 {
0197 return TriggerVector;
0198 }
0199
0200 if ( strcmp(what,"LiveVector") == 0)
0201 {
0202 return TriggerVector;
0203 }
0204
0205 if ( strcmp(what,"ScaledVector") == 0)
0206 {
0207 return ScaledVector;
0208 }
0209
0210 if ( strcmp(what,"TriggerInput") == 0)
0211 {
0212 return TriggerInput;
0213 }
0214
0215 if ( strcmp(what,"GTMAllBusyVector") == 0)
0216 {
0217 return GTM_AllBusyVector;
0218 }
0219
0220 if ( strcmp(what,"GTMBusyVector") == 0)
0221 {
0222 return GTM_BusyVector;
0223 }
0224
0225 if ( strcmp(what,"BunchNumber") == 0)
0226 {
0227 return BunchNumber;
0228 }
0229
0230
0231
0232 if ( i < 0 || i >=64) return 0;
0233
0234 if ( strcmp(what,"TRIGGERRAW") == 0)
0235 {
0236 return lValue(i, 0);
0237 }
0238
0239 if ( strcmp(what,"TRIGGERLIVE") == 0)
0240 {
0241 return lValue(i, 1);
0242 }
0243
0244 if ( strcmp(what,"TRIGGERSCALED") == 0)
0245 {
0246 return lValue(i, 2);
0247 }
0248
0249 if ( strcmp(what,"GL1PRAW") == 0)
0250 {
0251 if ( i < 0 || i > NR_GL1PSCALERS-1) return 0;
0252 return gl1p_scalers[i * 3];
0253 }
0254
0255 if ( strcmp(what,"GL1PLIVE") == 0)
0256 {
0257 if ( i < 0 || i > NR_GL1PSCALERS-1) return 0;
0258 return gl1p_scalers[i*3+1];
0259 }
0260
0261 if ( strcmp(what,"GL1PSCALED") == 0)
0262 {
0263 if ( i < 0 || i > NR_GL1PSCALERS-1) return 0;
0264 return gl1p_scalers[i*3+2];
0265 }
0266
0267
0268 return 0;
0269
0270 }
0271
0272
0273 void oncsSub_idgl1v1::dump(std::ostream &os)
0274 {
0275 identify(os);
0276 if ( _broken)
0277 {
0278 os << " ** corrupt packet **" << endl;
0279 return;
0280 }
0281
0282 os << "packet nr: " << (unsigned int) iValue(0) << endl;
0283 os << "Beam Clock: " << "0x" << hex << lValue(0, "BCO") << dec << " " << lValue(0, "BCO") << endl;
0284 os << "Trigger Input: " << "0x" << hex << lValue(0, "TriggerInput") << dec << " " << lValue(0, "TriggerInput") << endl;
0285 os << "Live Vector: " << "0x" << hex << lValue(0, "LiveVector") << dec << " " << lValue(0, "LiveVector") << endl;
0286 os << "Scaled Vector: " << "0x" << hex << lValue(0, "ScaledVector") << dec << " " << lValue(0, "ScaledVector") << endl;
0287 os << "GTM Busy Vector: " << "0x" << hex << lValue(0, "GTMBusyVector") << dec << " " << lValue(0, "GTMBusyVector") << endl;
0288 if ( _newformat)
0289 {
0290 os << "GTM All Busies: " << "0x" << hex << lValue(0, "GTMAllBusyVector") << dec << " " << lValue(0, "GTMAllBusyVector") << endl;
0291 }
0292 os << "Bunch Number: " << lValue(0, "BunchNumber") << endl << endl;
0293 os << "Trg # raw live scaled" << endl;
0294 os << "----------------------------------------------------------------" << endl;
0295
0296 int i;
0297
0298 for (i = 0; i< 64; i++)
0299 {
0300 if ( lValue(i, 0) || lValue(i, 1) || lValue(i, 2) )
0301 {
0302 os << setw(3) << i << " ";
0303 os << " " << setw(18) << lValue(i,0)
0304 << " " << setw(18) << lValue(i,1)
0305 << " " << setw(18) << lValue(i,2)
0306 << endl;
0307 }
0308 }
0309 os << endl;
0310
0311 os << "Gl1P # raw live scaled" << endl;
0312 os << "----------------------------------------------------------------" << endl;
0313
0314 for (i = 0; i < NR_GL1PSCALERS; i++)
0315 {
0316 if ( lValue(i, "GL1PRAW") || lValue(i, "GL1PLIVE") || lValue(i, "GL1PSCALED") )
0317 {
0318 os << setw(3) << i << " ";
0319 os << " " << setw(18) << lValue(i, "GL1PRAW")
0320 << " " << setw(18) << lValue(i, "GL1PLIVE")
0321 << " " << setw(18) << lValue(i, "GL1PSCALED")
0322 << endl;
0323 }
0324 }
0325 os << endl;
0326
0327
0328
0329 }
0330
0331
0332
0333