HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoDccPacket.cxx
Go to the documentation of this file.
1 /*******************************************************************************
2  HARPO readout
3  _____________________
4 
5  File: hrpfmt.c
6 
7  Description: This module profide fortran function for dcc header decoding
8 
9  Author: Igor Semeniouk semenjuk@llr.in2p3.fr
10 
11  Use code from D. Calvet calvet@hep.saclay.cea.fr clientUDP
12 
13 
14  History:
15  February 2012: created from content extracted in ethpacked.c
16 
17 *******************************************************************************/
18 
19 #include "HarpoDccPacket.h"
20 #include "dccmacro.h"
21 
22 #include <arpa/inet.h>
23 #include <strings.h>
24 #include <stdio.h>
25 
26 /*******************************************************************************
27 +++ FemAdcDataDecode
28 *******************************************************************************/
30 {
31  unsigned int ts;
32 
33  hdr->size = pck->size;
34 
35  hdr->swversion = ((DATA_PACKET_VER(pck->dcchdr)==0) ? 1 : 2);
36  hdr->pkgtype = GET_FRAME_TY_V2(pck->dcchdr);
37  hdr->dccindex = GET_DCC_INDEX(pck->dcchdr);
38  hdr->femindex = GET_FEM_INDEX(pck->dcchdr);
39 
40  hdr->msgtype = GET_RESP_TYPE(pck->hdr);
41  hdr->femecnt = GET_RESP_INDEX(pck->hdr);
42 
43  hdr->fecerror = GET_FEC_ERROR(pck->hdr);
44  hdr->synchfail = GET_SYNCH_FAIL(pck->hdr);
45  hdr->lostsynch = GET_LOS_FLAG(pck->hdr);
46 
47  hdr->readmode = GET_RB_MODE(pck->args);
48  hdr->compress = GET_RB_COMPRESS(pck->args);
49  hdr->arg1 = GET_RB_ARG1(pck->args);
50  hdr->arg2 = GET_RB_ARG2(pck->args);
51  // To be independed from Fec_per_fem call it later
52  //Arg12ToFecAsicChannel(Fec_Per_Fem, (unsigned short) GET_RB_ARG1(ntohs(pck->args)), (unsigned short) GET_RB_ARG2(ntohs(pck->args)), &fec, &asic, &channel);
53 
54  ts = (((int)(pck->ts_h))<<16) | (int) (pck->ts_l);
55 
56  hdr->evttype = GET_EVENT_TYPE(pck->ecnt);
57  hdr->evttype = GET_EVENT_COUNT(pck->ecnt);
58  hdr->timestamp = ts;
59  hdr->evttype = pck->scnt;
60  /*
61  //scnt = ntohs(pck->scnt) & 0x7FF; // ?????
62 
63  // Compute the number of short words in the packet
64  // Must subtract:
65  // . 2 bytes for DCC header,
66  // . 12 bytes for FEM header,
67  // . 2 bytes used for storing the size field itself,
68  // . 4 bytes used in the trailer for CRC32 or debug info
69  nbsw = (ntohs(pck->size) - 2 - 12 - 2 - 4) / sizeof(short);
70 
71  for (i=0;i<nbsw;i++)
72  {
73  samp = ntohs(pck->samp[i]);
74  if (samp & ARGUMENT_FLAG)
75  {
76  xil_printf("ArgRb (%3d)=0x%3x", i, GET_ARGUMENTS(samp));
77  Arg12ToFecAsicChannel(Fec_Per_Fem, (unsigned short) GET_RB_ARG1(samp), (unsigned short) GET_RB_ARG2(samp), &fec, &asic, &channel);
78  xil_printf(" (F:%d A:%d C:%d)\r\n", fec, asic, channel);
79  }
80  else if (samp & SAMPLE_COUNT_FLAG)
81  {
82  xil_printf("SamCnt(%3d)=0x%3x (%4d)\r\n", i, GET_SAMPLE_COUNT(samp), GET_SAMPLE_COUNT(samp));
83  }
84  else if (samp & CELL_INDEX_FLAG)
85  {
86  xil_printf("Cell (%3d)=0x%3x (%4d)\r\n", i, GET_CELL_INDEX(samp), GET_CELL_INDEX(samp));
87  }
88  else
89  {
90  xil_printf("Sample(%3d)=0x%3x (%4d)\r\n", i, samp, samp);
91  }
92  }
93  tmp = (((unsigned int) ntohs(pck->samp[i])) << 16) | ((unsigned int) ntohs(pck->samp[i+1]));
94  xil_printf("Trailer =0x%08x (%d)\r\n", tmp, tmp);
95  */
96  // printf("------------------------------------\r\n");
97 }
98 
99 /*******************************************************************************
100  DCC_Data_Decode
101 *******************************************************************************/
103 {
104  // DCC end of event packet
105  hdr->size = pck->size;
106  hdr->swversion = ((DATA_PACKET_VER(pck->dcchdr)==0) ? 1 : 2);
107  hdr->pkgtype = GET_FRAME_TY_V2(pck->dcchdr);
108  hdr->dccindex = GET_DCC_INDEX(pck->dcchdr);
109  hdr->femindex = GET_FEM_INDEX(pck->dcchdr);
110 
111  if (GET_FRAME_TY_V2(pck->dcchdr) & FRAME_FLAG_EOEV)
112  {
113  /* fem header ??? */
114 
115  return;
116  }
117  // DCC histogram packet
118  else if (GET_TYPE(pck->hdr) == RESP_TYPE_HISTOGRAM)
119  {
120  /* fem header and arguments for histogram packet */
121  hdr->msgtype = GET_RESP_TYPE(pck->hdr);
122  hdr->femecnt = GET_RESP_INDEX(pck->hdr);
123  hdr->fecerror = GET_FEC_ERROR(pck->hdr);
124  hdr->synchfail = GET_SYNCH_FAIL(pck->hdr);
125  hdr->lostsynch = GET_LOS_FLAG(pck->hdr);
126 
127  hdr->readmode = GET_RB_MODE(pck->args);
128  hdr->compress = GET_RB_COMPRESS(pck->args);
129  hdr->arg1 = GET_RB_ARG1(pck->args);
130  hdr->arg2 = GET_RB_ARG2(pck->args);
131 
132  return;
133  }
134 
135  else
136  {
137  printf("DCC_Data_Print: unknown frame type 0x%x\r\n",
138  GET_FRAME_TY_V2(pck->dcchdr));
139  }
140 }
141 
142 /*******************************************************************************
143  DataPacketV2_Decode ONLY for DCC_DATA
144 *******************************************************************************/
145 /* include "pedestal_packet.h" */
147 {
148  hdr->size = pck->size;
149  // DCC data packet has a different structure
150  if (GET_FRAME_TY_V2(pck->dcchdr) & FRAME_TYPE_DCC_DATA)
151  {
152  DCC_Data_Decode(/* (EndOfEventPacket*) */ pck, hdr);
153  return;
154  }
155 
156  // FEM data - Pedestal Histogram Mathematics
157  else if (GET_TYPE(pck->hdr) == RESP_TYPE_HISTOSTAT)
158  {
159  //Pedestal_PrintHistoMathPacket((PedestalHistoMathPacket *)pck);
160  return;
161  }
162 
163  // FEM data - Pedestal Histogram Bins
164  else if (GET_TYPE(pck->hdr) == RESP_TYPE_HISTOGRAM)
165  {
166  //Pedestal_PrintHistoBinPacket((PedestalHistoBinPacket *) pck);
167  return;
168  }
169 
170  // FEM data - Pedestal Histogram Summary
171  else if (GET_TYPE(pck->hdr) == RESP_TYPE_HISTOSUMMARY)
172  {
173  // Pedestal_PrintHistoSummaryPacket((PedestalHistoSummaryPacket *)pck);
174  return;
175  }
176 
177  // FEM data - ADC samples in zero-suppressed or non zero-suppressed mode
178  else if (GET_TYPE(pck->hdr) == RESP_TYPE_ADC_DATA)
179  {
180  FemAdcDataDecode(pck,hdr);
181  return;
182  }
183 }
184 
185 /*******************************************************************************
186  DataPacket_Decode
187 *******************************************************************************/
189 {
191  Bool_t res = false;
192  // printf(" * pc pl %p %p \n",pc, pl); // %#lx
193  if ( pc >= pl ) return res; // no more data
194  while (pc < pl && *pc == 0 ) pc++ ; // skip padding word
195  if ( pc >= pl ) return res; // no more data
196 
197  // printf(" pc %hx %hx %hx %hx \n",*pc, *(pc+1) , *(pc+2), *(pc+3));
198 
199  h = (PacketRxCommonHdr *) pc;
200 
201  // Structure of packet has old and new version
202  if (IS_DATA_PACKET_V2(h->hdr))
203  {
204  res = true ; // new v2 frame found
205  //memset(&frm,0,sizeof(HarpoDccFrame));
206  frm.reset();
207 
208  frm.dccHeader = pc; // Header @ current poit
209  frm.dccData = pc;
210  frm.dccData += 8;
211  //size of DataPacketV2 == 4112 !!!!
212  // frm.dccData += (sizeof(DataPacketV2)/sizeof(UShort_t));
213  frm.dccTrailer = pc;
214  frm.dccTrailer += (h->size/sizeof(UShort_t) - 2);
215  // printf("sizeof %ld \n",sizeof(DataPacketV2));
217  // printf(" ????????????? Decode %ul %ul %ul\n",
218  // frm.dccHeader,frm.dccData,frm.dccTrailer);
219  }
220  else
221  {
222  // Packet V1 not implemented
223  // DataPacketV1_Decode((DataPacketV1*) pck,&frm);
224  }
225  // Ajust current pointer
226  pc += h->size / sizeof(UShort_t);
227  // printf(" ** pc pl %p %p \n",pc, pl); // %#lx
228  return res;
229 }
230 
231 HarpoDccPacket::HarpoDccPacket(UShort_t *pck, long blen)
232 {
233  pbuf = pck;
234  pc = pck;
235  pl= pck;
236  pl += (blen/sizeof(UShort_t) - 2) ; // last word pointers
237 }
#define GET_EVENT_COUNT(word)
Definition: dccmacro.h:39
#define RESP_TYPE_HISTOSTAT
Definition: dccmacro.h:21
struct _PacketRxCommonHdr PacketRxCommonHdr
UInt_t lostsynch
Definition: HarpoDccFrame.h:33
Bool_t Decode(HarpoDccFrame &frm)
UShort_t * pl
A generic class for HARPO datectors The class is ....
Definition: HarpoDccFrame.h:6
UInt_t swversion
Definition: HarpoDccFrame.h:23
#define GET_FEC_ERROR(word)
Definition: dccmacro.h:27
#define DATA_PACKET_VER(word)
Definition: dccmacro.h:133
#define RESP_TYPE_ADC_DATA
Definition: dccmacro.h:17
#define FRAME_TYPE_DCC_DATA
Definition: dccmacro.h:115
UShort_t * pbuf
#define GET_DCC_INDEX(word)
Definition: dccmacro.h:119
UInt_t timestamp
Definition: HarpoDccFrame.h:41
void reset()
reset - clear all fields
#define GET_RB_MODE(word)
Definition: dccmacro.h:32
#define GET_RESP_INDEX(word)
Definition: dccmacro.h:24
#define GET_RB_ARG2(word)
Definition: dccmacro.h:34
#define IS_DATA_PACKET_V2(word)
Definition: dccmacro.h:128
UShort_t * dccHeader
Definition: HarpoDccFrame.h:49
#define GET_TYPE(word)
Definition: dccmacro.h:13
static void FemAdcDataDecode(DataPacketV2 *pck, HarpoDccFrame *hdr)
#define GET_SYNCH_FAIL(word)
Definition: dccmacro.h:29
UShort_t * dccTrailer
Definition: HarpoDccFrame.h:51
#define GET_EVENT_TYPE(word)
Definition: dccmacro.h:38
#define GET_FEM_INDEX(word)
Definition: dccmacro.h:118
#define RESP_TYPE_HISTOSUMMARY
Definition: dccmacro.h:22
UShort_t * dccData
Definition: HarpoDccFrame.h:50
#define GET_LOS_FLAG(word)
Definition: dccmacro.h:28
DataPacket DataPacketV2
Definition: dccmacro.h:99
#define FRAME_FLAG_EOEV
Definition: dccmacro.h:117
UShort_t * pc
unsigned int res
Definition: Pmm2Status.h:428
#define GET_RB_COMPRESS(word)
Definition: dccmacro.h:33
#define GET_FRAME_TY_V2(word)
Definition: dccmacro.h:120
UInt_t size
reset - clear all fields
Definition: HarpoDccFrame.h:21
#define RESP_TYPE_HISTOGRAM
Definition: dccmacro.h:20
#define GET_RB_ARG1(word)
Definition: dccmacro.h:35
static void DataPacketV2_Decode(DataPacketV2 *pck, HarpoDccFrame *hdr)
#define GET_RESP_TYPE(word)
Definition: dccmacro.h:23
UInt_t synchfail
Definition: HarpoDccFrame.h:32
static void DCC_Data_Decode(DataPacketV2 *pck, HarpoDccFrame *hdr)