File indexing completed on 2024-04-06 12:22:58
0001
0002
0003 use warnings;
0004 use strict;
0005 $|++;
0006
0007 use DBI;
0008
0009 package TB04::RunDB;
0010
0011 use POSIX;
0012 my $dummy = time;
0013
0014 sub new {
0015 my $proto = shift;
0016 my $class = ref($proto) || $proto;
0017 my $this = {};
0018
0019 bless($this, $class);
0020 return $this;
0021 }
0022
0023
0024 sub connect {
0025 my $this = shift;
0026
0027 my $dbh = DBI->connect("DBI:mysql:host=suncms100.cern.ch;db=rclog",
0028 "WWW", "myWeb01", {RaiseError => 1})
0029 or die DBI->errstr();
0030
0031 $this->{dbh} = $dbh;
0032 }
0033
0034
0035 sub load_from_db {
0036 my $this = shift;
0037 my $dbh = $this->{dbh} or die "Not connected to DB, $!\n";
0038
0039 my $sql = ;
0040 my $sth = $dbh->prepare($sql);
0041 $sth->execute();
0042 while (my ($run, $start, $stop) = $sth->fetchrow_array()) {
0043 $this->{runs}->{$run}->{since} = $start;
0044 $this->{runs}->{$run}->{till} = $stop;
0045 }
0046 }
0047
0048
0049 sub load_from_file {
0050 my $this = shift;
0051 my $file = shift;
0052
0053 open FILE, "<", $file or die $!;
0054 while (<FILE>) {
0055 chomp;
0056 my ($run, $start, $stop) = split /,/;
0057 $this->{runs}->{$run}->{since} = $start;
0058 $this->{runs}->{$run}->{till} = $stop;
0059 }
0060 close FILE;
0061 }
0062
0063
0064 sub fill_runs_table {
0065 my $this = shift;
0066 my $dest_db = shift;
0067
0068 foreach my $run (sort keys %{$this->{runs}}) {
0069 my $since = $this->{runs}->{$run}->{since};
0070 my $till = $this->{runs}->{$run}->{till};
0071 my $IoV = { since => $since, till => $till };
0072 $dest_db->insert_run(-run_number => $run,
0073 -IoV => $IoV );
0074 }
0075 }
0076
0077
0078 sub get_iov {
0079 my $this = shift;
0080 my $run = shift;
0081
0082 return $this->{runs}->{$run};
0083 }
0084
0085 sub get_dummy_iov {
0086 my $since = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime($dummy));
0087 $dummy++;
0088 my $till = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime($dummy));
0089 return {since=>$since, till=>$till};
0090 }
0091
0092
0093 sub dump_iov {
0094 my $this = shift;
0095 my $run = shift;
0096
0097 my $dbh = $this->{dbh} or die "Not connected to DB, $!\n";;
0098 my $sql = ;
0099 my $sth = $dbh->prepare($sql);
0100 $sth->execute();
0101 while (my @row = $sth->fetchrow_array()) {
0102 print join(",", @row), "\n";
0103 }
0104 }
0105
0106 1;