Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include <packet_gl1_evclocks.h>
0002 #include <string.h>
0003 
0004 Packet_gl1_evclocks::Packet_gl1_evclocks(PACKET_ptr data)
0005   : Packet_w4 (data){ }
0006 
0007 Packet_gl1_evclocks::~Packet_gl1_evclocks()
0008 {
0009 
0010 }
0011 
0012 int *Packet_gl1_evclocks::decode ( int *nwout)
0013 {
0014   int *p,*k;
0015   int i;
0016   int dlength = getDataLength();
0017 
0018   unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
0019   if (buf == 0) return 0;
0020  
0021   p = new int[dlength];
0022   k = p;
0023   for (i =0; i<dlength; i++) *k++ = buf[i];
0024 
0025   *nwout = dlength;
0026   return p;
0027 
0028 }
0029 
0030 int Packet_gl1_evclocks::iValue(const int ich, const char *what)
0031 {
0032 
0033   
0034   if (strcmp(what,"EVCLOCK")==0)
0035     {
0036 
0037       if( (ich<0) || (ich>3) ) return -1;  
0038       unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
0039       if (buf == 0) 
0040     return -1;
0041       else
0042     return buf[ich];
0043     }
0044   else if (strcmp(what,"PARVECT")==0)
0045     {
0046 
0047       if( (ich<0) || (ich>3) || (getDataLength()<8) ) return -1;  
0048       unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
0049       if (buf == 0) 
0050     return -1;
0051       else
0052     return buf[4+ich];
0053     }
0054 
0055   else return 0;
0056 
0057 }
0058 
0059 int Packet_gl1_evclocks::iValue(const int ich, const  int what)
0060 {
0061 
0062   switch (what) {
0063 
0064   case EVCLOCK:
0065     {
0066       
0067       if( (ich<0) || (ich>3) ) return -1;  
0068       unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
0069       if (buf == 0) 
0070     return -1;
0071       else
0072     return buf[ich];
0073 
0074       break;
0075     }
0076   case PARVECT:
0077     {
0078       
0079       if( (ich<0) || (ich>3) || (getDataLength()<8) ) return -1;  
0080       unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
0081       if (buf == 0) 
0082     return -1;
0083       else
0084     return buf[4+ich];
0085       
0086       break;
0087     }
0088   default:
0089     return -1; 
0090 
0091   }
0092 
0093 }
0094 
0095 void Packet_gl1_evclocks::dump ( OSTREAM &os)
0096 {
0097   int j,l,m,dlength;
0098   unsigned int delta = 0; 
0099 
0100   dlength = getDataLength();
0101   this->identify(os); 
0102 
0103   unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
0104   if (buf == 0) return; 
0105 
0106   os << std::endl;
0107   os << "GL1 Clock Counter Event Difference Data Packet:" << std::endl;
0108   os << " Clock counter for this event (N) = " << buf[0]; 
0109   if(dlength>=8) 
0110     os << ",  Partition = 0x" << std::hex << buf[4] << std::dec << std::endl;
0111   else 
0112     os << std::endl; 
0113  
0114   os << " Clock counter for N-1 event = " << buf[1]; 
0115   if(dlength>=8) os << ",  Partition = 0x" << std::hex << buf[5] << std::dec; 
0116   if(buf[0]>buf[1]) 
0117     delta = buf[0]-buf[1]; 
0118   else
0119     delta = 0xFFFFFFFF-buf[1] + buf[0] + 1; // Add 1 clock = 0x0
0120   os << std::endl << "     (delta from this event = " << delta << " clocks, " << delta*0.106 << " microseconds)" << std::endl; 
0121 
0122   os << " Clock counter for N-2 event = " << buf[2];
0123   if(dlength>=8) os << ",  Partition = 0x" << std::hex << buf[6] << std::dec; 
0124   if(buf[0]>buf[2]) 
0125     delta = buf[0]-buf[2]; 
0126   else
0127     delta = 0xFFFFFFFF-buf[2] + buf[0] + 1; // Add 1 clock = 0x0
0128   os << std::endl << "     (delta from this event = " << delta << " clocks, " << delta*0.106 << " microseconds)" << std::endl; 
0129 
0130   os << " Clock counter for N-3 event = " << buf[3];
0131   if(dlength>=8) os << ",  Partition = 0x" << std::hex << buf[7] << std::dec; 
0132   if(buf[0]>buf[3]) 
0133     delta = buf[0]-buf[3]; 
0134   else
0135     delta = 0xFFFFFFFF-buf[3] + buf[0] + 1; // Add 1 clock = 0x0
0136   os << std::endl << "     (delta from this event = " << delta << " clocks, " << delta*0.106 << " microseconds)" << std::endl; 
0137  
0138   os << std::endl; 
0139   
0140   // Finally, a generic HEX dump:
0141 
0142   char oldFill;
0143   oldFill=os.fill('0');
0144 
0145   j = 0;
0146   int* k=( int *) findPacketDataStart(packet);
0147   if ( k ==0 ) return;
0148 
0149   while (1)
0150   {
0151     os << std::endl << std::dec << SETW(5) << j << " |  ";
0152     for (l=0;l<4;l++)
0153     {
0154       os << std::hex << SETW(8) << k[j++] << " ";
0155       if (j>=dlength) break;
0156     }
0157     if (j>=dlength) break;
0158   } 
0159   os << std::endl;
0160   for(m=0;m<54;m++) os<<"=";
0161   os << std::dec << std::endl;
0162   os.fill(oldFill);
0163 
0164 
0165 }
0166