fetch-t2k_flux.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 #----------------------------------------------------------------------------------
4 # A perl script to download jnubeam hbook ntuples and convert them to ROOT format.
5 #
6 # Syntax:
7 # perl fetch-t2k_flux.pl
8 # --passwd <usual_t2k_password>
9 # --url <web_url>
10 # --prefix <file_prefix>
11 # [--suffix <file_suffix (default:'.hbk')>]
12 # --rmin <min_run_nu>
13 # --rmax <max_run_nu>
14 # [--target <local_disk_path (default: '.')>]
15 #
16 # Example:
17 # You want to download/convert the 07a near detector flux files
18 # (named as 'nu.nd280.<RUN_NUMBER>.hbk)
19 # living at http://jnusrv01.kek.jp/internal/t2k/nubeam/flux/07a/nd/
20 # You only want to download / convert the files corresponding to MC runs 20->80,
21 # and you want to copy all *hbk and *root files in /some/local/datadir/
22 # You need to type:
23 #
24 # perl fetch-t2k_flux.pl
25 # --passwd type_actual_passwd
26 # --url http://jnusrv01.kek.jp/internal/t2k/nubeam/flux/07a/nd/
27 # --prefix nu.nd280. --rmin 20 --rmax 80
28 # --target /some/local/datadir/
29 #
30 # Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
31 # STFC, Rutherford Appleton Lab
32 #----------------------------------------------------------------------------------
33 #
34 
35 $user = "t2k";
36 $passwd = "";
37 $url = "";
38 $file_prfx = "";
39 $file_sufx = ".hbk";
40 $run_min = 1;
41 $run_max = 999999;
42 
43 $iarg=0;
44 foreach (@ARGV) {
45  if($_ eq '--passwd') { $passwd = $ARGV[$iarg+1]; }
46  if($_ eq '--url' ) { $url = $ARGV[$iarg+1]; }
47  if($_ eq '--prefix') { $file_prfx = $ARGV[$iarg+1]; }
48  if($_ eq '--suffix') { $file_sufx = $ARGV[$iarg+1]; }
49  if($_ eq '--rmin') { $run_min = $ARGV[$iarg+1]; }
50  if($_ eq '--rmax') { $run_max = $ARGV[$iarg+1]; }
51  if($_ eq '--target') { $target = $ARGV[$iarg+1]; }
52  $iarg++;
53 }
54 
55 $i=0;
56 for($i=$run_min; $i<=$run_max; $i++) {
57 
58 # fetch hbook file from remote location
59  $filename_hbk = $file_prfx.$i.$file_sufx;
60  $fetch_cmd = "curl -O --user $user:$passwd $url/$filename_hbk";
61  print "@@@ $fetch_cmd \n";
62  system("$fetch_cmd");
63  if( $? != 0 ) {
64  print "*** Couldn't download $url/$filename_hbk \n";
65  }
66 
67 # convert to root
68  $filename_root = $filename_hbk;
69  $filename_root =~ s/.hbk/.root/;
70  $convert_cmd = "h2root $filename_hbk";
71  print "@@@ $convert_cmd \n";
72  `$convert_cmd`;
73 
74 # copy to local directory
75  if( -defined $target ) {
76  print "@@@ mv $filename_hbk $target \n";
77  `mv $filename_hbk $target`;
78  print "@@@ mv $filename_root $target \n";
79  `mv $filename_root $target`;
80  }
81 }
82