File indexing completed on 2025-08-03 08:20:49
0001 #include "oncsSub_iduppetdata_v104.h"
0002 #include <cstring>
0003
0004 #include <arpa/inet.h>
0005
0006 using namespace std;
0007
0008 oncsSub_iduppetdata_v104::oncsSub_iduppetdata_v104(subevtdata_ptr data)
0009 :oncsSubevent_w4 (data)
0010 {
0011 samples = 0;
0012 d_time = 0;
0013 d_timelength = 0;
0014 lval = 0;
0015 tval = 0;
0016 serialnumber = 0;
0017 udpheader1 = 0;
0018 udpheader2 = 0;
0019 sysword = 0;
0020 eventrate = 0;
0021 ratcap_upenn = 0;
0022 clock_sel = 0;
0023 }
0024
0025 oncsSub_iduppetdata_v104::~oncsSub_iduppetdata_v104()
0026 {
0027 if ( d_timelength )
0028 {
0029 delete [] d_time;
0030 d_time = 0;
0031 }
0032 if ( lval)
0033 {
0034 delete [] lval;
0035 lval = 0;
0036 }
0037 if ( tval)
0038 {
0039 delete [] tval;
0040 tval = 0;
0041 }
0042 }
0043
0044
0045 int *oncsSub_iduppetdata_v104::decode ( int *nwout)
0046 {
0047 int *p;
0048
0049
0050
0051 int i;
0052
0053 unsigned int *SubeventData = (unsigned int *) &SubeventHdr->data;
0054
0055 unsigned short *sdata = ( unsigned short *) &SubeventData[4];
0056
0057 int dlength = getLength()-4 - getPadding();
0058
0059 samples = (dlength - 3) /2;
0060
0061 p = new int [samples];
0062
0063 decoded_data2 = new int [samples];
0064 data2_length = samples;
0065
0066 decoded_data3 = new int [samples];
0067 data3_length = samples;
0068
0069 decoded_data4 = new int [samples];
0070 data4_length = samples;
0071
0072 lval = new long long [samples];
0073 tval = new long long [samples];
0074
0075 d_time = new double [samples];
0076 d_timelength = samples;
0077
0078 serialnumber = ntohl(SubeventData[0]);
0079 udpheader1 = ntohl(SubeventData[1]);
0080 udpheader2 = ntohl(SubeventData[2]);
0081 sysword = ntohl(SubeventData[3]);
0082
0083 eventrate = sysword & 0xfffffff;
0084 ratcap_upenn = ( sysword >> 28 ) & 1;
0085 clock_sel = ( sysword >> 29 ) & 1;
0086
0087
0088
0089 int k = 0;
0090
0091 for ( i = 0; i < 2*(dlength-4); i+=4 )
0092 {
0093
0094 unsigned long long y;
0095 unsigned long long x64 = ntohs( sdata[i+3]);
0096 x64 <<= 48;
0097
0098 y = ntohs( sdata[i+2]);
0099 y <<=32;
0100 x64 |= y;
0101
0102 y = ntohs( sdata[i+1]);
0103 y <<=16;
0104 x64 |= y;
0105
0106 y = ntohs( sdata[i]);
0107 x64 |= y;
0108
0109 unsigned long long t = x64 & 0x3fffffffffffL;
0110 unsigned int crystalid = ( x64 >> 52) & 0x1f;
0111 unsigned int block = ( x64 >> 57) & 0x1f;
0112 unsigned int rfgate = ( x64 >> 62) & 0x1;
0113 unsigned int cardiac = ( x64 >> 63) & 0x1;
0114
0115 p[k] = block;
0116 decoded_data2[k] = crystalid;
0117 lval[k] = x64;
0118 tval[k] = t;
0119 d_time[k] = t;
0120 decoded_data3[k] = rfgate;
0121 decoded_data4[k] = cardiac;
0122 k++;
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 }
0134
0135
0136 *nwout = k;
0137 return p;
0138 }
0139
0140 int oncsSub_iduppetdata_v104::iValue(const int ich,const char *what)
0141 {
0142
0143 if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0144
0145 if ( strcmp(what,"SAMPLES") == 0 )
0146 {
0147 return samples;
0148 }
0149
0150 if ( strcmp(what,"BLOCKID") == 0 )
0151 {
0152 if ( ich < 0 || ich >= samples) return 0;
0153 return decoded_data1[ich];
0154 }
0155
0156 if ( strcmp(what,"CRYSTALID") == 0 )
0157 {
0158 if ( ich < 0 || ich >= samples) return 0;
0159 return decoded_data2[ich];
0160 }
0161
0162 if ( strcmp(what,"RFGATE") == 0 )
0163 {
0164 if ( ich < 0 || ich >= samples) return 0;
0165 return decoded_data3[ich];
0166 }
0167
0168 if ( strcmp(what,"CARDIAC") == 0 )
0169 {
0170 if ( ich < 0 || ich >= samples) return 0;
0171 return decoded_data4[ich];
0172 }
0173
0174 if ( strcmp(what,"SERIAL") == 0 )
0175 {
0176 return serialnumber;
0177 }
0178
0179 if ( strcmp(what,"UDPHEADER1") == 0 )
0180 {
0181 return udpheader1;
0182 }
0183
0184 if ( strcmp(what,"UDPHEADER2") == 0 )
0185 {
0186 return udpheader2;
0187 }
0188
0189 if ( strcmp(what,"EVENTRATE") == 0 )
0190 {
0191 return eventrate;
0192 }
0193
0194 if ( strcmp(what,"RC_UP") == 0 )
0195 {
0196 return ratcap_upenn;
0197 }
0198
0199 if ( strcmp(what,"CLOCKSELECT") == 0 )
0200 {
0201 return clock_sel;
0202 }
0203
0204 return 0;
0205
0206 }
0207
0208 double oncsSub_iduppetdata_v104::dValue(const int ich)
0209 {
0210
0211 if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0212
0213 if ( ich < 0 || ich >= samples) return 0;
0214 return d_time[ich];
0215 }
0216
0217 long long oncsSub_iduppetdata_v104::lValue(const int ich)
0218 {
0219
0220 if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0221
0222 if ( ich < 0 || ich >= samples) return 0;
0223 return lval[ich];
0224 }
0225
0226 void oncsSub_iduppetdata_v104::dump ( OSTREAM& os )
0227 {
0228
0229 identify(os);
0230
0231 int i;
0232 int is = iValue(0,"SAMPLES");
0233
0234
0235 os << " Format: ";
0236 if ( iValue(0, "RC_UP") )
0237 {
0238 os << "Ratcap ";
0239 }
0240 else
0241 {
0242 os << "UPenn ";
0243 }
0244 os << endl;
0245
0246 os << " Clock setting: ";
0247 if ( iValue(0, "CLOCKSELECT") )
0248 {
0249 os << "Fine ";
0250 }
0251 else
0252 {
0253 os << "Coarse ";
0254 }
0255 os << endl;
0256
0257 os << " Event rate: " << iValue(0,"EVENTRATE") << endl;
0258 os << " UDP Header 1, 2: " << iValue(0,"UDPHEADER1")
0259 << " " << iValue(0,"UDPHEADER2") << endl;
0260 os << " Serial Number : " << iValue(0,"SERIAL") << endl;
0261
0262 os << " Samples: " << iValue(0,"SAMPLES") << std::endl;
0263 os << " sample B id C id time ( " << is << " Samples )" << std::endl;
0264
0265 for ( i = 0; i < is ; i++)
0266 {
0267 int prec = os.precision();
0268
0269 os << std::setw(5) << i << " | ";
0270
0271 os << std::setw(4) << iValue(i,"BLOCKID") << " ";
0272 os << std::setw(4) << iValue(i,"CRYSTALID") << " ";
0273 os << std::setw(24) << std::setprecision(24) << hex
0274
0275 << dValue(i)
0276 << dec << std::setprecision(prec) << " " ;
0277 os << std::setw(24) << std::setprecision(24) << hex << lValue(i) << dec
0278 << std::setprecision(prec) ;
0279
0280 os << std::endl;
0281 }
0282 os << std::endl;
0283 }
0284