Changeset 28168
- Timestamp:
- May 28, 2010, 5:39:15 PM (16 years ago)
- Location:
- branches/haf_branches/ipp.20100512/ippScripts
- Files:
-
- 2 edited
-
Build.PL (modified) (1 diff)
-
scripts/minidvodb_createdb.pl (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/haf_branches/ipp.20100512/ippScripts/Build.PL
r27504 r28168 61 61 scripts/magic_destreak_cleanup.pl 62 62 scripts/magic_destreak_defineruns.pl 63 scripts/minidvodb_createdb.pl 64 scripts/minidvodb_load.pl 63 65 scripts/ippdb.pl 64 66 scripts/ipp_cleanup.pl -
branches/haf_branches/ipp.20100512/ippScripts/scripts/minidvodb_createdb.pl
r28104 r28168 4 4 use strict; 5 5 use Carp; 6 6 use DateTime; 7 8 use DateTime::Format::Strptime; 9 use DateTime::Duration; 7 10 ## report the program and machine 8 11 use Sys::Hostname; … … 12 15 print "Starting script $0 on $host at $date\n\n"; 13 16 14 use DateTime; 17 15 18 my $mjd_start = DateTime->now->mjd; # MJD of starting script 16 19 … … 36 39 } 37 40 38 my ( $outroot, $dbname, $dvodb, $minidvodb_group, $camera, $verbose, $no_update,41 my ( $outroot, $dbname, $dvodb,$minidvodb_interval, $minidvodb_group, $camera, $verbose, $no_update, 39 42 $no_op, $redirect, $save_temps); 40 43 GetOptions( … … 44 47 'outroot|w=s' => \$outroot, # output file base name 45 48 'dvodb|w=s' => \$dvodb, # output DVO database 49 'interval|w=s' => \$minidvodb_interval, #interval between creation of minidvodbs (default = 1day) 46 50 'verbose' => \$verbose, # Print to stdout 47 51 'no-update' => \$no_update, # Update the database? … … 57 61 ) unless 58 62 defined $minidvodb_group and 59 #defined $camera and60 #defined $outroot and63 defined $camera and 64 defined $outroot and 61 65 defined $dvodb; 62 66 … … 72 76 } 73 77 78 74 79 # Recipes to use based on reduction class 75 80 … … 82 87 83 88 # the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs 84 89 my $create_new = 0; 85 90 # convert supplied DVO database name to UNIX filename 86 91 my $dvodbReal; … … 93 98 } 94 99 95 100 if (!defined $minidvodb_interval) { 101 $minidvodb_interval = 1; 102 } 96 103 97 104 98 105 unless ($no_op) { 99 106 100 101 102 #see if there is already a new_not_ready107 108 109 #see if there is already one in new state 103 110 my $fpaCommand1 = "$addtool -listminidvodbrun"; 104 111 $fpaCommand1 .= " -minidvodb_group '$minidvodb_group'"; 105 112 $fpaCommand1 .= " -state 'new'"; 106 $fpaCommand1 .= " -dbname $dbname" if defined $dbname;107 108 print $fpaCommand1;113 $fpaCommand1 .= " -dbname $dbname" if defined $dbname; 114 115 109 116 unless ($no_update) { 110 117 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 111 118 run(command => $fpaCommand1, verbose => $verbose); 112 unless ($success) { 113 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 114 warn("Unable to list minidvodb database: $error_code\n"); 115 exit($error_code); 116 } 117 print "xxx"; 118 print scalar(@{$stdout_buf}); 119 120 121 122 unless ($success) { 123 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 124 warn("Unable to list minidvodb database: $error_code\n"); 125 exit($error_code); 126 } 127 119 128 if (scalar(@{$stdout_buf})) { 120 129 $error_code = 3; … … 122 131 exit($error_code); 123 132 } 133 134 my $creation_date; 135 my $addRun_count; 136 my $minidvodb_name; 137 #find the active one's date, and find out if it has more than 1 addRun in it 138 139 my $fpaCommand2 = "$addtool -listminidvodbrun"; 140 $fpaCommand2 .= " -minidvodb_group '$minidvodb_group'"; 141 $fpaCommand2 .= " -state 'active'"; 142 $fpaCommand2 .= " -limit 1"; 143 $fpaCommand2 .= " -dbname $dbname" if defined $dbname; 144 145 #print $fpaCommand2; 146 147 148 my ( $success2, $error_code2, $full_buf2, $stdout_buf2, $stderr_buf2 ) = 149 run(command => $fpaCommand2, verbose => $verbose); 150 &my_die( "Unable to get listminidvodbrun",$minidvodb_group, $PS_EXIT_SYS_ERROR) unless $success2; 151 # if it didn't list something in active state (what?) then we definitely need to create a new one 152 if (defined(@$stdout_buf2)) { 153 my $metadata2 = $mdcParser->parse(join "", @$stdout_buf2) or 154 &my_die("Unable to parse metadata config", $minidvodb_group, $PS_EXIT_PROG_ERROR); 155 156 my $components2 = parse_md_list($metadata2) or 157 &my_die("Unable to parse metadata list", $minidvodb_group, $PS_EXIT_PROG_ERROR); 158 my $comp2 = $$components2[0]; 159 $minidvodb_name = $comp2->{minidvodb_name}; 160 $creation_date = $comp2->{creation_date}; 161 if (!defined($minidvodb_name)) { 162 &my_die("Unable to parse minidvodb_name", $minidvodb_group, $PS_EXIT_PROG_ERROR); 163 } 164 if (!defined($creation_date)) { 165 &my_die("Unable to parse creation_date", $minidvodb_group, $PS_EXIT_PROG_ERROR); 166 } 167 } else { 168 $create_new = 1; #this is to force it to make a new one 169 } 170 171 #find the number of add_ids that have been proccessed 172 my $fpaCommand3 = "$addtool -checkminidvodbrunaddrun"; 173 $fpaCommand3 .= " -minidvodb_group '$minidvodb_group'"; 174 $fpaCommand3 .= " -state 'active'"; 175 $fpaCommand3 .= " -minidvodb_name '$minidvodb_name'" if defined $minidvodb_name; 176 $fpaCommand3 .= " -limit 1"; 177 $fpaCommand3 .= " -dbname $dbname" if defined $dbname; 178 124 179 125 180 my ( $success3, $error_code3, $full_buf3, $stdout_buf3, $stderr_buf3 ) = 181 run(command => $fpaCommand3, verbose => $verbose); 182 &my_die( "Unable to get checkminidvodbunaddrun", $minidvodb_group, $PS_EXIT_SYS_ERROR) unless $success3; 183 184 if (defined(@$stdout_buf3)) { #checkminidvodb returns nothing IF there have been no addruns added to the db yet 185 my $metadata3 = $mdcParser->parse(join "", @$stdout_buf3) or 186 &my_die("Unable to parse metadata config", $minidvodb_group, $PS_EXIT_PROG_ERROR); 187 188 my $components3 = parse_md_list($metadata3) or 189 &my_die("Unable to parse metadata list", $minidvodb_group, $PS_EXIT_PROG_ERROR); 190 my $comp = $$components3[0]; 191 $addRun_count = $comp->{addRun_count}; 192 } 193 if (!defined($addRun_count)) { 194 ## there's nothing to parse if there's nothing 195 $addRun_count = 0; 196 } 197 198 199 if ($addRun_count > 30000) { 200 #it's too big, create_new 201 $create_new = 1; 202 } 203 if ($create_new == 0) { 204 my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S' ); 205 my $creation_dt = $parser->parse_datetime( $creation_date )->mjd; 206 if ($mjd_start- $creation_dt > $minidvodb_interval && $addRun_count > 0 ) { 207 #db is old and has stuff in it, want to create_new 208 $create_new = 1; 209 } 210 } 211 212 126 213 } 127 214 #create the minidvodb entry (well, the command for it) … … 129 216 $fpaCommand .= " -set_minidvodb_group $minidvodb_group"; 130 217 $fpaCommand .= " -set_mergedvodb_path $dvodbReal"; 131 $fpaCommand .= " -dbname $dbname" if defined $dbname; 132 print $fpaCommand; 133 # complain if it doesn't work 134 unless ($no_update) { 135 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 136 run(command => $fpaCommand, verbose => $verbose); 137 unless ($success) { 138 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 139 warn("Unable to add result to database: $error_code\n"); 140 exit($error_code); 141 } 142 } else { 143 print "skipping command: $fpaCommand\n"; 144 } 218 $fpaCommand .= " -dbname $dbname" if defined $dbname; 219 220 unless ($no_update or !$create_new) { 221 222 223 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 224 run(command => $fpaCommand, verbose => $verbose); 225 unless ($success) { 226 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 227 warn("Unable to add result to database: $error_code\n"); 228 exit($error_code); 229 } 230 } else { 231 print "skipping command: $fpaCommand\n"; 232 } 145 233 } 146 234 … … 150 238 my $minidvodb_group = shift; # Camtool identifier 151 239 my $exit_code = shift; # Exit code to add 152 240 153 241 $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code; 154 242 155 243 carp($msg); 156 244
Note:
See TracChangeset
for help on using the changeset viewer.
