EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
packet_id4scaler.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file packet_id4scaler.cc
1 #include "packet_id4scaler.h"
2 
4  : Packet_w4 (data){}
5 
6 int *Packet_id4scaler::decode ( int *nwout)
7 {
8  int *p,*k;
9 
10  int dlength = getDataLength();
11 
12  // int status = decode_id4scaler( temp
13  // ,(int *) findPacketDataStart(packet)
14  // ,dlngth
15  // ,MAX_OUTLENGTH, &olength);
16 
17 
18 
19  int * from = (int *) findPacketDataStart(packet);
20  if (from == 0)
21  {
22  *nwout = 0;
23  return 0;
24  }
25  int i;
26  p = new int[dlength];
27  k = p;
28  for (i =0; i<dlength; i++) *k++ = from[i];
29  *nwout = dlength;
30  return p;
31 }
32 
33 int Packet_id4scaler::iValue(const int channel,const char *what)
34 {
35  int *k = (int *) findPacketDataStart(packet);
36  if (k == 0)
37  {
38  return 0;
39  }
40 
41  int triggermasklength = k[2];
42  int scalerlength = k[3+triggermasklength];
43 
44  int rawIndex = 3+triggermasklength +1;
45  int lifeIndex = rawIndex + scalerlength;
46  int scaledIndex = lifeIndex + scalerlength;
47  int stringIndex = scaledIndex + scalerlength;
48 
49  if (strcmp(what,"NUMBERSCALERS") == 0) //
50  {
51  return scalerlength;
52  }
53 
54  else if (strcmp(what,"NUMBERMASKS") == 0) //
55  {
56  return triggermasklength;
57  }
58 
59  else if (strcmp(what,"TRIGGERMASK") == 0) //
60  {
61  if (channel <0 || channel >=triggermasklength) return 0;
62  return k[3+channel];
63  }
64 
65  else if (strcmp(what,"RAWSCALERS") == 0) //
66  {
67  if (channel <0 || channel >=scalerlength) return 0;
68  return k[rawIndex+channel];
69  }
70 
71  else if (strcmp(what,"LIFESCALERS") == 0 ||
72  strcmp(what,"LIVESCALERS") == 0) //
73  {
74  if (channel <0 || channel >=scalerlength) return 0;
75  return k[lifeIndex+channel];
76  }
77 
78  else if (strcmp(what,"SCALEDSCALERS") == 0) //
79  {
80  if (channel <0 || channel >=scalerlength) return 0;
81  return k[scaledIndex+channel];
82  }
83 
84  else if ( strcmp(what,"TIMESTRING")==0)
85  {
86  if (channel <0 || channel >= k[stringIndex] ) return EOF;
87  char *c = (char *) &k[stringIndex+1];
88  return c[channel];
89  }
90 
91  std::cout << "packet_id4scaler::iValue error unknown datum: " << what << std::endl;
92  return 0;
93 }
94 
95 long long Packet_id4scaler::lValue(const int channel, const char *what)
96 {
97  if (strcmp(what,"BEAMCLOCK") == 0 || strcmp(what,"BCLCK") == 0) // "BCLCK" because it's standard for other packets
98  {
99 
100  unsigned int *k = (unsigned int *) findPacketDataStart(packet);
101  if (k == 0)
102  {
103  return 0;
104  }
105 
106 
107 
108 #ifdef WIN32
109  ULONGLONG beamclock = k[0];
110 #else
111  unsigned long long beamclock = k[0];
112 #endif
113 
114  beamclock <<=32;
115  beamclock += k[1];
116 
117  std::cout << std::hex << k[0] << " " << k[1] << " " << beamclock << std::dec<< std::endl;
118  return beamclock;
119  }
120 
121  return 0;
122 }
123 
124 
126 {
127  int i;
128  this->identify(os);
129  int *k = (int *) findPacketDataStart(packet);
130  if (k == 0)
131  {
132  return;
133  }
134 
135  os << "Beamclock " << std::hex << std::setw(16)<< lValue(0,"BEAMCLOCK") << std::dec << std::endl;
136 
137  int triggermasklength = k[2];
138 
139  for (i=0; i< triggermasklength ; i++)
140  {
141  os << "Tiggermask " << i << " " << std::hex << iValue(0,"TRIGGERMASK") << std::dec << std::endl;
142  }
143 
144  os << "Scalers: raw | live | scaled" <<std::endl;
145 
146  for (i = 0; i< iValue(0,"NUMBERSCALERS"); i++)
147  {
148  os << SETW(3) << i << " "
149  << SETW(9) << iValue(i,"RAWSCALERS") << " "
150  << SETW(9) << iValue(i,"LIFESCALERS") << " "
151  << SETW(9) << iValue(i,"SCALEDSCALERS") << " "
152  << std::endl;
153  }
154 
155  os << "time string: ";
156  i = 0;
157  char c;
158  while ( (c = iValue(i++,"TIMESTRING")) ) os << c;
159 
160 
161  os << std::endl;
162 }
163