| 1 |
************************************************************************ |
| 2 |
* |
| 3 |
* Program scancalibs.f |
| 4 |
* |
| 5 |
* |
| 6 |
************************************************************************* |
| 7 |
|
| 8 |
program scancalibs |
| 9 |
|
| 10 |
include '../common/commontracker.f' |
| 11 |
include '../common/common_readraw.f' |
| 12 |
c include '../common/level0.f' |
| 13 |
include '../common/calib.f' |
| 14 |
include '../commonyoda/trk_calib_parameters.f' |
| 15 |
|
| 16 |
integer trk_DSP_ok(nviews)!mask of found DSP packets |
| 17 |
common/DSPok/trk_DSP_ok |
| 18 |
|
| 19 |
c------------------------------------------------------------------------ |
| 20 |
c |
| 21 |
c local variables |
| 22 |
c |
| 23 |
c------------------------------------------------------------------------ |
| 24 |
parameter (nfile_max=20) |
| 25 |
|
| 26 |
character*24 processing_date |
| 27 |
|
| 28 |
c local variables for input files |
| 29 |
character*60 name_temp |
| 30 |
character*3 aa(nfile_max) |
| 31 |
character*2 aaa |
| 32 |
character*40 in_file(nfile_max) !input data file |
| 33 |
character*40 in_dir !input data dir |
| 34 |
character*40 out_dir !output dir |
| 35 |
character*60 out_file !output rz file |
| 36 |
character*60 out_file_runinfo !output log file |
| 37 |
character*60 out_file_level0 !output rz file (level 0) |
| 38 |
character*60 out_file_calib !output rz file (calibration) |
| 39 |
character*8 date |
| 40 |
character*3 particle |
| 41 |
|
| 42 |
integer file_id(nfile_max),file_events(nfile_max) |
| 43 |
|
| 44 |
character*200 copystring |
| 45 |
|
| 46 |
integer this_eventn |
| 47 |
c integer this_calib |
| 48 |
|
| 49 |
c local variables for data unpacking |
| 50 |
logical found_cal_pkt !flag for calibration packets |
| 51 |
integer ffd !input file descriptor |
| 52 |
integer runerror !readevent error flag |
| 53 |
c integer ffd_pkt !pkt file descriptor |
| 54 |
c !(file temporaneo) |
| 55 |
integer*4 CPU_pkt_counter |
| 56 |
integer pkt_type |
| 57 |
|
| 58 |
c integer ndummy |
| 59 |
c data ndummy/1000/ |
| 60 |
|
| 61 |
logical trk_link(2) |
| 62 |
|
| 63 |
|
| 64 |
c local parameters |
| 65 |
parameter (lun_out_file_runinfo=49)!txt log file id number |
| 66 |
parameter (lun_out_file_calib=50) !output file id number |
| 67 |
parameter (lun_out_file_level0=51) !output file id number |
| 68 |
|
| 69 |
parameter (lun_in_file=52) !input file id number |
| 70 |
|
| 71 |
parameter (lun_pkt=53) !inpunt temp packet file |
| 72 |
|
| 73 |
|
| 74 |
parameter (max_event_number=50000) !maximum number of events |
| 75 |
|
| 76 |
|
| 77 |
c------------------------------------------------------------------------ |
| 78 |
c |
| 79 |
c reads input informations (through < go_readraw) |
| 80 |
c |
| 81 |
c------------------------------------------------------------------------ |
| 82 |
|
| 83 |
print*,'______________________________________________' |
| 84 |
|
| 85 |
print*,'Number of files to be analysed:' |
| 86 |
read(*,*)nfile |
| 87 |
print*,nfile |
| 88 |
print*,'Date YYMMDD:' |
| 89 |
300 format(a6) |
| 90 |
read(*,300)date |
| 91 |
print*,date |
| 92 |
print*,'List of file identifiers:' |
| 93 |
401 format('output_',A6,'_',A3,'.dat') !file name |
| 94 |
c 402 format('dt_temp/') !directory |
| 95 |
read(*,*)(file_id(i),i=1,nfile) |
| 96 |
write(*,*)(file_id(i),i=1,nfile) |
| 97 |
c write(in_dir,402)date |
| 98 |
c in_dir='dt_temp/' |
| 99 |
in_dir='raw-data/' |
| 100 |
do i=1,nfile |
| 101 |
iii = file_id(i) |
| 102 |
call intstr(iii,aa(i),3) |
| 103 |
c write(name_temp,400)date,date,aa(i) |
| 104 |
write(name_temp,401)date,aa(i) |
| 105 |
in_file(i)=name_temp(1:LNBLNK(name_temp)) |
| 106 |
print*,in_file(i) |
| 107 |
file_events(i)=0 |
| 108 |
enddo |
| 109 |
|
| 110 |
499 format(A40) |
| 111 |
print*,'output directory:' |
| 112 |
read(*,499)out_dir |
| 113 |
print*,out_dir |
| 114 |
c out_dir='rz/' |
| 115 |
print*,'Total number of events to be analized:' |
| 116 |
read(*,*)nev_total |
| 117 |
print*,nev_total |
| 118 |
print*,'______________________________________________' |
| 119 |
|
| 120 |
c------------------------------------------------------------------------ |
| 121 |
c |
| 122 |
c Opening log-file RUNINFO |
| 123 |
c |
| 124 |
c |
| 125 |
c------------------------------------------------------------------------ |
| 126 |
out_file_runinfo='scancalibs.dat' |
| 127 |
print*,'OUTPUT FILE: ', |
| 128 |
$ out_dir(1:LNBLNK(out_dir)) |
| 129 |
$ //out_file_runinfo(1:LNBLNK(out_file_runinfo)) |
| 130 |
open(UNIT=lun_out_file_runinfo |
| 131 |
$ ,FILE=out_dir(1:LNBLNK(out_dir)) |
| 132 |
$ //out_file_runinfo(1:LNBLNK(out_file_runinfo)) |
| 133 |
$ ,ACCESS='APPEND' |
| 134 |
$ ,FORM='FORMATTED' |
| 135 |
$ ,STATUS='UNKNOWN' |
| 136 |
$ ) |
| 137 |
*------------------------------------------------------------- |
| 138 |
* |
| 139 |
* start loop on data files |
| 140 |
* |
| 141 |
* |
| 142 |
*------------------------------------------------------------ |
| 143 |
* some flags to check the data stream |
| 144 |
found_cal_pkt=.false. |
| 145 |
n_cal_pkt=0 |
| 146 |
n_cal_pkt_last=0 |
| 147 |
|
| 148 |
nev0_c = 0 !global event counter |
| 149 |
nev0_good = 0 |
| 150 |
trk_link(1)=.false. |
| 151 |
trk_link(2)=.false. |
| 152 |
|
| 153 |
do ifile = 1,nfile !loop on data files |
| 154 |
|
| 155 |
print*,' ' |
| 156 |
print*,'OPENING PARTICLE FILE:' |
| 157 |
print*,in_file(ifile) |
| 158 |
print*,' ' |
| 159 |
|
| 160 |
open(unit=lun_in_file, |
| 161 |
$ file=in_dir(1:LNBLNK(in_dir)) |
| 162 |
$ //in_file(ifile)(1:LNBLNK(in_file(ifile))), |
| 163 |
$ status='old', |
| 164 |
$ form='unformatted', |
| 165 |
$ err=22) |
| 166 |
ffd = FNum(lun_in_file) !reads unix file descriptor |
| 167 |
|
| 168 |
file_events(ifile)=0 !sigle-file event counter |
| 169 |
nev_file_good = 0 |
| 170 |
c good0 = .true. |
| 171 |
this_eventn=0 |
| 172 |
|
| 173 |
this_CPU_pkt = 0 |
| 174 |
do iev = 1,min(nev_total,max_event_number) !events loop |
| 175 |
**************************************************************** |
| 176 |
* this routine search for a cpu header pointing to a tracker |
| 177 |
* packet, and save the content in a temp file |
| 178 |
* >>>>>> packet.dat <<<<<< |
| 179 |
call findcpuheader(runerror,ffd,pkt_type,CPU_pkt_counter) |
| 180 |
if(runerror.eq.-1) goto 24 |
| 181 |
if(runerror.eq.1) then |
| 182 |
print*,' ' |
| 183 |
print*,'readraw: FILE: ',in_file(ifile) |
| 184 |
print*,'readraw: END OF FILE AT EVENT ',iev-1 |
| 185 |
print*,'_____________________________________ ' |
| 186 |
c goto 9900 !end loop on files |
| 187 |
endif |
| 188 |
c print *,'>>> Previous CPU pkt',this_CPU_pkt |
| 189 |
c print *,'>>> Current CPU pkt',CPU_pkt_counter |
| 190 |
if(CPU_pkt_counter.le.this_CPU_pkt)then |
| 191 |
print*,' ' |
| 192 |
c print*,' >> The CPU pkt number is not progressive << ' |
| 193 |
c print*, ' (I suppose that what follows is rubbish) ' |
| 194 |
goto 9900 !next file |
| 195 |
endif |
| 196 |
this_CPU_pkt = CPU_pkt_counter |
| 197 |
name_temp='packet.dat' |
| 198 |
if(pkt_type.eq.z'12'.or.pkt_type.eq.z'13')then |
| 199 |
if(pkt_type.eq.z'12')then |
| 200 |
trk_link(1)=.true. |
| 201 |
print*,'Found link 1 >> ',trk_link(1),trk_link(2) |
| 202 |
else |
| 203 |
trk_link(2)=.true. |
| 204 |
print*,'Found link 2 >> ',trk_link(1),trk_link(2) |
| 205 |
endif |
| 206 |
c--**--**--**--**--**--**--**--**--**--**--**--**--**--**--** |
| 207 |
c ----------- |
| 208 |
c CALIBRATION |
| 209 |
c ----------- |
| 210 |
c--**--**--**--**--**--**--**--**--**--**--**--**--**--**--** |
| 211 |
|
| 212 |
|
| 213 |
c call trk_calib_pkt(runerror,ffd_pkt) |
| 214 |
call trkcalibpkt(runerror,name_temp) |
| 215 |
|
| 216 |
222 format(i3,3i6,6i4) |
| 217 |
do iview=1,6 |
| 218 |
write(lun_out_file_runinfo,222) |
| 219 |
$ DSPnumber(iview), |
| 220 |
$ ped_l1(iview),ped_l2(iview),ped_l3(iview), |
| 221 |
$ sig_l1(iview),sig_l2(iview),sig_l3(iview), |
| 222 |
$ nbad_l1(iview),nbad_l2(iview),nbad_l3(iview) |
| 223 |
write(*,222) |
| 224 |
$ DSPnumber(iview), |
| 225 |
$ ped_l1(iview),ped_l2(iview),ped_l3(iview), |
| 226 |
$ sig_l1(iview),sig_l2(iview),sig_l3(iview), |
| 227 |
$ nbad_l1(iview),nbad_l2(iview),nbad_l3(iview) |
| 228 |
enddo |
| 229 |
|
| 230 |
|
| 231 |
2222 continue |
| 232 |
|
| 233 |
elseif(pkt_type.eq.z'10'.or.pkt_type.eq.z'30')then |
| 234 |
c--**--**--**--**--**--**--**--**--**--**--**--**--**--**--** |
| 235 |
c ----- |
| 236 |
c EVENT |
| 237 |
c ----- |
| 238 |
c--**--**--**--**--**--**--**--**--**--**--**--**--**--**--** |
| 239 |
c call trkeventpkt(runerror,name_temp) |
| 240 |
8800 continue |
| 241 |
endif !end pkt type conditions |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
if( |
| 246 |
$ (pkt_type.eq.z'10'.or.pkt_type.eq.z'30').and. |
| 247 |
$ .true.) then |
| 248 |
c---------------------------------------------------------------- |
| 249 |
c an EVENT was found, |
| 250 |
c---------------------------------------------------------------- |
| 251 |
|
| 252 |
elseif( |
| 253 |
$ (pkt_type.eq.z'12'.or.pkt_type.eq.z'13').and. |
| 254 |
$ trk_link(1).eqv..true..and. |
| 255 |
$ trk_link(2).eqv..true..and. |
| 256 |
$ .true.) then |
| 257 |
print*,trk_link(1),trk_link(2),pkt_type |
| 258 |
c---------------------------------------------------------------- |
| 259 |
c a calibration packet was found |
| 260 |
c---------------------------------------------------------------- |
| 261 |
n_cal_pkt = n_cal_pkt + 1 |
| 262 |
nnnn=n_cal_pkt |
| 263 |
call intstr(nnnn,aaa,2) |
| 264 |
* *********************************************************** |
| 265 |
* *********************************************************** |
| 266 |
* *********************************************************** |
| 267 |
* *********************************************************** |
| 268 |
* write the output |
| 269 |
* *********************************************************** |
| 270 |
write(lun_out_file_runinfo,*) |
| 271 |
$ '----- ',date,file_id(ifile),n_cal_pkt |
| 272 |
write(*,*) |
| 273 |
$ '----- ',date,file_id(ifile),n_cal_pkt |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
* *********************************************************** |
| 279 |
* *********************************************************** |
| 280 |
* *********************************************************** |
| 281 |
* *********************************************************** |
| 282 |
* *********************************************************** |
| 283 |
|
| 284 |
do iview=1,nviews |
| 285 |
trk_DSP_ok(iview)=0 !init DSP flag |
| 286 |
enddo |
| 287 |
trk_link(1)=.false. |
| 288 |
trk_link(2)=.false. |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
endif |
| 295 |
9909 continue |
| 296 |
enddo !end loop on events |
| 297 |
9900 continue |
| 298 |
close(lun_in_file) |
| 299 |
|
| 300 |
|
| 301 |
enddo !end loop on data files |
| 302 |
|
| 303 |
close(lun_out_file_runinfo) |
| 304 |
|
| 305 |
9990 continue |
| 306 |
goto 9000 !go to end |
| 307 |
c----------------------------------------- |
| 308 |
c output file creation error |
| 309 |
c----------------------------------------- |
| 310 |
19 continue |
| 311 |
print*,' ' |
| 312 |
print*,'readraw: ERROR CREATING OUTPUT FILE: ',out_file |
| 313 |
print*,istat |
| 314 |
print*,' ' |
| 315 |
print*,' ' |
| 316 |
goto 9000 !the end |
| 317 |
c----------------------------------------- |
| 318 |
c particle input file opening error |
| 319 |
c----------------------------------------- |
| 320 |
22 continue |
| 321 |
print*,' ' |
| 322 |
print*,'readraw: ERROR OPENING PARTICLE FILE: ',in_file(ifile) |
| 323 |
print *,in_dir |
| 324 |
print *,in_dir(1:LNBLNK(in_dir)) |
| 325 |
$ //in_file(ifile)(1:LNBLNK(in_file(ifile))) |
| 326 |
print*,' ' |
| 327 |
goto 9000 !the end |
| 328 |
c----------------------------------------- |
| 329 |
c event found before calibration packet |
| 330 |
c----------------------------------------- |
| 331 |
20 continue |
| 332 |
print*,' ' |
| 333 |
print*,'readraw: EVENT FOUND BEFORE CALIBRATION PACKET: ' |
| 334 |
print*,in_file(ifile) |
| 335 |
print*,' ' |
| 336 |
goto 9000 !the end |
| 337 |
c----------------------------------------- |
| 338 |
c particle input file reading error |
| 339 |
c----------------------------------------- |
| 340 |
23 continue |
| 341 |
print*,' ' |
| 342 |
print*,'readraw: END OF FILE: ',in_file(ifile) |
| 343 |
print*,'readraw: FOWND AT EVENT ',iev |
| 344 |
print*,' ' |
| 345 |
goto 9000 !the end |
| 346 |
24 continue |
| 347 |
print*,' ' |
| 348 |
print*,'readraw: ERROR READING PARTICLE FILE: ',in_file(ifile) |
| 349 |
print*,'readraw: READ ERROR AT EVENT ',iev |
| 350 |
print*,' ' |
| 351 |
goto 9000 !the end |
| 352 |
|
| 353 |
c------------------------------------------------------------------------ |
| 354 |
c |
| 355 |
c closes files and exits |
| 356 |
c |
| 357 |
c------------------------------------------------------------------------ |
| 358 |
9000 continue |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
stop |
| 363 |
end |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
c include 'readraw_subroutines.f' |
| 368 |
c include 'trkunpack.f' |