ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oncsSub_idbspetdata.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file oncsSub_idbspetdata.cc
1 #include "oncsSub_idbspetdata.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_idbspetdata::decode ( int *nwout)
29 {
30  int *p;
31 
32  unsigned long long timebits, coarse_timestamp, fine_timestamp;
33  unsigned int word1, word2;
34 
35  int i;
36  unsigned int *SubeventData = (unsigned int *) &SubeventHdr->data;
37  // SubeventData++;
38  int dlength = getLength()-4 - getPadding() -1;
39  samples = dlength /2;
40 
41  p = new int [samples];
42 
43  decoded_data2 = new int [samples]; // crystal id
45 
46  decoded_data3 = new int [samples]; // event type
48 
49  lval = new long long [samples]; // raw samples
50 
51  d_time = new double [samples]; // time
53 
54  int k = 0; // the index where we put things, normally the same as i but
55  // we my drop samples
56  for ( i = 0; i < samples; i++)
57  {
58 
59  word2 = SubeventData[2*i];
60 
61  fine_timestamp = (word2 >> 2) & 0x3f;
62  if ( fine_timestamp <= 32)
63  {
64 
65  word1 = SubeventData[2*i+1];
66 
67  p[k] = (( word1 >> 24) & 0x3f); // block id
68  if ( p[k] ==3) p[k]=2;
69  else if ( p[k] ==2) p[k]=3;
70 
71  decoded_data2[k] = (( word1 >> 19) & 0x1f); //crystal id
72 
73  timebits = (word1 >> 18) & 0x1;
74  coarse_timestamp = timebits << 36; //fill bits 38,37,36
75  timebits = (word1 & 0xfffc) >> 2;
76  coarse_timestamp += timebits << 22; //fill bits 35 - 22
77  timebits = (word2 >> 18);
78  coarse_timestamp += timebits << 8; //fill bits 21 - 8
79  coarse_timestamp += (word2 >> 8) & 0xff; //fill bits 7 - 0
80  d_time[k] = coarse_timestamp*10;
81  lval[k] = word2;
82  lval[k] <<=32;
83  lval[k] |= word1 ;
84 
85  k++;
86  }
87 
88 
89  }
90 
91  samples = k;
92  *nwout = samples;
93  return p;
94 }
95 
96 int oncsSub_idbspetdata::iValue(const int ich,const char *what)
97 {
98 
100 
101  if ( strcmp(what,"SAMPLES") == 0 )
102  {
103  return samples;
104  }
105 
106  if ( strcmp(what,"BLOCKID") == 0 )
107  {
108  if ( ich < 0 || ich >= samples) return 0;
109  return decoded_data1[ich];
110  }
111 
112  if ( strcmp(what,"CRYSTALID") == 0 )
113  {
114  if ( ich < 0 || ich >= samples) return 0;
115  return decoded_data2[ich];
116  }
117 
118  return 0;
119 
120 }
121 
122 double oncsSub_idbspetdata::dValue(const int ich)
123 {
124 
126 
127  if ( ich < 0 || ich >= samples) return 0;
128  return d_time[ich];
129 }
130 
131 long long oncsSub_idbspetdata::lValue(const int ich)
132 {
133 
135 
136  if ( ich < 0 || ich >= samples) return 0;
137  return lval[ich];
138 }
139 
141 {
142  int i;
143  // int *SubeventData = &SubeventHdr->data;
144  int is = iValue(0,"SAMPLES");
145 
146  //os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
147 
148  os << " sample B id C id time ( " << is << " Samples )" << std::endl;
149 
150  for ( i = 0; i < is ; i++)
151  {
152  int prec = os.precision();
153 
154  os << std::setw(5) << i << " | ";
155 
156  os << std::setw(4) << iValue(i,"BLOCKID") << " ";
157  os << std::setw(4) << iValue(i,"CRYSTALID") << " ";
158  // os << std::setw(6) << std::hex << "0x" << iValue(i,"EVENTTYPE")
159  // << std::dec<< " ";
160  os << std::setw(24) << std::setprecision(24) << dValue(i)
161  << std::setprecision(prec) ;
162 
163  os << std::endl;
164  }
165  os << std::endl;
166 }
167