HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoDccEvent.cxx
Go to the documentation of this file.
1 //
2 // File HarpoDccEvent.cxx
3 //
15 #include "HarpoDccEvent.h"
16 #include "HarpoDccPacket.h"
17 #include "HarpoDebug.h"
18 #include <cstdlib>
19 #include <cstring>
20 #include <iostream>
21 #include <cassert>
22 // for swab
23 #include <unistd.h>
24 
25 ClassImp(HarpoDccEvent)
26 
28 {
29  fDet= XDCC;
30  memset(&fEventHeader,0,sizeof(fEventHeader));
31  fEventMap = (HarpoDccMap *) NULL;
32  fEventData = (UShort_t *)NULL;
33  decoder = new HarpoDccDecode();
34 
35  fZeroSuppr = false;
36  fTimeStamp = 0;
37  // std::cout << "Dcc Event Created" << std::endl;
38 }
39 
41 {
42  if(gHarpoDebug>1)
43  std::cout << fEventMap << " " << decoder << std::endl;
44  delete [] fEventData;
45  delete fEventMap;
46  // delete decoder;
47  decoder->Delete();
48  if(gHarpoDebug>1)
49  std::cout << "Dcc Event Deleted" << std::endl;
50 }
51 
52 void HarpoDccEvent::SetHeader(UInt_t len, UInt_t evnum)
53 {
55  fEventHeader.eventNumb=evnum;
56  if(gHarpoDebug>1)
57  std::cout << "Dcc Event SetHeader "
58  << fEventHeader.eventSize << " "
59  << fEventHeader.eventNumb << std::endl;
60  }
61 
62 void HarpoDccEvent::SetHeader(UShort_t *data)
63 {
64  memcpy(&fEventHeader,data,sizeof(EventHeader_t));
65 }
66 
67 void HarpoDccEvent::SetData(UShort_t *data, size_t dlen)
68 {
69  //if(fEventData!=NULL) delete [] fEventData;
70  fEventData = new UShort_t[dlen/sizeof(UShort_t)];
71 
72  swab(data,fEventData,dlen); // copy and ntohs ( byte swapping)
73  // memcpy(&fEventData,data,dlen);
74 
75  // std::cout << std::dec << fEventData[0] << " " << dlen << std::endl;
76  //std::cout << std::hex << fEventData[1] << std::endl;
77  //std::cout << std::hex << fEventData[2] << std::dec << std::endl;
78  // Decode Frames
79  HarpoDccPacket frm(fEventData,dlen);
80  HarpoDccFrame tmpFrame;
81  while (frm.Decode(tmpFrame) )
82  {
83  fFrames.push_back(tmpFrame);
84  }
85 }
86 
87 // void HarpoDccEvent::ResetData()
88 // {
89 // fFrames.clear();
90 // }
91 
92 
94 {
95  std::cout << "---DccEvent Plane " << fDet << std::endl;
96  std::cout << "Header num : " << fEventHeader.eventNumb
97  << " : size : " << fEventHeader.eventSize << std::endl;
98  // std::cout << " Num Frames : " << fFrames.size() << std::endl;
99  // std::cout << " FRame : " << fFrames[0].compress << std::endl;
100  //fFrames[0].print();
101 }
102 
103 // Defined in DetEvent
104 // EventHeader_t *HarpoDccEvent::GetHeader()
105 // {
106 // return &fEventHeader;
107 // }
108 
110 {
111  return fEventData;
112 }
113 
115 inline Int_t isCtlWord(UShort_t w)
116 {
117  w >>= 12;
118  if (w == 3 ) w=2;
119  return w;
120 }
121 
123 inline UShort_t iAdcData(UShort_t w) { return (w & 0xfff); }
124 
126 inline Int_t iBinIndex(UShort_t w) { return (w & 0x1ff); }
127 
129 inline void iChannelWord(UShort_t w, UShort_t &a1, UShort_t &a2)
130 {
131  w &= 0xDFFF;
132  a2 = ( (w & 0x1e00) >> 9 );
133  a1 = (w & 0x1FF);
134  // std::cout << "ArgRb " << std::hex << w << std::dec << " " << w << std::endl;
135 }
136 
138 // and skip other valuse which coreespond to special cols 511
139 // all noise channels index ( 288 ..304) after decoding
140 inline void fillIf(HarpoDccMap *m, Int_t row, Int_t col, UShort_t word)
141 {
142  // if ( ( row >= 0 ) && (row < m->map.GetNrows() )
143  // && (col >= 0 ) && (col < m->map.GetNcols()))
144  // m->map(row,col) = iAdcData(word) ;
145  m->SetRawData(row,col,iAdcData(word));
146 }
147 
149 {
150  Bool_t res = true;
151  Int_t rchannel, channel, i;
152 
153  if(fEventMap!=NULL) return kTRUE;
154 
155  if(gHarpoDebug>1)
156  Info("UnPackData","fEventMap does not exist. Unpacking RAW data");
157 
158  /* if(fEventMap==NULL) */ fEventMap = new HarpoDccMap();
159  // fEventMap->ResetMaps();
160 
161  std::list<HarpoDccFrame>::const_iterator frm;
162 
163  // std::cout << "<Dcc Map> raws "<< fEventMap->map.GetNrows()
164  // << " cols " << fEventMap->map.GetNcols() << std::endl;
165 
166  for(frm = fFrames.begin();frm != fFrames.end(); frm++)
167  {
168  if (frm->pkgtype == 0 ) {
169  if ( frm->compress == 0 )
170  {
171  //dbg
172  // frm->print();
173  // for (i=0;i<12;i++) {
174  // std::cout<< "dccData " << i << " " << std::hex
175  // << frm->dccData[i] << std::dec << std::endl;
176  // }
177  //dbg
178  if ( frm->size == 1044 ) { // All 512 words
179  rchannel = frm->ChannelNum() ; // channel from header
180  // std::cout << "0 rChannel " << rchannel
181  // << " size " << frm->size
182  // << " type : " << frm->msgtype << std::endl;
183  //
184  assert(rchannel >= 0 && rchannel < NALL);
185  channel = decoder->decode(rchannel,fDet);
186  //
187  for (i=0 ; i<NADC;i++)// Data[512] are special
188  {
189  fillIf(fEventMap,channel,i,frm->dccData[i]);
190  // fEventMap->map(channel,i) = iAdcData(frm->dccData[i]);
191  }
192  } else {
193  std::cout << " No Zero Supperssion frame size " <<
194  frm->size << " != 1044" << std::endl;
195  res = false;
196  }
197  }
198  else // Compressed data
199  {
200  rchannel = frm->ChannelNum();
201  assert(rchannel >= 0 && rchannel < NALL);
202  // std::cout << "z rChannel " << rchannel
203  // << " size " << frm->size
204  // << " type : " << frm->msgtype << std::endl;
205  //
206  channel = decoder->decode(rchannel,fDet);
207  //channel = rchannel;
208  //
209  //dbg
210  //frm->print();
211  // for (i=0;i<12;i++) {
212  // std::cout<< "dccData " << i << " " << std::hex
213  // << frm->dccData[i] << std::dec << std::endl;
214  // }
215  //dbg
216  UShort_t *samp;
217  UShort_t iival;
218  Int_t iibin = -1;
219  Int_t iitype = -1;
220  Bool_t flag512 = false;
221  int jj;
222  for (samp = frm->dccData, jj= 0; samp != frm->dccTrailer; samp++,jj++)
223  {
224  iival = *samp;
225  // std::cout << "Sampl(" << jj << ")="
226  // << std::hex << iival << std::dec << std::endl;
227  iitype = isCtlWord(iival);
228  if ( iitype == 0 ) { // Data Word
229  if( flag512 ) {
230  // std::cout << "Flag 512 data " << iibin
231  // << " = " << iival << std::endl;
232  } else {
233  if (iibin >= 0 && iibin < (511 + 10)) {
234  if ( iAdcData(iival) > 0) { // skeep padding and firs zeros
235  fillIf(fEventMap,channel,iibin-10,iival);
236  // fEventMap->map(channel,iibin-10) = iAdcData(iival);
237  }
238  } else {
239  // std::cout << "iibin index range " << iibin << std::endl;
240  }
241  }
242  iibin++;
243  } else if ( iitype == 1 ) { // New cluster index
244  iibin = iBinIndex(iival);
245  //std::cout << "iibin " << iibin << std::endl;
246  if ( iibin == 511 ) {
247  flag512 = true;
248  } else {
249  flag512 = false;
250  }
251  } else if ( iitype == 2 ) { // Found arg word
252  UShort_t a1;
253  UShort_t a2;
254  iChannelWord(iival,a1,a2);
255  // std::cout << std::hex << "Addr "
256  // << iival << " " << a1 << " " << a2
257  // << std::dec << std::endl;
258  //
259  rchannel = frm->ChannelNum(a1,a2);
260  channel = decoder->decode(rchannel,fDet);
261  //channel = rchannel;
262  flag512 = false;
263  } else if ( iitype == 4 ) { // channel word counter
264  // std::cout << "wcnt " << iival << std::endl;
265  // just skeep it
266  } else { // format error
267  std::cout << "Zero Supperssion frame bad data "
268  << std::hex << iival << std::dec << std::endl;
269  res = false;
270  break ;
271  }
272  }
273  } // zero sup
274  }
275  else
276  {
277  // std::cout << "Warning unsupported frame" << std::endl;
278  // frm->print();
279  }
280  }
281  // fEventMap->rmap.Draw();
282  // std::cout << "Unpack Data" << std::endl;
283 
284  fZeroSuppr = (fFrames.front().compress != 0);
285  fTimeStamp = fFrames.front().timestamp;
286 
287  return res;
288 }
289 
291 {
292  if(gHarpoDebug>1) std::cout << "HarpoDccEvent::GetMap" << std::endl;
293 
294  if (UnPackData()) {
295  if(gHarpoDebug>1)
296  Info("GetMap","Returning %p",(void *) fEventMap);
297  return fEventMap;
298  }
299  else {
300  return NULL;
301  }
302 }
303 
304 Bool_t HarpoDccEvent::IsZeroSuppressed(Int_t /* after */ )
305 {
306  return fZeroSuppr;
307  // return (fFrames.front().compress != 0);
308  // return (fFrames[after].compress != 0);
309 }
310 
311 ULong_t HarpoDccEvent::GetTimeStamp(Int_t /* after */)
312 {
313  if(gHarpoDebug>2) Info("GetTimeStamp","%d",fFrames.front().timestamp);
314  return fTimeStamp;
315  // return (ULong_t) fFrames.front().timestamp;
316 }
#define NALL
Definition: HarpoDccMap.h:15
Bool_t fZeroSuppr
we will not save it in Tree
Definition: HarpoDccEvent.h:61
Bool_t Decode(HarpoDccFrame &frm)
Bool_t UnPackData()
A generic class for HARPO datectors The class is ....
Definition: HarpoDccFrame.h:6
void iChannelWord(UShort_t w, UShort_t &a1, UShort_t &a2)
unpack args header word into arg1 and arg2
HarpoDccMap * fEventMap
Definition: HarpoDccEvent.h:57
virtual ~HarpoDccEvent()
void print() const
UInt_t eventSize
Raw Event size.
Definition: HarpoDetEvent.h:28
EventHeader_t fEventHeader
Definition: HarpoDetEvent.h:60
void SetHeader(UShort_t *data)
UShort_t * fEventData
Definition: HarpoDccEvent.h:51
ULong_t GetTimeStamp(Int_t after=0)
unpacked dcc data The class contains the data map for DCC or Feminos The data is stored as a 2D TMatr...
Definition: HarpoDccMap.h:29
HarpoDccDecode * decoder
Definition: HarpoDccEvent.h:59
A class which define DCC channel mapping.
#define NADC
Definition: HarpoDccMap.h:18
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
Int_t isCtlWord(UShort_t w)
Check if current word are special one : Arguments, Bin index or counter.
Unknown Detector.
Definition: HarpoDet.h:18
void fillIf(HarpoDccMap *m, Int_t row, Int_t col, UShort_t word)
Fill map onnly if index in map range (0..nRaws-1) (0..nCols-1)
Harpo Event Header.
Definition: HarpoDetEvent.h:26
ULong_t fTimeStamp
Definition: HarpoDccEvent.h:62
UShort_t * GetData()
std::list< HarpoDccFrame > fFrames
Event data buffer.
Definition: HarpoDccEvent.h:52
HarpoDccMap * GetMap()
unsigned int res
Definition: Pmm2Status.h:428
Int_t iBinIndex(UShort_t w)
index value
Bool_t IsZeroSuppressed(Int_t after=0)
Int_t decode(Int_t raw, Int_t plane)
Raw address to Strip Number decoding routine.
Decomposition of DCC buffer into DCC frames.
void SetRawData(Int_t i, Int_t j, Double_t val)
Definition: HarpoDccMap.cxx:94
void SetData(UShort_t *data, size_t dlen=EVENT_BUFFER_SIZE)
UInt_t eventNumb
Event number in run.
Definition: HarpoDetEvent.h:29
A class store HARPO EVENT : header and row data. Its provide also the methods for access to this data...
Definition: HarpoDccEvent.h:22
UShort_t iAdcData(UShort_t w)
12 bit adc value