fconv.pl
Go to the documentation of this file.
1 #-------------------------------------------------------------------------------------------
2 # File converter
3 #
4 # Syntax:
5 # % perl fconv.pl <options>
6 #
7 # Options:
8 # --rmin : Minimum run number
9 # --rmax : Maximum run number
10 # --prefix : File prefix
11 # --suffix : File suffix
12 # --dirname : File location [default: ./]
13 # --convcmd : Conversion command
14 #
15 # Example 1:
16 # Input: JNUBEAM HBOOK files nu.sk_horn250ka.RUNNU.hbk (where RUNNU=1,...,100)
17 # Located at: /opt/data/t2k_flux/10a/sk/
18 # Task: Convert to ROOT format
19 # Type:
20 # % perl fconv.pl --rmin 1 --rmax 100 --prefix nu.sk_horn250ka. --suffix .hbk \
21 # --dirname /opt/data/t2k_flux/10a/sk/ --convcmd 'h2root'
22 #
23 # Example 2:
24 # Input: GENIE GHEP event files gntp.ghep.RUNNU.root (where RUNNU=1000,...,1010)
25 # Located at: /opt/ghepfiles/
26 # Task: Convert first 10k events of each file in the GENIE summary ntuple format (GST)
27 # Type:
28 # % perl fconv.pl --rmin 100 --rmax 1010 --prefix gntp. --suffix .ghep.root \
29 # --dirname /opt/ghepfiles/ --convcmd 'gntpc -f gst -n 10000 -i '
30 #
31 # Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
32 # STFC, Rutherford Appleton Lab
33 #-------------------------------------------------------------------------------------------
34 
35 #!/usr/bin/perl
36 
37 $dirname="./";
38 
39 $iarg=0;
40 foreach (@ARGV) {
41  if($_ eq '--prefix') { $file_prfx = $ARGV[$iarg+1]; }
42  if($_ eq '--suffix') { $file_sufx = $ARGV[$iarg+1]; }
43  if($_ eq '--rmin') { $run_min = $ARGV[$iarg+1]; }
44  if($_ eq '--rmax') { $run_max = $ARGV[$iarg+1]; }
45  if($_ eq '--convcmd') { $convcmd = $ARGV[$iarg+1]; }
46  if($_ eq '--dirname') { $dirname = $ARGV[$iarg+1]; }
47  $iarg++;
48 }
49 die("** Aborting [You need to specify a minimum run number using the --rmin option]")
50 unless defined $run_min;
51 die("** Aborting [You need to specify a maximum run number using the --rmax option]")
52 unless defined $run_max;
53 die("** Aborting [You need to specify a file prefix using the --prefix option]")
54 unless defined $file_prfx;
55 die("** Aborting [You need to specify a file suffix using the --suffix option]")
56 unless defined $file_sufx;
57 die("** Aborting [You need to specify the conversion command using the --convcmd option]")
58 unless defined $convcmd;
59 
60 $i=0;
61 for($i=$run_min; $i<=$run_max; $i++) {
62  $filename = $dirname."/".$file_prfx.$i.$file_sufx;
63  if(-e $filename) {
64  $cmd = $convcmd." ".$filename;
65  print "Running: $cmd \n";
66  `$cmd`;
67 # system("$cmd");
68  }
69 }