File indexing completed on 2025-08-03 08:20:46
0001 #include "oncsSub_idbspetdata.h"
0002 #include <cstring>
0003
0004 oncsSub_idbspetdata::oncsSub_idbspetdata(subevtdata_ptr data)
0005 :oncsSubevent_w4 (data)
0006 {
0007 samples = 0;
0008 d_time = 0;
0009 d_timelength = 0;
0010 lval = 0;
0011 }
0012
0013 oncsSub_idbspetdata::~oncsSub_idbspetdata()
0014 {
0015 if ( d_timelength )
0016 {
0017 delete [] d_time;
0018 d_time = 0;
0019 }
0020 if ( lval)
0021 {
0022 delete [] lval;
0023 lval = 0;
0024 }
0025 }
0026
0027
0028 int *oncsSub_idbspetdata::decode ( int *nwout)
0029 {
0030 int *p;
0031
0032 unsigned long long timebits, coarse_timestamp, fine_timestamp;
0033 unsigned int word1, word2;
0034
0035 int i;
0036 unsigned int *SubeventData = (unsigned int *) &SubeventHdr->data;
0037
0038 int dlength = getLength()-4 - getPadding() -1;
0039 samples = dlength /2;
0040
0041 p = new int [samples];
0042
0043 decoded_data2 = new int [samples];
0044 data2_length = samples;
0045
0046 decoded_data3 = new int [samples];
0047 data3_length = samples;
0048
0049 lval = new long long [samples];
0050
0051 d_time = new double [samples];
0052 d_timelength = samples;
0053
0054 int k = 0;
0055
0056 for ( i = 0; i < samples; i++)
0057 {
0058
0059 word2 = SubeventData[2*i];
0060
0061 fine_timestamp = (word2 >> 2) & 0x3f;
0062 if ( fine_timestamp <= 32)
0063 {
0064
0065 word1 = SubeventData[2*i+1];
0066
0067 p[k] = (( word1 >> 24) & 0x3f);
0068 if ( p[k] ==3) p[k]=2;
0069 else if ( p[k] ==2) p[k]=3;
0070
0071 decoded_data2[k] = (( word1 >> 19) & 0x1f);
0072
0073 timebits = (word1 >> 18) & 0x1;
0074 coarse_timestamp = timebits << 36;
0075 timebits = (word1 & 0xfffc) >> 2;
0076 coarse_timestamp += timebits << 22;
0077 timebits = (word2 >> 18);
0078 coarse_timestamp += timebits << 8;
0079 coarse_timestamp += (word2 >> 8) & 0xff;
0080 d_time[k] = coarse_timestamp*10;
0081 lval[k] = word2;
0082 lval[k] <<=32;
0083 lval[k] |= word1 ;
0084
0085 k++;
0086 }
0087
0088
0089 }
0090
0091 samples = k;
0092 *nwout = samples;
0093 return p;
0094 }
0095
0096 int oncsSub_idbspetdata::iValue(const int ich,const char *what)
0097 {
0098
0099 if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0100
0101 if ( strcmp(what,"SAMPLES") == 0 )
0102 {
0103 return samples;
0104 }
0105
0106 if ( strcmp(what,"BLOCKID") == 0 )
0107 {
0108 if ( ich < 0 || ich >= samples) return 0;
0109 return decoded_data1[ich];
0110 }
0111
0112 if ( strcmp(what,"CRYSTALID") == 0 )
0113 {
0114 if ( ich < 0 || ich >= samples) return 0;
0115 return decoded_data2[ich];
0116 }
0117
0118 return 0;
0119
0120 }
0121
0122 double oncsSub_idbspetdata::dValue(const int ich)
0123 {
0124
0125 if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0126
0127 if ( ich < 0 || ich >= samples) return 0;
0128 return d_time[ich];
0129 }
0130
0131 long long oncsSub_idbspetdata::lValue(const int ich)
0132 {
0133
0134 if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0135
0136 if ( ich < 0 || ich >= samples) return 0;
0137 return lval[ich];
0138 }
0139
0140 void oncsSub_idbspetdata::dump ( OSTREAM& os )
0141 {
0142 int i;
0143
0144 int is = iValue(0,"SAMPLES");
0145
0146
0147
0148 os << " sample B id C id time ( " << is << " Samples )" << std::endl;
0149
0150 for ( i = 0; i < is ; i++)
0151 {
0152 int prec = os.precision();
0153
0154 os << std::setw(5) << i << " | ";
0155
0156 os << std::setw(4) << iValue(i,"BLOCKID") << " ";
0157 os << std::setw(4) << iValue(i,"CRYSTALID") << " ";
0158
0159
0160 os << std::setw(24) << std::setprecision(24) << dValue(i)
0161 << std::setprecision(prec) ;
0162
0163 os << std::endl;
0164 }
0165 os << std::endl;
0166 }
0167