Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oncsSub_idgl1v0.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file oncsSub_idgl1v0.cc
1 #include "oncsSub_idgl1v0.h"
2 
3 #include <string.h>
4 
5 using namespace std;
6 
8  :oncsSubevent_w4 (data)
9 {
10 
11  BCO = 0;
12  packet_nr = 0;
13 
14  memset (scalers, 0, sizeof(scalers) );
15  is_decoded = 0;
16 
17 }
18 
20 {
21  if (is_decoded) return 0;
22  is_decoded = 1;
23 
24  unsigned short *buffer = ( unsigned short *) &SubeventHdr->data;
25 
26 
27  // the first value is alaways "face" - we start at iValue(1)
28  // and (1) and (2) are a 32bit uint32.
29  packet_nr = ( buffer[1] << 16) | buffer[2];
30 
31 
32  // from here on out we have 64bit values
33 
34  // the BCO
35  int i = 3; // 3,4,5,6 are the BCO
36  BCO = 0;
37  for ( int j = 0; j < 3; j++)
38  {
39  BCO |= buffer[i+j];
40  BCO<<=16;
41  }
42  BCO |= buffer[i+3];
43 
44  // 7,8,9,10 are the bunch number
45  BunchNumber = 0;
46  i = 7;
47  for ( int j = 0; j < 3; j++)
48  {
49  BunchNumber |= buffer[i+j];
50  BunchNumber<<=16;
51  }
52  BunchNumber |= buffer[i+3];
53  BunchNumber &= 0x7f;
54 
55  //cout << "bunch number " << BunchNumber << endl;
56 
57  unsigned long long tag = 0;
58 
59  // 11,12,13,14 are 0x12345678ab - let's check
60  i = 11;
61  for ( int j = 0; j < 3; j++)
62  {
63  tag |= buffer[i+j];
64  tag<<=16;
65  }
66  tag |= buffer[i+3];
67 
68  if ( tag != 0x123456789abcdef)
69  {
70  cout << " wrong tag " << hex << "0x" << tag << dec << endl;
71  }
72 
73 
74  TriggerInput = 0;
75  TriggerVector = 0;
76 
77  // 15,16,17,18 are the trigger input
78  i = 15;
79  for ( int j = 0; j < 3; j++)
80  {
81  TriggerInput |= buffer[i+j];
82  TriggerInput<<=16;
83  }
84  TriggerInput |= buffer[i+3];
85 
86  // 19,20,21,22 are the trigger vector
87  i = 19;
88  for ( int j = 0; j < 3; j++)
89  {
90  TriggerVector |= buffer[i+j];
91  TriggerVector<<=16;
92  }
93  TriggerVector |= buffer[i+3];
94 
95  // cout << "TriggerInput " << hex << "0x" << TriggerInput << dec << endl;
96  // cout << "TriggerVector " << hex << "0x" << TriggerVector << dec << endl;
97 
98  // 23,24,25,26 are 0xdeadbeefbas5eba11 - let's check
99  i = 23;
100  tag = 0;
101  for ( int j = 0; j < 3; j++)
102  {
103  tag |= buffer[i+j];
104  tag<<=16;
105  }
106  tag |= buffer[i+3];
107 
108  if ( tag != 0xdeadbeefba5eba11)
109  {
110  cout << " wrong tag " << hex << "0x" << tag << dec << endl;
111  }
112 
113 
114  int index = 0;
115  unsigned long long s;
116  // here start the scalers
117  for ( i = 27 ; i < 27+3*4*64; i+=4)
118  {
119  s = 0;
120  for ( int j = 0; j < 3; j++)
121  {
122  s |= buffer[i+j];
123  s<<=16;
124  }
125  s |= buffer[i+3];
126 
127 
128  //cout << __FILE__ << " " << __LINE__ << " " << setw(3) << index << " " << hex << setw(10) << s << dec <<" " << s << endl;
129  scalers[index++] = s;
130 
131  }
132 
133 
134  return 0;
135 }
136 
138 {
139  decode();
140  return packet_nr;
141 }
142 
143 long long oncsSub_idgl1v0::lValue(const int i, const int k)
144 {
145  decode();
146  if ( i < 0 || i >=64 || k < 0 || k >2) return 0;
147  return scalers[3*i + k];
148 }
149 
150 long long oncsSub_idgl1v0::lValue(const int i, const char *what)
151 {
152  decode();
153 
154  if ( strcmp(what,"BCO") == 0)
155  {
156  return BCO;
157  }
158 
159  if ( strcmp(what,"TriggerVector") == 0)
160  {
161  return TriggerVector;
162  }
163 
164  if ( strcmp(what,"TriggerInput") == 0)
165  {
166  return TriggerInput;
167  }
168 
169  if ( strcmp(what,"BunchNumber") == 0)
170  {
171  return BunchNumber;
172  }
173 
174  if ( i < 0 || i >=64) return 0;
175 
176  if ( strcmp(what,"TRIGGERRAW") == 0)
177  {
178  return lValue(i, 0);
179  }
180 
181  if ( strcmp(what,"TRIGGERLIVE") == 0)
182  {
183  return lValue(i, 1);
184  }
185 
186  if ( strcmp(what,"TRIGGERSCALED") == 0)
187  {
188  return lValue(i, 2);
189  }
190 
191  return 0;
192 
193 }
194 
195 
196 void oncsSub_idgl1v0::dump(std::ostream &os)
197 {
198  identify(os);
199  os << "packet nr: " << iValue(0) << endl;
200  os << "Beam Clock: " << "0x" << hex << lValue(0, "BCO") << dec << " " << lValue(0, "BCO") << endl;
201  os << "Trigger Input: " << "0x" << hex << lValue(0, "TriggerInput") << dec << " " << lValue(0, "TriggerInput") << endl;
202  os << "Trigger Vector: " << "0x" << hex << lValue(0, "TriggerVector") << dec << " " << lValue(0, "TriggerVector") << endl;
203  os << "Bunch Number: " << lValue(0, "BunchNumber") << endl << endl;
204  os << "Trg # raw live scaled" << endl;
205  os << "----------------------------------------------------------------" << endl;
206 
207  int i;
208 
209  for (i = 0; i< 64; i++)
210  {
211  if ( lValue(i, 0) || lValue(i, 1) || lValue(i, 2) )
212  {
213  os << setw(3) << i << " ";
214  os << " " << setw(18) << lValue(i,0)
215  << " " << setw(18) << lValue(i,1)
216  << " " << setw(18) << lValue(i,2)
217  << endl;
218  }
219  }
220  os << endl;
221 }
222 
223 
224 
225