ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/scripts/mergeHists
Revision: 1.1
Committed: Thu Jun 14 17:42:30 2012 UTC (12 years, 10 months ago) by ahart
Branch: MAIN
Log Message:
Allow fuzzy dataset names for osudb and osusub. First commit of AnaTools directory.

File Contents

# User Rev Content
1 ahart 1.1 #!/usr/bin/env perl
2    
3     use strict;
4     use Getopt::Long;
5    
6     my %opt;
7     Getopt::Long::Configure ("bundling");
8     GetOptions (\%opt, "prefix|p=s", "help|h");
9    
10     printHelp () if $opt{"help"} || !$opt{"prefix"};
11     my $files = processArgs (\@ARGV);
12     my @rootFiles;
13     my $error = 0;
14     foreach my $file (@$files)
15     {
16     next if $file eq ".";
17     next if $file eq "..";
18     if ($file =~ m/\.root$/)
19     {
20     push (@rootFiles, $file);
21     next;
22     }
23     open (FILE, "<$file");
24     my @fileContents = <FILE>;
25     close (FILE);
26     my $fileContents = join ("", @fileContents);
27     next if !($fileContents =~ m/\(return value [^)]*\)/);
28     $fileContents =~ s/\n/ /g;
29     $fileContents =~ s/.*\(return value ([^)]*)\).*/$1/g;
30     if ($fileContents != 0)
31     {
32     printf "Error: return value of %2d in \"$file\"!\n", $fileContents;
33     $error = 1;
34     }
35     }
36     exit if $error;
37     my $rootFiles = join (" ", @rootFiles);
38     system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root");
39     system ("cutFlowTable $opt{'prefix'}.root cutFlow >& $opt{'prefix'}.tex");
40    
41     sub
42     processArgs
43     {
44     my $argv = shift;
45    
46     my @files;
47     foreach my $arg (@$argv)
48     {
49     $arg =~ s/\/*$//;
50     if (!(-e $arg))
51     {
52     print "$arg does not exist!\n";
53     exit;
54     }
55     next if ($arg =~ m/\/\.$/ || $arg =~ m/\/\.\.$/);
56     if (-d $arg)
57     {
58     opendir (DIR, $arg);
59     my @dirContents = readdir (DIR);
60     closedir (DIR);
61     for (my $i = 0; $i < @dirContents; $i++)
62     {
63     $dirContents[$i] = "$arg/$dirContents[$i]";
64     }
65     my $newFiles = processArgs (\@dirContents);
66     push (@files, @$newFiles);
67     }
68     else
69     {
70     push (@files, $arg);
71     }
72     }
73    
74     return \@files;
75     }
76    
77     sub
78     printHelp
79     {
80     my $exeName = $0;
81     $exeName =~ s/^.*\/([^\/]*)$/$1/;
82    
83     print "Usage: $exeName [OPTIONS] -p PREFIX DIRECTORIES_AND_FILES\n";
84     print "Merges ROOT files containing histograms and produces a cutflow table in the\n";
85     print "form of a LaTeX document from the histogram named \"cutFlow\". If there are\n";
86     print "Condor logs in the specified directories, checks for nonzero return values.\n";
87     print "\n";
88     print "Mandatory arguments to long options are mandatory for short options too.\n";
89     printf "%-29s%s\n", " -h, --help", "print this help message";
90     printf "%-29s%s\n", " -p, --prefix PREFIX", "output files are named PREFIX.root and PREFIX.tex";
91    
92     exit;
93     }