1 |
subroutine trkeventpkt(YODAflag,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 |
|
************************************************************************* |
7 |
|
|
8 |
include '../commonyoda/commontracker.f' |
subroutine trkeventpkt(YODAflag,buffer,length_buffer,curpos |
9 |
include '../commonyoda/dataformat.f' |
$ ) |
10 |
include '../commonyoda/level0.f' |
|
11 |
|
include '../common/commontracker.f' |
12 |
|
include '../common/common_readraw.f' |
13 |
|
include '../common/level0.f' |
14 |
|
|
15 |
* --------------------------------------------------- |
* --------------------------------------------------- |
16 |
* the general flag YODAflag contains information |
* the general flag YODAflag contains information |
17 |
* about the integrity of the packet. |
* about the integrity of the DSP packets. |
|
* |
|
|
* It is coded in bits: |
|
|
* |
|
|
* x xxxx xxxx xxxx xxxx |
|
|
* | |||| |||| |||| |||| |
|
|
* | |||| |||| |||| |||- integrity flag of 1 st DSP packet |
|
|
* | |||| |||| |||| ||-- " " " 2 nd " " |
|
|
* | |||| |||| |||| |--- " " " 3 rd " " |
|
|
* | |||| .............. |
|
|
* | |.................. |
|
|
* | ------------------- integrity flag of 12 th DSP packet |
|
|
* | |
|
|
* --------------------- flag that indicates if more than 12 |
|
|
* packets have been found |
|
|
* |
|
|
* EXAMPLE 1. |
|
|
* If the event packet is truncated and only three DSP packets |
|
|
* are present in the fragment, the last being TRUNCATED, |
|
|
* the YODAflag will be: |
|
|
* |
|
|
* YODAflag = b#00000000000000100 = 4 |
|
18 |
* |
* |
19 |
* and only the two integer packets will be stored. |
* If some packets are missing or the crc check fails, |
20 |
* |
* YODAflag is asserted |
|
* EXAMPLE 2. |
|
|
* If instead the corruption of a packet results from |
|
|
* checksum or crc, the YODAflag will be asserted as explained, |
|
|
* but the packet will be stored. |
|
21 |
* --------------------------------------------------- |
* --------------------------------------------------- |
|
integer YODAflag |
|
22 |
|
|
23 |
logical DEBUG,ALARMs |
c$$$ integer YODAflag |
|
common/DEBUGflag/DEBUG,ALARMS |
|
24 |
|
|
25 |
|
|
26 |
|
logical ALARMS |
27 |
|
|
|
integer ndummy |
|
|
data ndummy/1000/ |
|
28 |
|
|
29 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
|
integer ffd_pkt !pkt file descriptor |
|
|
* (file temporaneo) |
|
|
character*60 event_file_name !nome file |
|
|
|
|
|
integer lun_pkt |
|
|
data lun_pkt/20/ |
|
|
|
|
|
integer last_trigger(nviews) |
|
|
common/trigger_counter/last_trigger |
|
|
|
|
|
|
|
|
YODAflag=0 |
|
|
|
|
|
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 |
|
30 |
|
|
31 |
|
c$$$ parameter (MAXBUFFLEN=z'172c8') |
32 |
|
c$$$ integer*4 length_buffer |
33 |
|
c$$$ integer*1 buffer(MAXBUFFLEN) |
34 |
|
c$$$ integer curpos !current position in buffer |
35 |
|
c$$$ integer startcrc |
36 |
|
c$$$ integer stopcrc |
37 |
|
integer*1 crctemp |
38 |
|
|
39 |
|
* ------------------- |
40 |
|
* initializations |
41 |
|
YODAflag=1 !bad by default |
42 |
call initlevel0 |
call initlevel0 |
43 |
|
ALARMS=.false. |
44 |
TOTDATAlength = 0. !total length of data buffer |
npkt=0 !#good DSP packets |
45 |
do iview=1,nviews!ndummy !loop on views |
startcrc=0 |
46 |
call searchtrkheader(runerror,ffd_pkt) |
stopcrc=0 |
47 |
|
crctemp=0 |
48 |
|
* ------------------- |
49 |
|
|
50 |
|
* =================================== |
51 |
|
if(length_buffer.gt.MAXBUFFLEN)then |
52 |
|
print*,'trkeventpkt: buffer() size must be at least ',length_buffer,' !!!!' |
53 |
|
goto 2222 |
54 |
|
endif |
55 |
|
* =================================== |
56 |
|
|
57 |
|
|
58 |
|
do iview=1,nviews !loop on DSPs |
59 |
|
call searchtrkheader(runerror,buffer,length_buffer,curpos, |
60 |
|
$ startcrc) |
61 |
if(runerror.eq.1.or.runerror.eq.-1) then |
if(runerror.eq.1.or.runerror.eq.-1) then |
62 |
* -------------------------------------------------- |
* -------------------------------------------------- |
63 |
* no further DSP packet has been found ==> go to end |
* no DSP packet has been found ==> go to end |
64 |
* -------------------------------------------------- |
* -------------------------------------------------- |
65 |
goto 2222 !go to end |
goto 2222 !go to end |
66 |
endif |
endif |
67 |
|
|
68 |
if(checkheader.ne.2) then |
if(checkheader.ne.2) then |
69 |
print*,'>>>> ERROR <<<< (trkeventpkt)' |
print*,'>>>> ERROR <<<< (trkeventpkt)' |
70 |
print*,'>>>> CPU packet type ',!pkt_type, |
print*,'>>>> CPU packet type ',!pkt_type, |
79 |
goto 2525 !next view (==> search another DSP header) |
goto 2525 !next view (==> search another DSP header) |
80 |
endif |
endif |
81 |
|
|
82 |
call unpackdata(runerror,ffd_pkt) |
call unpackdata(runerror,buffer,length_buffer,curpos, |
83 |
|
$ startcrc,stopcrc,crctemp) |
84 |
if(runerror.eq.-1.or.runerror.eq.1)then |
if(runerror.eq.-1.or.runerror.eq.1)then |
85 |
* ----------------------------------------------- |
goto 2222 !go to end |
|
* an error occurred while reading the packet data |
|
|
* ===> assert packet error bit ===> go to end |
|
|
* ----------------------------------------------- |
|
|
YODAflag=ior(YODAflag,int(2**(iview-1))) |
|
|
goto 2222 !end |
|
86 |
endif |
endif |
|
|
|
|
if(ALARMs)then |
|
|
print*,' ' |
|
|
print*,' -----------------------------------',iview |
|
|
print*,' DSP number-----',DSPnumber_dat |
|
|
print*,' DAQ mode-------',DAQmode_dat |
|
|
print*,' event number ',eventn_dat |
|
|
print*,' datalength (13-bit w) ---- ',datalength_dat |
|
|
print*,' L-1 addr---',addrcluster_dat(1) |
|
|
print*,' signal-',signcluster_dat(1) |
|
|
print*,' L-2 addr---',addrcluster_dat(2) |
|
|
print*,' signal-',signcluster_dat(2) |
|
|
print*,' L-3 addr---',addrcluster_dat(3) |
|
|
print*,' signal-',signcluster_dat(3) |
|
|
print*,' FC------',fc_dat |
|
|
print*,' compression time ',compressiontime_dat |
|
|
print*,' FL1--',fl1_dat |
|
|
print*,' FL2--',fl2_dat |
|
|
print*,' FL3--',fl3_dat |
|
|
print*,' FL4--',fl4_dat |
|
|
print*,' FL5--',fl5_dat |
|
|
print*,' FL6--',fl6_dat |
|
|
|
|
|
print*,'*-*-*-*-*-*-TRAILER-*-*-*-*-*-*' |
|
|
print*,'* PNUM (periferal num) ',pnum_dat |
|
|
print*,'* CMDNUM (command) ',cmdnum_dat |
|
|
print*,'* BID (board id) ',bid_dat |
|
|
print*,'* ALARM ',alarm_dat |
|
|
print*,'*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*' |
|
87 |
|
|
88 |
DEBUG = .true. |
npkt = npkt + 1 |
|
endif |
|
|
|
|
|
trk_DSP_ok(DSPnumber_dat)=1 |
|
|
|
|
89 |
call fillview(iview) |
call fillview(iview) |
90 |
|
*-------- CRC check |
91 |
|
if(crc(iview).eq.0) then !OK |
92 |
|
*----------- ALARMS |
93 |
|
if( |
94 |
|
$ fl1(iview).ne.0.or. |
95 |
|
$ fl2(iview).ne.0.or. |
96 |
|
$ fl3(iview).ne.0.or. |
97 |
|
$ fl4(iview).ne.0.or. |
98 |
|
$ fl5(iview).ne.0.or. |
99 |
|
$ fl6(iview).ne.0.or. |
100 |
|
$ fc(iview).ne.0.or. |
101 |
|
$ DATAlength(iview).eq.0.or. |
102 |
|
$ .false.)ALARMS=.true. |
103 |
|
endif |
104 |
|
|
105 |
2525 continue |
2525 continue |
106 |
enddo !end loop on views |
enddo !end loop on views |
107 |
|
|
108 |
2222 continue |
2222 continue |
109 |
|
|
110 |
close (lun_pkt) |
if(npkt.eq.nviews)YODAflag=0 |
111 |
|
if(YODAflag.eq.0.and.(ALARMS.eqv..false.))good0=1 |
112 |
|
|
113 |
return |
return |
114 |
end |
end |
115 |
|
|
116 |
* ********************************************** |
* ********************************************************** |
117 |
|
* * * |
118 |
|
* * * |
119 |
|
* * * |
120 |
|
* * * |
121 |
|
* * * |
122 |
|
* ********************************************************** |
123 |
|
|
124 |
subroutine trkcalibpkt(runerror,event_file_name) |
subroutine trkcalibpkt(YODAflag,buffer,length_buffer,curpos |
125 |
|
$ ) |
|
include '../commonyoda/commontracker.f' |
|
|
include '../commonyoda/dataformat.f' |
|
|
include '../commonyoda/trk_calib_parameters.f' |
|
|
|
|
|
integer ndummy |
|
|
data ndummy/1000/ |
|
|
|
|
|
integer runerror !readevent error flag |
|
|
integer ffd_pkt !pkt file descriptor |
|
|
!(file temporaneo) |
|
|
character*60 event_file_name !nome file |
|
126 |
|
|
127 |
logical DEBUG,ALARMs |
include '../common/commontracker.f' |
128 |
data DEBUG/.false./ |
include '../common/common_readraw.f' |
129 |
|
include '../common/trk_calib_parameters.f' |
|
ccc data DEBUG/.true./ |
|
|
ccc common/DEBUGflag/DEBUG |
|
130 |
|
|
131 |
|
* --------------------------------------------------- |
132 |
|
* the general flag YODAflag contains information |
133 |
|
* about the integrity of the DSP packets. |
134 |
|
* |
135 |
|
* If some packets are missing or the crc check fails, |
136 |
|
* YODAflag is asserted |
137 |
|
* --------------------------------------------------- |
138 |
|
|
139 |
|
c$$$ integer YODAflag |
140 |
|
|
141 |
integer lun_pkt |
logical ALARMs |
|
data lun_pkt/10/ |
|
142 |
|
|
143 |
|
integer runerror !readevent error flag |
144 |
|
c$$$ parameter (MAXBUFFLEN=z'172c8') |
145 |
|
c$$$ integer*4 length_buffer |
146 |
|
c$$$ integer*1 buffer(MAXBUFFLEN) |
147 |
|
c$$$ integer curpos !current position in buffer |
148 |
|
c$$$ integer startcrc |
149 |
|
c$$$ integer stopcrc |
150 |
|
integer*1 crctemp |
151 |
|
|
152 |
|
* ------------------- |
153 |
|
* initializations |
154 |
|
YODAflag = 1 !bad by default |
155 |
|
call initcalib |
156 |
|
ALARMS=.false. |
157 |
|
npkt=0 !#good DSP packets |
158 |
|
startcrc=0 |
159 |
|
stopcrc=0 |
160 |
|
crctemp=0 |
161 |
|
* ------------------- |
162 |
|
|
163 |
open(unit=lun_pkt, |
do iview=1,nplanes !loop on views (DSP pkt) |
|
$ name=EVENT_FILE_NAME(1:lnblnk(EVENT_FILE_NAME)), |
|
|
$ status='old', |
|
|
$ form='unformatted' |
|
|
$ ) |
|
|
ffd_pkt = FNum(lun_pkt) !reads unix file descriptor |
|
|
|
|
164 |
|
|
165 |
|
call searchtrkheader(runerror,buffer,length_buffer,curpos, |
166 |
do iview=1,ndummy !loop on views (DSP pkt) |
$ startcrc) |
167 |
|
|
168 |
ALARMS=.false. |
if(runerror.eq.1.or.runerror.eq.-1) then |
|
|
|
|
call searchtrkheader(runerror,ffd_pkt) |
|
|
c if(runerror.eq.-1) goto 24 |
|
|
if(runerror.eq.-1) goto 2222 |
|
|
if(runerror.eq.1) then |
|
|
c print*,' ' |
|
|
c print*,'readraw: END OF CPU PACKET ' |
|
|
c print*,'______________________________________ ' |
|
169 |
goto 2222 !end loop on views (DSP pkt) |
goto 2222 !end loop on views (DSP pkt) |
170 |
endif |
endif |
171 |
|
|
172 |
if(checkheader.ne.3) then |
if(checkheader.ne.3) then |
173 |
print*,'>>>> ERROR <<<< (trkcalibpkt)' |
print*,'>>>> ERROR <<<< (trkcalibpkt)' |
174 |
print*,'>>>> CPU packet type ',!pkt_type, |
print*,'>>>> CPU packet type ',!pkt_type, |
183 |
goto 2424 !next view (==> search another DSP header) |
goto 2424 !next view (==> search another DSP header) |
184 |
endif |
endif |
185 |
|
|
186 |
call unpackcalibration(runerror,ffd_pkt) |
call unpackcalibration(runerror,buffer,length_buffer,curpos, |
187 |
c if(runerror.eq.-1) goto 24 |
$ startcrc,stopcrc,crctemp) |
188 |
if(runerror.eq.-1) goto 2222 |
if(runerror.eq.-1.or.runerror.eq.1)then |
189 |
c if(runerror.eq.1) goto 23 |
goto 2222 !end |
|
if(runerror.eq.1) goto 2222 |
|
|
|
|
|
if(nused_event.ne.0.or.ff.ne.0)then |
|
|
print*,'*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*' |
|
|
print*,'* !!! CALIBRATION FAILURE !!! *' |
|
|
print*,'*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*' |
|
|
c ALARMS=.true. |
|
|
endif |
|
|
if(ALARMS)then |
|
|
|
|
|
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 |
|
190 |
endif |
endif |
191 |
|
|
192 |
|
|
193 |
DAQmode(iview)=DAQmode_cal |
npkt = npkt + 1 |
194 |
DSPnumber(iview)=DSPnumber_cal |
call fillview_cal(iview) ! |
195 |
calibnumber(iview)=calibrationnumber |
*--------CRC check |
196 |
ncalib_event(iview)=nused_event |
if( crc_hcal(iview).eq.0.and. |
197 |
ped_l1(iview)=ped_1 |
$ crc_cal(iview,1).eq.0.and. |
198 |
ped_l2(iview)=ped_2 |
$ crc_cal(iview,2).eq.0.and. |
199 |
ped_l3(iview)=ped_3 |
$ crc_cal(iview,3).eq.0.and. |
200 |
sig_l1(iview)=sig_1 |
$ .true.)then |
201 |
sig_l2(iview)=sig_2 |
*----------- ALARMS |
202 |
sig_l3(iview)=sig_3 |
if( ncalib_event(iview).ne.0.or. |
203 |
nbad_l1(iview)=nbad_1 |
$ cal_flag(iview).ne.0.or. |
204 |
nbad_l2(iview)=nbad_2 |
$ .false.)ALARMS=.true. |
205 |
nbad_l3(iview)=nbad_3 |
endif |
|
cal_flag(iview)=ff |
|
206 |
|
|
|
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 |
|
207 |
2424 continue |
2424 continue |
208 |
enddo ! end loop on views (calibration pkt) |
enddo ! end loop on views (calibration pkt) |
|
2222 continue |
|
209 |
|
|
210 |
close (lun_pkt) |
if(npkt.eq.nplanes)YODAflag=0 |
211 |
|
if(YODAflag.eq.0.and.(ALARMS.eqv..false.))good0=1 |
212 |
|
|
213 |
|
2222 continue |
214 |
|
|
215 |
return |
return |
216 |
end |
end |
217 |
|
|
218 |
***...***...***...***...***...***...***...***...***...***...***...***...***...***...***...*** |
* ********************************************************** |
219 |
* |
* * * |
220 |
* |
* * * |
221 |
* |
* * * |
222 |
* |
* * * |
223 |
* |
* * * |
224 |
* |
* ********************************************************** |
|
* |
|
|
* |
|
|
***...***...***...***...***...***...***...***...***...***...***...***...***...***...***...*** |
|
225 |
|
|
226 |
subroutine searchtrkheader(runerror,ffd) |
subroutine searchtrkheader(runerror,buffer,length_buffer, |
227 |
|
$ curpos,startcrc) |
228 |
C............................................................. |
C............................................................. |
229 |
C Search for a valid tracker DSP header (=>one view) |
C Search for a valid tracker DSP header (=>one view) |
230 |
C and return the type of header |
C and return the type of header |
231 |
C............................................................. |
C............................................................. |
232 |
|
|
233 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
234 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
235 |
|
|
236 |
|
c$$$ parameter (MAXBUFFLEN=z'172c8') |
237 |
|
c$$$ integer*4 length_buffer |
238 |
|
c$$$ integer*1 buffer(MAXBUFFLEN) |
239 |
|
c$$$ integer curpos !current position in buffer |
240 |
|
c$$$ integer startcrc |
241 |
|
|
|
integer ffd !input file descriptor |
|
242 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
243 |
|
|
244 |
c-------------------------------------------------- |
c-------------------------------------------------- |
246 |
C so each DSP 13 bit |
C so each DSP 13 bit |
247 |
c first word starts at the beginnig of a 16 bit word |
c first word starts at the beginnig of a 16 bit word |
248 |
c-------------------------------------------------- |
c-------------------------------------------------- |
249 |
|
|
250 |
9100 continue |
9100 continue |
251 |
runerror=0 !error flag initialization |
runerror=0 !error flag initialization |
252 |
checkheader=0 |
checkheader=0 |
255 |
c looks for a DSP header beginning |
c looks for a DSP header beginning |
256 |
C (a word beginning with 1110) |
C (a word beginning with 1110) |
257 |
c-------------------------------------------------- |
c-------------------------------------------------- |
|
call findstart(runerror,ffd) |
|
258 |
|
|
259 |
|
call findstart(runerror,buffer,length_buffer,curpos) |
260 |
|
|
261 |
if(runerror.eq.1) goto 200 !end |
if(runerror.eq.1) goto 200 !end |
262 |
if(runerror.eq.-1)goto 200 !end |
if(runerror.eq.-1)goto 200 !end |
263 |
c-------------------------------------------------- |
c-------------------------------------------------- |
266 |
c writes them in 16 13-bit words to check for all |
c writes them in 16 13-bit words to check for all |
267 |
C DSP header features |
C DSP header features |
268 |
c-------------------------------------------------- |
c-------------------------------------------------- |
269 |
|
|
270 |
call hunpacker(header,runerror,ffd) |
call hunpacker(header,runerror,buffer,length_buffer,curpos, |
271 |
|
$ startcrc) |
272 |
|
|
273 |
if(runerror.eq.1) goto 200 !end |
if(runerror.eq.1) goto 200 !end |
274 |
if(runerror.eq.-1)goto 200 !end |
if(runerror.eq.-1)goto 200 !end |
275 |
c-------------------------------------------------- |
c-------------------------------------------------- |
306 |
c noise lurks around) so go a word ahead and |
c noise lurks around) so go a word ahead and |
307 |
c try again |
c try again |
308 |
c-------------------------------------------------- |
c-------------------------------------------------- |
309 |
if(checkheader.eq.1) then |
if(checkheader.eq.1) then |
310 |
call skipbyte(ffd) !new search |
curpos=curpos-(13*2)+1 !goes back 13 words, then half 16 bit word ahead |
311 |
goto 9100 |
goto 9100 |
312 |
endif |
endif |
313 |
|
|
314 |
200 continue |
200 continue |
315 |
end |
end |
316 |
|
|
317 |
*............................................................. |
* ********************************************************** |
318 |
|
* * * |
319 |
|
* * * |
320 |
|
* * * |
321 |
|
* * * |
322 |
|
* * * |
323 |
|
* ********************************************************** |
324 |
|
|
325 |
|
subroutine unpackcalibration(runerror,buffer,length_buffer,curpos, |
326 |
|
$ startcrc,stopcrc,crctemp) |
327 |
|
|
|
*............................................................. |
|
|
|
|
|
subroutine unpackcalibration(runerror,ffd) |
|
328 |
*............................................................. |
*............................................................. |
329 |
* decode calibration data |
* decode calibration data |
330 |
* header + data(PED SIG BAD) + trailer |
* header + data(PED SIG BAD) + trailer |
331 |
*............................................................ |
*............................................................ |
332 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
333 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
334 |
|
|
335 |
integer ffd !input file descriptor |
c$$$ parameter (MAXBUFFLEN=z'172c8') |
336 |
|
c$$$ integer*4 length_buffer |
337 |
|
c$$$ integer*1 buffer(MAXBUFFLEN) |
338 |
|
c$$$ integer curpos !current position in buffer |
339 |
|
c$$$ integer startcrc |
340 |
|
c$$$ integer stopcrc |
341 |
|
integer*1 crctemp |
342 |
|
integer*1 crc_trail |
343 |
|
|
344 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
|
c buffer temporanei |
|
345 |
integer*2 templ(nstrips_ladder) |
integer*2 templ(nstrips_ladder) |
346 |
real*4 tempf(nstrips_ladder) |
real*4 tempf(nstrips_ladder) |
347 |
|
|
348 |
|
|
349 |
|
|
350 |
12 format(z4) |
12 format(z4) |
351 |
|
|
352 |
*----------------------------------------------------------- |
*----------------------------------------------------------- |
360 |
DSPnumber_cal = iand(header(1),z'000f') |
DSPnumber_cal = iand(header(1),z'000f') |
361 |
dataword = ior(ishft(iand(header(2),z'03ff') |
dataword = ior(ishft(iand(header(2),z'03ff') |
362 |
$ ,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')) |
|
363 |
calibrationnumber = iand(header(4),z'03ff') |
calibrationnumber = iand(header(4),z'03ff') |
364 |
nused_event = iand(header(5),z'03ff') |
nused_event = iand(header(5),z'03ff') |
365 |
ped_1 = iand(header(6),z'03ff') |
ped_1 = iand(header(6),z'03ff') |
376 |
nbad_3 = iand(header(14),z'03ff') |
nbad_3 = iand(header(14),z'03ff') |
377 |
ff = ishft(iand(header(15),z'0300'),-8) |
ff = ishft(iand(header(15),z'0300'),-8) |
378 |
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 |
|
379 |
c----------------------------------------------------------- |
c----------------------------------------------------------- |
380 |
c the checksum is a 8-bit word calculated as the |
c the checksum is a 8-bit word calculated as the |
381 |
c XOR of the 16-bit data words, |
c XOR of the 16-bit data words, |
382 |
c hence the XOR between the two halfs |
c hence the XOR between the two halfs |
383 |
C---------------------------------------------------------- |
C---------------------------------------------------------- |
|
do il=1,3 !loop on ladders |
|
384 |
|
|
385 |
call readped(tempf,runerror,ffd) |
runerror=0 |
386 |
|
c$$$ |
387 |
|
c$$$ print*,'-----------------------------------' |
388 |
|
c$$$ print*,'unpackcalibration: readtrailer --- ', |
389 |
|
c$$$* $ trailer,runerror,buffer,length_buffer,curpos, |
390 |
|
c$$$ $ startcrc,stopcrc,crctemp |
391 |
|
c$$$ print*,'-----------------------------------' |
392 |
|
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
393 |
|
$ startcrc,stopcrc,crctemp) |
394 |
|
|
395 |
|
crc_trail=iand(trailer(3),z'00ff') |
396 |
|
|
397 |
|
c$$$ print *,'@@@@@@@@@@@@@ ',crctemp,crc_trail |
398 |
|
|
399 |
|
if (crctemp.eq.crc_trail)then |
400 |
|
crc_hcalib=0 |
401 |
|
else |
402 |
|
crc_hcalib=1 |
403 |
|
endif |
404 |
|
|
405 |
|
do il=1,3 !loop on ladders |
406 |
|
startcrc=curpos |
407 |
|
call readped(tempf,runerror,buffer,length_buffer,curpos) |
408 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
409 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
410 |
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) |
|
|
|
|
411 |
enddo |
enddo |
412 |
|
|
413 |
call readsig(tempf,runerror,ffd) |
call readsig(tempf,runerror,buffer,length_buffer,curpos) |
414 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
415 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
416 |
DSPsig_o(DSPnumber_cal,iss)=tempf(is) |
DSPsig_o(DSPnumber_cal,iss)=tempf(is) |
|
c print*,DSPsig_o(DSPnumber,iss) |
|
417 |
enddo |
enddo |
418 |
|
|
419 |
call readbad(templ,runerror,ffd) |
call readbad(templ,runerror,buffer,length_buffer,curpos) |
420 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
421 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
422 |
DSPbad_o(DSPnumber_cal,iss)=templ(is) |
DSPbad_o(DSPnumber_cal,iss)=templ(is) |
|
c print*,il,is,iss,DSPbad_o(DSPnumber,iss) |
|
423 |
enddo |
enddo |
424 |
|
|
|
C//// CAPIRE PERCHE` NON C'E` LA PAROLA DI FINE LADDER \\\\ |
|
|
c call readeol(word,runerror,ffd) |
|
425 |
11 format(i1,' ',z4) |
11 format(i1,' ',z4) |
426 |
c write(*,11)il,word |
|
427 |
call readtrailer(trailer,runerror,ffd) |
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
428 |
c$$$ do i=1,3 |
$ startcrc,stopcrc,crctemp) |
|
c$$$ write(*,12)trailer(i) |
|
|
c$$$ enddo |
|
429 |
|
|
430 |
c print*,'fine ladder' !??? |
crc_trail=iand(trailer(3),z'00ff') |
431 |
|
|
432 |
|
if (crctemp.eq.crc_trail)then |
433 |
|
crc_calib(il)=0 |
434 |
|
else |
435 |
|
crc_calib(il)=1 |
436 |
|
endif |
437 |
|
|
438 |
enddo !end loop on ladders |
enddo !end loop on ladders |
439 |
|
|
440 |
return |
return |
441 |
end |
end |
|
*............................................................. |
|
442 |
|
|
443 |
|
* ********************************************************** |
444 |
|
* * * |
445 |
|
* * * |
446 |
|
* * * |
447 |
|
* * * |
448 |
|
* * * |
449 |
|
* ********************************************************** |
450 |
|
|
451 |
|
subroutine unpackdata(runerror,buffer,length_buffer,curpos, |
452 |
|
$ startcrc,stopcrc,crctemp) |
453 |
|
|
|
subroutine unpackdata(runerror,ffd) |
|
454 |
*............................................................. |
*............................................................. |
455 |
* decode event data |
* decode event data |
456 |
* header + data + trailer |
* header + data + trailer |
457 |
*............................................................ |
*............................................................ |
|
include '../commonyoda/commontracker.f' |
|
|
include '../commonyoda/dataformat.f' |
|
|
include '../commonyoda/level0.f' |
|
|
|
|
|
integer ffd !input file descriptor |
|
|
integer runerror !readevent error flag |
|
|
integer l_tra |
|
458 |
|
|
459 |
logical DEBUG,ALARMs |
include '../common/commontracker.f' |
460 |
common/DEBUGflag/DEBUG,ALARMs |
include '../common/common_readraw.f' |
461 |
c data ALARMs/.false./ |
include '../common/level0.f' |
462 |
|
|
463 |
|
c$$$ parameter (MAXBUFFLEN=z'172c8') |
464 |
|
c$$$ integer*4 length_buffer |
465 |
|
c$$$ integer*1 buffer(MAXBUFFLEN) |
466 |
|
c$$$ integer curpos !current position in buffer |
467 |
|
c$$$ integer startcrc |
468 |
|
c$$$ integer stopcrc |
469 |
|
integer*1 crctemp |
470 |
|
integer*1 crcdat |
471 |
|
|
472 |
|
integer runerror !readevent error flag |
473 |
|
c integer l_tra |
474 |
|
|
475 |
ALARMs = .false. |
integer bid1_dat,bid2_dat,bid3_dat,bid4_dat,bid5_dat,bid6_dat |
476 |
|
$ ,bid7_dat,bid_dat_sum |
477 |
|
|
478 |
|
|
479 |
12 format(z4) |
12 format(z4) |
480 |
|
|
485 |
DAQmode_dat = ishft(iand(header(1),z'03f0'),-4) |
DAQmode_dat = ishft(iand(header(1),z'03f0'),-4) |
486 |
DSPnumber_dat = iand(header(1),z'000f') |
DSPnumber_dat = iand(header(1),z'000f') |
487 |
C ------------------------------------------------------ |
C ------------------------------------------------------ |
488 |
c words 2 and 3 give tshe number of transmitted 16-bit |
c words 2 and 3 give the number of transmitted 16-bit |
489 |
c words ( 13 header words + data ) |
c words ( 13 header words + data ) |
490 |
c NB: data are packed from 13-bit to 16-bit words, |
c NB: data are packed from 13-bit to 16-bit words, |
491 |
c so the stream is complited with zeros in order to have |
c so the stream is complited with zeros in order to have |
508 |
signcluster_dat(3) = iand(header(12),z'03ff') |
signcluster_dat(3) = iand(header(12),z'03ff') |
509 |
fc_dat = ishft(iand(header(13),z'0300'),-8) |
fc_dat = ishft(iand(header(13),z'0300'),-8) |
510 |
compressiontime_dat = iand(header(13),z'00ff') |
compressiontime_dat = iand(header(13),z'00ff') |
511 |
fl5_dat = ishft(iand(header(14),z'0300'),-8) |
c fl5_dat = ishft(iand(header(14),z'0300'),-8) |
512 |
fl4_dat = ishft(iand(header(14),z'0300'),-6) |
c fl4_dat = ishft(iand(header(14),z'0300'),-6) |
513 |
fl3_dat = ishft(iand(header(14),z'0300'),-4) |
c fl3_dat = ishft(iand(header(14),z'0300'),-4) |
514 |
fl2_dat = ishft(iand(header(14),z'0300'),-2) |
c fl2_dat = ishft(iand(header(14),z'0300'),-2) |
515 |
fl1_dat = iand(header(14),z'0300') |
c fl1_dat = iand(header(14),z'0300') |
516 |
fl6_dat = ishft(iand(header(15),z'0300'),-8) |
c fl6_dat = ishft(iand(header(15),z'0300'),-8) |
517 |
|
fl5_dat = iand(ishft(header(14),-8),z'0003') |
518 |
|
fl4_dat = iand(ishft(header(14),-6),z'0003') |
519 |
|
fl3_dat = iand(ishft(header(14),-4),z'0003') |
520 |
|
fl2_dat = iand(ishft(header(14),-2),z'0003') |
521 |
|
fl1_dat = iand(header(14),z'0003') |
522 |
|
fl6_dat = iand(ishft(header(15),-8),z'0003') |
523 |
checksum_dat = iand(header(15),z'00ff') |
checksum_dat = iand(header(15),z'00ff') |
524 |
|
|
|
if( |
|
|
$ fc_dat.ne.0.or. |
|
|
$ fl1_dat.ne.0.or. |
|
|
$ fl2_dat.ne.0.or. |
|
|
$ fl3_dat.ne.0.or. |
|
|
$ fl4_dat.ne.0.or. |
|
|
$ fl5_dat.ne.0.or. |
|
|
$ fl6_dat.ne.0.or. |
|
|
$ .false.)ALARMs=.true. |
|
525 |
c----------------------------------------------------------- |
c----------------------------------------------------------- |
526 |
c the cheacksum is a 8-bit word calculated as the |
c the cheacksum is a 8-bit word calculated as the |
527 |
c XOR of the 16-bit data words, |
c XOR of the 16-bit data words, |
530 |
runerror=0 |
runerror=0 |
531 |
nqualcosa=0 |
nqualcosa=0 |
532 |
if(l_tra.eq.0)then |
if(l_tra.eq.0)then |
|
ALARMs=.true. |
|
533 |
goto 18 !empty buffer |
goto 18 !empty buffer |
534 |
endif |
endif |
535 |
call dunpacker(l_tra,b_tra,runerror,ffd) |
|
536 |
if(runerror.eq.1.or.runerror.eq.-1) then |
if(l_tra.gt.MAXBTRALEN)then |
537 |
|
print*,'unpackdata: ' |
538 |
|
$ ,'tracker buffer length l_tra exceeds buffer dimension ' |
539 |
|
$ ,l_tra,MAXBTRALEN |
540 |
|
runerror=1 |
541 |
|
goto 50 |
542 |
|
endif |
543 |
|
call dunpacker(l_tra,b_tra,runerror,buffer,length_buffer,curpos) |
544 |
|
if(runerror.eq.1.or.runerror.eq.-1) then |
545 |
goto 50 !go to end |
goto 50 !go to end |
546 |
endif |
endif |
547 |
|
|
550 |
if (xx.eq.0) nqualcosa=nqualcosa -1 |
if (xx.eq.0) nqualcosa=nqualcosa -1 |
551 |
|
|
552 |
18 datalength_dat= nqualcosa |
18 datalength_dat= nqualcosa |
|
|
|
553 |
11 format(i1,' ',z4) |
11 format(i1,' ',z4) |
554 |
call readtrailer(trailer,runerror,ffd) |
|
555 |
|
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
556 |
|
$ startcrc,stopcrc,crctemp) |
557 |
|
|
558 |
*************************************************************** |
*************************************************************** |
559 |
* TRAILER * |
* TRAILER * |
571 |
alarm_dat=ishft(iand(trailer(2),z'0300'),-8) |
alarm_dat=ishft(iand(trailer(2),z'0300'),-8) |
572 |
aswr_dat=ior(ishft(iand(trailer(2),z'00ff'),8) |
aswr_dat=ior(ishft(iand(trailer(2),z'00ff'),8) |
573 |
$ ,ishft(iand(trailer(3),z'ff00'),-8)) |
$ ,ishft(iand(trailer(3),z'ff00'),-8)) |
574 |
crc_dat=iand(trailer(3),z'00ff') |
crcdat=iand(trailer(3),z'00ff') |
575 |
|
|
576 |
bid_dat_sum = (bid1_dat + bid2_dat + bid3_dat + bid4_dat + |
c$$$ print*,'######################',crcdat,crctemp |
|
& bid5_dat + bid6_dat + bid7_dat) |
|
577 |
|
|
|
bid_dat = bid_dat_sum/7 |
|
578 |
|
|
579 |
if ((bid_dat.ne.1.and.bid_dat.ne.2).or. |
if(crcdat.eq.crctemp)then |
580 |
$ (mod(bid_dat_sum,7).ne.0).or. |
crc_dat=0 |
581 |
$ .false.) then |
else |
582 |
write(*,*) '*** *** *** *** *** *** *** *** *** *** *** ***' |
crc_dat=1 |
|
write(*,*) 'unpack_data: TRAILER PACKET CORRUPTED - BID ' |
|
|
$ ,bid_dat |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** *** *** ***' |
|
|
ALARMs=.true. |
|
583 |
endif |
endif |
584 |
|
|
585 |
|
bid_dat_sum = (bid1_dat + bid2_dat + bid3_dat + bid4_dat + |
586 |
if (alarm_dat.eq.3) then |
& bid5_dat + bid6_dat + bid7_dat) |
|
write(*,*) '*** *** *** *** *** *** *** *** *** *** ***' |
|
|
write(*,*) 'unpack_data: TRAILER --- AQUISITION ALARM!!!' |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** *** ***' |
|
|
write(*,*) alarm_dat |
|
|
ALARMs=.true. |
|
|
|
|
|
endif |
|
|
|
|
|
if (alarm_dat.ne.3.and.alarm_dat.ne.0) then |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** *** *** *** **' |
|
|
write(*,*) 'unpack_data: TRAILER PACKET CORRUPTED - ALARM ' |
|
|
$ ,alarm_dat |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** *** *** *** **' |
|
|
ALARMs=.true. |
|
|
endif |
|
587 |
|
|
588 |
|
bid_dat = bid_dat_sum/7 |
589 |
|
|
590 |
50 return |
50 return |
591 |
end |
end |
592 |
|
|
593 |
|
* ********************************************************** |
594 |
|
* * * |
595 |
|
* * * |
596 |
|
* * * |
597 |
|
* * * |
598 |
|
* * * |
599 |
|
* ********************************************************** |
600 |
|
|
|
*............................................................................. |
|
601 |
subroutine initlevel0 |
subroutine initlevel0 |
|
|
|
|
include '../commonyoda/commontracker.f' |
|
|
include '../commonyoda/level0.f' |
|
602 |
|
|
603 |
|
include '../common/commontracker.f' |
604 |
|
include '../common/level0.f' |
605 |
|
|
606 |
|
good0=0 |
607 |
|
TOTDATAlength = 0 |
608 |
|
|
609 |
do i=1, nviews |
do i=1, nviews |
610 |
|
|
635 |
bid(i) = 1 |
bid(i) = 1 |
636 |
alarm(i)= 0 |
alarm(i)= 0 |
637 |
aswr(i) = 0 |
aswr(i) = 0 |
638 |
|
crc(i)=0 |
639 |
|
|
640 |
enddo |
enddo |
641 |
|
|
|
TOTDATAlength = 0 |
|
|
good0=.true. |
|
642 |
|
|
643 |
return |
return |
644 |
end |
end |
645 |
|
|
646 |
|
* ********************************************************** |
647 |
|
* * * |
648 |
|
* * * |
649 |
|
* * * |
650 |
|
* * * |
651 |
|
* * * |
652 |
|
* ********************************************************** |
653 |
|
|
|
* *** *** *** *** *** *** *** *** *** |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* *** *** *** *** *** *** *** *** *** |
|
654 |
subroutine fillview(i) |
subroutine fillview(i) |
655 |
c ----------------------------------------------------- |
c ----------------------------------------------------- |
656 |
c fill variables related to view i |
c fill variables related to view i |
658 |
c at the end of loop on views |
c at the end of loop on views |
659 |
c ---------------------------------------------------- |
c ---------------------------------------------------- |
660 |
|
|
661 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
662 |
include '../commonyoda/level0.f' |
include '../common/level0.f' |
663 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
664 |
|
|
665 |
|
|
666 |
DAQmode(i) = DAQmode_dat |
DAQmode(i) = DAQmode_dat |
667 |
DSPnumber(i) = DSPnumber_dat |
DSPnumber(i) = DSPnumber_dat |
685 |
fl6(i) = fl6_dat |
fl6(i) = fl6_dat |
686 |
checksum(i) = checksum_dat |
checksum(i) = checksum_dat |
687 |
DATAlength(i) = datalength_dat |
DATAlength(i) = datalength_dat |
688 |
|
crc(i) = crc_dat |
689 |
|
|
690 |
c ----------------------------------------------------------------------- |
c ----------------------------------------------------------------------- |
691 |
c filling TRAILER variables |
c filling TRAILER variables |
706 |
return |
return |
707 |
end |
end |
708 |
|
|
709 |
|
* ********************************************************** |
710 |
|
* * * |
711 |
|
* * * |
712 |
|
* * * |
713 |
|
* * * |
714 |
|
* * * |
715 |
|
* ********************************************************** |
716 |
|
|
717 |
|
subroutine fillview_cal(i) |
718 |
|
c ----------------------------------------------------- |
719 |
|
c fill variables related to view i |
720 |
|
c which will be stored in the calibration nt-ple |
721 |
|
c at the end of loop on views |
722 |
|
c ---------------------------------------------------- |
723 |
|
|
724 |
|
include '../common/commontracker.f' |
725 |
|
include '../common/trk_calib_parameters.f' |
726 |
|
include '../common/common_readraw.f' |
727 |
|
|
728 |
|
DAQmode(i) = DAQmode_cal |
729 |
|
DSPnumber(i) = DSPnumber_cal |
730 |
|
calibnumber(i) = calibrationnumber |
731 |
|
ncalib_event(i)= nused_event |
732 |
|
ped_l1(i) = ped_1 |
733 |
|
ped_l2(i) = ped_2 |
734 |
|
ped_l3(i) = ped_3 |
735 |
|
sig_l1(i) = sig_1 |
736 |
|
sig_l2(i) = sig_2 |
737 |
|
sig_l3(i) = sig_3 |
738 |
|
nbad_l1(i) = nbad_1 |
739 |
|
nbad_l2(i) = nbad_2 |
740 |
|
nbad_l3(i) = nbad_3 |
741 |
|
cal_flag(i) = ff |
742 |
|
|
743 |
|
do is=1,nstrips_view |
744 |
|
DSPbad_par(i,is) = DSPbad_o(DSPnumber_cal,is) |
745 |
|
DSPped_par(i,is) = DSPped_o(DSPnumber_cal,is) |
746 |
|
DSPsig_par(i,is) = DSPsig_o(DSPnumber_cal,is) |
747 |
|
enddo |
748 |
|
|
749 |
|
crc_hcal(i) = crc_hcalib |
750 |
|
crc_cal(i,1) = crc_calib(1) |
751 |
|
crc_cal(i,2) = crc_calib(2) |
752 |
|
crc_cal(i,3) = crc_calib(3) |
753 |
|
|
754 |
|
return |
755 |
|
end |
756 |
|
|
757 |
|
* ********************************************************** |
758 |
|
* * * |
759 |
|
* * * |
760 |
|
* * * |
761 |
|
* * * |
762 |
|
* * * |
763 |
|
* ********************************************************** |
764 |
|
|
765 |
|
subroutine initcalib |
766 |
|
include '../common/commontracker.f' |
767 |
|
include '../common/trk_calib_parameters.f' |
768 |
|
|
769 |
|
good0=0 |
770 |
|
|
771 |
|
do i=1,nplanes |
772 |
|
|
773 |
|
DAQmode(i) = 0 |
774 |
|
DSPnumber(i) = 0 |
775 |
|
calibnumber(i) = 0 |
776 |
|
ncalib_event(i)= 0 |
777 |
|
ped_l1(i) = 0 |
778 |
|
ped_l2(i) = 0 |
779 |
|
ped_l3(i) = 0 |
780 |
|
sig_l1(i) = 0 |
781 |
|
sig_l2(i) = 0 |
782 |
|
sig_l3(i) = 0 |
783 |
|
nbad_l1(i) = 0 |
784 |
|
nbad_l2(i) = 0 |
785 |
|
nbad_l3(i) = 0 |
786 |
|
cal_flag(i) = 0 |
787 |
|
|
788 |
|
do is=1,nstrips_view |
789 |
|
DSPbad_par(i,is) = 0 |
790 |
|
DSPped_par(i,is) = 0 |
791 |
|
DSPsig_par(i,is) = 0 |
792 |
|
enddo |
793 |
|
crc_hcal(i) = 0 |
794 |
|
crc_cal(i,1) = 0 |
795 |
|
crc_cal(i,2) = 0 |
796 |
|
crc_cal(i,3) = 0 |
797 |
|
enddo |
798 |
|
|
799 |
|
return |
800 |
|
end |