fetch_jnubeam_ntuples_old.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.pl
8 # --username <some_username>
9 # --passwd <some_password>
10 # --url <some_url>
11 # --prefix <file_prefix>
12 # --suffix <file_suffix>
13 # --rmin <min_run_nu>
14 # --rmax <max_run_nu>
15 # [--target <local_disk_path (default: '.')>]
16 #
17 # Example:
18 # You want to download/convert the 07a near detector flux files
19 # (named as 'nu.nd280.<RUN_NUMBER>.hbk)
20 # living at http://jnusrv01.kek.jp/internal/t2k/nubeam/flux/07a/nd/
21 # You only want to download / convert the files corresponding to MC runs 20->80,
22 # and you want to copy the downloaded files in /some/local/datadir/
23 # You need to type:
24 #
25 # perl fetch.pl
26 # --username t2k
27 # --passwd type_actual_passwd
28 # --url http://jnusrv01.kek.jp/internal/t2k/nubeam/flux/07a/nd/
29 # --prefix nu.nd280. --suffix .hbk --rmin 20 --rmax 80
30 # --target /some/local/datadir/
31 #
32 # Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
33 # STFC, Rutherford Appleton Lab
34 #----------------------------------------------------------------------------------
35 #
36 
37 $iarg=0;
38 foreach (@ARGV) {
39  if($_ eq '--username') { $username = $ARGV[$iarg+1]; }
40  if($_ eq '--passwd') { $passwd = $ARGV[$iarg+1]; }
41  if($_ eq '--url' ) { $url = $ARGV[$iarg+1]; }
42  if($_ eq '--prefix') { $file_prfx = $ARGV[$iarg+1]; }
43  if($_ eq '--suffix') { $file_sufx = $ARGV[$iarg+1]; }
44  if($_ eq '--rmin') { $run_min = $ARGV[$iarg+1]; }
45  if($_ eq '--rmax') { $run_max = $ARGV[$iarg+1]; }
46  if($_ eq '--target') { $target = $ARGV[$iarg+1]; }
47  $iarg++;
48 }
49 die("** Aborting [Undefined user name. Use the --username option]")
50 unless defined $username;
51 die("** Aborting [Undefined URL. Use the --url option]")
52 unless defined $url;
53 die("** Aborting [Undefined file prefix. Use the --prefix option]")
54 unless defined $file_prfx;
55 die("** Aborting [Undefined file suffix. Use the --suffix option]")
56 unless defined $file_sufx;
57 die("** Aborting [Undefined minimum run number. Use the --rmin option]")
58 unless defined $run_min;
59 die("** Aborting [Undefined maximum run number. Use the --rmax option]")
60 unless defined $run_max;
61 
62 $passwd = "" unless defined $passwd;
63 
64 $i=0;
65 for($i=$run_min; $i<=$run_max; $i++) {
66 
67 # fetch hbook file from remote location
68  $filename = $file_prfx.$i.$file_sufx;
69  $fetch_cmd = "curl -O --user $username:$passwd $url/$filename";
70  print "@@@ $fetch_cmd \n";
71  system("$fetch_cmd");
72  if( $? != 0 ) {
73  print "*** Couldn't download $url/$filename \n";
74  }
75 
76 # copy to local directory
77  if( -defined $target ) {
78  print "@@@ mv $filename $target \n";
79  `mv $filename $target`;
80  }
81 }
82