/[PAMELA software]/PamelaDigitizer/DigitizeRunHeader.cxx
ViewVC logotype

Contents of /PamelaDigitizer/DigitizeRunHeader.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Wed Oct 15 14:03:17 2008 UTC (16 years, 4 months ago) by pamelats
Branch: MAIN
CVS Tags: v3r04, v3r03
Changes since 1.1: +0 -28 lines
Cambiamenti principali: TOF, AC; cambiamenti di struttura (tutti *h esterni si trovano in Digitizer.h)

1 #include "Digitizer.h"
2
3 void Digitizer::DigitizeRunHeader(){
4 const Int_t lenRH = fRunHeaderbuffer*2;
5 UChar_t buffRH[lenRH];
6 UShort_t buffPSCU[8];
7 UChar_t *p;
8 p=buffRH;
9
10 // header: 16 bytes
11 DigitizePSCU(fRunHeaderbuffer*2,0x20,buffPSCU);
12 memcpy(p,buffPSCU,16*sizeof(UChar_t));
13 p+=16;
14
15 // time stamp (uint32): 0x82569c97
16 *(p++) = 0x82;
17 *(p++) = 0x56;
18 *(p++) = 0x9C;
19 *(p++) = 0x97;
20
21 // acq_setting_mode (uint8)
22 *(p++) = 2;
23
24 // obt (uint32)
25 ULong64_t obt = fOBT + 30LL;
26 while ( obt > 4294967295LL )
27 obt -= 4294967295LL;
28 fOBT = (UInt_t)obt;
29 //
30 *(p++) = (UChar_t)(fOBT >> 24);
31 *(p++) = (UChar_t)(fOBT >> 16);
32 *(p++) = (UChar_t)(fOBT >> 8);
33 *(p++) = (UChar_t)fOBT;
34
35 // last time_sync_info (uint32) (from file 000_001_00110)
36 *(p++) = 0x00;
37 *(p++) = 0x08;
38 *(p++) = 0x68;
39 *(p++) = 0xEF;
40
41 // fav. working schedule (uint8)
42 *(p++) = 0;
43
44 // eff. working schedule (uint8)
45 *(p++) = 0;
46
47 // trigger_mode_A (uint32)
48 *(p++) = 0;
49 *(p++) = 0;
50 *(p++) = 0;
51 *(p++) = 0x01;
52
53 // trigger_mode_B (uint32)
54 *(p++) = 0;
55 *(p++) = 0;
56 *(p++) = 0;
57 *(p++) = 0x03;
58
59 // acq_after_calib (0,1) (uint8)
60 *(p++) = 0;
61
62 // trk_calib_used (uint32)
63 *(p++) = 0;
64 *(p++) = 0;
65 *(p++) = 0;
66 *(p++) = 0x68;
67
68 // acq_build_info (4 zero bits + 28 1's) (uint32)
69 *(p++) = 0x3F;
70 *(p++) = 0xFF;
71 *(p++) = 0xFF;
72 *(p++) = 0xFF;
73
74 // acq_var_info (11 bits) (uint16)
75 *(p++) = 0x23;
76 *(p++) = 0x7F;
77
78 // cal_dsp_mask (uint8)
79 *(p++) = 0;
80
81 // crc (uint16)
82 UShort_t crcRH = (UShort_t)CM_Compute_CRC16((UINT16)0, (BYTE*)&buffRH, (UINT32)(fRunHeaderbuffer*2-2));
83 *(p++) = (UChar_t)(crcRH << 8);
84 *p = (UChar_t)crcRH;
85
86 memcpy(fDataRunHeader,buffRH,fRunHeaderbuffer*sizeof(UShort_t));
87 };
88
89 void Digitizer::DigitizeRunTrailer(){
90 UChar_t buffRT[fRunTrailerbuffer*2];
91 UShort_t buffPSCU[8];
92 UChar_t *p;
93 p=buffRT;
94
95 // header: 16 bytes
96 DigitizePSCU(fRunHeaderbuffer*2,0x21,buffPSCU);
97 memcpy(p,buffPSCU,16*sizeof(UChar_t));
98 p+=16;
99
100 // pkt_counter (uint32)
101 fCounterPhys++;
102 fCounter++;
103 while ( fCounterPhys > 16777215 )
104 fCounterPhys -= 16777215;
105 //
106 *(p++) = (UChar_t)(fCounterPhys >> 24);
107 *(p++) = (UChar_t)(fCounterPhys >> 16);
108 *(p++) = (UChar_t)(fCounterPhys >> 8);
109 *(p++) = (UChar_t)fCounterPhys;
110
111 // pkt_readyCounter: valid packets in the run (uint32)
112 *(p++) = 0;
113 *(p++) = 0;
114 *(p++) = 0;
115 *(p++) = 0;
116
117 // obt (uint32)
118 ULong64_t obt = fOBT + 30LL;
119 while ( obt > 4294967295LL )
120 obt -= 4294967295LL;
121 fOBT = (UInt_t)obt;
122 //
123 *(p++) = (UChar_t)(fOBT >> 24);
124 *(p++) = (UChar_t)(fOBT >> 16);
125 *(p++) = (UChar_t)(fOBT >> 8);
126 *(p++) = (UChar_t)fOBT;
127
128 // last time_sync_info (uint32)
129 *(p++) = 0;
130 *(p++) = 0;
131 *(p++) = 0;
132 *(p++) = 0;
133
134 // crc (uint16)
135 UShort_t crcRT = (UShort_t)CM_Compute_CRC16((UINT16)0, (BYTE*)(buffRT), (UINT32)(fRunTrailerbuffer*2-2));
136 *(p++) = (UChar_t)(crcRT << 8);
137 *p = (UChar_t)crcRT;
138
139 memcpy(fDataRunTrailer,buffRT,fRunTrailerbuffer*sizeof(UShort_t));
140 };
141
142 void Digitizer::AddPadding(){
143 //
144 Float_t pd0 = (fLen+16)/64.;
145 Float_t pd1 = pd0 - (Float_t)int(pd0);
146 Float_t padfrac = 64. - pd1 * 64.;
147 //
148 UInt_t padbytes = (UInt_t)padfrac;
149 if ( padbytes > 0 && padbytes < 64 ){
150 //
151 // here the padding length
152 //
153 fPadding = padbytes+64;
154 //
155 // random padding bytes
156 //
157 for (Int_t ur=0; ur<32; ur++){
158 fDataPadding[ur] = (UShort_t)rand();
159 };
160 };
161 };
162
163
164 void Digitizer::DigitizePSCU(UInt_t length, UChar_t type, UShort_t *pPSCU) {
165 //
166 UChar_t buff[16];
167 //
168 // CPU signature
169 //
170 buff[0] = 0xFA;
171 buff[1] = 0xFE;
172 buff[2] = 0xDE;
173 //
174 // packet type (twice)
175 //
176 buff[3] = type;
177 buff[4] = type;
178 //
179 // counter
180 //
181 fCounter++;
182 while ( fCounter > 16777215 ){
183 fCounter -= 16777215;
184 };
185 //
186 buff[5] = (UChar_t)(fCounter >> 16);
187 buff[6] = (UChar_t)(fCounter >> 8);
188 buff[7] = (UChar_t)fCounter;
189 //
190 // on board time
191 //
192 ULong64_t obt = fOBT + 30LL;
193 //
194 while ( obt > 4294967295LL ){
195 obt -= 4294967295LL;
196 };
197 fOBT = (UInt_t)obt;
198 //
199 buff[8] = (UChar_t)(fOBT >> 24);
200 buff[9] = (UChar_t)(fOBT >> 16);
201 buff[10] = (UChar_t)(fOBT >> 8);
202 buff[11] = (UChar_t)fOBT;
203 //
204 // Packet length
205 //
206 fLen = length;
207 //
208 buff[12] = (UChar_t)(fLen >> 16);
209 buff[13] = (UChar_t)(fLen >> 8);
210 buff[14] = (UChar_t)fLen;
211 //
212 // CPU header CRC
213 //
214 buff[15] = (BYTE)CM_Compute_CRC16((UINT16)0, (BYTE*)&buff, (UINT32)15);
215 //
216 //memcpy(fDataPSCU,buff,16*sizeof(UChar_t));
217 memcpy(pPSCU,buff,16*sizeof(UChar_t));
218 //
219 };

  ViewVC Help
Powered by ViewVC 1.1.23