ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oncsSub_idrcpetdata.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file oncsSub_idrcpetdata.cc
1 #include "oncsSub_idrcpetdata.h"
2 #include <cstring>
3 
5  :oncsSubevent_w4 (data)
6 {
7  samples = 0;
8  d_time = 0;
9  d_timelength = 0;
10  lval = 0;
11 }
12 
14 {
15  if ( d_timelength )
16  {
17  delete [] d_time;
18  d_time = 0;
19  }
20  if ( lval)
21  {
22  delete [] lval;
23  lval = 0;
24  }
25 }
26 
27 
28 int *oncsSub_idrcpetdata::decode ( int *nwout)
29 {
30  int *p;
31 
32  unsigned long long timebits, coarse_timestamp, fine_timestamp;
33  unsigned int word1, word2;
34  unsigned int clockID;
35 
36 
37  int i;
38  unsigned int *SubeventData = (unsigned int *) &SubeventHdr->data;
39  // SubeventData++;
40  int dlength = getLength()-4 - getPadding() -1;
41  samples = dlength /2;
42 
43  p = new int [samples]; //block id
44 
45  decoded_data2 = new int [samples]; // crystal id
47 
48  decoded_data3 = new int [samples]; // event type
50 
51  lval = new long long [samples]; // raw samples
52 
53  d_time = new double [samples]; // time
55 
56  int k = 0;
57 
58  for ( i = 0; i < samples; i++)
59  {
60 
61  word2 = (unsigned int) SubeventData[2*i];
62  fine_timestamp = (word2 >> 2) & 0x3f;
63 
64  if (fine_timestamp <= 32)
65  {
66 
67  word1 = (unsigned int) SubeventData[2*i+1];
68  clockID = (word1 >> 30) & 0x3;
69 
70  p[k] = (word1 >> 26) & 0xf; //block id
71  if ( p[k] ==3) p[k]=2;
72  else if ( p[k] ==2) p[k]=3;
73 
74  decoded_data2[k] = (word1 >> 21) & 0x1f; // crystal id
75 
76  timebits = (word1 >> 18) & 0x7;
77  coarse_timestamp = timebits << 36; //fill bits 38,37,36
78  timebits = (word1 & 0xfffc) >> 2;
79  coarse_timestamp += timebits << 22; //fill bits 35 - 22
80  timebits = (word2 >> 18);
81  coarse_timestamp += timebits << 8; //fill bits 21 - 8
82  coarse_timestamp += (word2 >> 8) & 0xff; //fill bits 7 - 0
83  d_time[k] = (coarse_timestamp - clockID)*18 - (fine_timestamp);
84 
85  lval[i] = word2;
86  lval[i] <<=32;
87  lval[i] |= word1 ;
88 
89  k++;
90  }
91 
92  // std::cout << std::hex << lval[i] << std::dec<< std::endl;
93  }
94  samples = k;
95  *nwout = samples;
96  return p;
97 }
98 
99 //int oncsSub_idrcpetdata::iValue(const int ch)
100  //{
101 
102 // if ( decoded_data1 == 0 ) decoded_data1 = decode(&data1_length);
103 
104 // if ( ch < 0 || ch >31 ) return 0;
105 
106 // return decoded_data1[ch];
107 
108 //}
109 
110 int oncsSub_idrcpetdata::iValue(const int ich,const char *what)
111 {
112 
114 
115  if ( strcmp(what,"SAMPLES") == 0 )
116  {
117  return samples;
118  }
119 
120  if ( strcmp(what,"BLOCKID") == 0 )
121  {
122  if ( ich < 0 || ich >= samples) return 0;
123  return decoded_data1[ich];
124  }
125 
126  if ( strcmp(what,"CRYSTALID") == 0 )
127  {
128  if ( ich < 0 || ich >= samples) return 0;
129  return decoded_data2[ich];
130  }
131 
132  return 0;
133 
134 }
135 
136 double oncsSub_idrcpetdata::dValue(const int ich)
137 {
138 
140 
141  if ( ich < 0 || ich >= samples) return 0;
142  return d_time[ich];
143 }
144 
145 long long oncsSub_idrcpetdata::lValue(const int ich)
146 {
147 
149 
150  if ( ich < 0 || ich >= samples) return 0;
151  return lval[ich];
152 }
153 
154 
156 {
157  int i;
158  // int *SubeventData = &SubeventHdr->data;
159  int is = iValue(0,"SAMPLES");
160 
161  // os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
162 
163  os << " sample B id C id time ( " << is << " Samples )" << std::endl;
164 
165  for ( i = 0; i < is ; i++)
166  {
167  int prec = os.precision();
168 
169  os << std::setw(5) << i << " | ";
170 
171  os << std::setw(4) << iValue(i,"BLOCKID") << " ";
172  os << std::setw(4) << iValue(i,"CRYSTALID") << " ";
173  // os << std::setw(6) << std::hex << "0x" << iValue(i,"EVENTTYPE")
174  // << std::dec<< " ";
175  os << std::setw(24) << std::setprecision(24) << dValue(i)
176  << std::setprecision(prec) ;
177 
178  os << std::endl;
179  }
180  os << std::endl;
181 }
182