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 |
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 |
|
parameter (MAXBUFFLEN=z'172c8') |
32 |
|
integer*4 length_buffer |
33 |
|
integer*1 buffer(MAXBUFFLEN) |
34 |
|
integer curpos !current position in buffer |
35 |
|
integer startcrc |
36 |
|
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 |
|
do iview=1,nviews !loop on DSPs |
51 |
|
call searchtrkheader(runerror,buffer,length_buffer,curpos, |
52 |
|
$ startcrc) |
53 |
if(runerror.eq.1.or.runerror.eq.-1) then |
if(runerror.eq.1.or.runerror.eq.-1) then |
54 |
* -------------------------------------------------- |
* -------------------------------------------------- |
55 |
* no further DSP packet has been found ==> go to end |
* no DSP packet has been found ==> go to end |
56 |
* -------------------------------------------------- |
* -------------------------------------------------- |
57 |
goto 2222 !go to end |
goto 2222 !go to end |
58 |
endif |
endif |
59 |
|
|
60 |
if(checkheader.ne.2) then |
if(checkheader.ne.2) then |
61 |
print*,'>>>> ERROR <<<< (trkeventpkt)' |
print*,'>>>> ERROR <<<< (trkeventpkt)' |
62 |
print*,'>>>> CPU packet type ',!pkt_type, |
print*,'>>>> CPU packet type ',!pkt_type, |
71 |
goto 2525 !next view (==> search another DSP header) |
goto 2525 !next view (==> search another DSP header) |
72 |
endif |
endif |
73 |
|
|
74 |
call unpackdata(runerror,ffd_pkt) |
call unpackdata(runerror,buffer,length_buffer,curpos, |
75 |
|
$ startcrc,stopcrc,crctemp) |
76 |
if(runerror.eq.-1.or.runerror.eq.1)then |
if(runerror.eq.-1.or.runerror.eq.1)then |
77 |
* ----------------------------------------------- |
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 |
|
78 |
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*,'*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*' |
|
79 |
|
|
80 |
DEBUG = .true. |
npkt = npkt + 1 |
|
endif |
|
|
|
|
|
trk_DSP_ok(DSPnumber_dat)=1 |
|
|
|
|
81 |
call fillview(iview) |
call fillview(iview) |
82 |
|
*-------- CRC check |
83 |
|
if(crc(iview).eq.0) then !OK |
84 |
|
*----------- ALARMS |
85 |
|
if( |
86 |
|
$ fl1(iview).ne.0.or. |
87 |
|
$ fl2(iview).ne.0.or. |
88 |
|
$ fl3(iview).ne.0.or. |
89 |
|
$ fl4(iview).ne.0.or. |
90 |
|
$ fl5(iview).ne.0.or. |
91 |
|
$ fl6(iview).ne.0.or. |
92 |
|
$ fc(iview).ne.0.or. |
93 |
|
$ DATAlength(iview).eq.0.or. |
94 |
|
$ .false.)ALARMS=.true. |
95 |
|
endif |
96 |
|
|
97 |
2525 continue |
2525 continue |
98 |
enddo !end loop on views |
enddo !end loop on views |
99 |
|
|
100 |
2222 continue |
2222 continue |
101 |
|
|
102 |
close (lun_pkt) |
if(npkt.eq.nviews)YODAflag=0 |
103 |
|
if(YODAflag.eq.0.and.(ALARMS.eqv..false.))good0=1 |
104 |
|
|
105 |
return |
return |
106 |
end |
end |
107 |
|
|
108 |
* ********************************************** |
* ********************************************************** |
109 |
|
* * * |
110 |
|
* * * |
111 |
|
* * * |
112 |
|
* * * |
113 |
|
* * * |
114 |
|
* ********************************************************** |
115 |
|
|
116 |
subroutine trkcalibpkt(runerror,event_file_name) |
subroutine trkcalibpkt(YODAflag,buffer,length_buffer,curpos |
117 |
|
$ ) |
118 |
|
|
119 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
120 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
121 |
include '../commonyoda/trk_calib_parameters.f' |
include '../common/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 |
|
|
|
|
|
logical DEBUG,ALARMs |
|
|
data DEBUG/.false./ |
|
|
|
|
|
ccc data DEBUG/.true./ |
|
|
ccc common/DEBUGflag/DEBUG |
|
122 |
|
|
123 |
|
* --------------------------------------------------- |
124 |
|
* the general flag YODAflag contains information |
125 |
|
* about the integrity of the DSP packets. |
126 |
|
* |
127 |
|
* If some packets are missing or the crc check fails, |
128 |
|
* YODAflag is asserted |
129 |
|
* --------------------------------------------------- |
130 |
|
|
131 |
|
integer YODAflag |
132 |
|
|
133 |
integer lun_pkt |
logical ALARMs |
|
data lun_pkt/10/ |
|
134 |
|
|
135 |
|
integer runerror !readevent error flag |
136 |
|
parameter (MAXBUFFLEN=z'172c8') |
137 |
|
integer*4 length_buffer |
138 |
|
integer*1 buffer(MAXBUFFLEN) |
139 |
|
integer curpos !current position in buffer |
140 |
|
integer startcrc |
141 |
|
integer stopcrc |
142 |
|
integer*1 crctemp |
143 |
|
|
144 |
|
* ------------------- |
145 |
|
* initializations |
146 |
|
YODAflag = 1 !bad by default |
147 |
|
call initcalib |
148 |
|
ALARMS=.false. |
149 |
|
npkt=0 !#good DSP packets |
150 |
|
startcrc=0 |
151 |
|
stopcrc=0 |
152 |
|
crctemp=0 |
153 |
|
* ------------------- |
154 |
|
|
155 |
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 |
|
|
|
|
156 |
|
|
157 |
|
call searchtrkheader(runerror,buffer,length_buffer,curpos, |
158 |
do iview=1,ndummy !loop on views (DSP pkt) |
$ startcrc) |
159 |
|
|
160 |
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*,'______________________________________ ' |
|
161 |
goto 2222 !end loop on views (DSP pkt) |
goto 2222 !end loop on views (DSP pkt) |
162 |
endif |
endif |
163 |
|
|
164 |
if(checkheader.ne.3) then |
if(checkheader.ne.3) then |
165 |
print*,'>>>> ERROR <<<< (trkcalibpkt)' |
print*,'>>>> ERROR <<<< (trkcalibpkt)' |
166 |
print*,'>>>> CPU packet type ',!pkt_type, |
print*,'>>>> CPU packet type ',!pkt_type, |
175 |
goto 2424 !next view (==> search another DSP header) |
goto 2424 !next view (==> search another DSP header) |
176 |
endif |
endif |
177 |
|
|
178 |
call unpackcalibration(runerror,ffd_pkt) |
call unpackcalibration(runerror,buffer,length_buffer,curpos, |
179 |
c if(runerror.eq.-1) goto 24 |
$ startcrc,stopcrc,crctemp) |
180 |
if(runerror.eq.-1) goto 2222 |
if(runerror.eq.-1.or.runerror.eq.1)then |
181 |
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 |
|
182 |
endif |
endif |
183 |
|
|
184 |
|
|
185 |
DAQmode(iview)=DAQmode_cal |
npkt = npkt + 1 |
186 |
DSPnumber(iview)=DSPnumber_cal |
call fillview_cal(iview) ! |
187 |
calibnumber(iview)=calibrationnumber |
*--------CRC check |
188 |
ncalib_event(iview)=nused_event |
if( crc_hcal(iview).eq.0.and. |
189 |
ped_l1(iview)=ped_1 |
$ crc_cal(iview,1).eq.0.and. |
190 |
ped_l2(iview)=ped_2 |
$ crc_cal(iview,2).eq.0.and. |
191 |
ped_l3(iview)=ped_3 |
$ crc_cal(iview,3).eq.0.and. |
192 |
sig_l1(iview)=sig_1 |
$ .true.)then |
193 |
sig_l2(iview)=sig_2 |
*----------- ALARMS |
194 |
sig_l3(iview)=sig_3 |
if( ncalib_event(iview).ne.0.or. |
195 |
nbad_l1(iview)=nbad_1 |
$ cal_flag(iview).ne.0.or. |
196 |
nbad_l2(iview)=nbad_2 |
$ .false.)ALARMS=.true. |
197 |
nbad_l3(iview)=nbad_3 |
endif |
|
cal_flag(iview)=ff |
|
198 |
|
|
|
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 |
|
199 |
2424 continue |
2424 continue |
200 |
enddo ! end loop on views (calibration pkt) |
enddo ! end loop on views (calibration pkt) |
|
2222 continue |
|
201 |
|
|
202 |
close (lun_pkt) |
if(npkt.eq.nplanes)YODAflag=0 |
203 |
|
if(YODAflag.eq.0.and.(ALARMS.eqv..false.))good0=1 |
204 |
|
|
205 |
|
2222 continue |
206 |
|
|
207 |
return |
return |
208 |
end |
end |
209 |
|
|
210 |
***...***...***...***...***...***...***...***...***...***...***...***...***...***...***...*** |
* ********************************************************** |
211 |
* |
* * * |
212 |
* |
* * * |
213 |
* |
* * * |
214 |
* |
* * * |
215 |
* |
* * * |
216 |
* |
* ********************************************************** |
|
* |
|
|
* |
|
|
***...***...***...***...***...***...***...***...***...***...***...***...***...***...***...*** |
|
217 |
|
|
218 |
subroutine searchtrkheader(runerror,ffd) |
subroutine searchtrkheader(runerror,buffer,length_buffer, |
219 |
|
$ curpos,startcrc) |
220 |
C............................................................. |
C............................................................. |
221 |
C Search for a valid tracker DSP header (=>one view) |
C Search for a valid tracker DSP header (=>one view) |
222 |
C and return the type of header |
C and return the type of header |
223 |
C............................................................. |
C............................................................. |
224 |
|
|
225 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
226 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
227 |
|
|
228 |
|
parameter (MAXBUFFLEN=z'172c8') |
229 |
|
integer*4 length_buffer |
230 |
|
integer*1 buffer(MAXBUFFLEN) |
231 |
|
integer curpos !current position in buffer |
232 |
|
integer startcrc |
233 |
|
|
|
integer ffd !input file descriptor |
|
234 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
235 |
|
|
236 |
c-------------------------------------------------- |
c-------------------------------------------------- |
238 |
C so each DSP 13 bit |
C so each DSP 13 bit |
239 |
c first word starts at the beginnig of a 16 bit word |
c first word starts at the beginnig of a 16 bit word |
240 |
c-------------------------------------------------- |
c-------------------------------------------------- |
241 |
|
|
242 |
9100 continue |
9100 continue |
243 |
runerror=0 !error flag initialization |
runerror=0 !error flag initialization |
244 |
checkheader=0 |
checkheader=0 |
247 |
c looks for a DSP header beginning |
c looks for a DSP header beginning |
248 |
C (a word beginning with 1110) |
C (a word beginning with 1110) |
249 |
c-------------------------------------------------- |
c-------------------------------------------------- |
|
call findstart(runerror,ffd) |
|
250 |
|
|
251 |
|
call findstart(runerror,buffer,length_buffer,curpos) |
252 |
|
|
253 |
if(runerror.eq.1) goto 200 !end |
if(runerror.eq.1) goto 200 !end |
254 |
if(runerror.eq.-1)goto 200 !end |
if(runerror.eq.-1)goto 200 !end |
255 |
c-------------------------------------------------- |
c-------------------------------------------------- |
258 |
c writes them in 16 13-bit words to check for all |
c writes them in 16 13-bit words to check for all |
259 |
C DSP header features |
C DSP header features |
260 |
c-------------------------------------------------- |
c-------------------------------------------------- |
261 |
|
|
262 |
call hunpacker(header,runerror,ffd) |
call hunpacker(header,runerror,buffer,length_buffer,curpos, |
263 |
|
$ startcrc) |
264 |
|
|
265 |
if(runerror.eq.1) goto 200 !end |
if(runerror.eq.1) goto 200 !end |
266 |
if(runerror.eq.-1)goto 200 !end |
if(runerror.eq.-1)goto 200 !end |
267 |
c-------------------------------------------------- |
c-------------------------------------------------- |
298 |
c noise lurks around) so go a word ahead and |
c noise lurks around) so go a word ahead and |
299 |
c try again |
c try again |
300 |
c-------------------------------------------------- |
c-------------------------------------------------- |
301 |
if(checkheader.eq.1) then |
if(checkheader.eq.1) then |
302 |
call skipbyte(ffd) !new search |
curpos=curpos-(13*2)+1 !goes back 13 words, then half 16 bit word ahead |
303 |
goto 9100 |
goto 9100 |
304 |
endif |
endif |
305 |
|
|
306 |
200 continue |
200 continue |
307 |
end |
end |
308 |
|
|
309 |
*............................................................. |
* ********************************************************** |
310 |
|
* * * |
311 |
|
* * * |
312 |
|
* * * |
313 |
|
* * * |
314 |
|
* * * |
315 |
|
* ********************************************************** |
316 |
|
|
317 |
|
subroutine unpackcalibration(runerror,buffer,length_buffer,curpos, |
318 |
|
$ startcrc,stopcrc,crctemp) |
319 |
|
|
|
*............................................................. |
|
|
|
|
|
subroutine unpackcalibration(runerror,ffd) |
|
320 |
*............................................................. |
*............................................................. |
321 |
* decode calibration data |
* decode calibration data |
322 |
* header + data(PED SIG BAD) + trailer |
* header + data(PED SIG BAD) + trailer |
323 |
*............................................................ |
*............................................................ |
324 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
325 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
326 |
|
|
327 |
integer ffd !input file descriptor |
parameter (MAXBUFFLEN=z'172c8') |
328 |
|
integer*4 length_buffer |
329 |
|
integer*1 buffer(MAXBUFFLEN) |
330 |
|
integer curpos !current position in buffer |
331 |
|
integer startcrc |
332 |
|
integer stopcrc |
333 |
|
integer*1 crctemp |
334 |
|
integer*1 crc_trail |
335 |
|
|
336 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
|
c buffer temporanei |
|
337 |
integer*2 templ(nstrips_ladder) |
integer*2 templ(nstrips_ladder) |
338 |
real*4 tempf(nstrips_ladder) |
real*4 tempf(nstrips_ladder) |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
12 format(z4) |
12 format(z4) |
343 |
|
|
344 |
*----------------------------------------------------------- |
*----------------------------------------------------------- |
352 |
DSPnumber_cal = iand(header(1),z'000f') |
DSPnumber_cal = iand(header(1),z'000f') |
353 |
dataword = ior(ishft(iand(header(2),z'03ff') |
dataword = ior(ishft(iand(header(2),z'03ff') |
354 |
$ ,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')) |
|
355 |
calibrationnumber = iand(header(4),z'03ff') |
calibrationnumber = iand(header(4),z'03ff') |
356 |
nused_event = iand(header(5),z'03ff') |
nused_event = iand(header(5),z'03ff') |
357 |
ped_1 = iand(header(6),z'03ff') |
ped_1 = iand(header(6),z'03ff') |
368 |
nbad_3 = iand(header(14),z'03ff') |
nbad_3 = iand(header(14),z'03ff') |
369 |
ff = ishft(iand(header(15),z'0300'),-8) |
ff = ishft(iand(header(15),z'0300'),-8) |
370 |
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 |
|
371 |
c----------------------------------------------------------- |
c----------------------------------------------------------- |
372 |
c the checksum is a 8-bit word calculated as the |
c the checksum is a 8-bit word calculated as the |
373 |
c XOR of the 16-bit data words, |
c XOR of the 16-bit data words, |
374 |
c hence the XOR between the two halfs |
c hence the XOR between the two halfs |
375 |
C---------------------------------------------------------- |
C---------------------------------------------------------- |
|
do il=1,3 !loop on ladders |
|
376 |
|
|
377 |
call readped(tempf,runerror,ffd) |
runerror=0 |
378 |
|
c$$$ |
379 |
|
c$$$ print*,'-----------------------------------' |
380 |
|
c$$$ print*,'unpackcalibration: readtrailer --- ', |
381 |
|
c$$$* $ trailer,runerror,buffer,length_buffer,curpos, |
382 |
|
c$$$ $ startcrc,stopcrc,crctemp |
383 |
|
c$$$ print*,'-----------------------------------' |
384 |
|
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
385 |
|
$ startcrc,stopcrc,crctemp) |
386 |
|
|
387 |
|
crc_trail=iand(trailer(3),z'00ff') |
388 |
|
|
389 |
|
c$$$ print *,'@@@@@@@@@@@@@ ',crctemp,crc_trail |
390 |
|
|
391 |
|
if (crctemp.eq.crc_trail)then |
392 |
|
crc_hcalib=0 |
393 |
|
else |
394 |
|
crc_hcalib=1 |
395 |
|
endif |
396 |
|
|
397 |
|
do il=1,3 !loop on ladders |
398 |
|
startcrc=curpos |
399 |
|
call readped(tempf,runerror,buffer,length_buffer,curpos) |
400 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
401 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
402 |
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) |
|
|
|
|
403 |
enddo |
enddo |
404 |
|
|
405 |
call readsig(tempf,runerror,ffd) |
call readsig(tempf,runerror,buffer,length_buffer,curpos) |
406 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
407 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
408 |
DSPsig_o(DSPnumber_cal,iss)=tempf(is) |
DSPsig_o(DSPnumber_cal,iss)=tempf(is) |
|
c print*,DSPsig_o(DSPnumber,iss) |
|
409 |
enddo |
enddo |
410 |
|
|
411 |
call readbad(templ,runerror,ffd) |
call readbad(templ,runerror,buffer,length_buffer,curpos) |
412 |
do is=1,nstrips_ladder |
do is=1,nstrips_ladder |
413 |
iss=is+nstrips_ladder*(il-1) |
iss=is+nstrips_ladder*(il-1) |
414 |
DSPbad_o(DSPnumber_cal,iss)=templ(is) |
DSPbad_o(DSPnumber_cal,iss)=templ(is) |
|
c print*,il,is,iss,DSPbad_o(DSPnumber,iss) |
|
415 |
enddo |
enddo |
416 |
|
|
|
C//// CAPIRE PERCHE` NON C'E` LA PAROLA DI FINE LADDER \\\\ |
|
|
c call readeol(word,runerror,ffd) |
|
417 |
11 format(i1,' ',z4) |
11 format(i1,' ',z4) |
418 |
c write(*,11)il,word |
|
419 |
call readtrailer(trailer,runerror,ffd) |
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
420 |
c$$$ do i=1,3 |
$ startcrc,stopcrc,crctemp) |
|
c$$$ write(*,12)trailer(i) |
|
|
c$$$ enddo |
|
421 |
|
|
422 |
c print*,'fine ladder' !??? |
crc_trail=iand(trailer(3),z'00ff') |
423 |
|
|
424 |
|
if (crctemp.eq.crc_trail)then |
425 |
|
crc_calib(il)=0 |
426 |
|
else |
427 |
|
crc_calib(il)=1 |
428 |
|
endif |
429 |
|
|
430 |
enddo !end loop on ladders |
enddo !end loop on ladders |
431 |
|
|
432 |
return |
return |
433 |
end |
end |
|
*............................................................. |
|
434 |
|
|
435 |
|
* ********************************************************** |
436 |
|
* * * |
437 |
|
* * * |
438 |
|
* * * |
439 |
|
* * * |
440 |
|
* * * |
441 |
|
* ********************************************************** |
442 |
|
|
443 |
|
subroutine unpackdata(runerror,buffer,length_buffer,curpos, |
444 |
|
$ startcrc,stopcrc,crctemp) |
445 |
|
|
|
subroutine unpackdata(runerror,ffd) |
|
446 |
*............................................................. |
*............................................................. |
447 |
* decode event data |
* decode event data |
448 |
* header + data + trailer |
* header + data + trailer |
449 |
*............................................................ |
*............................................................ |
|
include '../commonyoda/commontracker.f' |
|
|
include '../commonyoda/dataformat.f' |
|
|
include '../commonyoda/level0.f' |
|
450 |
|
|
451 |
integer ffd !input file descriptor |
include '../common/commontracker.f' |
452 |
|
include '../common/common_readraw.f' |
453 |
|
include '../common/level0.f' |
454 |
|
|
455 |
|
parameter (MAXBUFFLEN=z'172c8') |
456 |
|
integer*4 length_buffer |
457 |
|
integer*1 buffer(MAXBUFFLEN) |
458 |
|
integer curpos !current position in buffer |
459 |
|
integer startcrc |
460 |
|
integer stopcrc |
461 |
|
integer*1 crctemp |
462 |
|
integer*1 crcdat |
463 |
|
|
464 |
integer runerror !readevent error flag |
integer runerror !readevent error flag |
465 |
integer l_tra |
integer l_tra |
466 |
|
|
467 |
logical DEBUG,ALARMs |
integer bid1_dat,bid2_dat,bid3_dat,bid4_dat,bid5_dat,bid6_dat |
468 |
common/DEBUGflag/DEBUG,ALARMs |
$ ,bid7_dat,bid_dat_sum |
469 |
c data ALARMs/.false./ |
|
|
|
|
|
|
|
|
ALARMs = .false. |
|
470 |
|
|
471 |
12 format(z4) |
12 format(z4) |
472 |
|
|
477 |
DAQmode_dat = ishft(iand(header(1),z'03f0'),-4) |
DAQmode_dat = ishft(iand(header(1),z'03f0'),-4) |
478 |
DSPnumber_dat = iand(header(1),z'000f') |
DSPnumber_dat = iand(header(1),z'000f') |
479 |
C ------------------------------------------------------ |
C ------------------------------------------------------ |
480 |
c words 2 and 3 give tshe number of transmitted 16-bit |
c words 2 and 3 give the number of transmitted 16-bit |
481 |
c words ( 13 header words + data ) |
c words ( 13 header words + data ) |
482 |
c NB: data are packed from 13-bit to 16-bit words, |
c NB: data are packed from 13-bit to 16-bit words, |
483 |
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 |
fl6_dat = ishft(iand(header(15),z'0300'),-8) |
fl6_dat = ishft(iand(header(15),z'0300'),-8) |
509 |
checksum_dat = iand(header(15),z'00ff') |
checksum_dat = iand(header(15),z'00ff') |
510 |
|
|
|
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. |
|
511 |
c----------------------------------------------------------- |
c----------------------------------------------------------- |
512 |
c the cheacksum is a 8-bit word calculated as the |
c the cheacksum is a 8-bit word calculated as the |
513 |
c XOR of the 16-bit data words, |
c XOR of the 16-bit data words, |
516 |
runerror=0 |
runerror=0 |
517 |
nqualcosa=0 |
nqualcosa=0 |
518 |
if(l_tra.eq.0)then |
if(l_tra.eq.0)then |
|
ALARMs=.true. |
|
519 |
goto 18 !empty buffer |
goto 18 !empty buffer |
520 |
endif |
endif |
521 |
call dunpacker(l_tra,b_tra,runerror,ffd) |
|
522 |
|
call dunpacker(l_tra,b_tra,runerror,buffer,length_buffer,curpos) |
523 |
if(runerror.eq.1.or.runerror.eq.-1) then |
if(runerror.eq.1.or.runerror.eq.-1) then |
524 |
goto 50 !go to end |
goto 50 !go to end |
525 |
endif |
endif |
529 |
if (xx.eq.0) nqualcosa=nqualcosa -1 |
if (xx.eq.0) nqualcosa=nqualcosa -1 |
530 |
|
|
531 |
18 datalength_dat= nqualcosa |
18 datalength_dat= nqualcosa |
|
|
|
532 |
11 format(i1,' ',z4) |
11 format(i1,' ',z4) |
533 |
call readtrailer(trailer,runerror,ffd) |
|
534 |
|
call readtrailer(trailer,runerror,buffer,length_buffer,curpos, |
535 |
|
$ startcrc,stopcrc,crctemp) |
536 |
|
|
537 |
*************************************************************** |
*************************************************************** |
538 |
* TRAILER * |
* TRAILER * |
550 |
alarm_dat=ishft(iand(trailer(2),z'0300'),-8) |
alarm_dat=ishft(iand(trailer(2),z'0300'),-8) |
551 |
aswr_dat=ior(ishft(iand(trailer(2),z'00ff'),8) |
aswr_dat=ior(ishft(iand(trailer(2),z'00ff'),8) |
552 |
$ ,ishft(iand(trailer(3),z'ff00'),-8)) |
$ ,ishft(iand(trailer(3),z'ff00'),-8)) |
553 |
crc_dat=iand(trailer(3),z'00ff') |
crcdat=iand(trailer(3),z'00ff') |
554 |
|
|
555 |
bid_dat_sum = (bid1_dat + bid2_dat + bid3_dat + bid4_dat + |
c$$$ print*,'######################',crcdat,crctemp |
|
& bid5_dat + bid6_dat + bid7_dat) |
|
556 |
|
|
|
bid_dat = bid_dat_sum/7 |
|
557 |
|
|
558 |
if ((bid_dat.ne.1.and.bid_dat.ne.2).or. |
if(crcdat.eq.crctemp)then |
559 |
$ (mod(bid_dat_sum,7).ne.0).or. |
crc_dat=0 |
560 |
$ .false.) then |
else |
561 |
write(*,*) '*** *** *** *** *** *** *** *** *** *** *** ***' |
crc_dat=1 |
|
write(*,*) 'unpack_data: TRAILER PACKET CORRUPTED - BID ' |
|
|
$ ,bid_dat |
|
|
write(*,*) '*** *** *** *** *** *** *** *** *** *** *** ***' |
|
|
ALARMs=.true. |
|
562 |
endif |
endif |
563 |
|
|
564 |
|
bid_dat_sum = (bid1_dat + bid2_dat + bid3_dat + bid4_dat + |
565 |
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 |
|
566 |
|
|
567 |
|
bid_dat = bid_dat_sum/7 |
568 |
|
|
569 |
50 return |
50 return |
570 |
end |
end |
571 |
|
|
572 |
|
* ********************************************************** |
573 |
|
* * * |
574 |
|
* * * |
575 |
|
* * * |
576 |
|
* * * |
577 |
|
* * * |
578 |
|
* ********************************************************** |
579 |
|
|
|
*............................................................................. |
|
580 |
subroutine initlevel0 |
subroutine initlevel0 |
|
|
|
|
include '../commonyoda/commontracker.f' |
|
|
include '../commonyoda/level0.f' |
|
581 |
|
|
582 |
|
include '../common/commontracker.f' |
583 |
|
include '../common/level0.f' |
584 |
|
|
585 |
|
good0=0 |
586 |
|
TOTDATAlength = 0 |
587 |
|
|
588 |
do i=1, nviews |
do i=1, nviews |
589 |
|
|
614 |
bid(i) = 1 |
bid(i) = 1 |
615 |
alarm(i)= 0 |
alarm(i)= 0 |
616 |
aswr(i) = 0 |
aswr(i) = 0 |
617 |
|
crc(i)=0 |
618 |
|
|
619 |
enddo |
enddo |
620 |
|
|
|
TOTDATAlength = 0 |
|
|
good0=.true. |
|
621 |
|
|
622 |
return |
return |
623 |
end |
end |
624 |
|
|
625 |
|
* ********************************************************** |
626 |
|
* * * |
627 |
|
* * * |
628 |
|
* * * |
629 |
|
* * * |
630 |
|
* * * |
631 |
|
* ********************************************************** |
632 |
|
|
|
* *** *** *** *** *** *** *** *** *** |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* *** *** *** *** *** *** *** *** *** |
|
633 |
subroutine fillview(i) |
subroutine fillview(i) |
634 |
c ----------------------------------------------------- |
c ----------------------------------------------------- |
635 |
c fill variables related to view i |
c fill variables related to view i |
637 |
c at the end of loop on views |
c at the end of loop on views |
638 |
c ---------------------------------------------------- |
c ---------------------------------------------------- |
639 |
|
|
640 |
include '../commonyoda/commontracker.f' |
include '../common/commontracker.f' |
641 |
include '../commonyoda/level0.f' |
include '../common/level0.f' |
642 |
include '../commonyoda/dataformat.f' |
include '../common/common_readraw.f' |
643 |
|
|
644 |
|
|
645 |
DAQmode(i) = DAQmode_dat |
DAQmode(i) = DAQmode_dat |
646 |
DSPnumber(i) = DSPnumber_dat |
DSPnumber(i) = DSPnumber_dat |
664 |
fl6(i) = fl6_dat |
fl6(i) = fl6_dat |
665 |
checksum(i) = checksum_dat |
checksum(i) = checksum_dat |
666 |
DATAlength(i) = datalength_dat |
DATAlength(i) = datalength_dat |
667 |
|
crc(i) = crc_dat |
668 |
|
|
669 |
c ----------------------------------------------------------------------- |
c ----------------------------------------------------------------------- |
670 |
c filling TRAILER variables |
c filling TRAILER variables |
685 |
return |
return |
686 |
end |
end |
687 |
|
|
688 |
|
* ********************************************************** |
689 |
|
* * * |
690 |
|
* * * |
691 |
|
* * * |
692 |
|
* * * |
693 |
|
* * * |
694 |
|
* ********************************************************** |
695 |
|
|
696 |
|
subroutine fillview_cal(i) |
697 |
|
c ----------------------------------------------------- |
698 |
|
c fill variables related to view i |
699 |
|
c which will be stored in the calibration nt-ple |
700 |
|
c at the end of loop on views |
701 |
|
c ---------------------------------------------------- |
702 |
|
|
703 |
|
include '../common/commontracker.f' |
704 |
|
include '../common/trk_calib_parameters.f' |
705 |
|
include '../common/common_readraw.f' |
706 |
|
|
707 |
|
DAQmode(i) = DAQmode_cal |
708 |
|
DSPnumber(i) = DSPnumber_cal |
709 |
|
calibnumber(i) = calibrationnumber |
710 |
|
ncalib_event(i)= nused_event |
711 |
|
ped_l1(i) = ped_1 |
712 |
|
ped_l2(i) = ped_2 |
713 |
|
ped_l3(i) = ped_3 |
714 |
|
sig_l1(i) = sig_1 |
715 |
|
sig_l2(i) = sig_2 |
716 |
|
sig_l3(i) = sig_3 |
717 |
|
nbad_l1(i) = nbad_1 |
718 |
|
nbad_l2(i) = nbad_2 |
719 |
|
nbad_l3(i) = nbad_3 |
720 |
|
cal_flag(i) = ff |
721 |
|
|
722 |
|
do is=1,nstrips_view |
723 |
|
DSPbad_par(i,is) = DSPbad_o(DSPnumber_cal,is) |
724 |
|
DSPped_par(i,is) = DSPped_o(DSPnumber_cal,is) |
725 |
|
DSPsig_par(i,is) = DSPsig_o(DSPnumber_cal,is) |
726 |
|
enddo |
727 |
|
|
728 |
|
crc_hcal(i) = crc_hcalib |
729 |
|
crc_cal(i,1) = crc_calib(1) |
730 |
|
crc_cal(i,2) = crc_calib(2) |
731 |
|
crc_cal(i,3) = crc_calib(3) |
732 |
|
|
733 |
|
return |
734 |
|
end |
735 |
|
|
736 |
|
* ********************************************************** |
737 |
|
* * * |
738 |
|
* * * |
739 |
|
* * * |
740 |
|
* * * |
741 |
|
* * * |
742 |
|
* ********************************************************** |
743 |
|
|
744 |
|
subroutine initcalib |
745 |
|
include '../common/commontracker.f' |
746 |
|
include '../common/trk_calib_parameters.f' |
747 |
|
|
748 |
|
good0=0 |
749 |
|
|
750 |
|
do i=1,nplanes |
751 |
|
|
752 |
|
DAQmode(i) = 0 |
753 |
|
DSPnumber(i) = 0 |
754 |
|
calibnumber(i) = 0 |
755 |
|
ncalib_event(i)= 0 |
756 |
|
ped_l1(i) = 0 |
757 |
|
ped_l2(i) = 0 |
758 |
|
ped_l3(i) = 0 |
759 |
|
sig_l1(i) = 0 |
760 |
|
sig_l2(i) = 0 |
761 |
|
sig_l3(i) = 0 |
762 |
|
nbad_l1(i) = 0 |
763 |
|
nbad_l2(i) = 0 |
764 |
|
nbad_l3(i) = 0 |
765 |
|
cal_flag(i) = 0 |
766 |
|
|
767 |
|
do is=1,nstrips_view |
768 |
|
DSPbad_par(i,is) = 0 |
769 |
|
DSPped_par(i,is) = 0 |
770 |
|
DSPsig_par(i,is) = 0 |
771 |
|
enddo |
772 |
|
crc_hcal(i) = 0 |
773 |
|
crc_cal(i,1) = 0 |
774 |
|
crc_cal(i,2) = 0 |
775 |
|
crc_cal(i,3) = 0 |
776 |
|
enddo |
777 |
|
|
778 |
|
return |
779 |
|
end |