/[PAMELA software]/tracker/ground/source/readraw/readraw.f
ViewVC logotype

Contents of /tracker/ground/source/readraw/readraw.f

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Wed Mar 8 15:00:40 2006 UTC (18 years, 9 months ago) by pam-fi
Branch: MAIN, trk-ground
CVS Tags: R3v02, HEAD
Changes since 1.1: +0 -0 lines
First CVS release of tracker ground software (R3v02) 

1 ************************************************************************
2 *
3 * Program readraw.F
4 *
5 * Read downlink data files and unpacks tracker physics
6 * event and calibration data
7 *
8 *
9 * 10-11/9/2005 modified by david fedele to read buffer-data
10 * instead raw-data-file
11 *
12 * 29/11/2005 modified by david fedele to include crc control
13 *************************************************************************
14
15
16 program readraw
17
18 include '../common/commontracker.f'
19 include '../common/common_readraw.f'
20 include '../common/level0.f'
21 include '../common/calib.f'
22
23 include '../tof/common_tof.f'
24
25 c------------------------------------------------------------------------
26 c
27 c local variables
28 c
29 c------------------------------------------------------------------------
30 parameter (nfile_max=20)
31
32 character*24 processing_date
33
34 c local variables for input files
35 character*60 name_temp
36 character*2 aaa
37 character*40 base_file(nfile_max) !base file name
38 character*40 in_file(nfile_max) !input data file
39 character*40 in_dir !input data dir
40 character*40 out_dir !output dir
41 character*60 out_file_level0 !output rz file (level 0)
42 character*60 out_file_calib !output rz file (calibration)
43 character*60 out_file_tof !output rz file (TOF)
44 character*60 out_file_list !output text file (calib list)
45 character*10 input_string(nfile_max)
46
47 c local variables for data unpacking
48 integer ffd !input file descriptor
49 integer runerror !readevent error flag
50 parameter (MAXBUFFLEN=z'172c8')
51 integer*4 length_buffer
52 integer*1 buffer(MAXBUFFLEN)
53 integer curpos !current position in buffer
54 c*****************************************************
55 cccccc 29/11/2005 modified by david fedele
56 integer startcrc
57 integer stopcrc
58 integer*1 crctemp
59 c*****************************************************
60
61 integer acq_build_info !runheader field telling which of the front-ends have been included in the acquisition in the run
62 integer trk_calib_used !runheader field telling which kind of calibration has been used for the events of the run
63 integer trk_calib_used_old
64
65 logical DEBUG,ALARMs
66 common/DEBUGflag/DEBUG,ALARMS
67
68 logical trk_link(2)
69
70 c flags
71 integer last_CPU_pkt !to check pkt_num inside a downlink is consecutive
72 integer last_CPU_pkt_loc !to check pkt_num inside a downlink is consecutive
73 integer last_obt
74 logical runheader
75 logical runtrailer
76 logical found_calib
77 logical skip
78 logical exitflag
79 logical default_calib_written
80 logical online_calib_written
81
82 integer n_cal_pkt !count calibration packets
83
84 integer calib_default
85 integer calib_lastonline !store the identification number of the last calibration file
86
87 character*40 calib_default_file !file containing the default calibration info
88 data calib_default_file/'default_calib.rz'/
89
90 c local parameters
91 parameter (lun_out_file_calib=50) !output file id number
92 parameter (lun_out_file_level0=51) !output file id number
93 parameter (lun_out_file_tof=52) !output file id number
94
95 parameter (lun_in_file=53) !input file id number
96
97
98 parameter (max_event_number=50000) !maximum number of events
99
100 integer last_trigger(nviews)
101 common/trigger_counter/last_trigger
102 data last_trigger/12*0./
103
104
105 COMMON/QUEST/IQUEST(100) !permette di ottenere ntuple funzionanti nonostante
106 ! il messaggio dei 64K di RZOUT...!???
107
108 c*****************************************************
109 cccccc 20/9/2005 modified by david fedele
110 swcode=202
111 c*****************************************************
112 c------------------------------------------------------------------------
113 c
114 c HBOOK initialization
115 c
116 c------------------------------------------------------------------------
117
118 call HLIMIT(NWPAWC)
119
120
121 c------------------------------------------------------------------------
122 c
123 c reads input informations (through < go_readraw)
124 c
125 c------------------------------------------------------------------------
126 call fdate(processing_date)
127 write(*,101)
128 $ processing_date
129 101 format(/
130 $ ,'*** *** *** *** *** *** *** *** *** *** *** *** ***',/
131 $ ,'* *',/
132 $ ,'* READRAW *',/
133 $ ,'* *',/
134 $ ,'*** *** *** *** *** *** *** *** *** *** *** *** ***',/
135 $ ,a24,/
136 $ )
137
138 print*,'Number of files to be analysed:'
139 read(*,*)nfile
140 print*,nfile
141
142 499 format(A40)
143
144 c in_dir='raw-data/'
145 print*,'raw-data directory:'
146 read(*,499)in_dir
147 print*,in_dir
148
149
150 print*,'List of file identifiers: (DATE_NUM)'
151 300 format(A10)
152 read(*,300)(input_string(i),i=1,nfile)
153 do i=1,nfile
154 print*,input_string(i)
155 enddo
156
157 401 format('DW_',A10) !base file name
158 4401 format(a,'.dat') !input file name
159
160 do i=1,nfile
161 write(name_temp,401)input_string(i)
162 base_file(i)=name_temp(1:LNBLNK(name_temp))
163 write(name_temp,4401) base_file(i)(1:LNBLNK(base_file(i)))
164 in_file(i)=name_temp(1:LNBLNK(name_temp))
165 enddo
166
167 print*,'output directory:'
168 read(*,499)out_dir
169 print*,out_dir
170
171 print*,'Maximum number of events to be analized:'
172 read(*,*)nev_total
173 print*,nev_total
174 print*,'---------------------------------------------------'
175
176 *-------------------------------------------------------------
177 * init
178 * (some flags to check the data stream)
179 *------------------------------------------------------------
180 last_CPU_pkt = 0
181 last_obt = 0
182 iev_total=0 !total number of events
183 found_calib=.false.
184 trk_link(1)=.false.
185 trk_link(2)=.false.
186
187 c trk_calib_used=0
188 which_calib=0
189 calib_default=0
190 calib_lastonline=0
191
192
193 c------------------------------------------------------------------------
194 c
195 c loop on files
196 c
197 c------------------------------------------------------------------------
198
199 do ifile = 1,nfile !files loop
200
201 c------------------------------------------------------------------------
202 c init
203 c------------------------------------------------------------------------
204 runheader=.false.
205 runtrailer=.false.
206 default_calib_written=.false.
207 online_calib_written=.false.
208 exitflag=.false.
209 c nev_file_good = 0
210 n_cal_pkt=0
211 n_cal_list=0 !calibration file identifier in the calibration list file
212 trk_calib_used_old=0
213 n_run_pkt=0
214 last_CPU_pkt_loc = 0
215
216 nev0=0 !global event counter
217 nev0_good = 0 !total number of good events
218
219 nev_run=0 !event counter relative to the run
220 trk_calib_used=0
221 c which_calib=0
222
223 c------------------------------------------------------------------------
224 c open input file
225 c------------------------------------------------------------------------
226
227 print*,' '
228 print*,'OPENING PARTICLE FILE:'
229 print*,in_file(ifile)
230 print*,' '
231
232 open(unit=lun_in_file,
233 $ file=in_dir(1:LNBLNK(in_dir))
234 $ //in_file(ifile)(1:LNBLNK(in_file(ifile))),
235 $ status='old',
236 $ form='unformatted',
237 $ err=22)
238 ffd = FNum(lun_in_file) !reads unix file descriptor
239
240 c------------------------------------------------------------------------
241 c open output file and book ntuple structure
242 c------------------------------------------------------------------------
243 502 format(a,'_level0.rz')
244 write(out_file_level0,502)
245 $ base_file(ifile)(1:LNBLNK(base_file(ifile)))
246
247 5022 format(a,'_tof.rz')
248 write(out_file_tof,5022)
249 $ base_file(ifile)(1:LNBLNK(base_file(ifile)))
250
251 50222 format(a,'_calib.txt')
252 write(out_file_list,50222)
253 $ base_file(ifile)(1:LNBLNK(base_file(ifile)))
254
255
256 IQUEST(10)=64000
257 c permette di ottenere ntuple funzionanti nonostante
258 c il messaggio dei 64K di RZOUT... !???
259
260 write(*,103)
261 $ out_file_level0,out_file_tof
262 103 format(
263 $ ' ------------------------------------',/
264 $ ,' Creating rz files:',/
265 $ ,' ',a40,/
266 $ ,' ',a40,/
267 $ ,' ------------------------------------',/
268 $ )
269 * --------------------------
270 * create LEVEL0 tracker file
271 * --------------------------
272 call HROPEN(lun_out_file_level0,
273 $ 'LEVEL0',
274 $ out_dir(1:LNBLNK(out_dir))
275 $ //out_file_level0(1:LNBLNK(out_file_level0)),
276 $ 'QNP',4096,istat) !opens rz
277 if(istat.ne.0) goto 17
278 call HCDIR('//LEVEL0',' ')
279 call book_level0
280 * --------------------------
281 * create TOF tracker file
282 * --------------------------
283 call HROPEN(lun_out_file_tof,
284 $ 'TOF',
285 $ out_dir(1:LNBLNK(out_dir))
286 $ //out_file_tof(1:LNBLNK(out_file_tof)),
287 $ 'QNP',4096,istat) !opens rz
288 if(istat.ne.0) goto 17
289 call HCDIR('//TOF',' ')
290 call book_tof
291
292 * --------------------------------
293 * create tracker calibration list
294 * --------------------------------
295 open(UNIT=lun_calib_list
296 $ ,FILE=out_dir(1:LNBLNK(out_dir))
297 $ //out_file_list(1:LNBLNK(out_file_list))
298 $ ,FORM='FORMATTED'
299 $ ,STATUS='UNKNOWN'
300 $ )
301
302 c------------------------------------------------------------------------
303 c
304 c loop on events
305 c
306 c------------------------------------------------------------------------
307
308 do iev = 1,min(nev_total,max_event_number) !event loop
309
310 skip=.false.
311
312 iev_total=iev_total+1
313 if(iev_total.eq.nev_total) then
314 exitflag=.true.
315 goto 9900 !close files and exit if nev_total is reached
316 endif
317
318 ****************************************************************
319 * this routine search for a cpu header pointing to a tracker
320 * packet, and save the content in a buffer
321
322 c*****************************************************
323 cccccc 11/9/2005 modified by david fedele
324 c packet, and save the content in a temp file
325 * >>>>>> packet.dat <<<<<<
326 c********************************************************
327 c------------------------------------------------------------------------
328 c look for a cpu packet header
329 c------------------------------------------------------------------------
330 iskipcpu=0
331 88 continue
332 call findcpuheader(runerror,ffd,pkt_type,pkt_num
333 $ ,obt,buffer,length_buffer)
334 if(runerror.ne.0) then
335 * unexpected end of file
336 if(iskipcpu.ne.0)then
337 print*,'**** READRAW: WARNING '
338 $ //'- Skipped all packets. '
339 $ //'(>>> Reduce the file separately!)'
340 print*,''
341 endif
342 goto 9900 !next file
343 endif
344 if(iev.eq.1.and.iskipcpu.eq.0)then
345 print*,'FIRST CPU PKT: '
346 $ ,' pkt ID ',pkt_type
347 $ ,' - pkt N.',pkt_num
348 $ ,' - OBT ',obt
349 print*,''
350 endif
351
352 **** CHECK CPU-pkt SEQUENCE
353 * ------------------------------------------------
354 * 1) if at the end of the file there are pkts
355 * remained in the memory, these are skipped
356 * ------------------------------------------------
357 if(pkt_num.le.last_CPU_pkt_loc)then
358 goto 9900 !next file
359 endif
360 * ------------------------------------------------
361 * 2) if through the chained downlinks the
362 * packets are not consecutive a warning is set.
363 * In case there is overlapping of pkts
364 * it search the next consecutive packet.
365 * ------------------------------------------------
366 if(pkt_num.le.last_CPU_pkt)then
367 if(iskipcpu.eq.0)then
368 print*,' '
369 print*,'**** READRAW: WARNING '
370 $ //'- Not consecutive CPU packet '
371 $ //'(from pkt ',last_CPU_pkt,' to ',pkt_num,')'
372 endif
373 iskipcpu=iskipcpu+1
374 good0=.false.
375 if(pkt_type.eq.z'10'.or.pkt_type.eq.z'30')then
376 nev0=nev0+1
377 *****************************************************
378 cccccc 20/9/2005 modified by david fedele
379 ccc call init_level0
380 call initlevel0
381 c********************************************************
382 call initlevel0
383 call HCDIR('//LEVEL0',' ')
384 call HFNT(ntp_level0) !ntuple filling
385 good=.false.
386 call init_tof
387 call HCDIR('//TOF',' ')
388 call HFNT(ntp_tof) !ntuple filling
389 endif
390 if(pkt_num.eq.last_CPU_pkt.and.obt.ne.last_obt)goto 9900 !next file
391 if(pkt_num.lt.last_CPU_pkt)goto 88 !search next cpu header
392 endif
393 if(iskipcpu.ne.0)then
394 print*,'**** READRAW: WARNING '
395 $ //'- ',iskipcpu,' pkts overlap'
396
397 print*,''
398 print*,'NEXT CPU PKT: '
399 $ ,' pkt ID ',pkt_type
400 $ ,' - pkt N.',pkt_num
401 $ ,' - OBT ',obt
402 print*,''
403 endif
404
405 last_CPU_pkt = pkt_num
406 last_CPU_pkt_loc = pkt_num
407 last_obt = obt
408
409 c*****************************************************
410 cccccc 10/9/2005 modified by david fedele
411 c name_temp='bin-aux/packet.dat'
412 c*****************************************************
413
414
415 ******************************************************
416 ******************************************************
417 ******************************************************
418 ******************************************************
419 ******************************************************
420 ******************************************************
421 ******************************************************
422 ******************************************************
423
424 c------------------------------------------------------------------------
425 c read the packet according to packet type as indicated in the header
426 c------------------------------------------------------------------------
427
428 if(pkt_type.eq.z'12'.or.pkt_type.eq.z'13')then
429 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
430 c -----------
431 c CALIBRATION
432 c -----------
433 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
434 if(pkt_type.eq.z'12')then
435 trk_link(1)=.true.
436 print*,''
437 print*,'CALIB 1'
438 $ ,' - pkt N.',pkt_num
439 $ ,' - OBT ',obt
440 else
441 trk_link(2)=.true.
442 print*,'CALIB 2'
443 $ ,' - pkt N.',pkt_num
444 $ ,' - OBT ',obt
445 endif
446 c****************************************************
447 cccccc 10/9/2005 modified by david fedele
448 cccccc call trkcalibpkt(runerror,name_temp)
449 curpos=1
450 c*****************************************************
451 cccccc 29/11/2005 modified by david fedele
452 startcrc=0
453 stopcrc=0
454 c*****************************************************
455 call trkcalibpkt(runerror,buffer,length_buffer,curpos,
456 $ startcrc,stopcrc,crctemp)
457 c****************************************************
458
459 elseif(pkt_type.eq.z'10'.or.pkt_type.eq.z'30')then
460 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
461 c -----
462 c EVENT
463 c -----
464 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
465
466 c*****************************************************
467 cccccc 10/9/2005 modified by david fedele
468 c good0=.true.
469 c call init_level0
470 c call trkeventpkt(runerror,name_temp)
471 curpos=1
472 c*****************************************************
473 cccccc 29/11/2005 modified by david fedele
474 startcrc=0
475 stopcrc=0
476 c*****************************************************
477 call trkeventpkt(runerror,buffer,length_buffer,curpos,
478 $ startcrc,stopcrc,crctemp)
479 c*****************************************************
480 if(runerror.ne.0)then
481 good0=.false.
482 DEBUG = .true.
483 endif
484
485 call init_tof
486 good=.true.
487 call triggerunpack(buffer,length_buffer,me)
488 if(me.eq.1)good=.false.
489 call tofunpack(buffer,length_buffer,me)
490 if(me.eq.1)good=.false.
491
492 elseif(pkt_type.eq.z'83')then
493 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
494 c -----
495 c ALARM
496 c -----
497 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
498
499 print*,' '
500 print*,'ALARM '
501 $ ,' - pkt N.',pkt_num
502 $ ,' - OBT ',obt
503 call trkalarmpkt(buffer,length_buffer,runerror)
504
505 elseif(pkt_type.eq.z'20')then
506 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
507 c -----
508 c RUNHEADER PACKET
509 c -----
510 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
511 c this gives the TRK_CALIB_USED field and the ACQ_BUILD_INFO only
512 c inside the runheader packet
513
514 runheader=.true. !a run header has been found
515 runtrailer=.false. !
516 n_run_pkt=n_run_pkt+1 !run counter (relative to downlink)
517 nev_run=0 !event counter relative to the run
518
519 print*,'RUN # ',n_run_pkt
520 $ ,' - pkt N.',pkt_num
521 $ ,' - OBT ',obt
522
523 call runheaderpkt(buffer,length_buffer
524 $ ,trk_calib_used,acq_build_info)
525
526 elseif(pkt_type.eq.z'21')then
527 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
528 c -----
529 c RUNTRAILER PACKET
530 c -----
531 c-- **--**--**--**--**--**--**--**--**--**--**--**--**--**--**
532 runtrailer=.true. !
533 print*,'RUN # ',n_run_pkt
534 $ ,' - Calib. used ',trk_calib_used
535 $ ,' - Events ',nev_run
536 if(which_calib.eq.0)then
537 print*,'RUN # ',n_run_pkt
538 $ ,' - Calib. entry ',which_calib
539 $ ,' - File **NONE**'
540 else
541 print*,'RUN # ',n_run_pkt
542 $ ,' - Calib. entry ',which_calib
543 $ ,' - File ',file_calib
544 endif
545 print*,'--------'
546 endif !end pkt type conditions
547
548
549 ******************************************************
550 ******************************************************
551 ******************************************************
552 ******************************************************
553 ******************************************************
554 ******************************************************
555
556
557 c----------------------------------------------------------------
558 c
559 c elaborate the packet content
560 c
561 c----------------------------------------------------------------
562
563 c----------------------------------------------------------------
564 c calibration packet: if both 12 and 13 calibration packets
565 c (corresponding to the X and Y views (in which order?!))
566 c have been found, store them
567 c----------------------------------------------------------------
568 if(
569 $ (pkt_type.eq.z'12'.or.pkt_type.eq.z'13').and.
570 $ trk_link(1).and.
571 $ trk_link(2).and.
572 $ .true.) then
573 c print*,trk_link(1),trk_link(2),pkt_type
574 c----------------------------------------------------------------
575 c a calibration packet has been found
576 c create a new calibration file: DW_DATE_NUM_NN_calib.rz
577 c where NN=n_cal_pkt
578 c --> book and fill histos
579 c----------------------------------------------------------------
580 found_calib=.true.
581
582 n_cal_pkt = n_cal_pkt + 1
583 nnnn=n_cal_pkt
584 call intstr(nnnn,aaa,2)
585 503 format(a,'_',a2,'_calib.rz')
586 write(out_file_calib,503)
587 $ base_file(ifile)(1:LNBLNK(base_file(ifile))),
588 $ aaa
589
590 write(*,106)out_file_calib
591 106 format(
592 $ ' ------------------------------------',/
593 $ ,' Creating CALIBRATION rz file ',/
594 $ ,' ',a40,/
595 $ ,' ------------------------------------',/
596 $ )
597
598 call HROPEN(lun_out_file_calib,
599 $ 'CALIB',
600 $ out_dir(1:LNBLNK(out_dir))
601 $ //out_file_calib(1:LNBLNK(out_file_calib)),
602 $ 'QNP',4096,istat) !opens rz
603 if(istat.ne.0) goto 19
604 call HCDIR('//CALIB',' ')
605
606 call book_histos
607 call fill_histos
608
609 call HCDIR('//CALIB',' ')
610 do iview=1,nviews
611 call HROUT(id_hi_bad+iview,ICYCLE,'T')
612 call HROUT(id_hi_ped+iview,ICYCLE,'T')
613 call HROUT(id_hi_sig+iview,ICYCLE,'T')
614 call HDELET(id_hi_bad+iview)
615 call HDELET(id_hi_ped+iview)
616 call HDELET(id_hi_sig+iview)
617 enddo
618 call HREND('CALIB')
619 close(lun_out_file_calib)
620 do iview=1,nviews
621 trk_DSP_ok(iview)=0 !init DSP flag
622 enddo
623 trk_link(1)=.false.
624 trk_link(2)=.false.
625
626
627 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++
628 * add a entry to the calibration list file
629 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++
630 file_calib=out_file_calib(1:LNBLNK(out_file_calib))
631 online_calib_written=.false.
632 c call add_calib_entry
633 c calib_lastonline=n_cal_list !store the identification number of the last calibration file used
634 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++
635
636 c----------------------------------------------------------------
637 c runheader packet: use trk_calib_used and acq_build_info info
638 c----------------------------------------------------------------
639 elseif(
640 $ (pkt_type.eq.z'20')
641 $ .and..true.) then
642
643 if((trk_calib_used.eq.1) !use previous calibration
644 $ .or.(trk_calib_used.eq.2)) then
645
646 if(.not.found_calib) then
647 c----------------------------------------------------------------
648 * here if the first file is not the first of a data set
649 c----------------------------------------------------------------
650 print*,'**** READRAW: WARNING '
651 $ //'- Missing calibration! (useless run)'
652 else
653 if(.not.online_calib_written) then
654 c----------------------------------------------------------------
655 * for the first run of a file, create a new entry in the calibration list file,
656 * pointing to the last calibration of the previous file (out_file_calib)
657 c----------------------------------------------------------------
658 * ++++++++++++++++++++++++++++++++++++++++++++++
659 file_calib=
660 $ out_file_calib(1:LNBLNK(out_file_calib))
661 call add_calib_entry
662 calib_lastonline=n_cal_list
663 * ++++++++++++++++++++++++++++++++++++++++++++++
664 online_calib_written=.true.
665 endif
666 * for a normal event, use the last online-calibration file
667 which_calib=calib_lastonline !<<<<<<<<<<<<<<<<<
668 endif
669 c----------------------------------------------------------------
670 c if default calibration has been used, write the default
671 c calibration file name in the calibration list file
672 c----------------------------------------------------------------
673 elseif((trk_calib_used.eq.104) !use default calibration
674 $ ) then
675
676 if(.not.default_calib_written)then
677 c if(calib_default.eq.0)then
678 c 777 continue
679 default_calib_written=.true.
680 * +++++++++++++++++++++++++++++++++++++++++++++++++++
681 * add a entry to the calibration list file
682 * +++++++++++++++++++++++++++++++++++++++++++++++++++
683 file_calib=calib_default_file
684 call add_calib_entry
685 calib_default=n_cal_list
686 * +++++++++++++++++++++++++++++++++++++++++++++++++++
687 endif
688 which_calib=calib_default !<<<<<<<<<<<<<<<<<<<
689
690 else
691 print*,'**** READRAW: ERROR:'
692 $ //' Wrong calibration identifier for run'
693 $ //' starting at event ',iev,'(runheader packet'
694 $ //' number: ',pkt_num,')'
695 which_calib=0
696 endif
697
698
699 c----------------------------------------------------------------
700 c check if the tracker has been included in this run
701 c----------------------------------------------------------------
702
703 if(iand(acq_build_info,z'00ffff00')
704 $ .eq.z'00000000') then
705 skip=.true. !skip the event if no DSP has been included in ACQ
706 endif
707
708 c----------------------------------------------------------------
709 c- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
710 c
711 c
712 c event packet.
713 c z'10'=normal event,
714 c z'30'=full event for special calibration
715 c
716 c
717 c- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
718 c----------------------------------------------------------------
719 elseif(
720 $ (pkt_type.eq.z'10'.or.pkt_type.eq.z'30')
721 $ .and..true.) then
722
723
724 if((pkt_type.eq.z'10')
725 $ .and.(.not.runheader)
726 $ .and.nev_run.eq.0) then
727 print*,'**** READRAW: WARNING - Missing RunHeader '
728 endif
729
730 if(.not.skip) then
731
732
733 **** CHECK TRIGGER SEQUENCE ****
734 * ---------------------------------------------------------
735 do idsp=1,nviews
736 if(trk_DSP_ok(idsp).eq.1)then
737 if(eventn(idsp).ne.(last_trigger(idsp)+1)
738 $ .and.eventn(idsp).ne.1
739 $ .and.last_trigger(idsp).ne.0)
740 $ write(*,8181)
741 $ idsp,last_trigger(idsp),eventn(idsp)
742 $ ,last_CPU_pkt
743 last_trigger(idsp)=eventn(idsp)
744 endif
745 enddo
746 8181 format('DSP ',i2,' >> JUMP from trigger ',i6,' to '
747 $ ,i6,' (CPU pkt N.',i8,')')
748 * ---------------------------------------------------------
749 **** CHECK NUMBER OF DSP PACKETS
750 dsptot=0
751 do iview=1,nviews
752 dsptot=dsptot+trk_DSP_ok(iview)
753 trk_DSP_ok(iview)=0 !init DSP flag
754 enddo
755
756 if(dsptot.lt.nviews)then
757 good0=.false.
758 print *,'DSP pkt found: '
759 $ ,(trk_DSP_ok(iview),iview=1,12)
760 $ ,' (CPU pkt N.',last_CPU_pkt,')'
761 elseif(DEBUG)then
762 print*,' (CPU pkt N.',last_CPU_pkt,')'
763 DEBUG = .false.
764 endif
765 * ---------------------------------------------------------
766
767
768 * ---------------------------------------------------------
769 * for the first event of a file, create a new entry in the
770 * calibration list file, pointing to the last calibration
771 * of the previous file (out_file_calib)
772 * ---------------------------------------------------------
773 if((nev_run.eq.0).and.
774 $ (.not.runheader).and.
775 $ which_calib.ne.0) then
776 call add_calib_entry
777 if(which_calib.eq.calib_lastonline)then
778 calib_lastonline=n_cal_list
779 online_calib_written=.true.
780 elseif(which_calib.eq.calib_default)then
781 calib_default=n_cal_list
782 default_calib_written=.true.
783 endif
784 which_calib=n_cal_list
785 endif
786 * ---------------------------------------------------------
787
788
789
790 * event counter relative to the run
791 if(pkt_type.eq.z'10')nev_run=nev_run+1
792
793 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
794 C then the nt-uple is filled
795 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
796
797 if(good0.and.which_calib.ne.0) nev0_good = nev0_good +1
798
799 c nev_trk= iev
800
801 nev0=nev0+1
802 call HCDIR('//LEVEL0',' ')
803 call HFNT(ntp_level0) !ntuple filling
804
805 call HCDIR('//TOF',' ')
806 call HFNT(ntp_tof) !ntuple filling
807
808
809 endif
810
811
812
813
814 c----------------------------------------------------------------
815 c alarm packet
816 c----------------------------------------------------------------
817 elseif(
818 $ pkt_type.eq.z'83'.and.
819 $ .true.) then
820
821 print*,''
822 print*,'@@@@@@@@@@@@ ALARM @@@@@@@@@@@@@@@'
823 print*,''
824
825
826 endif !pkt_type condition
827
828 9909 continue
829
830
831 enddo !end loop on events
832
833 9900 continue
834
835 if(.not.runtrailer)then
836 print*,'RUN # ',n_run_pkt
837 $ ,' - Calib. used ',trk_calib_used
838 $ ,' - Events ',nev_run
839 if(which_calib.eq.0)then
840 print*,'RUN # ',n_run_pkt
841 $ ,' - Calib. entry ',which_calib
842 $ ,' - File **NONE**'
843 else
844 print*,'RUN # ',n_run_pkt
845 $ ,' - Calib. entry ',which_calib
846 $ ,' - File ',file_calib
847 endif
848 print*,' '
849 endif
850
851
852
853 c------------------------------------------------------------------------
854 c
855 c closes files and exits
856 c
857 c------------------------------------------------------------------------
858
859 c*****************************************************
860 cccccc 10/9/2005 modified by david fedele
861 c call system('rm -f '//name_temp)
862 c*****************************************************
863 close(lun_in_file)
864
865 c nev0_good = nev0_good + nev_file_good
866
867 print*,' '
868 print*,'CLOSING FILES:'
869 print*,out_file_level0
870 print*,out_file_tof
871 print*,' '
872
873 call HCDIR('//LEVEL0',' ')
874 c call HPRNTU(ntp_level0) !prints ntuple structure
875 c deletes all but the last cycles of all key
876 c from the current working RZ directory
877 call RZPURG(-1)
878 call HROUT(ntp_level0,ICYCLE,'T')
879 call HREND('LEVEL0')
880 close(lun_out_file_level0)
881
882 call HCDIR('//TOF',' ')
883 c call HPRNTU(ntp_tof) !prints ntuple structure
884 c deletes all but the last cycles of all key
885 c from the current working RZ directory
886 call RZPURG(-1)
887 call HROUT(ntp_tof,ICYCLE,'T')
888 call HREND('TOF')
889 close(lun_out_file_tof)
890
891
892 close(lun_calib_list)
893
894
895 write(*,107)
896 c $ iev,
897 c $ nev_file_good
898 $ nev0,
899 $ nev0_good
900 107 format(
901 $ ' ------------------------------------',/
902 $ ,' | Number of events ',i8,' |'/
903 $ ,' | Good events ',i8,' |'/
904 $ ,' ------------------------------------',/
905 $ )
906
907
908
909 if(exitflag) goto 9990 !nev_total has been reached --> exit
910
911 print*,'LAST CPU PKT: '
912 $ ,' pkt ID ',pkt_type
913 $ ,' - pkt N.',pkt_num
914 $ ,' - OBT ',obt
915
916
917 enddo !end loop on files
918
919 9990 continue
920
921
922 goto 9000 !go to end
923 c-----------------------------------------
924 c level0 file creation error
925 c-----------------------------------------
926 17 continue
927 print*,' '
928 print*,'readraw: ERROR CREATING OUTPUT FILE: ',out_file_level0
929 print*,istat
930 print*,' '
931 print*,' '
932 goto 9000 !the end
933 c-----------------------------------------
934 c tof file creation error
935 c-----------------------------------------
936 18 continue
937 print*,' '
938 print*,'readraw: ERROR CREATING OUTPUT FILE: ',out_file_tof
939 print*,istat
940 print*,' '
941 print*,' '
942 goto 9000 !the end
943 c-----------------------------------------
944 c calibration file creation error
945 c-----------------------------------------
946 19 continue
947 print*,' '
948 print*,'readraw: ERROR CREATING OUTPUT FILE: ',out_file_calib
949 print*,istat
950 print*,' '
951 print*,' '
952 goto 9000 !the end
953 c-----------------------------------------
954 c particle input file opening error
955 c-----------------------------------------
956 22 continue
957 print*,' '
958 print*,'readraw: ERROR OPENING PARTICLE FILE: ',in_file(ifile)
959 print *,in_dir
960 print *,in_dir(1:LNBLNK(in_dir))
961 $ //in_file(ifile)(1:LNBLNK(in_file(ifile)))
962 print*,' '
963 goto 9000 !the end
964
965
966 c------------------------------------------------------------------------
967 c
968 c exit
969 c
970 c------------------------------------------------------------------------
971 9000 continue
972
973
974 stop
975 end

  ViewVC Help
Powered by ViewVC 1.1.23