Dear ROOT users,
I have to serialyze an analysis with a Perl script. This is my first Perl script, so I’d like to have a little help!
I have to use these commands:
root -l
.L C14TotalFit.cc
and, for each rootfile into “rootfile” folder, I have to call my function:
C14TotalFit("/home/rootfiles/nomefile.root", “/home/results/nomefile.root”)
This is the script I created, but it doesn’t seem to work; in particular, I get these errors on the terminal:
[…]$ chmod u+x doC14.pl
[…]$ ./doC14.pl
root -l
.L ‘/home/C14Fit/C14TotalFit.cc
C14TotalFit("/home/rootfiles/filename001.root", “/home/results/filename001.root”)‘
sh: -c: line 0: syntax error near unexpected token "/home/rootfiles/filename001.root",' sh: -c: line 0:
C14TotalFit("/home/rootfiles/filename001.root", “/home/results/filename001.root”)’’
Here’s the code:
[code]#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use Cwd;
my $infile_path = ‘/home/rootfiles’; # path of rootfiles
my $outfile_path = ‘/home/results’; # path of results
my $here = getcwd; # current working directory
foreach my $arg (@ARGV){
if (($arg =~ /^help$/i) || ($arg =~/^usage$/i)){
# usage();
exit;
}
elsif ($arg =~ /^infile_path=(\w+)/){
$infile_path = $1;
}
elsif ($arg =~ /^outfile_path=(\w+)/){
$outfile_path = $1;
}
else {
die " ERROR: unknown parameter $arg \n";
}
}
chdir $infile_path or die “Cannot chroot to $infile_path: $!\n”;
my @files = glob($infile_path."/*.root");
my $init = “root -l”;
print $init."\n";
$init
;
my $load = “.L '${here}/C14TotalFit.cc”;
print $load."\n";
$load
;
root -l
.L C14TotalFit.cc
foreach my $file (@files){
C14TotalFit("/home/rootfiles/nomefile.root", “/home/results/nomefile.root”)
my $cmd = "C14TotalFit(\"";
$cmd = $cmd.$infile_path.'/';
$cmd = $cmd.basename($file);
$cmd = $cmd."\", \"";
$cmd = $cmd.$outfile_path.'/';
$cmd = $cmd.basename($file);
$cmd = $cmd."\")'";
print $cmd."\n";
`$cmd`;
}[/code]
Thank you!!