Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "oncsSub_iddrs4v1.h"
0002 #include <string.h>
0003 #include <iostream>
0004 #include <iomanip>
0005 
0006 using namespace std;
0007 
0008 oncsSub_iddrs4v1::oncsSub_iddrs4v1(subevtdata_ptr data)
0009   :oncsSubevent_w4 (data)
0010 {
0011   wave = 0;
0012   //  int dummy;
0013   // decode(&dummy);
0014 }
0015 
0016 oncsSub_iddrs4v1::~oncsSub_iddrs4v1()
0017 {
0018   if ( wave) delete [] wave;
0019 }
0020 
0021 int *oncsSub_iddrs4v1::decode ( int *nwout)
0022 {
0023 
0024 
0025   samples = SubeventHdr->data & 0xffff;
0026   enabled_channelmask = (SubeventHdr->data >> 16) & 0xf;
0027 
0028   float *d = (float *) &SubeventHdr->data;
0029   d++;
0030   int len = samples;
0031   for ( int i =0; i<4; i++)
0032     {
0033       if ( enabled_channelmask & ( 1<<i) ) 
0034     {
0035       channel_offset[i] = len;
0036       len += samples;
0037     }
0038     }
0039   wave = new float[len];
0040   memcpy ( wave, d, len * sizeof(float));
0041     
0042   *nwout = 0;
0043   return 0;
0044 }
0045 
0046 float oncsSub_iddrs4v1::rValue ( const int isample,const char * what)
0047 {
0048   if ( isample < 0 || isample > samples) return 0;
0049   
0050   if ( ! wave) 
0051     {
0052       int dummy;
0053       decode (&dummy);
0054     }
0055 
0056 
0057   if ( strcmp(what,"TIME") == 0 )
0058   {
0059     return wave[isample]; // the first 1024 sample are the time base
0060   }
0061   return 0;
0062 
0063 }
0064 
0065 int oncsSub_iddrs4v1::iValue ( const int i,const char * what)
0066 {
0067   if ( ! wave) 
0068     {
0069       int dummy;
0070       decode (&dummy);
0071     }
0072 
0073   if ( strcmp(what,"SAMPLES") == 0 )
0074   {
0075     return samples; 
0076   }
0077 
0078   else if ( strcmp(what,"ENABLED") == 0 )
0079   {
0080     return ( (enabled_channelmask & ( 1 <<  i)) !=0);
0081   }
0082 
0083   return 0;
0084 }
0085 
0086 float oncsSub_iddrs4v1::rValue ( const int isample,const int ich)
0087 {
0088   if ( isample < 0 || isample > 1023) return 0;
0089   if ( ich < 0 || ich > 4) return 0;
0090 
0091   if (ich == 4) return rValue(isample,"TIME");
0092   
0093   if ( ! wave) 
0094     {
0095       int dummy;
0096       decode (&dummy);
0097     }
0098 
0099   return wave[channel_offset[ich] +isample]; 
0100 
0101 }
0102 
0103 
0104 void  oncsSub_iddrs4v1::dump ( OSTREAM& os )
0105 {
0106   identify(os);
0107   int i;
0108   
0109   os << " Samples " << iValue(0, "SAMPLES")  << "  enabled channnels: ";
0110   for ( i = 0; i< 4; i++)
0111     {
0112       if ( iValue (i, "ENABLED" ) ) 
0113     {
0114       os << "  " << i; 
0115     }
0116     }
0117   os << endl;
0118 
0119   os << "   ch |       time";
0120   if ( enabled_channelmask & 1)  os << "          ch0";
0121   if ( enabled_channelmask & 2)  os << "          ch1";
0122   if ( enabled_channelmask & 4)  os << "          ch2";
0123   if ( enabled_channelmask & 8)  os << "          ch3";
0124   os << endl;
0125 
0126   for ( i = 0; i < samples; i++)
0127     {
0128       os << setw(5) << i << " | ";
0129       os << setw(10) << rValue(i, "TIME") << "   ";
0130       if ( enabled_channelmask & 1)  os << setw(10) << rValue(i, 0) << "   ";
0131       if ( enabled_channelmask & 2)  os << setw(10) << rValue(i, 1) << "   ";
0132       if ( enabled_channelmask & 4)  os << setw(10) << rValue(i, 2) << "   ";
0133       if ( enabled_channelmask & 8)  os << setw(10) << rValue(i, 3) << "   ";
0134       os << endl;
0135     }
0136 }
0137 
0138