1 |
subroutine trkeventpkt(runerror,event_file_name) |
************************************************************************* |
2 |
|
* 20/1/2006 modified by elena vannuccini to code error flag |
3 |
|
* 10/9/2005 modified by david fedele to read buffer-data |
4 |
|
* instead raw-data-file |
5 |
|
* 29/11/2005 modified by david fedele to include crc control |
6 |
|
* 24/06/2006 modified by elena vannuccini |
7 |
|
* 25/06/2006 modified by david fedele |
8 |
|
************************************************************************* |
9 |
|
|
10 |
|
subroutine trkeventpkt(YODAflag,buffer,length_buffer,curpos) |
11 |
|
|
12 |
|
include '../common/commontracker.f' |
13 |
|
include '../common/common_readraw.f' |
14 |
|
include '../common/level0.f' |
15 |
|
|
16 |
include '../commonyoda/commontracker.f' |
logical ALARMS |
|
include '../commonyoda/dataformat.f' |
|
|
c include '../commonyoda/trk_calib_parameters.f' |
|
|
include '../commonyoda/level0.f' |
|
|
|
|
|
|
|
|
integer ndummy |
|
|
data ndummy/1000/ |
|
|
|
|
17 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
18 |
integer ffd_pkt !pkt file descriptor |
integer*1 crctemp |
|
!(file temporaneo) |
|
|
character*60 event_file_name !nome file |
|
|
c print*,' lun_pkt-----',int(lun_pkt); |
|
|
open(unit=lun_pkt, |
|
|
$ name=EVENT_FILE_NAME(1:lnblnk(EVENT_FILE_NAME)), |
|
|
$ status='old', |
|
|
$ form='unformatted' |
|
|
$ ) |
|
|
ffd_pkt = FNum(lun_pkt) !reads unix file descriptor |
|
|
|
|
19 |
|
|
20 |
|
* ------------------- |
21 |
|
* initializations |
22 |
|
* --------------------------------------------------- |
23 |
|
* the general flag YODAflag contains information |
24 |
|
* about the integrity of the DSP packets. |
25 |
|
* |
26 |
|
* If some packets are missing or the crc check fails, |
27 |
|
* YODAflag is asserted |
28 |
|
* --------------------------------------------------- |
29 |
|
YODAflag=1 !bad by default |
30 |
call initlevel0 |
call initlevel0 |
31 |
|
ALARMS=.false. |
32 |
TOTDATAlength = 0. !total length of data buffer |
npkt=0 !#good DSP packets |
33 |
do iview=1,ndummy !loop on views |
startcrc=0 |
34 |
call searchtrkheader(runerror,ffd_pkt) |
stopcrc=0 |
35 |
c if(runerror.eq.-1) goto 24 |
crctemp=0 |
36 |
if(runerror.eq.-1) goto 2222 |
* ------------------- |
37 |
if(runerror.eq.1) then |
|
38 |
print*,' ' |
* =================================== |
39 |
print*,'readraw: END OF CPU PACKET ' |
if(length_buffer.gt.MAXBUFFLEN)then |
40 |
print*,'______________________________________ ' |
print*,'trkeventpkt: buffer() size must be at least ' |
41 |
c goto 9900 !end loop on files |
$ ,length_buffer,' !!!!' |
42 |
c goto 8800 !end loop on views (DSP pkt) |
goto 2222 |
43 |
goto 2222 |
endif |
44 |
|
* =================================== |
45 |
|
|
46 |
|
|
47 |
|
do iview=1,nviews !loop on DSPs |
48 |
|
call searchtrkheader(runerror,buffer,length_buffer,curpos, |
49 |
|
$ startcrc) |
50 |
|
if(runerror.eq.1.or.runerror.eq.-1) then |
51 |
|
* -------------------------------------------------- |
52 |
|
* no DSP packet has been found ==> go to end |
53 |
|
* -------------------------------------------------- |
54 |
|
goto 2222 !go to end |
55 |
endif |
endif |
56 |
|
|
57 |
if(checkheader.ne.2) then |
if(checkheader.ne.2) then |
58 |
print*,'>>>> ERROR <<<< (trkeventpkt)' |
print*,'>>>> ERROR <<<< (trkeventpkt)' |
59 |
print*,'>>>> CPU packet type ',!pkt_type, |
print*,'>>>> CPU packet type ',!pkt_type, |
60 |
$ ' does not match DSP type ',checkheader |
$ ' does not match DSP packet type ',checkheader |
|
c goto 9909 ! next event (==> search another CPU header) |
|
61 |
DAQmode_temp = ishft(iand(header(1),z'03f0'),-4) |
DAQmode_temp = ishft(iand(header(1),z'03f0'),-4) |
62 |
DSPnumber_temp = iand(header(1),z'000f') |
DSPnumber_temp = iand(header(1),z'000f') |
63 |
print*,' -----------------------------------' |
print*,' -----------------------------------' |
68 |
goto 2525 !next view (==> search another DSP header) |
goto 2525 !next view (==> search another DSP header) |
69 |
endif |
endif |
70 |
|
|
71 |
call unpackdata(runerror,ffd_pkt) |
call unpackdata(runerror,buffer,length_buffer,curpos, |
72 |
c if(runerror.eq.-1) goto 24 |
$ startcrc,stopcrc,crctemp) |
73 |
if(runerror.eq.-1) goto 2222 |
if(runerror.eq.-1.or.runerror.eq.1)then |
74 |
c if(runerror.eq.1) goto 23 |
goto 2222 !go to end |
75 |
if(runerror.eq.1) goto 2222 |
else if(runerror.eq.2) then |
76 |
|
crc_dat=2 !flag for corrupted packet |
77 |
print*,' ' |
endif |
78 |
print*,' -----------------------------------',iview |
|
79 |
print*,' DSP number-----',DSPnumber_dat |
npkt = npkt + 1 |
|
print*,' DAQ mode-------',DAQmode_dat |
|
|
print*,' event number ',eventn_dat |
|
|
|
|
|
trk_DSP_ok(DSPnumber_dat)=1 |
|
|
|
|
80 |
call fillview(iview) |
call fillview(iview) |
81 |
|
*--------CRC check |
82 |
|
if(crc(iview).eq.0.or.crc(iview).eq.2) then !OK |
83 |
|
*----------- ALARMS |
84 |
|
if( |
85 |
|
$ fl1(iview).ne.0.or. |
86 |
|
$ fl2(iview).ne.0.or. |
87 |
|
$ fl3(iview).ne.0.or. |
88 |
|
$ fl4(iview).ne.0.or. |
89 |
|
$ fl5(iview).ne.0.or. |
90 |
|
$ fl6(iview).ne.0.or. |
91 |
|
$ fc(iview).ne.0.or. |
92 |
|
$ DATAlength(iview).eq.0.or. |
93 |
|
$ .false.)ALARMS=.true. |
94 |
|
endif |
95 |
|
|
96 |
2525 continue |
2525 continue |
97 |
enddo !end loop on views |
enddo !end loop on views |
98 |
|
|
99 |
2222 continue |
2222 continue |
100 |
|
|
101 |
close (lun_pkt) |
if(npkt.eq.nviews)YODAflag=0 |
102 |
|
if(YODAflag.eq.0.and.(ALARMS.eqv..false.))good0=1 |
103 |
|
|
104 |
return |
return |
105 |
end |
end |
106 |
|
|
107 |
* ********************************************** |
* ********************************************************** |
108 |
|
* * * |
109 |
|
* * * |
110 |
|
* * * |
111 |
|
* * * |
112 |
|
* * * |
113 |
|
* ********************************************************** |
114 |
|
|
115 |
c subroutine trk_calib_pkt(runerror,ffd_pkt) |
subroutine trkcalibpkt(YODAflag,buffer,length_buffer,curpos |
116 |
subroutine trkcalibpkt(runerror,event_file_name) |
$ ) |
117 |
|
|
118 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
119 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
120 |
include '../commonyoda/trk_calib_parameters.f' |
include '../common/trk_calib_parameters.f' |
121 |
|
|
122 |
integer ndummy |
logical ALARMs |
|
data ndummy/1000/ |
|
|
|
|
123 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
124 |
integer ffd_pkt !pkt file descriptor |
integer*1 crctemp |
|
!(file temporaneo) |
|
|
character*60 event_file_name !nome file |
|
|
|
|
|
open(unit=lun_pkt, |
|
|
$ name=EVENT_FILE_NAME(1:lnblnk(EVENT_FILE_NAME)), |
|
|
$ status='old', |
|
|
$ form='unformatted' |
|
|
$ ) |
|
|
ffd_pkt = FNum(lun_pkt) !reads unix file descriptor |
|
125 |
|
|
126 |
|
* ------------------- |
127 |
|
* initializations |
128 |
|
* --------------------------------------------------- |
129 |
|
* the general flag YODAflag contains information |
130 |
|
* about the integrity of the DSP packets. |
131 |
|
* |
132 |
|
* If some packets are missing or the crc check fails, |
133 |
|
* YODAflag is asserted |
134 |
|
* --------------------------------------------------- |
135 |
|
YODAflag = 1 !bad by default |
136 |
|
call initcalib |
137 |
|
ALARMS=.false. |
138 |
|
npkt=0 !#good DSP packets |
139 |
|
startcrc=0 |
140 |
|
stopcrc=0 |
141 |
|
crctemp=0 |
142 |
|
* ------------------- |
143 |
|
|
144 |
|
* =================================== |
145 |
|
if(length_buffer.gt.MAXBUFFLEN)then |
146 |
|
print*,'trkeventpkt: buffer() size must be at least ' |
147 |
|
$ ,length_buffer,' !!!!' |
148 |
|
goto 2222 |
149 |
|
endif |
150 |
|
* =================================== |
151 |
|
|
152 |
do iview=1,ndummy !loop on views (DSP pkt) |
do iview=1,nplanes !loop on views (DSP pkt) |
153 |
call searchtrkheader(runerror,ffd_pkt) |
|
154 |
c if(runerror.eq.-1) goto 24 |
call searchtrkheader(runerror,buffer,length_buffer,curpos, |
155 |
if(runerror.eq.-1) goto 2222 |
$ startcrc) |
156 |
if(runerror.eq.1) then |
|
157 |
print*,' ' |
if(runerror.eq.1.or.runerror.eq.-1) then |
|
print*,'readraw: END OF CPU PACKET ' |
|
|
print*,'______________________________________ ' |
|
158 |
goto 2222 !end loop on views (DSP pkt) |
goto 2222 !end loop on views (DSP pkt) |
159 |
endif |
endif |
160 |
|
|
161 |
if(checkheader.ne.3) then |
if(checkheader.ne.3) then |
162 |
print*,'>>>> ERROR <<<< (trkcalibpkt)' |
print*,'>>>> ERROR <<<< (trkcalibpkt)' |
163 |
print*,'>>>> CPU packet type ',!pkt_type, |
print*,'>>>> CPU packet type ',!pkt_type, |
172 |
goto 2424 !next view (==> search another DSP header) |
goto 2424 !next view (==> search another DSP header) |
173 |
endif |
endif |
174 |
|
|
175 |
call unpackcalibration(runerror,ffd_pkt) |
call unpackcalibration(runerror,buffer,length_buffer,curpos, |
176 |
c if(runerror.eq.-1) goto 24 |
$ startcrc,stopcrc,crctemp) |
177 |
if(runerror.eq.-1) goto 2222 |
if(runerror.eq.-1.or.runerror.eq.1)then |
178 |
c if(runerror.eq.1) goto 23 |
goto 2222 !end |
|
if(runerror.eq.1) goto 2222 |
|
|
|
|
|
|
|
|
print*,'Calibration packet ==> ',iview |
|
|
|
|
|
print*,'---- Calibration packet ',iview,' ----' |
|
|
print*,' DSP number ',DSPnumber_cal |
|
|
print*,' DAQ mode ',DAQmode_cal |
|
|
print*,' calibration run ',calibrationnumber |
|
|
print*,' n. event used ',nused_event |
|
|
print*,' <PED> ladder 1 ',ped_1 |
|
|
print*,' <PED> ladder 2 ',ped_2 |
|
|
print*,' <PED> ladder 3 ',ped_3 |
|
|
print*,' <SIG> ladder 1 ',sig_1 |
|
|
print*,' <SIG> ladder 2 ',sig_2 |
|
|
print*,' <SIG> ladder 3 ',sig_3 |
|
|
print*,' n.BAD ladder 1 ',nbad_1 |
|
|
print*,' n.BAD ladder 2 ',nbad_2 |
|
|
print*,' n.BAD ladder 3 ',nbad_3 |
|
|
print*,' error flag ',ff |
|
|
if(nused_event.ne.0.or.ff.ne.0)then |
|
|
print*,'*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*' |
|
|
print*,'* !!! CALIBRATION FAILURE !!! *' |
|
|
print*,'*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*' |
|
179 |
endif |
endif |
180 |
|
|
181 |
|
|
182 |
|
npkt = npkt + 1 |
183 |
|
call fillview_cal(iview) ! |
184 |
|
*--------CRC check |
185 |
|
if( crc_hcal(iview).eq.0.and. |
186 |
|
$ crc_cal(iview,1).eq.0.and. |
187 |
|
$ crc_cal(iview,2).eq.0.and. |
188 |
|
$ crc_cal(iview,3).eq.0.and. |
189 |
|
$ .true.)then |
190 |
|
*----------- ALARMS |
191 |
|
if( ncalib_event(iview).ne.0.or. |
192 |
|
$ cal_flag(iview).ne.0.or. |
193 |
|
$ .false.)ALARMS=.true. |
194 |
|
endif |
195 |
|
|
|
DAQmode(iview)=DAQmode_cal |
|
|
DSPnumber(iview)=DSPnumber_cal |
|
|
calibnumber(iview)=calibrationnumber |
|
|
ncalib_event(iview)=nused_event |
|
|
ped_l1(iview)=ped_1 |
|
|
ped_l2(iview)=ped_2 |
|
|
ped_l3(iview)=ped_3 |
|
|
sig_l1(iview)=sig_1 |
|
|
sig_l2(iview)=sig_2 |
|
|
sig_l3(iview)=sig_3 |
|
|
nbad_l1(iview)=nbad_1 |
|
|
nbad_l2(iview)=nbad_2 |
|
|
nbad_l3(iview)=nbad_3 |
|
|
cal_flag(iview)=ff |
|
|
|
|
|
do is=1,nstrips_view |
|
|
DSPbad_par(iview,is)=DSPbad_o(DSPnumber_cal,is) |
|
|
DSPped_par(iview,is)=DSPped_o(DSPnumber_cal,is) |
|
|
DSPsig_par(iview,is)=DSPsig_o(DSPnumber_cal,is) |
|
|
enddo |
|
|
c |
|
|
trk_DSP_ok(DSPnumber_cal)=1 |
|
|
c---------------------------------------------------------- |
|
|
c NVIEWS calibration packets should have been found |
|
|
c---------------------------------------------------------- |
|
|
c if(n_cal_pkt.eq.nviews)then |
|
|
c found_cal_pkt = .true. |
|
|
c n_cal_pkt = 0 |
|
|
c endif |
|
196 |
2424 continue |
2424 continue |
197 |
enddo ! end loop on views (calibration pkt) |
enddo ! end loop on views (calibration pkt) |
198 |
|
|
199 |
2222 continue |
2222 continue |
200 |
|
|
201 |
close (lun_pkt) |
if(npkt.eq.nplanes)YODAflag=0 |
202 |
|
if(YODAflag.eq.0.and.(ALARMS.eqv..false.))good0=1 |
203 |
|
|
204 |
return |
return |
205 |
end |
end |
206 |
|
|
207 |
***...***...***...***...***...***...***...***...***...***...***...***...***...***...***...*** |
* ********************************************************** |
208 |
* |
* * * |
209 |
* |
* * * |
210 |
* |
* * * |
211 |
* |
* * * |
212 |
* |
* * * |
213 |
* |
* ********************************************************** |
|
* |
|
|
* |
|
|
***...***...***...***...***...***...***...***...***...***...***...***...***...***...***...*** |
|
214 |
|
|
215 |
subroutine searchtrkheader(runerror,ffd) |
subroutine searchtrkheader(runerror,buffer,length_buffer, |
216 |
|
$ curpos,startcrc) |
217 |
C............................................................. |
C............................................................. |
218 |
C Search for a valid tracker DSP header (=>one view) |
C Search for a valid tracker DSP header (=>one view) |
219 |
C and return the type of header |
C and return the type of header |
220 |
C............................................................. |
C............................................................. |
221 |
|
|
222 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
223 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
224 |
|
|
|
integer ffd !input file descriptor |
|
225 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
226 |
|
|
227 |
c-------------------------------------------------- |
c-------------------------------------------------- |
229 |
C so each DSP 13 bit |
C so each DSP 13 bit |
230 |
c first word starts at the beginnig of a 16 bit word |
c first word starts at the beginnig of a 16 bit word |
231 |
c-------------------------------------------------- |
c-------------------------------------------------- |
232 |
|
|
233 |
9100 continue |
9100 continue |
234 |
runerror=0 !error flag initialization |
runerror=0 !error flag initialization |
235 |
checkheader=0 |
checkheader=0 |
238 |
c looks for a DSP header beginning |
c looks for a DSP header beginning |
239 |
C (a word beginning with 1110) |
C (a word beginning with 1110) |
240 |
c-------------------------------------------------- |
c-------------------------------------------------- |
|
call findstart(runerror,ffd) |
|
241 |
|
|
242 |
if(runerror.eq.1) goto 200 |
call findstart(runerror,buffer,length_buffer,curpos) |
243 |
if(runerror.eq.-1)then |
|
244 |
runerror=1 !in this case I dont want the |
if(runerror.eq.1) goto 200 !end |
245 |
!the program to crash |
if(runerror.eq.-1)goto 200 !end |
|
goto 200 |
|
|
endif |
|
246 |
c-------------------------------------------------- |
c-------------------------------------------------- |
247 |
c the first word could be a DSP header first word: |
c the first word could be a DSP header first word: |
248 |
C reads 13 8-bit words and |
C reads 13 8-bit words and |
249 |
c writes them in 16 13-bit words to check for all |
c writes them in 16 13-bit words to check for all |
250 |
C DSP header features |
C DSP header features |
251 |
c-------------------------------------------------- |
c-------------------------------------------------- |
252 |
runerror=0 |
|
253 |
|
call hunpacker(header,runerror,buffer,length_buffer,curpos, |
254 |
call hunpacker(header,runerror,ffd) |
$ startcrc) |
255 |
|
|
256 |
if(runerror.eq.1) goto 200 |
if(runerror.eq.1) goto 200 !end |
257 |
c if(runerror.eq.-1) goto 200 |
if(runerror.eq.-1)goto 200 !end |
|
if(runerror.eq.-1)then |
|
|
runerror=1 !in this case I dont want the |
|
|
!the program to crash |
|
|
goto 200 |
|
|
endif |
|
258 |
c-------------------------------------------------- |
c-------------------------------------------------- |
259 |
c extracts and controls header: |
c extracts and controls header: |
260 |
c-------------------------------------------------- |
c-------------------------------------------------- |
262 |
c |0001|1100|0000|0000| for acquisition |
c |0001|1100|0000|0000| for acquisition |
263 |
c |0001|1111|1111|1111| for calibration |
c |0001|1111|1111|1111| for calibration |
264 |
c-------------------------------------------------- |
c-------------------------------------------------- |
265 |
if(iand(header(16),z'ffff').eq.z'1c00') then !last header |
if(iand(header(16),z'ffff').eq.z'1c00') then |
266 |
checkheader=2 ! event |
checkheader=2 ! event packet |
267 |
elseif(iand(header(16),z'ffff').eq.z'1fff') then !last header |
elseif(iand(header(16),z'ffff').eq.z'1fff') then |
268 |
checkheader=3 ! calibration packet |
checkheader=3 ! calibration packet |
269 |
else |
else |
270 |
checkheader=1 ! not a valid DSP header |
checkheader=1 ! not a valid DSP header |
289 |
c noise lurks around) so go a word ahead and |
c noise lurks around) so go a word ahead and |
290 |
c try again |
c try again |
291 |
c-------------------------------------------------- |
c-------------------------------------------------- |
292 |
if(checkheader.eq.1) then |
if(checkheader.eq.1) then |
293 |
call skipbyte(ffd) |
curpos=curpos-(13*2)+1 !goes back 13 words, then half 16 bit word ahead |
294 |
goto 9100 |
goto 9100 |
295 |
endif |
endif |
296 |
|
|
297 |
200 continue |
200 continue |
298 |
end |
end |
299 |
|
|
300 |
*............................................................. |
* ********************************************************** |
301 |
|
* * * |
302 |
|
* * * |
303 |
|
* * * |
304 |
|
* * * |
305 |
|
* * * |
306 |
|
* ********************************************************** |
307 |
|
|
308 |
|
subroutine unpackcalibration(runerror,buffer,length_buffer,curpos, |
309 |
|
$ startcrc,stopcrc,crctemp) |
310 |
|
|
|
*............................................................. |
|
|
|
|
|
subroutine unpackcalibration(runerror,ffd) |
|
311 |
*............................................................. |
*............................................................. |
312 |
* decode calibration data |
* decode calibration data |
313 |
* header + data(PED SIG BAD) + trailer |
* header + data(PED SIG BAD) + trailer |
314 |
*............................................................ |
*............................................................ |
315 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
316 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
317 |
|
|
318 |
integer ffd !input file descriptor |
integer*1 crctemp |
319 |
|
integer*1 crc_trail |
320 |
|
|
321 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
|
c buffer temporanei |
|
322 |
integer*2 templ(nstrips_ladder) |
integer*2 templ(nstrips_ladder) |
323 |
real*4 tempf(nstrips_ladder) |
real*4 tempf(nstrips_ladder) |
324 |
|
|
325 |
|
|
326 |
|
|
327 |
12 format(z4) |
12 format(z4) |
328 |
|
|
329 |
*----------------------------------------------------------- |
*----------------------------------------------------------- |
337 |
DSPnumber_cal = iand(header(1),z'000f') |
DSPnumber_cal = iand(header(1),z'000f') |
338 |
dataword = ior(ishft(iand(header(2),z'03ff') |
dataword = ior(ishft(iand(header(2),z'03ff') |
339 |
$ ,10),iand(header(3),z'03ff')) |
$ ,10),iand(header(3),z'03ff')) |
|
c calibrationnumber = ior(ishft(iand(header(4) |
|
|
c $ ,z'03ff'),10),iand(header(5),z'03ff')) |
|
340 |
calibrationnumber = iand(header(4),z'03ff') |
calibrationnumber = iand(header(4),z'03ff') |
341 |
nused_event = iand(header(5),z'03ff') |
nused_event = iand(header(5),z'03ff') |
342 |
ped_1 = iand(header(6),z'03ff') |
ped_1 = iand(header(6),z'03ff') |
353 |
nbad_3 = iand(header(14),z'03ff') |
nbad_3 = iand(header(14),z'03ff') |
354 |
ff = ishft(iand(header(15),z'0300'),-8) |
ff = ishft(iand(header(15),z'0300'),-8) |
355 |
checksum_cal = iand(header(15),z'00ff') |
checksum_cal = iand(header(15),z'00ff') |
|
|
|
|
runerror=0 |
|
|
call readtrailer(trailer,runerror,ffd) |
|
|
c$$$ do i=1,3 |
|
|
c$$$ write(*,12)trailer(i) |
|
|
c$$$ enddo |
|
356 |
c----------------------------------------------------------- |
c----------------------------------------------------------- |
357 |
c the checksum is a 8-bit word calculated as the |
c the checksum is a 8-bit word calculated as the |
358 |
c XOR of the 16-bit data words, |
c XOR of the 16-bit data words, |
359 |
c hence the XOR between the two halfs |
c hence the XOR between the two halfs |
360 |
C---------------------------------------------------------- |
C---------------------------------------------------------- |
|
do il=1,3 !loop on ladders |
|
361 |
|
|
362 |
call readped(tempf,runerror,ffd) |
runerror=0 |
363 |
|
c$$$ |
364 |
|
c$$$ print*,'-----------------------------------' |
365 |
|
c$$$ print*,'unpackcalibration: readtrailer --- ', |
366 |
|
c$$$* $ trailer,runerror,buffer,length_buffer,curpos, |
367 |
|
c$$$ $ startcrc,stopcrc,crctemp |
368 |
|
c$$$ print*,'-----------------------------------' |
369 |
|
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
370 |
|
$ startcrc,stopcrc,crctemp) |
371 |
|
|
372 |
|
crc_trail=iand(trailer(3),z'00ff') |
373 |
|
|
374 |
|
c$$$ print *,'@@@@@@@@@@@@@ ',crctemp,crc_trail |
375 |
|
|
376 |
|
if (crctemp.eq.crc_trail)then |
377 |
|
crc_hcalib=0 |
378 |
|
else |
379 |
|
crc_hcalib=1 |
380 |
|
endif |
381 |
|
|
382 |
|
do il=1,3 !loop on ladders |
383 |
|
startcrc=curpos |
384 |
|
call readped(tempf,runerror,buffer,length_buffer,curpos) |
385 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
386 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
387 |
DSPped_o(DSPnumber_cal,iss)=tempf(is) |
DSPped_o(DSPnumber_cal,iss)=tempf(is) |
|
c print*,il,iss,DSPped_o(DSPnumber,iss) |
|
|
c print *,DSPnumber_cal,iss,tempf(is) |
|
|
|
|
388 |
enddo |
enddo |
389 |
|
|
390 |
call readsig(tempf,runerror,ffd) |
call readsig(tempf,runerror,buffer,length_buffer,curpos) |
391 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
392 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
393 |
DSPsig_o(DSPnumber_cal,iss)=tempf(is) |
DSPsig_o(DSPnumber_cal,iss)=tempf(is) |
|
c print*,DSPsig_o(DSPnumber,iss) |
|
394 |
enddo |
enddo |
395 |
|
|
396 |
call readbad(templ,runerror,ffd) |
call readbad(templ,runerror,buffer,length_buffer,curpos) |
397 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
398 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
399 |
DSPbad_o(DSPnumber_cal,iss)=templ(is) |
DSPbad_o(DSPnumber_cal,iss)=templ(is) |
|
c print*,il,is,iss,DSPbad_o(DSPnumber,iss) |
|
400 |
enddo |
enddo |
401 |
|
|
|
C//// CAPIRE PERCHE` NON C'E` LA PAROLA DI FINE LADDER \\\\ |
|
|
c call readeol(word,runerror,ffd) |
|
402 |
11 format(i1,' ',z4) |
11 format(i1,' ',z4) |
403 |
c write(*,11)il,word |
|
404 |
call readtrailer(trailer,runerror,ffd) |
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
405 |
c$$$ do i=1,3 |
$ startcrc,stopcrc,crctemp) |
|
c$$$ write(*,12)trailer(i) |
|
|
c$$$ enddo |
|
406 |
|
|
407 |
c print*,'fine ladder' !??? |
crc_trail=iand(trailer(3),z'00ff') |
408 |
|
|
409 |
|
if (crctemp.eq.crc_trail)then |
410 |
|
crc_calib(il)=0 |
411 |
|
else |
412 |
|
crc_calib(il)=1 |
413 |
|
endif |
414 |
|
|
415 |
enddo !end loop on ladders |
enddo !end loop on ladders |
416 |
|
|
417 |
return |
return |
418 |
end |
end |
|
*............................................................. |
|
419 |
|
|
420 |
|
* ********************************************************** |
421 |
|
* * * |
422 |
|
* * * |
423 |
|
* * * |
424 |
|
* * * |
425 |
|
* * * |
426 |
|
* ********************************************************** |
427 |
|
|
428 |
|
subroutine unpackdata(runerror,buffer,length_buffer,curpos, |
429 |
|
$ startcrc,stopcrc,crctemp) |
430 |
|
|
|
subroutine unpackdata(runerror,ffd) |
|
431 |
*............................................................. |
*............................................................. |
432 |
* decode event data |
* decode event data |
433 |
* header + data + trailer |
* header + data + trailer |
434 |
*............................................................ |
*............................................................ |
|
include '../commonyoda/commontracker.f' |
|
|
include '../commonyoda/dataformat.f' |
|
|
include '../commonyoda/level0.f' |
|
435 |
|
|
436 |
integer ffd !input file descriptor |
include '../common/commontracker.f' |
437 |
integer runerror !readevent error flag |
include '../common/common_readraw.f' |
438 |
integer l_tra |
include '../common/level0.f' |
439 |
|
|
440 |
|
integer*1 crctemp |
441 |
|
integer*1 crcdat |
442 |
|
|
443 |
|
integer runerror !readevent error flag |
444 |
|
c integer l_tra |
445 |
|
|
446 |
|
integer bid1_dat,bid2_dat,bid3_dat,bid4_dat,bid5_dat,bid6_dat |
447 |
|
$ ,bid7_dat,bid_dat_sum |
448 |
|
|
449 |
|
|
450 |
12 format(z4) |
12 format(z4) |
451 |
|
|
452 |
*----------------------------------------------------------- |
*----------------------------------------------------------- |
456 |
DAQmode_dat = ishft(iand(header(1),z'03f0'),-4) |
DAQmode_dat = ishft(iand(header(1),z'03f0'),-4) |
457 |
DSPnumber_dat = iand(header(1),z'000f') |
DSPnumber_dat = iand(header(1),z'000f') |
458 |
C ------------------------------------------------------ |
C ------------------------------------------------------ |
459 |
c words 2 and 3 give tshe number of transmitted 16-bit |
c words 2 and 3 give the number of transmitted 16-bit |
460 |
c words ( 13 header words + data ) |
c words ( 13 header words + data ) |
461 |
c NB: data are packed from 13-bit to 16-bit words, |
c NB: data are packed from 13-bit to 16-bit words, |
462 |
c so the stream is complited with zeros in order to have |
c so the stream is complited with zeros in order to have |
463 |
c a number of bits multiple of 16 |
c a number of bits multiple of 16 |
464 |
|
C ------------------------------------------------------ |
465 |
l_tra = ior(ishft(iand(header(2),z'03ff') |
l_tra = ior(ishft(iand(header(2),z'03ff') |
466 |
$ ,10),iand(header(3),z'03ff')) |
$ ,10),iand(header(3),z'03ff')) |
467 |
l_tra=l_tra-13 |
l_tra=l_tra-13 |
479 |
signcluster_dat(3) = iand(header(12),z'03ff') |
signcluster_dat(3) = iand(header(12),z'03ff') |
480 |
fc_dat = ishft(iand(header(13),z'0300'),-8) |
fc_dat = ishft(iand(header(13),z'0300'),-8) |
481 |
compressiontime_dat = iand(header(13),z'00ff') |
compressiontime_dat = iand(header(13),z'00ff') |
482 |
fl5_dat = ishft(iand(header(14),z'0300'),-8) |
c fl5_dat = ishft(iand(header(14),z'0300'),-8) |
483 |
fl4_dat = ishft(iand(header(14),z'0300'),-6) |
c fl4_dat = ishft(iand(header(14),z'0300'),-6) |
484 |
fl3_dat = ishft(iand(header(14),z'0300'),-4) |
c fl3_dat = ishft(iand(header(14),z'0300'),-4) |
485 |
fl2_dat = ishft(iand(header(14),z'0300'),-2) |
c fl2_dat = ishft(iand(header(14),z'0300'),-2) |
486 |
fl1_dat = iand(header(14),z'0300') |
c fl1_dat = iand(header(14),z'0300') |
487 |
fl6_dat = ishft(iand(header(15),z'0300'),-8) |
c fl6_dat = ishft(iand(header(15),z'0300'),-8) |
488 |
|
fl5_dat = iand(ishft(header(14),-8),z'0003') |
489 |
|
fl4_dat = iand(ishft(header(14),-6),z'0003') |
490 |
|
fl3_dat = iand(ishft(header(14),-4),z'0003') |
491 |
|
fl2_dat = iand(ishft(header(14),-2),z'0003') |
492 |
|
fl1_dat = iand(header(14),z'0003') |
493 |
|
fl6_dat = iand(ishft(header(15),-8),z'0003') |
494 |
checksum_dat = iand(header(15),z'00ff') |
checksum_dat = iand(header(15),z'00ff') |
495 |
|
|
496 |
c----------------------------------------------------------- |
c----------------------------------------------------------- |
497 |
c the cheacksum is a 8-bit word calculated as the |
c the cheacksum is a 8-bit word calculated as the |
498 |
c XOR of the 16-bit data words, |
c XOR of the 16-bit data words, |
499 |
c hence the XOR between the two halfs |
c hence the XOR between the two halfs |
500 |
C---------------------------------------------------------- |
C---------------------------------------------------------- |
501 |
runerror=0 |
runerror=0 |
502 |
call dunpacker(l_tra,b_tra,runerror,ffd) |
nqualcosa=0 |
503 |
|
if(l_tra.eq.0)then |
504 |
|
goto 18 !empty buffer |
505 |
|
endif |
506 |
|
|
507 |
|
if(l_tra.gt.MAXBUFFLEN .or.(curpos+l_tra-1).ge.MAXBUFFLEN )then |
508 |
|
print*,'unpackdata: ' |
509 |
|
$ ,'tracker buffer length l_tra ',l_tra |
510 |
|
$ ,' exceeds tracker buffer dimensions ' |
511 |
|
print*,'(packet corrupted)' |
512 |
|
cc runerror=1 |
513 |
|
runerror=2 |
514 |
|
goto 50 |
515 |
|
endif |
516 |
|
call dunpacker(l_tra,b_tra,runerror,buffer,length_buffer,curpos) |
517 |
|
if(runerror.eq.1.or.runerror.eq.-1) then |
518 |
|
goto 50 !go to end |
519 |
|
endif |
520 |
|
|
521 |
nqualcosa = (real(l_tra))/13*16 |
nqualcosa = (real(l_tra))/13*16 |
522 |
xx = b_tra(nqualcosa) |
xx = b_tra(nqualcosa) |
523 |
if (xx.eq.0) nqualcosa=nqualcosa -1 |
if (xx.eq.0) nqualcosa=nqualcosa -1 |
524 |
datalength_dat= nqualcosa |
|
525 |
c$$$ TOTDATAlength = TOTDATAlength + datalength_dat |
18 datalength_dat= nqualcosa |
|
c$$$ do i=1,datalength_dat |
|
|
c$$$ id = id + 1 |
|
|
c$$$ datatracker(id) = b_tra(i) |
|
|
c$$$ enddo |
|
|
|
|
|
|
|
|
|
|
526 |
11 format(i1,' ',z4) |
11 format(i1,' ',z4) |
527 |
c write(*,11)il,word |
|
528 |
call readtrailer(trailer,runerror,ffd) |
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
529 |
c$$$ do i=1,3 |
$ startcrc,stopcrc,crctemp) |
|
c$$$ write(*,12)trailer(i) |
|
|
c$$$ enddo |
|
530 |
|
|
531 |
*************************************************************** |
*************************************************************** |
532 |
* TRAILER * |
* TRAILER * |
544 |
alarm_dat=ishft(iand(trailer(2),z'0300'),-8) |
alarm_dat=ishft(iand(trailer(2),z'0300'),-8) |
545 |
aswr_dat=ior(ishft(iand(trailer(2),z'00ff'),8) |
aswr_dat=ior(ishft(iand(trailer(2),z'00ff'),8) |
546 |
$ ,ishft(iand(trailer(3),z'ff00'),-8)) |
$ ,ishft(iand(trailer(3),z'ff00'),-8)) |
547 |
crc_dat=iand(trailer(3),z'00ff') |
crcdat=iand(trailer(3),z'00ff') |
|
|
|
|
bid_dat_sum = (bid1_dat + bid2_dat + bid3_dat + bid4_dat + |
|
|
& bid5_dat + bid6_dat + bid7_dat) |
|
548 |
|
|
549 |
bid_dat = bid_dat_sum/7 |
c$$$ print*,'######################',crcdat,crctemp |
550 |
|
|
|
if (bid_dat.ne.1.and.bid_dat.ne.2) then |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** ***' |
|
|
write (*,*) 'unpack_data: TRAILER PACKET CORRUPTED' |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** ***' |
|
|
endif |
|
|
if (mod(bid_dat_sum,7).ne.0) then |
|
|
bid_dat = 0 |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** ***' |
|
|
write (*,*) 'unpack_data: TRAILER PACKET CORRUPTED' |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** ***' |
|
|
endif |
|
|
|
|
|
if (alarm_dat.eq.3) then |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** ***' |
|
|
write(*,*) 'unpack_data: AQUISITION ALARM' |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** ***' |
|
551 |
|
|
552 |
|
if(crcdat.eq.crctemp)then |
553 |
|
crc_dat=0 |
554 |
|
else |
555 |
|
crc_dat=1 |
556 |
endif |
endif |
|
|
|
|
if (alarm_dat.ne.3.and.alarm_dat.ne.0) then |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** ***' |
|
|
write(*,*) 'unpack_data: TRAILER PACKET CORRUPTED' |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** ***' |
|
557 |
|
|
558 |
endif |
bid_dat_sum = (bid1_dat + bid2_dat + bid3_dat + bid4_dat + |
559 |
|
& bid5_dat + bid6_dat + bid7_dat) |
560 |
|
|
561 |
|
bid_dat = bid_dat_sum/7 |
562 |
|
|
563 |
return |
50 return |
564 |
end |
end |
565 |
|
|
566 |
|
* ********************************************************** |
567 |
|
* * * |
568 |
|
* * * |
569 |
|
* * * |
570 |
|
* * * |
571 |
|
* * * |
572 |
|
* ********************************************************** |
573 |
|
|
|
*............................................................................. |
|
574 |
subroutine initlevel0 |
subroutine initlevel0 |
|
|
|
|
include '../commonyoda/level0.f' |
|
575 |
|
|
576 |
|
include '../common/commontracker.f' |
577 |
|
include '../common/level0.f' |
578 |
|
|
579 |
|
good0=0 |
580 |
|
TOTDATAlength = 0 |
581 |
|
|
582 |
do i=1, nviews |
do i=1, nviews |
583 |
|
|
608 |
bid(i) = 1 |
bid(i) = 1 |
609 |
alarm(i)= 0 |
alarm(i)= 0 |
610 |
aswr(i) = 0 |
aswr(i) = 0 |
611 |
|
crc(i)=0 |
612 |
|
|
613 |
enddo |
enddo |
614 |
|
|
|
TOTDATAlength = 0 |
|
|
good0=.true. |
|
615 |
|
|
616 |
return |
return |
617 |
end |
end |
618 |
|
|
619 |
|
* ********************************************************** |
620 |
|
* * * |
621 |
|
* * * |
622 |
|
* * * |
623 |
|
* * * |
624 |
|
* * * |
625 |
|
* ********************************************************** |
626 |
|
|
|
* *** *** *** *** *** *** *** *** *** |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* *** *** *** *** *** *** *** *** *** |
|
627 |
subroutine fillview(i) |
subroutine fillview(i) |
628 |
c ----------------------------------------------------- |
c ----------------------------------------------------- |
629 |
c fill variables related to view i |
c fill variables related to view i |
631 |
c at the end of loop on views |
c at the end of loop on views |
632 |
c ---------------------------------------------------- |
c ---------------------------------------------------- |
633 |
|
|
634 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
635 |
include '../commonyoda/level0.f' |
include '../common/level0.f' |
636 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
637 |
|
|
638 |
|
|
639 |
DAQmode(i) = DAQmode_dat |
DAQmode(i) = DAQmode_dat |
640 |
DSPnumber(i) = DSPnumber_dat |
DSPnumber(i) = DSPnumber_dat |
658 |
fl6(i) = fl6_dat |
fl6(i) = fl6_dat |
659 |
checksum(i) = checksum_dat |
checksum(i) = checksum_dat |
660 |
DATAlength(i) = datalength_dat |
DATAlength(i) = datalength_dat |
661 |
|
crc(i) = crc_dat |
662 |
|
|
663 |
c ----------------------------------------------------------------------- |
c ----------------------------------------------------------------------- |
664 |
c filling TRAILER variables |
c filling TRAILER variables |
670 |
alarm(i)= alarm_dat |
alarm(i)= alarm_dat |
671 |
aswr(i) = aswr_dat |
aswr(i) = aswr_dat |
672 |
|
|
|
print*,'*-*-*-*-*-*-TRAILER-*-*-*-*-*-*' |
|
|
print*,'* PNUM (periferal num) ',pnum_dat |
|
|
print*,'* CMDNUM (command) ',cmdnum_dat |
|
|
print*,'* BID (board id) ',bid_dat |
|
|
print*,'* ALARM ',alarm_dat |
|
|
print*,'*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*' |
|
|
|
|
673 |
do idat=1,datalength_dat |
do idat=1,datalength_dat |
674 |
id = TOTDATAlength + idat |
id = TOTDATAlength + idat |
675 |
datatracker(id) = b_tra(idat) |
datatracker(id) = b_tra(idat) |
679 |
return |
return |
680 |
end |
end |
681 |
|
|
682 |
|
* ********************************************************** |
683 |
|
* * * |
684 |
|
* * * |
685 |
|
* * * |
686 |
|
* * * |
687 |
|
* * * |
688 |
|
* ********************************************************** |
689 |
|
|
690 |
|
subroutine fillview_cal(i) |
691 |
|
c ----------------------------------------------------- |
692 |
|
c fill variables related to view i |
693 |
|
c which will be stored in the calibration nt-ple |
694 |
|
c at the end of loop on views |
695 |
|
c ---------------------------------------------------- |
696 |
|
|
697 |
|
include '../common/commontracker.f' |
698 |
|
include '../common/trk_calib_parameters.f' |
699 |
|
include '../common/common_readraw.f' |
700 |
|
|
701 |
|
DAQmode(i) = DAQmode_cal |
702 |
|
DSPnumber(i) = DSPnumber_cal |
703 |
|
calibnumber(i) = calibrationnumber |
704 |
|
ncalib_event(i)= nused_event |
705 |
|
ped_l1(i) = ped_1 |
706 |
|
ped_l2(i) = ped_2 |
707 |
|
ped_l3(i) = ped_3 |
708 |
|
sig_l1(i) = sig_1 |
709 |
|
sig_l2(i) = sig_2 |
710 |
|
sig_l3(i) = sig_3 |
711 |
|
nbad_l1(i) = nbad_1 |
712 |
|
nbad_l2(i) = nbad_2 |
713 |
|
nbad_l3(i) = nbad_3 |
714 |
|
cal_flag(i) = ff |
715 |
|
|
716 |
|
do is=1,nstrips_view |
717 |
|
DSPbad_par(i,is) = DSPbad_o(DSPnumber_cal,is) |
718 |
|
DSPped_par(i,is) = DSPped_o(DSPnumber_cal,is) |
719 |
|
DSPsig_par(i,is) = DSPsig_o(DSPnumber_cal,is) |
720 |
|
enddo |
721 |
|
|
722 |
|
crc_hcal(i) = crc_hcalib |
723 |
|
crc_cal(i,1) = crc_calib(1) |
724 |
|
crc_cal(i,2) = crc_calib(2) |
725 |
|
crc_cal(i,3) = crc_calib(3) |
726 |
|
|
727 |
|
return |
728 |
|
end |
729 |
|
|
730 |
|
* ********************************************************** |
731 |
|
* * * |
732 |
|
* * * |
733 |
|
* * * |
734 |
|
* * * |
735 |
|
* * * |
736 |
|
* ********************************************************** |
737 |
|
|
738 |
|
subroutine initcalib |
739 |
|
include '../common/commontracker.f' |
740 |
|
include '../common/trk_calib_parameters.f' |
741 |
|
|
742 |
|
good0=0 |
743 |
|
|
744 |
|
do i=1,nplanes |
745 |
|
|
746 |
|
DAQmode(i) = 0 |
747 |
|
DSPnumber(i) = 0 |
748 |
|
calibnumber(i) = 0 |
749 |
|
ncalib_event(i)= 0 |
750 |
|
ped_l1(i) = 0 |
751 |
|
ped_l2(i) = 0 |
752 |
|
ped_l3(i) = 0 |
753 |
|
sig_l1(i) = 0 |
754 |
|
sig_l2(i) = 0 |
755 |
|
sig_l3(i) = 0 |
756 |
|
nbad_l1(i) = 0 |
757 |
|
nbad_l2(i) = 0 |
758 |
|
nbad_l3(i) = 0 |
759 |
|
cal_flag(i) = 0 |
760 |
|
|
761 |
|
do is=1,nstrips_view |
762 |
|
DSPbad_par(i,is) = 0 |
763 |
|
DSPped_par(i,is) = 0 |
764 |
|
DSPsig_par(i,is) = 0 |
765 |
|
enddo |
766 |
|
crc_hcal(i) = 0 |
767 |
|
crc_cal(i,1) = 0 |
768 |
|
crc_cal(i,2) = 0 |
769 |
|
crc_cal(i,3) = 0 |
770 |
|
enddo |
771 |
|
|
772 |
|
return |
773 |
|
end |