make_genie_sim_file_list.pl
Go to the documentation of this file.
1 #-------------------------------------------------------------------------------------------
2 # Create XML file list expected by GENIE validation programs
3 #
4 # Syntax:
5 # % perl make_genie_sim_file_list.pl <inputs>
6 #
7 # where inputs is a list of "file_paths,model_name" pairs.
8 # Multiple ':'-separated file paths can be specified.
9 #
10 # Example:
11 # %perl make_genie_sim_file_list.pl /some/path/,model_name /another/path1:/another/path2,another_model_name ...
12 #
13 # Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
14 # STFC, Rutherford Appleton Lab
15 #-------------------------------------------------------------------------------------------
16 
17 #!/usr/bin/perl
18 
19 my %data = ();
20 
21 foreach (@ARGV) {
22  my ($file_paths, $model_name) = split(',', $_);
23  $data{$model_name} .= $file_paths;
24 }
25 
26 print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n\n";
27 print "<genie_simulation_outputs> \n";
28 
29 while( my ($model_name, $file_paths) = each %data )
30 {
31  #print "$model_name --> $file_paths \n";
32  print "\n\n";
33  print "\t <model name=\"$model_name\"> \n";
34 
35  @file_path_array = split(':',$file_paths);
36  foreach(@file_path_array) {
37  $dirname = $_;
38  opendir my $dir, $dirname or die "Can not open directory: $!";
39  my @files = grep { !/^\./ } readdir $dir;
40  closedir $dir;
41  foreach(@files) {
42  $filename = $_;
43  if($filename =~ m/.ghep.root$/) {
44  print "\t\t <evt_file format=\"ghep\"> $dirname/$filename </evt_file> \n";
45  }
46  elsif($filename =~ m/.gst.root$/) {
47  print "\t\t <evt_file format=\"gst\"> $dirname/$filename </evt_file> \n";
48  }
49  elsif($filename =~ m/.root$/) {
50  print "\t\t <xsec_file> $dirname/$filename </xsec_file> \n";
51  }
52  }
53  }
54  print "\t </model> \n\n";
55 }
56 
57 print "</genie_simulation_outputs> \n";
58