Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:48

0001 #include "oncsSub_idrcpetdata.h"
0002 #include <cstring>
0003 
0004 oncsSub_idrcpetdata::oncsSub_idrcpetdata(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_idrcpetdata::~oncsSub_idrcpetdata()
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_idrcpetdata::decode ( int *nwout)
0029 {
0030   int *p;
0031 
0032   unsigned long long timebits, coarse_timestamp, fine_timestamp;
0033   unsigned int word1, word2;
0034   unsigned int clockID;
0035 
0036 
0037   int i;
0038   unsigned int *SubeventData = (unsigned int *) &SubeventHdr->data;
0039   //  SubeventData++;
0040   int dlength = getLength()-4 - getPadding() -1;
0041   samples = dlength /2;
0042 
0043   p = new int [samples];  //block id
0044 
0045   decoded_data2 = new int [samples]; //  crystal id
0046   data2_length = samples;
0047 
0048   decoded_data3 = new int [samples];  // event type
0049   data3_length = samples;
0050 
0051   lval  = new long long [samples];  // raw samples
0052 
0053   d_time = new double [samples];     // time
0054   d_timelength = samples;
0055 
0056   int k = 0;
0057 
0058   for ( i = 0; i < samples; i++) 
0059     {
0060 
0061       word2 = (unsigned int) SubeventData[2*i];
0062       fine_timestamp = (word2 >> 2) & 0x3f;
0063 
0064       if (fine_timestamp <= 32)
0065     {
0066 
0067       word1 = (unsigned int) SubeventData[2*i+1];
0068       clockID = (word1 >> 30) & 0x3;
0069 
0070       p[k] = (word1 >> 26) & 0xf;  //block id
0071       if (  p[k] ==3)  p[k]=2;
0072       else if (  p[k] ==2)  p[k]=3;
0073 
0074       decoded_data2[k]  = (word1 >> 21) & 0x1f;  // crystal id
0075 
0076       timebits = (word1 >> 18) & 0x7;
0077       coarse_timestamp = timebits << 36; //fill bits 38,37,36
0078       timebits = (word1 & 0xfffc) >> 2;
0079       coarse_timestamp += timebits << 22; //fill bits 35 - 22
0080       timebits = (word2 >> 18);
0081       coarse_timestamp += timebits << 8; //fill bits 21 - 8
0082       coarse_timestamp += (word2 >> 8) & 0xff; //fill bits 7 - 0
0083       d_time[k] = (coarse_timestamp - clockID)*18 - (fine_timestamp);
0084 
0085       lval[i] = word2;
0086       lval[i] <<=32;
0087       lval[i] |= word1 ;
0088 
0089       k++;
0090     }
0091 
0092       //      std::cout << std::hex << lval[i] << std::dec<< std::endl;
0093     }
0094   samples = k;
0095   *nwout = samples;
0096   return p;
0097 }
0098 
0099 //int oncsSub_idrcpetdata::iValue(const int ch)
0100   //{
0101 
0102 //  if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0103 
0104 //  if ( ch < 0 || ch >31 ) return 0;
0105 
0106 //  return decoded_data1[ch];
0107 
0108 //}
0109 
0110 int oncsSub_idrcpetdata::iValue(const int ich,const char *what)
0111 {
0112 
0113   if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0114 
0115   if ( strcmp(what,"SAMPLES") == 0 )
0116   {
0117     return samples;
0118   }
0119 
0120   if ( strcmp(what,"BLOCKID") == 0 )
0121   {
0122     if ( ich < 0 || ich >= samples) return 0;
0123     return decoded_data1[ich];
0124   }
0125 
0126   if ( strcmp(what,"CRYSTALID") == 0 )
0127   {
0128     if ( ich < 0 || ich >= samples) return 0;
0129     return decoded_data2[ich];
0130   }
0131 
0132   return 0;
0133 
0134 }
0135 
0136 double oncsSub_idrcpetdata::dValue(const int ich)
0137 {
0138 
0139   if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0140 
0141   if ( ich < 0 || ich >= samples) return 0;
0142     return d_time[ich];
0143 }
0144 
0145 long long  oncsSub_idrcpetdata::lValue(const int ich)
0146 {
0147 
0148   if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
0149 
0150   if ( ich < 0 || ich >= samples) return 0;
0151     return lval[ich];
0152 }
0153 
0154 
0155 void  oncsSub_idrcpetdata::dump ( OSTREAM& os )
0156 {
0157   int i;
0158   //  int *SubeventData = &SubeventHdr->data;
0159   int is =  iValue(0,"SAMPLES");
0160 
0161   //  os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
0162 
0163   os << " sample  B id    C id   time   ( " << is << " Samples )" << std::endl;
0164   
0165   for ( i = 0; i < is ; i++)
0166     {
0167       int prec = os.precision();
0168 
0169       os << std::setw(5) << i << "  |  "; 
0170  
0171       os << std::setw(4) << iValue(i,"BLOCKID") << "  ";
0172       os << std::setw(4) << iValue(i,"CRYSTALID") << "  ";
0173       //      os << std::setw(6) << std::hex << "0x" << iValue(i,"EVENTTYPE") 
0174       //     << std::dec<< "    ";
0175       os << std::setw(24) << std::setprecision(24) << dValue(i)
0176      << std::setprecision(prec) ;
0177     
0178       os << std::endl;
0179     }
0180   os << std::endl;
0181 }
0182