Changeset 34919
- Timestamp:
- Jan 12, 2013, 2:24:56 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20121219/Ohana/src/dvopsps
- Files:
-
- 4 edited
-
include/dvopsps.h (modified) (1 diff)
-
src/insert_detections_dvopsps.c (modified) (1 diff)
-
src/insert_detections_dvopsps_catalog.c (modified) (5 diffs)
-
test/dbadmin.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20121219/Ohana/src/dvopsps/include/dvopsps.h
r34916 r34919 43 43 int insert_detections_dvopsps PROTO(()); 44 44 int insert_detections_dvopsps_parallel PROTO((SkyTable *sky)); 45 int insert_detections_mysql PROTO((Average *average, Measure *measure, MYSQL *mysql)); 46 int insert_detections_dvopsps_catalog PROTO((Catalog *catalog, MYSQL *mysql)); 45 int insert_detections_dvopsps_catalog PROTO((Catalog *catalog, MYSQL *mysql)); 47 46 48 47 MYSQL *mysql_dvopsps_connect PROTO((MYSQL *mysqlBase)); 48 49 int insert_detections_mysql PROTO((Average *average, Measure *measure, MYSQL *mysql)); 50 51 int insert_detections_mysql_commit PROTO((IOBuffer *buffer, MYSQL *mysql)); 52 int insert_detections_mysql_value PROTO((IOBuffer *buffer, Average *average, Measure *measure)); 53 int insert_detections_mysql_init PROTO((IOBuffer *buffer)); -
branches/eam_branches/ipp-20121219/Ohana/src/dvopsps/src/insert_detections_dvopsps.c
r34918 r34919 1 1 # include "dvopsps.h" 2 # define USE_MYSQL 02 # define USE_MYSQL 1 3 3 4 4 // determine the relevant catalogs, launch parallel clients if desired -
branches/eam_branches/ipp-20121219/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c
r34918 r34919 1 1 # include "dvopsps.h" 2 3 # define MARKTIME(MSG,...) { \ 4 float dtime; \ 5 gettimeofday (&stop, (void *) NULL); \ 6 dtime = DTIME (stop, start); \ 7 fprintf (stderr, MSG, __VA_ARGS__); } 2 8 3 9 int insert_detections_dvopsps_catalog (Catalog *catalog, MYSQL *mysql) { … … 5 11 off_t i, j; 6 12 int missingID = 0; 13 struct timeval start, stop; 14 15 IOBuffer buffer; 16 buffer.Nalloc = 0; 7 17 8 18 Average *average = catalog->average; … … 11 21 off_t found = 0; 12 22 23 gettimeofday (&start, (void *) NULL); 24 25 insert_detections_mysql_init (&buffer); 26 27 if (!mysql) { 28 catalog[0].Naverage = 5; 29 } 13 30 for (i = 0; i < catalog[0].Naverage; i++) { 14 31 … … 21 38 22 39 // XXX check return status 23 insert_detections_mysql (&average[i], &measure[m+j], mysql); 40 insert_detections_mysql_value (&buffer, &average[i], &measure[m+j]); 41 42 if (buffer.Nalloc > 0x100000) { 43 insert_detections_mysql_commit (&buffer, mysql); 44 if (0) { 45 FlushIOBuffer (&buffer); 46 } else { 47 buffer.Nbuffer = 0; 48 bzero (buffer.buffer, buffer.Nalloc); 49 } 50 insert_detections_mysql_init (&buffer); 51 } 24 52 25 53 found ++; 26 54 } 27 55 } 56 insert_detections_mysql_commit (&buffer, mysql); 28 57 29 fprintf (stderr, "inserted "OFF_T_FMT" rows, skipped %d without IDs\n", found, missingID);58 MARKTIME("-- inserted "OFF_T_FMT" rows in %f sec, skipped %d without IDs\n", found, dtime, missingID); 30 59 return (TRUE); 31 60 } 32 61 33 int insert_detections_mysql (Average *average, Measure *measure, MYSQL *mysql) {62 int insert_detections_mysql_init (IOBuffer *buffer) { 34 63 35 // XXX length OK? 36 char sql[1024]; 64 if (buffer->Nalloc == 0) { 65 InitIOBuffer (buffer, 1024); 66 } 37 67 68 PrintIOBuffer (buffer, "INSERT INTO dvoDetection (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n"); 69 70 return TRUE; 71 } 72 73 int insert_detections_mysql_value (IOBuffer *buffer, Average *average, Measure *measure) { 74 75 // XXX I am changing the def of ippObjID if I use the code below 38 76 PhotCode *code = GetPhotcodebyCode(measure->photcode); 39 sprintf(sql, 40 "INSERT INTO dvoDetection (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES (%d, %u, %lu, %lu, %lu, %u, %f, %f, %f, %f, %lf, %lf, %f, %f)", 77 PrintIOBuffer (buffer, " (%d, %u, %lu, %lu, %lu, %u, %f, %f, %f, %f, %lf, %lf, %f, %f),\n", 41 78 measure->imageID, // imageID 42 79 measure->detID, // ippDetectID 43 80 measure->extID, // detectID 44 ( uint64_t)average->catID*1000000000+ (uint64_t)average->objID, // ippObjID81 ((uint64_t)average->catID << 32) + (uint64_t)average->objID, // ippObjID 45 82 average->extID, // objID 46 83 measure->dbFlags, // flags … … 54 91 measure->dYccd * 0.01 * fabs(measure->pltscale) // estimate of decErr 55 92 ); 56 93 return TRUE; 94 } 95 96 int insert_detections_mysql_commit (IOBuffer *buffer, MYSQL *mysql) { 97 98 // check that the last two chars are ,\n and replace with ;\n 99 if (!strcmp(&buffer->buffer[buffer->Nbuffer-2], ",\n")) { 100 fprintf (stderr, "valid sql\n"); 101 buffer->buffer[buffer->Nbuffer-2] = ';'; 102 } else { 103 fprintf (stderr, "invalid sql?\n"); 104 return FALSE; 105 } 106 57 107 // XXX check return status 58 108 if (mysql) { 59 mysql_query(mysql, sql);109 mysql_query(mysql, buffer->buffer); 60 110 } else { 61 fprintf (stderr, "%s\n", sql);111 fprintf (stderr, "%s\n", buffer->buffer); 62 112 } 63 113 -
branches/eam_branches/ipp-20121219/Ohana/src/dvopsps/test/dbadmin.sh
r34917 r34919 47 47 endif 48 48 49 if ("$1" == "delete") then 50 if ($#argv != 4) goto usage; 51 set dbhost = $2 52 set dbname = $3 53 set dbuser = $4 54 55 mysql -h $dbhost -u $dbuser -p <<EOF > /dev/null 56 USE $dbname; 57 describe dvoDetection; 58 EOF 59 60 if ($status) then 61 echo "database does not contain dvoDetections, not deleting" 62 exit 1; 63 endif 64 65 echo "database is valid, deleting" 66 mysql -h $dbhost -u $dbuser -p <<EOF 67 drop database $dbname; 68 EOF 69 70 exit 0; 71 endif 72 49 73 usage: 50 74 echo "USAGE: dbadmin.sh (options)"
Note:
See TracChangeset
for help on using the changeset viewer.
