Changeset 38937
- Timestamp:
- Oct 21, 2015, 5:44:52 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
ippScripts/scripts/addstar_run.pl (modified) (12 diffs)
-
ippTasks/addstar.pro (modified) (5 diffs)
-
ippTools/share/addtool_find_ffsummary_id.sql (modified) (1 diff)
-
ippTools/share/addtool_find_ffsummary_id_dvo.sql (modified) (1 diff)
-
ippTools/src/addtool.c (modified) (55 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/addstar_run.pl
r38090 r38937 31 31 my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1); 32 32 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1); 33 my $fftool = can_run('fftool') or (warn "Can't find fftool" and $missing_tools = 1); 34 33 35 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 36 34 37 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1); 38 my $loadgalphot = can_run('loadgalphot') or (warn "Can't find loadgalphot" and $missing_tools = 1); 39 35 40 if ($missing_tools) { 36 41 warn("Can't find required tools."); … … 92 97 } 93 98 99 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 100 101 # Output products 102 $ipprc->outroot_prepare($outroot); 103 104 105 # 106 # Step 1: sort out reductions / recipes 107 # 108 109 94 110 # Recipes to use based on reduction class 95 111 $reduction = 'DEFAULT' unless defined $reduction; … … 101 117 #} 102 118 103 if ($stage =~/fullforce/) {119 if ($stage eq 'fullforce') { 104 120 $reduction='DEFAULT'; 105 121 #hardwired because why not 106 122 } 107 if ($stage =~/diff/) { 123 elsif ($stage eq 'fullforce_summary') { 124 $reduction = 'DEFAULT'; 125 } 126 elsif ($stage eq 'diff') { 108 127 $reduction='DEFAULT'; 109 128 #hardwired because why not … … 112 131 my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); 113 132 # XXX This is now not used: do we still need it? 114 if ($stage =~/cam/) {133 if ($stage eq 'cam') { 115 134 $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use 116 135 } 117 if ($stage =~/stack/) {136 elsif ($stage eq 'stack') { 118 137 $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STACK'); # Recipe to use 138 } 139 elsif ($stage eq 'skycal') { 140 $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use 119 141 } 120 142 #if ($stage =~/staticsky/) { 121 143 # $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STATICSKY'); # Recipe to use 122 144 #} 123 if ($stage =~/skycal/) {124 $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use125 }126 145 127 146 … … 129 148 &my_die("Unrecognised ADDSTAR recipe", $add_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar; 130 149 131 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files132 133 # Output products134 $ipprc->outroot_prepare($outroot);135 150 136 151 # the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs 152 153 # 154 # Step 2: Determine where sources should come from, modify them as needed. 155 # 156 137 157 138 158 # it was PSASTRO.OUTPUT … … 141 161 my $fpaObjectsAlt = $fpaObjects; 142 162 143 if ($stage =~ /skycal/) {163 if ($stage eq 'skycal') { 144 164 #should be ok for skycal? 145 165 print "using $fpaObjects for $stage\n"; 146 166 } 147 if ($stage =~/diff/) {167 elsif ($stage eq 'diff') { 148 168 print "using $fpaObjects for $stage\n"; 149 169 } 150 if ($stage =~/fullforce/) {170 elsif ($stage eq 'fullforce') { 151 171 print "using $fpaObjects for $stage\n"; 152 172 } 153 173 154 155 156 if ($stage =~ /cam/) { 174 if ($stage eq 'cam') { 157 175 # if it is cam stage we need to be careful when grabbing the filename. 158 176 # This breaks down into a few steps: … … 197 215 } 198 216 199 if (($stage =~/stack/ || $stage =~ /skycal/ || $stage =~/diff/ || $stage=~/fullforce/)) { 217 if (($stage eq 'stack') || 218 ($stage eq 'skycal') || 219 ($stage eq 'diff') || 220 ($stage eq 'fullforce')|| 221 ($stage eq 'fullforce_summary')) { 200 222 $fpaObjects =~ s/smf$/cmf/; 201 223 $fpaObjectsAlt =~ s/smf$/cmf/; 202 203 224 } 204 225 … … 206 227 my $fpaObjects2; 207 228 my $checkalt = 0; 208 if ($stage =~/staticsky/) {229 if ($stage eq 'staticsky') { 209 230 $checkalt = 1; 210 231 my $sources = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $stageroot); #this is mostly rigtht except the .cmf needs either … … 239 260 $fpaObjects = $fpaObjects1; 240 261 } 241 242 243 } 262 } 263 264 265 # 266 # Step 3 Set up addtool/loadgalphot commands. 267 # 244 268 245 269 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); … … 251 275 $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal ) or &my_die("can't get path for dvodb", $add_id, $PS_EXIT_CONFIG_ERROR); 252 276 } 277 253 278 my $dtime_addstar = 0; 254 279 if (defined $dvodbReal) { 255 280 if ($minidvodb) { 256 my $command = " addtool -listminidvodbrun ";281 my $command = "$addtool -listminidvodbrun "; 257 282 $command .= " -minidvodb_group $minidvodb_group" if defined $minidvodb_group; 258 283 $command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; … … 285 310 unless ($no_op) { 286 311 print $dvodbReal; 287 288 312 ## addstar can either save the full set of detections, or just 289 313 ## the image metadata, in the dvodb. this is set in the … … 311 335 } 312 336 313 # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default) 314 my $command = "$addstar -update"; # XXX optionally set -update? 315 $command .= " -D CAMERA $camdir"; 316 $command .= " -D CATDIR $minidvodb_path"; 317 $command .= " -D ZERO_POINT_OPTION $zeroPointOption"; 318 $command .= " $realFile"; 319 $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference 320 $command .= " -image" if $image_only; 321 if ($stage =~ /staticsky/) { 322 $command .= " -accept-astrom -quick-airmass"; 323 } #careful here - this matches staticsky and staticsky_multi 324 if ($stage =~ /skycal/) { 325 $command .= " -quick-airmass"; 326 } #careful here - this matches staticsky and staticsky_multi 327 if ($stage =~ /diff/) { 328 $command .= " -accept-astrom"; 337 my $command; 338 339 if ($stage ne 'fullforce_summary') { 340 # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default) 341 $command = "$addstar -update"; # XXX optionally set -update? 342 $command .= " -D CAMERA $camdir"; 343 $command .= " -D CATDIR $minidvodb_path"; 344 $command .= " -D ZERO_POINT_OPTION $zeroPointOption"; 345 $command .= " $realFile"; 346 $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference 347 $command .= " -image" if $image_only; 348 if ($stage =~ /staticsky/) { 349 $command .= " -accept-astrom -quick-airmass"; 350 } #careful here - this matches staticsky and staticsky_multi 351 if ($stage =~ /skycal/) { 352 $command .= " -quick-airmass"; 353 } #careful here - this matches staticsky and staticsky_multi 354 if ($stage =~ /diff/) { 355 $command .= " -accept-astrom"; 356 } 357 if ($stage =~ /fullforce/) { 358 $command .= " -accept-astrom -xrad"; 359 } 329 360 } 330 if ($stage =~ /fullforce/) { 331 $command .= " -accept-astrom -xrad"; 361 else { # Full force summary case 362 # We need to know the filter to set up the photcode, as the summaries do not include that in the header. 363 # We /could/ set up the addtool stuff to pass that in to the script when needed, but that would require adding 364 # a lot of extra hooks and option handlers. Therefore, call out to fftool, and get the filter that way, and 365 # construct the correct photcode. 366 367 my $photcode = ''; 368 { 369 my $ff_command = "$fftool -dbname ${dbname} -summary -ff_id ${stage_id}"; 370 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 371 run(command => $command, verbose => $verbose); 372 unless ($success) { 373 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 374 &my_die("Unable to fetch filter via fftool: $error_code", $add_id, $error_code); 375 } 376 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 377 &my_die("Unable to determine ff summary information.", $add_id, $error_code); 378 my $metadata = parse_md_list($MDlist); 379 my $ffSummary = $metadata->[0]; 380 my $filter = $ffSummary->{filter}; 381 382 $filter =~ s/\.00000//; 383 $photcode = "GPC1.${filter}.ForcedWarp"; 384 } 385 386 $command = "$loadgalphot -v "; 387 $command .= " -D CAMERA $camdir "; 388 $command .= " -D CATDIR $minidvodb_path "; 389 $command .= " $realFile "; 390 $command .= " -p $photcode "; 332 391 } 333 392 334 393 my $mjd_addstar_start = DateTime->now->mjd; # MJD of starting script 335 394 336 395 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 337 396 run(command => $command, verbose => $verbose); -
trunk/ippTasks/addstar.pro
r38582 r38937 244 244 $addstar_revert_DB_SC = 0 245 245 $addstar_revert_DB_FF = 0 246 $addstar_revert_DB_FFS = 0 246 247 $addstar_revert_DB_DF = 0 248 247 249 248 250 #$LOADEXEC_ADD = 300 … … 452 454 sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID 453 455 end 456 if ("$STAGE" == "fullforce_summary") 457 sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID 458 end 454 459 455 460 … … 468 473 $run = $run --stage_id $STAGE_ID 469 474 end 470 if ("$STAGE" == "skycal")475 if ("$STAGE" == "skycal") 471 476 $run = $run --stage_id $STAGE_ID 472 477 end 473 if ("$STAGE" == "diff")478 if ("$STAGE" == "diff") 474 479 $run = $run --stage_id $STAGE_ID --stage_extra1 $STAGE_EXTRA1 475 480 end 476 if ("$STAGE" == "fullforce")481 if ("$STAGE" == "fullforce") 477 482 $run = $run --stage_id $STAGE_ID --stage_extra1 $STAGE_EXTRA1 483 end 484 if ("$STAGE" == "fullforce_summary") 485 # This shouldn't need a stage_extra1, as there are no subcomponents to the ff summary. 486 $run = $run --stage_id 478 487 end 479 488 … … 596 605 sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID 597 606 end 607 if ("$STAGE" == "fullforce_summary") 608 sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID 609 end 598 610 599 611 … … 949 961 end 950 962 end 963 964 task addstar.revert.fullforce_summary 965 host local 966 967 periods -poll 5.0 968 periods -exec 60.0 969 periods -timeout 1200 970 npending 1 971 active false 972 973 stdout NULL 974 stderr $LOGDIR/revert.log 975 976 task.exec 977 if ($LABEL:n == 0) break 978 $run = addtool -revertprocessedexp -stage fullforce_summary 979 if ($DB:n == 0) 980 option DEFAULT 981 else 982 # save the DB name for the exit tasks 983 option $DB:$addstar_revert_DB_FFS 984 $run = $run -dbname $DB:$addstar_revert_DB_FFS 985 $addstar_revert_DB_FFS ++ 986 if ($addstar_revert_DB_FFS >= $DB:n) set addstar_revert_DB_FFS = 0 987 end 988 add_poll_labels run 989 command $run 990 end 991 992 # success 993 task.exit 0 994 end 995 996 # locked list 997 task.exit default 998 showcommand failure 999 end 1000 1001 task.exit crash 1002 showcommand crash 1003 end 1004 1005 # operation times out? 1006 task.exit timeout 1007 showcommand timeout 1008 end 1009 end -
trunk/ippTools/share/addtool_find_ffsummary_id.sql
r38846 r38937 1 SELECT 2 fullForceRun.* 3 FROM 4 fullForceRun 5 JOIN fullForceSummary using (ff_id) 6 7 LEFT JOIN (SELECT ff_id AS added_ff_id, 8 addRun.dvodb AS previous_dvodb 9 FROM addRun 10 JOIN fullForceRun on (ff_id = stage_id and addRun.stage = 'fullforce_summary') 11 ) as foo 12 ON ff_id = added_ff_id 13 --AND stage = 'skycal' 1 SELECT fullForceRun.* FROM fullForceRun 2 JOIN fullForceSummary USING (ff_id) 3 LEFT JOIN ( 4 SELECT ff_id AS added_ff_id, 5 addRun.dvodb AS previous_dvodb 6 FROM addRun 7 JOIN fullForceRun ON (ff_id = stage_id and addRun.stage = 'fullforce_summary') 8 ) as foo 9 ON ff_id = added_ff_id 10 -- AND stage = 'skycal' 14 11 -- hook for qualifying the join on the previous_dvodb 15 12 AND %s -
trunk/ippTools/share/addtool_find_ffsummary_id_dvo.sql
r38846 r38937 1 SELECT fullForceRun.* FROM fullForceRun JOIN fullForceSummary using (ff_id) 2 JOIN skycalRun using (skycal_id) join stackRun using (stack_id) 3 JOIN skycell using (skycell_id, tess_id) 1 SELECT fullForceRun.* FROM fullForceRun 2 JOIN fullForceSummary USING (ff_id) 3 JOIN skycalRun USING (skycal_id) 4 JOIN stackRun USING (stack_id) 5 JOIN skycell USING (skycell_id, tess_id) 4 6 5 WHERE fullForceRun.state = 'full' and fullForceSummary.quality = 0 and fullForceSummary.fault = 0 6 AND fullForceRun.ff_id NOT IN (SELECT fullForceRun.ff_id 7 FROM addRun 8 JOIN fullForceRun on (fullForceRun.ff_id = addRun.stage_id and addRun.stage = 'fullforce_summary') JOIN fullForceSummary on (fullForceRun.ff_id = fullForceSummary.ff_id) 7 WHERE fullForceRun.state = 'full' 8 AND fullForceSummary.quality = 0 9 AND fullForceSummary.fault = 0 10 AND fullForceRun.ff_id NOT IN ( 11 SELECT fullForceRun.ff_id FROM addRun 12 JOIN fullForceRun ON (fullForceRun.ff_id = addRun.stage_id and addRun.stage = 'fullforce_summary') 13 JOIN fullForceSummary ON (fullForceRun.ff_id = fullForceSummary.ff_id) 9 14 WHERE addRun.stage = 'fullforce_summary' AND %s 10 )15 ) -
trunk/ippTools/src/addtool.c
r38848 r38937 124 124 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffRun.diff_id", "=="); 125 125 PXOPT_COPY_S64(config->args, where, "-ff_id", "fullForceRun.ff_id", "=="); 126 127 PXOPT_LOOKUP_STR(stage, config->args, "-stage", false, false); 128 if (strcmp(stage, "cam")== 0) { 129 pxcamGetSearchArgs (config, where); 130 pxAddLabelSearchArgs (config, where, "-label", "camRun.label", "=="); // define using camRun label 131 pxAddLabelSearchArgs (config, where, "-data_group","camRun.data_group", "=="); // define using camRun label 132 PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "=="); 133 } 134 if (strcmp(stage, "stack")== 0) { 135 pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "=="); // define using camRun label 136 pxAddLabelSearchArgs (config, where, "-data_group","stackRun.data_group", "=="); // define using camRun label 137 PXOPT_COPY_STR(config->args, where, "-reduction", "stackRun.reduction", "=="); 138 pxAddLabelSearchArgs (config, where, "-filter", "stackRun.filter", "=="); // define using camRun label 139 } 140 if (strcmp(stage, "staticsky")== 0) { 141 pxAddLabelSearchArgs (config, where, "-label", "staticskyRun.label", "=="); // define using camRun label 142 pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label 143 PXOPT_COPY_STR(config->args, where, "-reduction", "staticskyRun.reduction", "=="); 144 //no filter here 145 } 146 if (strcmp(stage, "skycal")==0) { 147 pxAddLabelSearchArgs (config, where, "-label", "skycalRun.label", "=="); //define using skycalRun label 148 pxAddLabelSearchArgs (config, where, "-data_group","skycalRun.data_group", "=="); 149 PXOPT_COPY_STR(config->args, where, "-reduction", "skycalRun.reduction", "=="); 150 } 151 if (strcmp(stage, "diff")==0) { 152 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); //define using skycalRun label 153 pxAddLabelSearchArgs (config, where, "-data_group","diffRun.data_group", "=="); 154 PXOPT_COPY_STR(config->args, where, "-reduction", "diffRun.reduction", "=="); 155 } 156 if (strcmp(stage, "fullforce")==0) { 157 pxAddLabelSearchArgs (config, where, "-label", "fullForceRun.label", "=="); //define using skycalRun label 158 pxAddLabelSearchArgs (config, where, "-data_group","fullForceRun.data_group", "=="); 159 PXOPT_COPY_STR(config->args, where, "-reduction", "fullForceRun.reduction", "=="); 160 } 161 if (strcmp(stage, "fullforce_summary")==0) { 162 //should be nearly identical to fullforce (uses the same tables) 163 pxAddLabelSearchArgs (config, where, "-label", "fullForceRun.label", "=="); 164 pxAddLabelSearchArgs (config, where, "-data_group","fullForceRun.data_group", "=="); 165 PXOPT_COPY_STR(config->args, where, "-reduction", "fullForceRun.reduction", "=="); 166 } 167 168 169 170 if (!psListLength(where->list)) { 171 psFree(where); 172 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 173 return false; 174 } 175 126 176 127 // PXOPT_LOOKUP_STR(stage, config->args, "-stage", false, false); 177 128 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false); … … 194 145 PXOPT_LOOKUP_F32(mindec, config->args, "-set_mindec", false, false); 195 146 PXOPT_LOOKUP_F32(maxdec, config->args, "-set_maxdec", false, false); 147 148 // Handle stages 149 PXOPT_LOOKUP_STR(stage, config->args, "-stage", false, false); 150 if (strcmp(stage, "cam") == 0) { 151 pxcamGetSearchArgs (config, where); 152 pxAddLabelSearchArgs (config, where, "-label", "camRun.label", "=="); // define using camRun label 153 pxAddLabelSearchArgs (config, where, "-data_group","camRun.data_group", "=="); // define using camRun label 154 PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "=="); 155 } 156 else if (strcmp(stage, "stack") == 0) { 157 pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "=="); // define using camRun label 158 pxAddLabelSearchArgs (config, where, "-data_group","stackRun.data_group", "=="); // define using camRun label 159 PXOPT_COPY_STR(config->args, where, "-reduction", "stackRun.reduction", "=="); 160 pxAddLabelSearchArgs (config, where, "-filter", "stackRun.filter", "=="); // define using camRun label 161 } 162 else if (strcmp(stage, "staticsky") == 0) { 163 pxAddLabelSearchArgs (config, where, "-label", "staticskyRun.label", "=="); // define using camRun label 164 pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label 165 PXOPT_COPY_STR(config->args, where, "-reduction", "staticskyRun.reduction", "=="); 166 //no filter here 167 } 168 else if (strcmp(stage, "skycal") == 0) { 169 pxAddLabelSearchArgs (config, where, "-label", "skycalRun.label", "=="); //define using skycalRun label 170 pxAddLabelSearchArgs (config, where, "-data_group","skycalRun.data_group", "=="); 171 PXOPT_COPY_STR(config->args, where, "-reduction", "skycalRun.reduction", "=="); 172 } 173 else if (strcmp(stage, "diff") == 0) { 174 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); //define using diffRun label 175 pxAddLabelSearchArgs (config, where, "-data_group","diffRun.data_group", "=="); 176 PXOPT_COPY_STR(config->args, where, "-reduction", "diffRun.reduction", "=="); 177 } 178 else if (strcmp(stage, "fullforce") == 0) { 179 pxAddLabelSearchArgs (config, where, "-label", "fullForceRun.label", "=="); //define using fullForceRun label 180 pxAddLabelSearchArgs (config, where, "-data_group","fullForceRun.data_group", "=="); 181 PXOPT_COPY_STR(config->args, where, "-reduction", "fullForceRun.reduction", "=="); 182 } 183 else if (strcmp(stage, "fullforce_summary")==0) { 184 //should be nearly identical to fullforce (uses the same tables) 185 pxAddLabelSearchArgs (config, where, "-label", "fullForceRun.label", "=="); 186 pxAddLabelSearchArgs (config, where, "-data_group","fullForceRun.data_group", "=="); 187 PXOPT_COPY_STR(config->args, where, "-reduction", "fullForceRun.reduction", "=="); 188 } 189 190 if (!psListLength(where->list)) { 191 psFree(where); 192 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 193 return false; 194 } 196 195 196 // Select either destreaked or uncensored data. CZW: Should this be defaulted to uncensored? 197 if (!(destreaked && uncensored) && (destreaked || uncensored)) { 198 //if one of destreaked and uncensored is true, but not both 199 if (destreaked) { 200 psTrace("addtool.c", PS_LOG_INFO, "using -destreaked\n"); 201 } else { 202 psTrace("addtool.c", PS_LOG_INFO, "using -unscensored\n"); 203 } 204 } else { 205 if (destreaked && uncensored) { 206 psError(PS_ERR_UNKNOWN, false, "Both -destreaked and -uncensored are selected. Please use one or the other, not both, \n"); 207 return false; 208 } 209 if (!destreaked && !uncensored) { 210 psError(PS_ERR_UNKNOWN, false, "Neither -destreaked or -uncensored are selected. Please use one.\n"); 211 return false; 212 } 213 } 214 if ((strcmp(stage,"diff") == 0) || 215 (strcmp(stage,"fullforce") == 0) || 216 (strcmp(stage,"fullforce_summary") == 0)) { 217 if (! (dvodb)) { 218 psError(PS_ERR_UNKNOWN, false, "The SQL is not correctly written to handle this case (-set_dvodb not specified), so stopping here."); 219 return(false); 220 } 221 } 222 223 197 224 // prevent queueing an addRun if a given exposure has already been added to 198 225 // the given dvo database 199 226 psString dvodb_string = NULL; 200 227 psString bare_query = NULL; 201 202 if (!(destreaked && uncensored) && (destreaked || uncensored)) { 203 //if one of destreaked and uncensored is true, but not both 204 if (destreaked) { 205 psTrace("addtool.c", PS_LOG_INFO, "using -destreaked\n"); 206 } else { 207 psTrace("addtool.c", PS_LOG_INFO, "using -unscensored\n"); 208 } 209 } else { 210 if (destreaked && uncensored) { 211 psError(PS_ERR_UNKNOWN, false, "Both -destreaked and -uncensored are selected. Please use one or the other, not both, \n"); 212 return false; 213 } 214 if (!destreaked && !uncensored) { 215 psError(PS_ERR_UNKNOWN, false, "Neither -destreaked or -uncensored are selected. Please use one.\n"); 216 return false; 217 } 218 } 219 220 221 222 228 223 229 if (strcmp(stage,"cam") == 0 ) { 224 if (dvodb) {225 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_cam_id_dvo.sql\n%s\n", dvodb,stage);230 if (dvodb) { 231 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_cam_id_dvo.sql\n%s\n", dvodb,stage); 226 232 // find the cam_id of all the exposures that we want to queue up. 227 233 bare_query = pxDataGet("addtool_find_cam_id_dvo.sql"); 228 234 // user supplied dvodb 229 235 psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb); 230 } else {231 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_cam_id.sql\n%s\n",stage);236 } else { 237 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_cam_id.sql\n%s\n",stage); 232 238 // find the cam_id of all the exposures that we want to queue up. 233 239 bare_query = pxDataGet("addtool_find_cam_id.sql"); 234 240 // inherit dvodb from camRun, avoid matching NULL 235 241 psStringAppend(&dvodb_string, "(camRun.dvodb IS NOT NULL AND previous_dvodb = camRun.dvodb)"); 236 } 237 } 238 if (strcmp(stage,"stack") == 0) { 239 if (dvodb ) { 240 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_stack_id_dvo.sql\n%s\n", dvodb,stage); 242 } 243 } 244 245 else if (strcmp(stage,"stack") == 0) { 246 if (dvodb) { 247 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_stack_id_dvo.sql\n%s\n", dvodb,stage); 241 248 // find the cam_id of all the exposures that we want to queue up. 242 249 bare_query = pxDataGet("addtool_find_stack_id_dvo.sql"); 243 250 // user supplied dvodb 244 251 psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb); 245 } else {246 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_stack_id.sql\n%s\n",stage);252 } else { 253 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_stack_id.sql\n%s\n",stage); 247 254 // find the cam_id of all the exposures that we want to queue up. 248 255 bare_query = pxDataGet("addtool_find_stack_id.sql"); 249 256 // inherit dvodb from camRun, avoid matching NULL 250 257 psStringAppend(&dvodb_string, "(stackRun.dvodb IS NOT NULL AND previous_dvodb = stackRun.dvodb)"); 251 }252 } 253 254 if (strcmp(stage,"staticsky") == 0) {258 } 259 } 260 261 else if (strcmp(stage,"staticsky") == 0) { 255 262 if (dvodb ) { 256 263 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_sky_id_multi_dvo.sql\n%s\n", dvodb,stage); … … 267 274 } 268 275 } 269 270 if (strcmp(stage,"skycal") == 0) {271 if (dvodb ) {276 277 else if (strcmp(stage,"skycal") == 0) { 278 if (dvodb) { 272 279 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_skycal_id_dvo.sql\n%s\n", dvodb,stage); 273 // find the skycal_id of all the exposures that we want to queue up. 280 // find the skycal_id of all the exposures that we want to queue up. 274 281 bare_query = pxDataGet("addtool_find_skycal_id_dvo.sql"); 275 // user supplied dvodb 282 // user supplied dvodb 276 283 psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb); 277 284 } else { 278 285 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_skycal_id.sql\n%s\n",stage); 279 // find the skycal_id of all the exposures that we want to queue up. 286 // find the skycal_id of all the exposures that we want to queue up. 280 287 bare_query = pxDataGet("addtool_find_skycal_id.sql"); 281 // inherit dvodb from skycalRun, avoid matching NULL 288 // inherit dvodb from skycalRun, avoid matching NULL 282 289 psStringAppend(&dvodb_string, "(skycalRun.dvodb IS NOT NULL AND previous_dvodb = skycalRun.dvodb)"); 283 290 // this is silly, there is no dvodb in skycalRun...? … … 285 292 } 286 293 287 if (strcmp(stage,"diff") == 0) {288 if (dvodb ) {294 else if (strcmp(stage,"diff") == 0) { 295 if (dvodb) { 289 296 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_diff_id_dvo.sql\n%s\n", dvodb,stage); 290 // find the skycal_id of all the exposures that we want to queue up. 297 // find the skycal_id of all the exposures that we want to queue up. 291 298 bare_query = pxDataGet("addtool_find_diff_id_dvo.sql"); 292 // user supplied dvodb 299 // user supplied dvodb 293 300 psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb); 294 301 } else { 295 302 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_diff_id.sql\n%s\n",stage); 296 // find the skycal_id of all the exposures that we want to queue up. 303 // find the skycal_id of all the exposures that we want to queue up. 297 304 bare_query = pxDataGet("addtool_find_diff_id.sql"); 298 // inherit dvodb from skycalRun, avoid matching NULL 305 // inherit dvodb from skycalRun, avoid matching NULL 299 306 psStringAppend(&dvodb_string, "(diffRun.dvodb IS NOT NULL AND previous_dvodb = diffRun.dvodb)"); 300 307 // this is silly, there is no dvodb in skycalRun...? 301 308 } 302 303 304 } 305 306 if (strcmp(stage,"fullforce") == 0) { 307 if (dvodb ) { 309 } 310 311 else if (strcmp(stage,"fullforce") == 0) { 312 if (dvodb) { 308 313 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_ff_id_dvo.sql\n%s\n", dvodb,stage); 309 // find the skycal_id of all the exposures that we want to queue up. 314 // find the skycal_id of all the exposures that we want to queue up. 310 315 bare_query = pxDataGet("addtool_find_ff_id_dvo.sql"); 311 // user supplied dvodb 316 // user supplied dvodb 312 317 psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb); 313 318 } else { 314 319 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_ff_id.sql\n%s\n",stage); 315 // find the skycal_id of all the exposures that we want to queue up. 320 // find the skycal_id of all the exposures that we want to queue up. 316 321 bare_query = pxDataGet("addtool_find_ff_id.sql"); 317 // inherit dvodb from skycalRun, avoid matching NULL 322 // inherit dvodb from skycalRun, avoid matching NULL 318 323 psStringAppend(&dvodb_string, "(fullForceRun.dvodb IS NOT NULL AND previous_dvodb = fullForceRun.dvodb)"); 319 324 // this is silly, there is no dvodb in skycalRun...? 320 325 } 321 326 } 322 323 if (strcmp(stage,"fullforce_summary") == 0) { 324 if (dvodb ) { 327 else if (strcmp(stage,"fullforce_summary") == 0) { 328 if (dvodb) { 325 329 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_ffsummary_id_dvo.sql\n%s\n", dvodb,stage); 326 // find the skycal_id of all the exposures that we want to queue up. 330 // find the skycal_id of all the exposures that we want to queue up. 327 331 bare_query = pxDataGet("addtool_find_ffsummary_id_dvo.sql"); 328 // user supplied dvodb 332 // user supplied dvodb 329 333 psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb); 330 334 } else { 331 335 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_ffsummary_id.sql\n%s\n",stage); 332 // find the skycal_id of all the exposures that we want to queue up. 336 // find the skycal_id of all the exposures that we want to queue up. 333 337 bare_query = pxDataGet("addtool_find_ffsummary_id.sql"); 334 // inherit dvodb from skycalRun, avoid matching NULL 338 // inherit dvodb from skycalRun, avoid matching NULL 335 339 psStringAppend(&dvodb_string, "(fullForceRun.dvodb IS NOT NULL AND previous_dvodb = fullForceRun.dvodb)"); 336 340 // this is silly, there is no dvodb in skycalRun...? 337 341 } 338 342 } 339 340 341 342 343 343 344 344 if (!bare_query) { 345 345 psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement"); … … 347 347 return false; 348 348 } 349 349 350 // Take the bare query and add the dvodb selector 350 351 psString query = NULL; … … 357 358 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 358 359 psStringAppend(&query, " AND %s", whereClause); 359 if (strcmp(stage,"diff") == 0) { 360 361 if ((strcmp(stage,"diff") == 0)|| 362 (strcmp(stage,"fullforce") == 0)|| 363 (strcmp(stage,"fullforce_summary") == 0)) { 360 364 //diff needs the ra /deg stuff 365 //ff needs the ra /deg stuff 366 //ff summary needs the ra /deg stuff 361 367 psStringAppend(&query, " AND radeg >= %f", minra); 362 368 psStringAppend(&query, " AND radeg <= %f", maxra); 363 369 psStringAppend(&query, " AND decdeg >= %f", mindec); 364 370 psStringAppend(&query, " AND decdeg <= %f", maxdec); 365 366 }367 if (strcmp(stage,"fullforce") == 0) {368 //ff needs the ra /deg stuff369 psStringAppend(&query, " AND radeg >= %f", minra);370 psStringAppend(&query, " AND radeg <= %f", maxra);371 psStringAppend(&query, " AND decdeg >= %f", mindec);372 psStringAppend(&query, " AND decdeg <= %f", maxdec);373 374 }375 if (strcmp(stage,"fullforce_summary") == 0) {376 //ff needs the ra /deg stuff377 psStringAppend(&query, " AND radeg >= %f", minra);378 psStringAppend(&query, " AND radeg <= %f", maxra);379 psStringAppend(&query, " AND decdeg >= %f", mindec);380 psStringAppend(&query, " AND decdeg <= %f", maxdec);381 382 371 } 383 372 … … 391 380 if (destreaked) { 392 381 //This picks the magicked/censored ones 393 if (strcmp(stage,"cam") == 0) { 382 if ((strcmp(stage,"cam") == 0)|| 383 (strcmp(stage,"stack") == 0)) { 394 384 psStringAppend(&query, " AND (camRun.magicked > 0)"); 395 }396 if (strcmp(stage,"stack") == 0) {397 psStringAppend(&query, " AND (stackRun.magicked > 0)");398 385 } 399 386 // staticSky/skycal have no magicked column. … … 407 394 psStringAppend(&query, " AND (stackRun.magicked = 0)"); 408 395 } 409 410 } 411 412 //if we grab a group of camRun/stackRuns that have multiple camRun/stackRun pointing to the same exp_id/stack_id, and that exp_id/stack_id has never before been added to addRun, we need to group by exp_id/stack_id to ensure that only 1 of the camRun/stackRun for that exp_id is added to the addRun stage. 413 396 } 397 398 // if we grab a group of camRun/stackRuns that have multiple camRun/stackRun pointing to the same exp_id/stack_id, and that exp_id/stack_id has never before been added to addRun, we need to group by exp_id/stack_id to ensure that only 1 of the camRun/stackRun for that exp_id is added to the addRun stage. 399 414 400 if (strcmp(stage,"cam") == 0) { 415 psStringAppend(&query, " GROUP BY exp_id"); 416 } 417 if (strcmp(stage,"stack") == 0) { 418 psStringAppend(&query, " GROUP BY stack_id"); 419 } 420 // if (strcmp(stage,"staticsky") == 0) { 421 // psStringAppend(&query, " GROUP BY stack_id"); 422 // } 423 if (strcmp(stage,"staticsky") == 0) { 424 psStringAppend(&query, " GROUP BY sky_id, stack_id"); //some reason it needs this 425 } 426 if (strcmp(stage,"skycal") == 0) { 427 psStringAppend(&query, " GROUP BY skycal_id, sky_id, stack_id "); //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there 428 } 429 //needs to be checked HAF xxx 430 if (strcmp(stage,"diff") == 0) { 431 432 psStringAppend(&query, " GROUP BY diff_id, diff_skyfile_id "); //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there 433 } 434 //needs to be checked HAF xxx 435 if (strcmp(stage,"fullforce") == 0) { 436 psStringAppend(&query, " GROUP BY ff_id, warp_id "); //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there 437 } 438 if (strcmp(stage,"fullforce_summary") == 0) { 439 psStringAppend(&query, " GROUP BY ff_id "); //needs to be checked, but should be fine: want 1 ff summary cmf. 440 } 441 442 psError(PS_ERR_UNKNOWN, false , query); 443 401 psStringAppend(&query, " GROUP BY exp_id"); 402 } 403 else if (strcmp(stage,"stack") == 0) { 404 psStringAppend(&query, " GROUP BY stack_id"); 405 } 406 else if (strcmp(stage,"staticsky") == 0) { 407 psStringAppend(&query, " GROUP BY sky_id, stack_id"); //some reason it needs this 408 } 409 else if (strcmp(stage,"skycal") == 0) { 410 psStringAppend(&query, " GROUP BY skycal_id, sky_id, stack_id "); //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there 411 } 412 //needs to be checked HAF xxx 413 else if (strcmp(stage,"diff") == 0) { 414 psStringAppend(&query, " GROUP BY diff_id, diff_skyfile_id "); //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there 415 } 416 //needs to be checked HAF xxx 417 else if (strcmp(stage,"fullforce") == 0) { 418 psStringAppend(&query, " GROUP BY ff_id, warp_id "); //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there 419 } 420 else if (strcmp(stage,"fullforce_summary") == 0) { 421 psStringAppend(&query, " GROUP BY ff_id "); //needs to be checked, but should be fine: want 1 ff summary cmf. 422 } 423 psError(PS_ERR_UNKNOWN, false , query); 444 424 445 425 psTrace("addtool.c", PS_LOG_INFO,"query: \n\n%s\n\n",query); … … 447 427 if (!p_psDBRunQuery(config->dbh, query)) { 448 428 psError(PS_ERR_UNKNOWN, false, "database error, \n%s\n", query); 449 psFree(query);450 return false;429 psFree(query); 430 return false; 451 431 } 452 432 psFree(query); 453 433 454 434 psArray *output = p_psDBFetchResult(config->dbh); 455 435 if (!output) { 456 psError(PS_ERR_UNKNOWN, false, "database error");457 return false;436 psError(PS_ERR_UNKNOWN, false, "database error"); 437 return false; 458 438 } 459 439 if (!psArrayLength(output)) { 460 psTrace("addtool", PS_LOG_INFO, "no rows found");461 psFree(output);462 return true;463 } 464 440 psTrace("addtool", PS_LOG_INFO, "no rows found"); 441 psFree(output); 442 return true; 443 } 444 465 445 if (pretend) { 466 // negative simple so the default is true467 if (!ippdbPrintMetadatas(stdout, output, "addRun", !simple)) {468 psError(PS_ERR_UNKNOWN, false, "failed to print array");469 psFree(output);470 return false;471 }472 psFree(output);473 return true;474 } 475 446 // negative simple so the default is true 447 if (!ippdbPrintMetadatas(stdout, output, "addRun", !simple)) { 448 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 449 psFree(output); 450 return false; 451 } 452 psFree(output); 453 return true; 454 } 455 476 456 // loop over our list of camRun rows to check the supplied and selected dvodb and workdir values: 477 457 if (strcmp(stage,"cam") == 0) { 478 for (long i = 0; i < psArrayLength(output); i++) {458 for (long i = 0; i < psArrayLength(output); i++) { 479 459 psMetadata *md = output->data[i]; 480 460 481 461 camRunRow *row = camRunObjectFromMetadata(md); 482 462 483 463 if (!row) { 484 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");485 psFree(output);486 return false;487 } 488 464 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun"); 465 psFree(output); 466 return false; 467 } 468 489 469 if (!dvodb && !row->dvodb) { 490 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, cam_id %" PRId64, row->label, row->cam_id);491 psFree(output);492 return false;470 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, cam_id %" PRId64, row->label, row->cam_id); 471 psFree(output); 472 return false; 493 473 } 494 474 if (!workdir && !row->workdir) { 495 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, cam_id %" PRId64, row->label, row->cam_id);496 psFree(output);497 return false;498 } 499 475 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, cam_id %" PRId64, row->label, row->cam_id); 476 psFree(output); 477 return false; 478 } 479 500 480 psFree(row); 501 }502 } 503 if (strcmp(stage,"stack") == 0) {504 for (long i = 0; i < psArrayLength(output); i++) {481 } 482 } 483 else if (strcmp(stage,"stack") == 0) { 484 for (long i = 0; i < psArrayLength(output); i++) { 505 485 psMetadata *md = output->data[i]; 506 486 507 487 stackRunRow *row = stackRunObjectFromMetadata(md); 508 488 509 489 if (!row) { 510 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");511 psFree(output);512 return false;513 } 514 490 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun"); 491 psFree(output); 492 return false; 493 } 494 515 495 if (!dvodb && !row->dvodb) { 516 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, stack_id %" PRId64, row->label, row->stack_id);517 psFree(output);518 return false;496 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, stack_id %" PRId64, row->label, row->stack_id); 497 psFree(output); 498 return false; 519 499 } 520 500 if (!workdir && !row->workdir) { 521 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, stack_id %" PRId64, row->label, row->stack_id);522 psFree(output);523 return false;524 } 525 501 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, stack_id %" PRId64, row->label, row->stack_id); 502 psFree(output); 503 return false; 504 } 505 526 506 psFree(row); 527 } 528 } 529 530 531 532 if (strcmp(stage,"staticsky") == 0) { 533 for (long i = 0; i < psArrayLength(output); i++) { 507 } 508 } 509 else if (strcmp(stage,"staticsky") == 0) { 510 for (long i = 0; i < psArrayLength(output); i++) { 534 511 psMetadata *md = output->data[i]; 535 512 bool status = false; … … 543 520 return false; 544 521 } 545 522 546 523 staticskyRunRow *row = staticskyRunObjectFromMetadata(md); 547 524 548 525 if (!row) { 549 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");550 psFree(output);551 return false;552 } 553 526 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun"); 527 psFree(output); 528 return false; 529 } 530 554 531 if (!dvodb) { //there's no staticsky.dvodb 555 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, sky_id %" PRId64, row->label, row->sky_id);556 psFree(output);557 return false;532 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, sky_id %" PRId64, row->label, row->sky_id); 533 psFree(output); 534 return false; 558 535 } 559 536 if (!workdir && !row->workdir) { 560 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, sky_id %" PRId64, row->label, row->sky_id);561 psFree(output);562 return false;563 } 564 537 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, sky_id %" PRId64, row->label, row->sky_id); 538 psFree(output); 539 return false; 540 } 541 565 542 psFree(row); 566 } 567 } 568 569 if (strcmp(stage,"skycal") == 0) { 543 } 544 } 545 else if (strcmp(stage,"skycal") == 0) { 570 546 for (long i = 0; i < psArrayLength(output); i++) { 571 547 psMetadata *md = output->data[i]; 572 548 573 549 skycalRunRow *row = skycalRunObjectFromMetadata(md); 574 550 … … 578 554 return false; 579 555 } 580 556 581 557 if (!dvodb) { // there's no skycalRun.dvodb 582 558 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, skycal_id %" PRId64, row->label, row->skycal_id); … … 589 565 return false; 590 566 } 591 567 592 568 psFree(row); 593 569 } 594 570 } 595 596 if (strcmp(stage,"diff") == 0) { 597 571 else if (strcmp(stage,"diff") == 0) { 598 572 for (long i = 0; i < psArrayLength(output); i++) { 599 573 psMetadata *md = output->data[i]; 600 574 601 575 diffRunRow *row = diffRunObjectFromMetadata(md); 602 576 … … 606 580 return false; 607 581 } 608 582 609 583 if (!dvodb) { // there's no skycalRun.dvodb 610 584 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, diff_id %" PRId64, row->label, row->diff_id); … … 617 591 return false; 618 592 } 619 593 620 594 psFree(row); 621 595 } 622 596 } 623 624 if (strcmp(stage,"fullforce") == 0) { 597 else if (strcmp(stage,"fullforce") == 0) { 625 598 for (long i = 0; i < psArrayLength(output); i++) { 626 599 psMetadata *md = output->data[i]; 627 600 628 601 fullForceRunRow *row = fullForceRunObjectFromMetadata(md); 629 602 630 603 if (!row) { 631 604 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fullforceRun"); … … 644 617 return false; 645 618 } 646 619 647 620 psFree(row); 648 621 } 649 622 } 650 651 if (strcmp(stage,"fullforce_summary") == 0) { 623 else if (strcmp(stage,"fullforce_summary") == 0) { 652 624 for (long i = 0; i < psArrayLength(output); i++) { 653 625 psMetadata *md = output->data[i]; 654 626 //i believe this is correct for ff_summary as well: 655 627 fullForceRunRow *row = fullForceRunObjectFromMetadata(md); 656 628 657 629 if (!row) { 658 630 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fullforceRun"); … … 660 632 return false; 661 633 } 662 634 663 635 if (!dvodb) { // there's no skycalRun.dvodb 664 636 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, ff_id %" PRId64, row->label, row->ff_id); … … 671 643 return false; 672 644 } 673 645 674 646 psFree(row); 675 647 } 676 648 } 677 649 678 650 679 651 // start a transaction so we don't end up with an exp without any associted … … 690 662 // old values in place (i.e., passing the values through). 691 663 692 // loop over our list of camRun rows664 693 665 if (strcmp(stage,"cam") == 0) { 694 for (long i = 0; i < psArrayLength(output); i++) { 666 // loop over our list of camRun rows 667 for (long i = 0; i < psArrayLength(output); i++) { 695 668 psMetadata *md = output->data[i]; 696 669 psS64 stage_id =0; 697 670 698 camRunRow *row = camRunObjectFromMetadata(md);699 stage_id = row->cam_id;671 camRunRow *row = camRunObjectFromMetadata(md); 672 stage_id = row->cam_id; 700 673 701 674 if (!row) { 702 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");703 psFree(output);704 return false;705 } 706 675 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun"); 676 psFree(output); 677 return false; 678 } 679 707 680 // queue the exp 708 681 if (!pxaddQueueByCamID(config, … … 720 693 minidvodb_group, 721 694 minidvodb_name 722 )) {723 if (!psDBRollback(config->dbh)) {724 psError(PS_ERR_UNKNOWN, false, "database error sfg");725 }726 psError(PS_ERR_UNKNOWN, false,727 "failed to trying to queue stage %s %" PRId64,stage, stage_id);728 psFree(row);729 psFree(output);730 return false;695 )) { 696 if (!psDBRollback(config->dbh)) { 697 psError(PS_ERR_UNKNOWN, false, "database error sfg"); 698 } 699 psError(PS_ERR_UNKNOWN, false, 700 "failed to trying to queue stage %s %" PRId64,stage, stage_id); 701 psFree(row); 702 psFree(output); 703 return false; 731 704 } 732 705 psFree(row); 733 }734 }735 if (strcmp(stage,"stack") == 0) {736 for (long i = 0; i < psArrayLength(output); i++) {706 } 707 } 708 else if (strcmp(stage,"stack") == 0) { 709 for (long i = 0; i < psArrayLength(output); i++) { 737 710 psMetadata *md = output->data[i]; 738 711 psS64 stage_id =0; 739 712 740 stackRunRow *row = stackRunObjectFromMetadata(md);741 stage_id = row->stack_id;713 stackRunRow *row = stackRunObjectFromMetadata(md); 714 stage_id = row->stack_id; 742 715 743 716 if (!row) { 744 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");745 psFree(output);746 return false;747 } 748 717 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun"); 718 psFree(output); 719 return false; 720 } 721 749 722 // queue the exp 750 723 if (!pxaddQueueByCamID(config, … … 762 735 minidvodb_group, 763 736 minidvodb_name 764 )) {765 if (!psDBRollback(config->dbh)) {766 psError(PS_ERR_UNKNOWN, false, "database error sfg");767 }768 psError(PS_ERR_UNKNOWN, false,769 "failed to trying to queue stage %s %" PRId64,stage, stage_id);770 psFree(row);771 psFree(output);772 return false;737 )) { 738 if (!psDBRollback(config->dbh)) { 739 psError(PS_ERR_UNKNOWN, false, "database error sfg"); 740 } 741 psError(PS_ERR_UNKNOWN, false, 742 "failed to trying to queue stage %s %" PRId64,stage, stage_id); 743 psFree(row); 744 psFree(output); 745 return false; 773 746 } 774 747 psFree(row); 775 } 776 } 777 778 if (strcmp(stage,"staticsky") == 0) { 779 for (long i = 0; i < psArrayLength(output); i++) { 748 } 749 } 750 else if (strcmp(stage,"staticsky") == 0) { 751 for (long i = 0; i < psArrayLength(output); i++) { 780 752 psMetadata *md = output->data[i]; 781 753 psS64 stage_id =0; … … 783 755 //psS32 num_inputs = psMetadataLookupS32(&status, md, "num_inputs"); 784 756 psS32 stack_id = psMetadataLookupS32(&status, md, "stack_id"); 785 757 786 758 if (!status) { 787 759 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id"); … … 792 764 793 765 if (!row) { 794 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");795 psFree(output);796 return false;797 } 798 766 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun"); 767 psFree(output); 768 return false; 769 } 770 799 771 // queue the exp 800 772 //for (int filter_id = 0; filter_id < num_inputs; filter_id++) { 801 if (!pxaddQueueByCamID(config,773 if (!pxaddQueueByCamID(config, 802 774 stage, 803 775 stage_id, … … 813 785 minidvodb_group, 814 786 minidvodb_name 815 )) { 816 if (!psDBRollback(config->dbh)) { 817 psError(PS_ERR_UNKNOWN, false, "database error sfg"); 818 } 819 psError(PS_ERR_UNKNOWN, false, 820 "failed to trying to queue stage %s %" PRId64,stage, stage_id); 821 psFree(row); 822 psFree(output); 823 return false; 787 )) { 788 if (!psDBRollback(config->dbh)) { 789 psError(PS_ERR_UNKNOWN, false, "database error sfg"); 824 790 } 825 //} 791 psError(PS_ERR_UNKNOWN, false, 792 "failed to trying to queue stage %s %" PRId64,stage, stage_id); 793 psFree(row); 794 psFree(output); 795 return false; 796 } 797 //} 826 798 psFree(row); 827 } 828 } 829 830 if (strcmp(stage,"skycal") == 0) { 831 for (long i = 0; i < psArrayLength(output); i++) { 799 } 800 } 801 else if (strcmp(stage,"skycal") == 0) { 802 for (long i = 0; i < psArrayLength(output); i++) { 832 803 psMetadata *md = output->data[i]; 833 804 psS64 stage_id =0; 834 805 835 skycalRunRow *row = skycalRunObjectFromMetadata(md);836 stage_id = row->skycal_id;806 skycalRunRow *row = skycalRunObjectFromMetadata(md); 807 stage_id = row->skycal_id; 837 808 838 809 if (!row) { 839 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");840 psFree(output);841 return false;842 } 843 810 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun"); 811 psFree(output); 812 return false; 813 } 814 844 815 // queue the exp 845 816 if (!pxaddQueueByCamID(config, … … 857 828 minidvodb_group, 858 829 minidvodb_name 859 )) {860 if (!psDBRollback(config->dbh)) {861 psError(PS_ERR_UNKNOWN, false, "database error sfg");862 }863 psError(PS_ERR_UNKNOWN, false,864 "failed to trying to queue stage %s %" PRId64,stage, stage_id);865 psFree(row);866 psFree(output);867 return false;830 )) { 831 if (!psDBRollback(config->dbh)) { 832 psError(PS_ERR_UNKNOWN, false, "database error sfg"); 833 } 834 psError(PS_ERR_UNKNOWN, false, 835 "failed to trying to queue stage %s %" PRId64,stage, stage_id); 836 psFree(row); 837 psFree(output); 838 return false; 868 839 } 869 840 psFree(row); 870 } 871 } 872 873 if (strcmp(stage,"diff") == 0) { 874 875 for (long i = 0; i < psArrayLength(output); i++) { 841 } 842 } 843 else if (strcmp(stage,"diff") == 0) { 844 for (long i = 0; i < psArrayLength(output); i++) { 876 845 psMetadata *md = output->data[i]; 877 846 psS64 stage_id =0; … … 885 854 return false; 886 855 } 887 888 856 889 857 if (!row) { 890 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");891 psFree(output);892 return false;858 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun"); 859 psFree(output); 860 return false; 893 861 } 894 862 … … 908 876 minidvodb_group, 909 877 minidvodb_name 910 )) {911 if (!psDBRollback(config->dbh)) {912 psError(PS_ERR_UNKNOWN, false, "database error sfg");913 }914 psError(PS_ERR_UNKNOWN, false,915 "failed to trying to queue stage %s %" PRId64,stage, stage_id);916 psFree(row);917 psFree(output);918 return false;878 )) { 879 if (!psDBRollback(config->dbh)) { 880 psError(PS_ERR_UNKNOWN, false, "database error sfg"); 881 } 882 psError(PS_ERR_UNKNOWN, false, 883 "failed to trying to queue stage %s %" PRId64,stage, stage_id); 884 psFree(row); 885 psFree(output); 886 return false; 919 887 } 920 888 psFree(row); 921 } 922 } 923 924 if (strcmp(stage,"fullforce") == 0) { 925 for (long i = 0; i < psArrayLength(output); i++) { 889 } 890 } 891 else if (strcmp(stage,"fullforce") == 0) { 892 for (long i = 0; i < psArrayLength(output); i++) { 926 893 psMetadata *md = output->data[i]; 927 894 psS64 stage_id =0; … … 935 902 return false; 936 903 } 937 904 938 905 if (!row) { 939 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");940 psFree(output);941 return false;942 } 943 906 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun"); 907 psFree(output); 908 return false; 909 } 910 944 911 // queue the exp 945 912 if (!pxaddQueueByCamID(config, … … 957 924 minidvodb_group, 958 925 minidvodb_name 959 )) {960 if (!psDBRollback(config->dbh)) {961 psError(PS_ERR_UNKNOWN, false, "database error sfg");962 }963 psError(PS_ERR_UNKNOWN, false,964 "failed to trying to queue stage %s %" PRId64,stage, stage_id);965 psFree(row);966 psFree(output);967 return false;926 )) { 927 if (!psDBRollback(config->dbh)) { 928 psError(PS_ERR_UNKNOWN, false, "database error sfg"); 929 } 930 psError(PS_ERR_UNKNOWN, false, 931 "failed to trying to queue stage %s %" PRId64,stage, stage_id); 932 psFree(row); 933 psFree(output); 934 return false; 968 935 } 969 936 psFree(row); 970 }971 } 972 if (strcmp(stage,"fullforce_summary") == 0) {937 } 938 } 939 else if (strcmp(stage,"fullforce_summary") == 0) { 973 940 for (long i = 0; i < psArrayLength(output); i++) { 974 941 psMetadata *md = output->data[i]; … … 979 946 980 947 if (!row) { 981 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fullforceRun");982 psFree(output);983 return false;984 } 985 948 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fullforceRun"); 949 psFree(output); 950 return false; 951 } 952 986 953 // queue the exp 987 954 if (!pxaddQueueByCamID(config, … … 999 966 minidvodb_group, 1000 967 minidvodb_name 1001 )) {1002 if (!psDBRollback(config->dbh)) {1003 psError(PS_ERR_UNKNOWN, false, "database error sfg");1004 }1005 psError(PS_ERR_UNKNOWN, false,1006 "failed to trying to queue stage %s %" PRId64,stage, stage_id);1007 psFree(row);1008 psFree(output);1009 return false;968 )) { 969 if (!psDBRollback(config->dbh)) { 970 psError(PS_ERR_UNKNOWN, false, "database error sfg"); 971 } 972 psError(PS_ERR_UNKNOWN, false, 973 "failed to trying to queue stage %s %" PRId64,stage, stage_id); 974 psFree(row); 975 psFree(output); 976 return false; 1010 977 } 1011 978 psFree(row); 1012 } 1013 } 1014 1015 1016 1017 1018 979 } 980 } 1019 981 psFree(output); 1020 982 … … 1054 1016 } 1055 1017 psString query = NULL; 1056 if (strcmp(stage, "cam") ==0) {1018 if (strcmp(stage, "cam") == 0) { 1057 1019 query = psStringCopy("UPDATE addRun JOIN camRun on (cam_id = stage_id and stage = 'cam') JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)"); 1058 1020 } 1059 if (strcmp(stage, "stack")==0) {1021 else if (strcmp(stage, "stack") == 0) { 1060 1022 query = psStringCopy("UPDATE addRun JOIN stackRun on (stack_id = stage_id and stage = 'stack')"); 1061 1023 } 1062 if (strcmp(stage, "staticsky")==0) {1024 else if (strcmp(stage, "staticsky") == 0) { 1063 1025 query = psStringCopy("UPDATE addRun JOIN staticskyRun on (sky_id = stage_id and stage = 'staticsky')"); 1064 1026 } 1065 if (strcmp(stage, "skycal")==0) {1027 else if (strcmp(stage, "skycal") == 0) { 1066 1028 query = psStringCopy("UPDATE addRun JOIN skycalRun on (skycal_id = stage_id and stage = 'skycal')"); 1067 1029 } 1068 if (strcmp(stage, "diff")==0) {1030 else if (strcmp(stage, "diff") == 0) { 1069 1031 query = psStringCopy("UPDATE addRun JOIN diffInputSkyfile on (diff_id = stage_id and diff_skyfile_id = stage_extra1 and stage = 'diff') JOIN diffSkyfile on (diff_id, skycell_id) JOIN diffRun using (diff_id)"); 1070 1032 } 1071 if (strcmp(stage, "fullforce")==0) {1033 else if (strcmp(stage, "fullforce") == 0) { 1072 1034 query = psStringCopy("UPDATE addRun JOIN fullForceResult on (ff_id = stage_id and warp_id = stage_extra1 and stage = 'fullforce') JOIN fullForceRun on (ff_id)"); 1073 1035 } 1074 if (strcmp(stage, "fullforce_summary")==0) {1036 else if (strcmp(stage, "fullforce_summary") == 0) { 1075 1037 query = psStringCopy("UPDATE addRun JOIN fullForceSummary on (ff_id = stage_id and stage = 'fullforce_summary') JOIN fullForceRun on (ff_id)"); 1076 1038 } … … 1112 1074 psString query = NULL; 1113 1075 1114 if (strcmp(stage, "cam") ==0) {1076 if (strcmp(stage, "cam") == 0) { 1115 1077 query = pxDataGet("addtool_find_pendingexp_cam.sql"); 1116 1078 } 1117 if (strcmp(stage, "stack")==0) {1079 else if (strcmp(stage, "stack") == 0) { 1118 1080 query = pxDataGet("addtool_find_pendingexp_stack.sql"); 1119 1081 } 1120 if (strcmp(stage, "staticsky")==0) {1082 else if (strcmp(stage, "staticsky") == 0) { 1121 1083 query = pxDataGet("addtool_find_pendingexp_staticsky_multi.sql"); 1122 1084 } 1123 if (strcmp(stage, "skycal")==0) {1085 else if (strcmp(stage, "skycal") == 0) { 1124 1086 query = pxDataGet("addtool_find_pendingexp_skycal.sql"); 1125 1087 } 1126 if (strcmp(stage, "diff")==0) {1088 else if (strcmp(stage, "diff") == 0) { 1127 1089 query = pxDataGet("addtool_find_pendingexp_diff.sql"); 1128 1090 } 1129 if (strcmp(stage, "fullforce")==0) {1091 else if (strcmp(stage, "fullforce") == 0) { 1130 1092 query = pxDataGet("addtool_find_pendingexp_ff.sql"); 1131 1093 } 1132 if (strcmp(stage, "fullforce_summary")==0) {1094 else if (strcmp(stage, "fullforce_summary") == 0) { 1133 1095 query = pxDataGet("addtool_find_pendingexp_ffsummary.sql"); 1134 1096 } … … 1151 1113 psStringAppend(&query, " GROUP BY %s", "stack_id"); 1152 1114 } 1153 if (strcmp(stage, "skycal") == 0) {1115 else if (strcmp(stage, "skycal") == 0) { 1154 1116 //this group by is needed to join against all the warps (to get camera) 1155 1117 psStringAppend(&query, " GROUP BY %s", "skycal_id"); 1156 1118 } 1157 if (strcmp(stage, "staticsky") == 0) {1119 else if (strcmp(stage, "staticsky") == 0) { 1158 1120 //this group by is needed to join against all the warps (to get camera) 1159 1121 psStringAppend(&query, " GROUP BY %s", "sky_id, stage_extra1"); 1160 1122 } 1161 if (strcmp(stage, "diff") == 0) {1123 else if (strcmp(stage, "diff") == 0) { 1162 1124 //this group by is needed to join against all the warps (to get camera) 1163 1125 if (multiadd) { 1164 1126 psStringAppend(&query, " GROUP BY %s", "diff_id"); 1165 1127 } else { 1166 psStringAppend(&query, " GROUP BY %s", "diff_id, stage_extra1");1167 } 1168 } 1169 if (strcmp(stage, "fullforce") == 0) {1128 psStringAppend(&query, " GROUP BY %s", "diff_id, stage_extra1"); 1129 } 1130 } 1131 else if (strcmp(stage, "fullforce") == 0) { 1170 1132 //this group by is needed to join against all the warps (to get camera) 1171 1133 if (multiadd) { … … 1175 1137 } 1176 1138 } 1177 1178 if (strcmp(stage, "fullforce_summary") == 0) { 1139 else if (strcmp(stage, "fullforce_summary") == 0) { 1179 1140 //this group by is needed to join against all the warps (to get camera) 1180 1141 psStringAppend(&query, "GROUP BY %s", "ff_id"); … … 1183 1144 // treat limit == 0 as "no limit" 1184 1145 if (limit) { 1185 psString limitString = psDBGenerateLimitSQL(limit);1186 psStringAppend(&query, " %s", limitString);1187 psFree(limitString);1146 psString limitString = psDBGenerateLimitSQL(limit); 1147 psStringAppend(&query, " %s", limitString); 1148 psFree(limitString); 1188 1149 } 1189 1150 if (!p_psDBRunQuery(config->dbh, query)) { 1190 psError(PS_ERR_UNKNOWN, false, "database error");1191 psFree(query);1192 return false;1151 psError(PS_ERR_UNKNOWN, false, "database error"); 1152 psFree(query); 1153 return false; 1193 1154 } 1194 1155 // printf ("%s\n", query); 1195 1156 //psTrace("addtool.c", PS_LOG_INFO, "used this query:\n %s\n",query); 1196 1157 psFree(query); 1197 1158 1198 1159 psArray *output = p_psDBFetchResult(config->dbh); 1199 1160 if (!output) { 1200 psError(PS_ERR_UNKNOWN, false, "database error");1201 return false;1161 psError(PS_ERR_UNKNOWN, false, "database error"); 1162 return false; 1202 1163 } 1203 1164 if (!psArrayLength(output)) { 1204 psTrace("addtool", PS_LOG_INFO, "no rows found");1205 psFree(output);1206 return true;1207 } 1208 1165 psTrace("addtool", PS_LOG_INFO, "no rows found"); 1166 psFree(output); 1167 return true; 1168 } 1169 1209 1170 // negate simple so the default is true 1210 1171 if (!ippdbPrintMetadatas(stdout, output, "addPendingExp", !simple)) { 1211 psError(PS_ERR_UNKNOWN, false, "failed to print array");1212 psFree(output);1213 return false;1214 } 1215 1172 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1173 psFree(output); 1174 return false; 1175 } 1176 1216 1177 psFree(output); 1217 1178 1218 1179 return true; 1219 1180 } … … 1222 1183 { 1223 1184 PS_ASSERT_PTR_NON_NULL(config, false); 1224 1185 1225 1186 // required 1226 1187 // PXOPT_LOOKUP_S64(add_id, config->args, "-add_id", true, false); 1227 1188 1228 1189 // optional 1229 1190 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); … … 1233 1194 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 1234 1195 PXOPT_LOOKUP_S64(stage_extra1, config->args, "-stage_extra1", false, false); 1235 1196 1236 1197 PXOPT_LOOKUP_BOOL(multiadd, config->args, "-multiadd", false); 1237 1198 // generate restrictions … … 1256 1217 psString query = pxDataGet("addtool_find_pendingexp.sql"); 1257 1218 if (!query) { 1258 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");1259 return false;1260 } 1261 1219 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1220 return false; 1221 } 1222 1262 1223 // use psDBGenerateWhereSQL because the SQL yields an intermediate table 1263 1224 if (psListLength(where->list)) { 1264 psString whereClaus = psDBGenerateWhereConditionSQL(where, NULL);1265 psStringAppend(&query, " AND %s", whereClaus);1266 psFree(whereClaus);1225 psString whereClaus = psDBGenerateWhereConditionSQL(where, NULL); 1226 psStringAppend(&query, " AND %s", whereClaus); 1227 psFree(whereClaus); 1267 1228 } 1268 1229 psFree(where); 1269 1230 1270 1231 //if (multiadd) { 1271 1232 // psStringAppend(&query, "group by %s", "stage_extra1"); 1272 1233 //} 1273 1234 1274 1235 if (!p_psDBRunQuery(config->dbh, query)) { 1275 psError(PS_ERR_UNKNOWN, false, "database error");1276 psFree(query);1277 return false;1278 } 1279 1236 psError(PS_ERR_UNKNOWN, false, "database error"); 1237 psFree(query); 1238 return false; 1239 } 1240 1280 1241 psFree(query); 1281 1242 1282 1243 psArray *output = p_psDBFetchResult(config->dbh); 1283 1244 if (!output) { 1284 psError(PS_ERR_UNKNOWN, false, "database error");1285 return false;1245 psError(PS_ERR_UNKNOWN, false, "database error"); 1246 return false; 1286 1247 } 1287 1248 1288 1249 if (!psArrayLength(output)) { 1289 psTrace("addtool", PS_LOG_INFO, "no rows found");1290 psFree(output);1291 return false;1292 } 1293 1250 psTrace("addtool", PS_LOG_INFO, "no rows found"); 1251 psFree(output); 1252 return false; 1253 } 1254 1294 1255 if (!psDBTransaction(config->dbh)) { 1295 psError(PS_ERR_UNKNOWN, false, "database error");1296 psFree(output);1297 return false;1298 } 1299 1256 psError(PS_ERR_UNKNOWN, false, "database error"); 1257 psFree(output); 1258 return false; 1259 } 1260 1300 1261 for (long i =0; i<psArrayLength(output);i++) { 1262 addRunRow *pendingRow = addRunObjectFromMetadata(output->data[i]); 1301 1263 1302 addRunRow *pendingRow = addRunObjectFromMetadata(output->data[i]); 1303 1304 addProcessedExpRow *row = addProcessedExpRowAlloc( 1305 pendingRow->add_id, 1306 dtime_addstar, 1307 path_base, 1308 dvodb_path, 1309 fault 1310 ); 1311 1312 if (!addProcessedExpInsertObject(config->dbh, row)) { 1264 addProcessedExpRow *row = addProcessedExpRowAlloc( 1265 pendingRow->add_id, 1266 dtime_addstar, 1267 path_base, 1268 dvodb_path, 1269 fault 1270 ); 1271 1272 if (!addProcessedExpInsertObject(config->dbh, row)) { 1313 1273 // rollback 1314 1274 if (!psDBRollback(config->dbh)) { 1315 psError(PS_ERR_UNKNOWN, false, "database error");1275 psError(PS_ERR_UNKNOWN, false, "database error"); 1316 1276 } 1317 1277 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1319 1279 psFree(pendingRow); 1320 1280 return false; 1321 } 1322 1323 //if there is a minidvodb_name, set it in addRun (it's not known until it is processed) 1324 if (minidvodb_name) { 1325 psString setName = NULL; 1326 psStringAppend (&setName, "UPDATE addRun set minidvodb_name = '%s' where add_id = %" PRId64, minidvodb_name, row->add_id); 1327 if (!p_psDBRunQuery(config->dbh, setName)) { 1328 if (!psDBRollback(config->dbh)) { 1329 psError(PS_ERR_UNKNOWN, false, "database error"); 1330 } 1281 } 1282 1283 //if there is a minidvodb_name, set it in addRun (it's not known until it is processed) 1284 if (minidvodb_name) { 1285 psString setName = NULL; 1286 psStringAppend (&setName, "UPDATE addRun set minidvodb_name = '%s' where add_id = %" PRId64, minidvodb_name, row->add_id); 1287 if (!p_psDBRunQuery(config->dbh, setName)) { 1288 if (!psDBRollback(config->dbh)) { 1289 psError(PS_ERR_UNKNOWN, false, "database error"); 1290 } 1291 psError(PS_ERR_UNKNOWN, false, "database error"); 1292 1293 return false; 1294 } 1295 } 1296 //if there is a stage_extra1, set it in addRun (it's not known until it is processed) 1297 if (stage_extra1) { 1298 psString setExtra = NULL; 1299 psStringAppend (&setExtra, "UPDATE addRun set stage_extra1 = %" PRId64, stage_extra1); 1300 psStringAppend (&setExtra, " where add_id = %" PRId64, row->add_id); 1301 1302 if (!p_psDBRunQuery(config->dbh, setExtra)) { 1303 if (!psDBRollback(config->dbh)) { 1304 psError(PS_ERR_UNKNOWN, false, "database error"); 1305 } 1306 psError(PS_ERR_UNKNOWN, false, "database error"); 1307 1308 return false; 1309 } 1310 } 1311 1312 1313 1314 1315 // since there is only one exp per 'new' set addRun.state = 'full' 1316 // but check to make sure there are no faults 1317 1318 if (!fault) { 1319 if (!pxaddRunSetState(config, row->add_id, "full")) { 1320 psError(PS_ERR_UNKNOWN, false, "failed to change addRun.state for add_id: %" PRId64, row->add_id); 1321 psFree(row); 1322 psFree(pendingRow); 1323 return false; 1324 } 1325 } 1326 psFree(row); 1327 psFree(pendingRow); 1328 1329 if (!psDBCommit(config->dbh)) { 1331 1330 psError(PS_ERR_UNKNOWN, false, "database error"); 1332 1333 return false; 1334 } 1335 } 1336 //if there is a stage_extra1, set it in addRun (it's not known until it is processed) 1337 if (stage_extra1) { 1338 psString setExtra = NULL; 1339 psStringAppend (&setExtra, "UPDATE addRun set stage_extra1 = %" PRId64, stage_extra1); 1340 psStringAppend (&setExtra, " where add_id = %" PRId64, row->add_id); 1341 1342 if (!p_psDBRunQuery(config->dbh, setExtra)) { 1343 if (!psDBRollback(config->dbh)) { 1344 psError(PS_ERR_UNKNOWN, false, "database error"); 1345 } 1346 psError(PS_ERR_UNKNOWN, false, "database error"); 1347 1348 return false; 1349 } 1350 } 1351 1352 1353 1354 1355 // since there is only one exp per 'new' set addRun.state = 'full' 1356 // but check to make sure there are no faults 1357 1358 if (!fault) { 1359 if (!pxaddRunSetState(config, row->add_id, "full")) { 1360 psError(PS_ERR_UNKNOWN, false, "failed to change addRun.state for add_id: %" PRId64, row->add_id); 1361 psFree(row); 1362 psFree(pendingRow); 1363 return false; 1364 } 1365 } 1366 psFree(row); 1367 psFree(pendingRow); 1368 1369 if (!psDBCommit(config->dbh)) { 1370 psError(PS_ERR_UNKNOWN, false, "database error"); 1371 return false; 1372 } 1373 } 1374 1331 return false; 1332 } 1333 } 1334 1375 1335 return true; 1376 1336 } … … 1507 1467 pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "=="); 1508 1468 PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "=="); 1509 1469 1510 1470 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 1511 psFree(where);1512 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");1513 return false;1514 } 1515 1471 psFree(where); 1472 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1473 return false; 1474 } 1475 1516 1476 if (!psDBTransaction(config->dbh)) { 1517 psError(PS_ERR_UNKNOWN, false, "database error");1518 psFree(where);1519 return false;1520 } 1521 1477 psError(PS_ERR_UNKNOWN, false, "database error"); 1478 psFree(where); 1479 return false; 1480 } 1481 1522 1482 { 1523 1483 psString query = NULL; 1524 1484 if (strcmp(stage, "cam") == 0) { 1525 query = pxDataGet("addtool_revertprocessedexp_cam.sql"); 1526 } 1527 1528 if (strcmp(stage, "stack") == 0) { 1529 query = pxDataGet("addtool_revertprocessedexp_stack.sql"); 1530 } 1531 if (strcmp(stage, "staticsky") == 0) { 1532 query = pxDataGet("addtool_revertprocessedexp_staticsky_multi.sql"); 1533 } 1534 if (strcmp(stage, "skycal") == 0) { 1535 query = pxDataGet("addtool_revertprocessedexp_skycal.sql"); 1536 } 1537 if (strcmp(stage, "diff") == 0) { 1538 query = pxDataGet("addtool_revertprocessedexp_diff.sql"); 1539 } 1540 if (strcmp(stage, "fullforce") == 0) { 1541 query = pxDataGet("addtool_revertprocessedexp_ff.sql"); 1542 } 1543 if (strcmp(stage, "fullforce_summary") == 0) { 1544 query = pxDataGet("addtool_revertprocessedexp_ffsummary.sql"); 1545 } 1546 1547 1485 query = pxDataGet("addtool_revertprocessedexp_cam.sql"); 1486 } 1487 else if (strcmp(stage, "stack") == 0) { 1488 query = pxDataGet("addtool_revertprocessedexp_stack.sql"); 1489 } 1490 else if (strcmp(stage, "staticsky") == 0) { 1491 query = pxDataGet("addtool_revertprocessedexp_staticsky_multi.sql"); 1492 } 1493 else if (strcmp(stage, "skycal") == 0) { 1494 query = pxDataGet("addtool_revertprocessedexp_skycal.sql"); 1495 } 1496 else if (strcmp(stage, "diff") == 0) { 1497 query = pxDataGet("addtool_revertprocessedexp_diff.sql"); 1498 } 1499 else if (strcmp(stage, "fullforce") == 0) { 1500 query = pxDataGet("addtool_revertprocessedexp_ff.sql"); 1501 } 1502 else if (strcmp(stage, "fullforce_summary") == 0) { 1503 query = pxDataGet("addtool_revertprocessedexp_ffsummary.sql"); 1504 } 1548 1505 1549 1506 if (!query) { 1550 // rollback1507 // rollback 1551 1508 if (!psDBRollback(config->dbh)) { 1552 psError(PS_ERR_UNKNOWN, false, "database error");1553 }1554 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");1555 psFree(where);1556 return false;1557 }1558 1559 // use psDBGenerateWhereConditionalSQL with AND ... because the SQL ends in a WHERE1560 if (where && psListLength(where->list)) {1561 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);1562 psStringAppend(&query, " AND %s", whereClause);1563 psFree(whereClause);1564 }1565 1566 if (!p_psDBRunQuery(config->dbh, query)) {1567 // rollback1568 if (!psDBRollback(config->dbh)) {1569 psError(PS_ERR_UNKNOWN, false, "database error");1570 }1571 psError(PS_ERR_UNKNOWN, false, "database error");1572 psFree(query);1573 psFree(where);1574 return false;1575 }1576 psFree(query);1509 psError(PS_ERR_UNKNOWN, false, "database error"); 1510 } 1511 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1512 psFree(where); 1513 return false; 1514 } 1515 1516 // use psDBGenerateWhereConditionalSQL with AND ... because the SQL ends in a WHERE 1517 if (where && psListLength(where->list)) { 1518 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1519 psStringAppend(&query, " AND %s", whereClause); 1520 psFree(whereClause); 1521 } 1522 1523 if (!p_psDBRunQuery(config->dbh, query)) { 1524 // rollback 1525 if (!psDBRollback(config->dbh)) { 1526 psError(PS_ERR_UNKNOWN, false, "database error"); 1527 } 1528 psError(PS_ERR_UNKNOWN, false, "database error"); 1529 psFree(query); 1530 psFree(where); 1531 return false; 1532 } 1533 psFree(query); 1577 1534 } 1578 1535 psFree(where); 1579 1536 1580 1537 if (!psDBCommit(config->dbh)) { 1581 psError(PS_ERR_UNKNOWN, false, "database error");1582 return false;1583 } 1584 1538 psError(PS_ERR_UNKNOWN, false, "database error"); 1539 return false; 1540 } 1541 1585 1542 return true; 1586 1543 } … … 1682 1639 1683 1640 // required 1684 1685 1641 PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-set_minidvodb_group", true, false); 1686 //optional 1642 1643 //optional 1687 1644 PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-set_minidvodb_name", false, false); 1688 1645 PXOPT_LOOKUP_STR(minidvodb_path, config->args, "-set_minidvodb_path", false, false); … … 1703 1660 return false; 1704 1661 } 1705 1662 1706 1663 if (!minidvodbRunInsert(config->dbh, 1707 0, // job_id1708 minidvodb_name,1709 minidvodb_group,1710 minidvodbpath,1711 "new",1712 01713 )) {1664 0, // job_id 1665 minidvodb_name, 1666 minidvodb_group, 1667 minidvodbpath, 1668 "new", 1669 0 1670 )) { 1714 1671 psError(PS_ERR_UNKNOWN, false, "database error"); 1715 1672 return false; 1716 1673 } 1717 1674 1718 1675 psU64 affected = psDBAffectedRows(config->dbh); 1719 1676 if (affected != 1) { … … 1723 1680 return false; 1724 1681 } 1725 1682 1726 1683 psS64 minidvodb_id = psDBLastInsertID(config->dbh); 1727 1684 printf("%" PRId64 "\n", minidvodb_id); 1728 1685 1729 1686 1730 1687 if (!minidvodb_name) { 1731 1688 psStringAppend(&minidvodb_name, "%s.%" PRIu64,minidvodb_group,minidvodb_id); … … 1734 1691 psStringAppend(&minidvodb_path,"/%s",minidvodb_name); 1735 1692 } 1736 1737 1693 1738 1694 psString query = NULL; … … 1786 1742 if (minidvodb_path) { 1787 1743 if (cnt) { 1788 psStringAppend(&query, "%s", comma);1789 } 1790 1744 psStringAppend(&query, "%s", comma); 1745 } 1746 1791 1747 psStringAppend(&query, " minidvodb_path = '%s'", minidvodb_path); 1792 1748 cnt++; … … 1910 1866 } 1911 1867 psFree(query); 1912 return false;1913 } 1914 psFree(query2);1915 psFree(where);1916 1917 return true;1918 1868 return false; 1869 } 1870 psFree(query2); 1871 psFree(where); 1872 1873 return true; 1874 1919 1875 } 1920 1876 … … 1936 1892 1937 1893 if (!psListLength(where->list)) { 1938 psFree(where);1939 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");1940 return false;1894 psFree(where); 1895 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1896 return false; 1941 1897 } 1942 1898 … … 1950 1906 1951 1907 if (!bare_query) { 1952 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");1953 return false;1908 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1909 return false; 1954 1910 } 1955 1911 … … 1957 1913 if (psListLength(where->list)) { 1958 1914 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1959 psStringAppend(&where_string, " WHERE %s", whereClause);1960 psFree(whereClause);1961 //search params are defined above1915 psStringAppend(&where_string, " WHERE %s", whereClause); 1916 psFree(whereClause); 1917 //search params are defined above 1962 1918 } 1963 1919 … … 1966 1922 psStringAppend(&query," %s ", where_string); 1967 1923 1968 1969 1970 1971 1972 1924 if (!all_addrun_states) { 1973 1925 psStringAppend(&query, " AND (cnt2 = cnt) "); … … 2082 2034 PS_ASSERT_PTR_NON_NULL(config, false); 2083 2035 2084 // required2036 // required 2085 2037 // PXOPT_LOOKUP_U64(minidvodb_id, config->args, "-minidvodb_id", true, false); 2086 2038 PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-minidvodb_group", true, false); 2087 2039 2088 // optional2040 // optional 2089 2041 PXOPT_LOOKUP_F32(dtime_relphot, config->args, "-dtime_relphot", false, false); 2090 2042 PXOPT_LOOKUP_F32(dtime_resort, config->args, "-dtime_resort", false, false); … … 2093 2045 PXOPT_LOOKUP_TIME(epoch, config->args, "-epoch", false, false); 2094 2046 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 2095 //generate restrictions 2047 2048 //generate restrictions 2096 2049 psMetadata *where = psMetadataAlloc(); 2097 2050 PXOPT_COPY_S64(config->args, where, "-minidvodb_id", "minidvodbRun.minidvodb_id", "=="); … … 2138 2091 psFree(output); 2139 2092 minidvodbProcessedRow *row = minidvodbProcessedRowAlloc( 2140 pendingRow->minidvodb_id,2141 dtime_resort,2142 dtime_relphot,2143 dtime_script,2144 epoch,2145 fault2146 );2147 2093 pendingRow->minidvodb_id, 2094 dtime_resort, 2095 dtime_relphot, 2096 dtime_script, 2097 epoch, 2098 fault 2099 ); 2100 2148 2101 if (!minidvodbProcessedInsertObject(config->dbh, row)) { 2149 2102 // rollback … … 2171 2124 psFree(row); 2172 2125 psFree(pendingRow); 2173 2174 2175 2176 2177 2126 2178 2127 //commit the changes … … 2342 2291 PXOPT_LOOKUP_F32(dtime_relphot, config->args, "-set_dtime_relphot", false, false); 2343 2292 PXOPT_LOOKUP_F32(dtime_resort, config->args, "-set_dtime_resort", false, false); 2344 PXOPT_LOOKUP_F32(dtime_script, config->args, "-set_dtime_script", false, false);2293 PXOPT_LOOKUP_F32(dtime_script, config->args, "-set_dtime_script", false, false); 2345 2294 PXOPT_COPY_S64(config->args, where, "-minidvodb_id", "minidvodbProcessed.minidvodb_id", "=="); 2346 2295 PXOPT_COPY_STR(config->args, where, "-minidvodb_name", "minidvodbRun.minidvodb_name", "==");
Note:
See TracChangeset
for help on using the changeset viewer.
