15 |
|
sub downloadRelease; |
16 |
|
sub datasetExists; |
17 |
|
sub uploadConfig; |
18 |
+ |
sub locationExists; |
19 |
|
|
20 |
|
our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped"; |
21 |
|
|
42 |
|
print "The Python config and ntuple release must be given!\n"; |
43 |
|
exit; |
44 |
|
} |
45 |
+ |
if ($opt{"location"} && locationExists ($opt{"location"})) |
46 |
+ |
{ |
47 |
+ |
print "This location is already registered in the database!\n"; |
48 |
+ |
exit; |
49 |
+ |
} |
50 |
|
if ($ARGV[0] eq "uploadRelease") |
51 |
|
{ |
52 |
|
my $parentDir = "./$opt{'release'}"; |
293 |
|
my $query; |
294 |
|
if ($id < 0) |
295 |
|
{ |
296 |
+ |
$query = "select id from ntuple where dataset='$dataset'"; |
297 |
+ |
$db->selectdb ("ntuple"); |
298 |
+ |
$results = $db->query ($query); |
299 |
+ |
if ($results->numrows ()) |
300 |
+ |
{ |
301 |
+ |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
302 |
+ |
my $response = <STDIN>; |
303 |
+ |
$response =~ s/\n//g; |
304 |
+ |
$response = "n" if !$response; |
305 |
+ |
exit if substr (lc ($response), 0, 1) ne 'y'; |
306 |
+ |
} |
307 |
+ |
|
308 |
|
$query = "select max(id) from ntuple"; |
309 |
|
$db->selectdb ("ntuple"); |
310 |
|
$results = $db->query ($query); |
724 |
|
$db->selectdb ("ntuple"); |
725 |
|
$results = $db->query ($query); |
726 |
|
} |
727 |
+ |
|
728 |
+ |
sub |
729 |
+ |
locationExists |
730 |
+ |
{ |
731 |
+ |
my $location = shift; |
732 |
+ |
|
733 |
+ |
$location =~ s/^(.*)\/+$/$1/; |
734 |
+ |
my $query = "select id from ntuple where location like '$location%'"; |
735 |
+ |
$db->selectdb ("ntuple"); |
736 |
+ |
my $results = $db->query ($query); |
737 |
+ |
return 1 if $results->numrows (); |
738 |
+ |
|
739 |
+ |
if ($location =~ m/^\/store\/.*$/) |
740 |
+ |
{ |
741 |
+ |
$location =~ s/^\/store\/(.*)$/\/data\/se\/store\/$1/; |
742 |
+ |
} |
743 |
+ |
elsif ($location =~ m/^\/data\/se\/store\/.*$/) |
744 |
+ |
{ |
745 |
+ |
$location =~ s/^\/data\/se\/store\/(.*)$/\/store\/$1/; |
746 |
+ |
} |
747 |
+ |
|
748 |
+ |
my $query = "select id from ntuple where location like '$location%'"; |
749 |
+ |
$db->selectdb ("ntuple"); |
750 |
+ |
my $results = $db->query ($query); |
751 |
+ |
return 1 if $results->numrows (); |
752 |
+ |
|
753 |
+ |
return 0; |
754 |
+ |
} |