Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:57

0001 #! /usr/bin/perl
0002 # tar up all Run_*.root histo files run by run into directory
0003 # given in second arg
0004 
0005 use warnings;
0006 use strict;
0007 use Getopt::Long;
0008 
0009 
0010 my $dryrun;
0011 GetOptions("test"=>\$dryrun);
0012 
0013 if ( $#ARGV < 1 )
0014 {
0015     print "\nthis tars up all histogram files of a given run, arguments:\n 1st: indir, 2nd: outdir\n\n";
0016     print"flags:\n";
0017     print "--test: run in test mode\n";
0018     exit(2);
0019 }
0020 
0021 if (defined $dryrun)
0022 {
0023     print "running in test mode\n";
0024 }
0025 
0026 
0027 if (! -d $ARGV[0])
0028 {
0029     print "input directory $ARGV[0] not found\n";
0030     exit(2);
0031 }
0032 if (! -d $ARGV[1])
0033 {
0034     print "output directory $ARGV[1] not found\n";
0035     exit(2);
0036 }
0037 
0038 
0039 my %map = ();
0040 
0041 open(F,"find $ARGV[0]  -maxdepth 1 -type f -name 'Run*.root' |");
0042 
0043 
0044 while (my $line = <F> )
0045 {
0046     chomp $line;
0047     if ($line =~ /Run_(\d+)-.+_.+/)
0048     {
0049     my $runstr=$1;
0050     $map{$runstr}++;
0051     }
0052     elsif ($line =~ /Run_-(\d+)-.+_.+/)
0053     {
0054     die "negative runnumber -$1 in file $line\n";
0055     }
0056     else
0057     {
0058     die "could not extract run number from $line\n";
0059     }
0060 }
0061 close(F);
0062 
0063 foreach my $i (sort keys %map)
0064 {
0065     print "Tarring Run $i\n";
0066     if (! defined $dryrun)
0067     { 
0068     system("cd $ARGV[0]; tar -czvf $ARGV[1]/Run_$i.tar.gz *_$i\-*");
0069     }
0070 }
0071 
0072 exit