Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
packet_gl1_evclocks.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file packet_gl1_evclocks.cc
1 #include <packet_gl1_evclocks.h>
2 #include <string.h>
3 
5  : Packet_w4 (data){ }
6 
8 {
9 
10 }
11 
12 int *Packet_gl1_evclocks::decode ( int *nwout)
13 {
14  int *p,*k;
15  int i;
16  int dlength = getDataLength();
17 
18  unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
19  if (buf == 0) return 0;
20 
21  p = new int[dlength];
22  k = p;
23  for (i =0; i<dlength; i++) *k++ = buf[i];
24 
25  *nwout = dlength;
26  return p;
27 
28 }
29 
30 int Packet_gl1_evclocks::iValue(const int ich, const char *what)
31 {
32 
33 
34  if (strcmp(what,"EVCLOCK")==0)
35  {
36 
37  if( (ich<0) || (ich>3) ) return -1;
38  unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
39  if (buf == 0)
40  return -1;
41  else
42  return buf[ich];
43  }
44  else if (strcmp(what,"PARVECT")==0)
45  {
46 
47  if( (ich<0) || (ich>3) || (getDataLength()<8) ) return -1;
48  unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
49  if (buf == 0)
50  return -1;
51  else
52  return buf[4+ich];
53  }
54 
55  else return 0;
56 
57 }
58 
59 int Packet_gl1_evclocks::iValue(const int ich, const int what)
60 {
61 
62  switch (what) {
63 
64  case EVCLOCK:
65  {
66 
67  if( (ich<0) || (ich>3) ) return -1;
68  unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
69  if (buf == 0)
70  return -1;
71  else
72  return buf[ich];
73 
74  break;
75  }
76  case PARVECT:
77  {
78 
79  if( (ich<0) || (ich>3) || (getDataLength()<8) ) return -1;
80  unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
81  if (buf == 0)
82  return -1;
83  else
84  return buf[4+ich];
85 
86  break;
87  }
88  default:
89  return -1;
90 
91  }
92 
93 }
94 
96 {
97  int j,l,m,dlength;
98  unsigned int delta = 0;
99 
100  dlength = getDataLength();
101  this->identify(os);
102 
103  unsigned int* buf = (unsigned int *) findPacketDataStart(packet);
104  if (buf == 0) return;
105 
106  os << std::endl;
107  os << "GL1 Clock Counter Event Difference Data Packet:" << std::endl;
108  os << " Clock counter for this event (N) = " << buf[0];
109  if(dlength>=8)
110  os << ", Partition = 0x" << std::hex << buf[4] << std::dec << std::endl;
111  else
112  os << std::endl;
113 
114  os << " Clock counter for N-1 event = " << buf[1];
115  if(dlength>=8) os << ", Partition = 0x" << std::hex << buf[5] << std::dec;
116  if(buf[0]>buf[1])
117  delta = buf[0]-buf[1];
118  else
119  delta = 0xFFFFFFFF-buf[1] + buf[0] + 1; // Add 1 clock = 0x0
120  os << std::endl << " (delta from this event = " << delta << " clocks, " << delta*0.106 << " microseconds)" << std::endl;
121 
122  os << " Clock counter for N-2 event = " << buf[2];
123  if(dlength>=8) os << ", Partition = 0x" << std::hex << buf[6] << std::dec;
124  if(buf[0]>buf[2])
125  delta = buf[0]-buf[2];
126  else
127  delta = 0xFFFFFFFF-buf[2] + buf[0] + 1; // Add 1 clock = 0x0
128  os << std::endl << " (delta from this event = " << delta << " clocks, " << delta*0.106 << " microseconds)" << std::endl;
129 
130  os << " Clock counter for N-3 event = " << buf[3];
131  if(dlength>=8) os << ", Partition = 0x" << std::hex << buf[7] << std::dec;
132  if(buf[0]>buf[3])
133  delta = buf[0]-buf[3];
134  else
135  delta = 0xFFFFFFFF-buf[3] + buf[0] + 1; // Add 1 clock = 0x0
136  os << std::endl << " (delta from this event = " << delta << " clocks, " << delta*0.106 << " microseconds)" << std::endl;
137 
138  os << std::endl;
139 
140  // Finally, a generic HEX dump:
141 
142  char oldFill;
143  oldFill=os.fill('0');
144 
145  j = 0;
146  int* k=( int *) findPacketDataStart(packet);
147  if ( k ==0 ) return;
148 
149  while (1)
150  {
151  os << std::endl << std::dec << SETW(5) << j << " | ";
152  for (l=0;l<4;l++)
153  {
154  os << std::hex << SETW(8) << k[j++] << " ";
155  if (j>=dlength) break;
156  }
157  if (j>=dlength) break;
158  }
159  os << std::endl;
160  for(m=0;m<54;m++) os<<"=";
161  os << std::dec << std::endl;
162  os.fill(oldFill);
163 
164 
165 }
166