Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "oncsSub_idgl1v0.h"
0002 
0003 #include <string.h>
0004 
0005 using namespace std;
0006 
0007 oncsSub_idgl1v0::oncsSub_idgl1v0(subevtdata_ptr data)
0008   :oncsSubevent_w4 (data)
0009 {
0010 
0011   BCO = 0;
0012   packet_nr = 0;
0013 
0014   memset (scalers, 0, sizeof(scalers) );
0015   memset (gl1p_scalers, 0, sizeof(gl1p_scalers) );
0016   is_decoded = 0;
0017   GTM_BusyVector = 0;
0018   _broken = 0;
0019 }
0020   
0021 int oncsSub_idgl1v0::decode ()
0022 {
0023   if (is_decoded) return 0;
0024   is_decoded = 1;
0025   
0026   //we get 2000bytes= 500 words + 4 works header
0027   if ( SubeventHdr->sub_length < 504  ||  SubeventHdr->sub_id != 14001)
0028     {
0029       _broken = 1;
0030       return 1;
0031     }
0032 
0033 
0034   unsigned short *buffer = ( unsigned short *)  &SubeventHdr->data;
0035 
0036   
0037   // the first value is alaways "face" - we start at iValue(1)
0038   // and (1) and (2) are a 32bit uint32.
0039   packet_nr = ( buffer[1] << 16) | buffer[2];
0040   
0041   
0042   // from here on out we have 64bit values
0043   
0044   // the BCO
0045   int i = 3;  // 3,4,5,6 are the BCO
0046   BCO = 0;
0047   for ( int j = 0; j < 3; j++)
0048     {
0049       BCO |= buffer[i+j];
0050       BCO<<=16;
0051     }
0052   BCO |= buffer[i+3];
0053 
0054   // 7,8,9,10 are the bunch number
0055   BunchNumber = 0;
0056   i = 7;
0057   for ( int j = 0; j < 3; j++)
0058     {
0059       BunchNumber |= buffer[i+j];
0060       BunchNumber<<=16;
0061     }
0062   BunchNumber |= buffer[i+3];
0063   BunchNumber &= 0x7f;
0064   
0065   //cout << "bunch number " << BunchNumber << endl;
0066 
0067   unsigned int tag = 0;
0068 
0069   // 11,12,13,14 are 0x12345678ab - let's check
0070   i = 11;
0071   tag = buffer[11];
0072   tag<<=16;
0073   tag |= buffer[12];
0074 
0075   // if ( tag != 0x1234567)
0076   //   {
0077   //     cout << endl << " wrong tag" << hex << "0x" << tag << dec << endl;
0078   //   }
0079 
0080   GTM_BusyVector = buffer[13];
0081   GTM_BusyVector <<= 16;
0082   GTM_BusyVector |= buffer[14];
0083   
0084 
0085   TriggerInput = 0;
0086   TriggerVector = 0;
0087 
0088   // 15,16,17,18 are the trigger input 
0089   i = 15;
0090   for ( int j = 0; j < 3; j++)
0091     {
0092       TriggerInput |= buffer[i+j];
0093       TriggerInput<<=16;
0094     }
0095   TriggerInput |= buffer[i+3];
0096   
0097   // 19,20,21,22 are the trigger vector
0098   i = 19;
0099   for ( int j = 0; j < 3; j++)
0100     {
0101       TriggerVector |= buffer[i+j];
0102       TriggerVector<<=16;
0103     }
0104   TriggerVector |= buffer[i+3];
0105   
0106   //  cout << "TriggerInput " << hex << "0x" << TriggerInput << dec << endl;
0107   //  cout << "TriggerVector " << hex << "0x" << TriggerVector << dec << endl;
0108 
0109   // 23,24,25,26 are 0xdeadbeefbas5eba11 - let's check
0110   i = 23;
0111   unsigned long long tag64 = 0;
0112   for ( int j = 0; j < 3; j++)
0113     {
0114       tag64 |= buffer[i+j];
0115       tag64 <<=16;
0116     }
0117   tag64 |= buffer[i+3];
0118 
0119   // if ( tag64 != 0xdeadbeefba5eba11)
0120   //   {
0121   //     cout << endl << " wrong tag " << hex << "0x" << tag << dec << endl;
0122   //   }
0123   
0124   
0125   int index = 0;
0126   unsigned long long s;
0127   // here start the scalers
0128   for ( i = 27 ; i < 27+3*4*64; i+=4)
0129     {
0130       s = 0;
0131       for ( int j = 0; j < 3; j++)
0132     {
0133       s |=  buffer[i+j];
0134       s<<=16;
0135     }
0136       s |=  buffer[i+3];
0137       
0138       
0139       //cout << __FILE__ << " " << __LINE__ << " " << setw(3) << index << "  " << hex << setw(10) << s  << dec <<"   " << s << endl;
0140       scalers[index++] = s;
0141       
0142     }
0143   
0144   // here start the gl1_p scalers
0145   index = 0;
0146   for ( i = 27+3*4*64; i < 27+3*4*64 + 3*2*16; i+=2)
0147     {
0148       s = 0;
0149       s = buffer[i];
0150     s<<=16;
0151       s |=  buffer[i+1];
0152       
0153       
0154       //cout << __FILE__ << " " << __LINE__ << " " << setw(3) << index << "  "  << hex << setw(10) << s  << dec <<"  " << s << endl;
0155       gl1p_scalers[index++] = s;
0156       
0157     }
0158   
0159   return 0;  
0160 }
0161 
0162 int oncsSub_idgl1v0::iValue(const int i)
0163 {
0164   decode();
0165   if ( _broken) return 0;
0166   return packet_nr;
0167 }
0168 
0169 long long oncsSub_idgl1v0::lValue(const int i, const int k)
0170 {
0171   decode();
0172   if ( _broken) return 0;
0173   if ( i < 0 || i >=64 || k < 0 || k >2) return 0;
0174   return scalers[3*i + k];
0175 }
0176 
0177 long long oncsSub_idgl1v0::lValue(const int i, const char *what)
0178 {
0179   decode();
0180   if ( _broken) return 0;
0181   
0182   if ( strcmp(what,"BCO") == 0)
0183     {
0184       return BCO;
0185     }
0186   
0187   if ( strcmp(what,"TriggerVector") == 0)
0188     {
0189       return TriggerVector;
0190     }
0191 
0192   if ( strcmp(what,"TriggerInput") == 0)
0193     {
0194       return TriggerInput;
0195     }
0196   
0197   if ( strcmp(what,"GTMBusyVector") == 0)
0198     {
0199       return GTM_BusyVector;
0200     }
0201   
0202   if ( strcmp(what,"BunchNumber") == 0)
0203     {
0204       return BunchNumber;
0205     }
0206   
0207   
0208 
0209   if ( i < 0 || i >=64) return 0;
0210 
0211   if ( strcmp(what,"TRIGGERRAW") == 0)
0212     {
0213       return lValue(i, 0);
0214     }
0215 
0216   if ( strcmp(what,"TRIGGERLIVE") == 0)
0217     {
0218       return lValue(i, 1);
0219     }
0220 
0221   if ( strcmp(what,"TRIGGERSCALED") == 0)
0222     {
0223       return lValue(i, 2);
0224     }
0225 
0226   if ( strcmp(what,"GL1PRAW") == 0)
0227     {
0228       if ( i < 0 || i > 15) return 0;
0229       return gl1p_scalers[i * 3];
0230     }
0231 
0232   if ( strcmp(what,"GL1PLIVE") == 0)
0233     {
0234       if ( i < 0 || i > 15) return 0;
0235       return gl1p_scalers[i*3+1];
0236     }
0237 
0238   if ( strcmp(what,"GL1PSCALED") == 0)
0239     {
0240       if ( i < 0 || i > 15) return 0;
0241       return gl1p_scalers[i*3+2];
0242     }
0243 
0244   
0245   return 0;
0246 
0247 }
0248 
0249 
0250 void oncsSub_idgl1v0::dump(std::ostream &os)
0251 {
0252   identify(os);
0253   if ( _broken) 
0254     {
0255       os << " ** corrupt packet **" << endl;
0256       return;
0257     }
0258   
0259   os << "packet nr:       " << (unsigned int) iValue(0) << endl;
0260   os << "Beam Clock:      " << "0x" << hex << lValue(0, "BCO") << dec  << "   "  << lValue(0, "BCO") << endl;
0261   os << "Trigger Input:   " << "0x" << hex <<  lValue(0, "TriggerInput")  << dec << "   " << lValue(0, "TriggerInput") << endl;
0262   os << "Trigger Vector:  " << "0x" << hex <<  lValue(0, "TriggerVector") << dec << "   " << lValue(0, "TriggerVector") << endl;
0263   os << "GTM Busy Vector: " << "0x" << hex <<  lValue(0, "GTMBusyVector") << dec << "   " << lValue(0, "GTMBusyVector") << endl;
0264   os << "Bunch Number:    " << lValue(0, "BunchNumber") << endl << endl;
0265   os << "Trg #                  raw              live              scaled" << endl;
0266   os << "----------------------------------------------------------------" << endl;
0267   
0268   int i;
0269   
0270   for (i = 0; i< 64; i++)
0271     {
0272       if ( lValue(i, 0) ||  lValue(i, 1) ||  lValue(i, 2) )
0273     {
0274       os << setw(3) << i << "    ";
0275       os << " " << setw(18) << lValue(i,0)
0276          << " " << setw(18) << lValue(i,1)
0277          << " " << setw(18) << lValue(i,2)
0278          << endl;
0279     }
0280     }
0281   os << endl;
0282 
0283   os << "Gl1P #                raw              live              scaled" << endl;
0284   os << "----------------------------------------------------------------" << endl;
0285   
0286   for (i = 0; i< 16; i++)
0287     {
0288       if ( lValue(i, "GL1PRAW") ||  lValue(i, "GL1PLIVE") ||  lValue(i, "GL1PSCALED") )
0289     {
0290       os << setw(3) << i << "    ";
0291       os << " " << setw(18) << lValue(i, "GL1PRAW")
0292          << " " << setw(18) << lValue(i, "GL1PLIVE")
0293          << " " << setw(18) << lValue(i, "GL1PSCALED")
0294          << endl;
0295     }
0296     }
0297   os << endl;
0298 
0299 
0300 
0301 }
0302 
0303 
0304 
0305