| 1 | To calculate the source position for each event (from the '''Events''' table) in the camera, a tool called `calcsource` was developed. |
| 2 | |
| 3 | The toll is called like this |
| 4 | {{{ |
| 5 | calcsource YYMMDDNNN |
| 6 | }}} |
| 7 | where '''YYMMDDNNN''' is the identifier of a run created from the night of sun-set '''YYMMDD''' and the run-id '''NNN'''. It is also known as FileId. |
| 8 | |
| 9 | == Getting the source == |
| 10 | |
| 11 | The tool then requests right ascension and declination of the source observed with a given run by the following query: |
| 12 | |
| 13 | {{{#!sql |
| 14 | SELECT |
| 15 | Source.fRightAscension, |
| 16 | Source.fDeclination, |
| 17 | Source.fSourceName |
| 18 | FROM |
| 19 | RunInfo |
| 20 | LEFT JOIN |
| 21 | Source USING (fSourceKey) |
| 22 | WHERE |
| 23 | fNight=20YYMMDD |
| 24 | AND |
| 25 | fRunID=NNN |
| 26 | }}} |
| 27 | |
| 28 | Here, YYMMDD and NNN are again the parts from the FileId given as positional option. |
| 29 | |
| 30 | The table names `Source` and `RunInfo` can be altered by the options `--table.source` and `--table.runinfo`. |
| 31 | |
| 32 | == Getting events == |
| 33 | |
| 34 | Then, a list of all event times and the pointing position in terms of right ascension/declination together with the corresponding event number is obtained for the given run by |
| 35 | {{{#!sql |
| 36 | SELECT |
| 37 | `Ra`, |
| 38 | `Dec`, |
| 39 | MJD, |
| 40 | MilliSec, |
| 41 | NanoSec, |
| 42 | EvtNumber |
| 43 | FROM |
| 44 | Events |
| 45 | WHERE |
| 46 | FileId=YYMMDDNNN |
| 47 | }}} |
| 48 | |
| 49 | The FileId comes again from the command line argument. The table name for the '''Events''' table can be altered by `--table.events`. |
| 50 | |
| 51 | For source and pointing position, zenith distance and azimuth is calculated using `libnova` and the wrapper `Nova::GetHrzFromEqu`. The result is then rotated into the camera and projected on a plane which gives the x/y coordinates in the camera. |
| 52 | |
| 53 | The result is then inserted into a table '''Position''' which name can be altered with `--table.position`. By default, all entries corresponding to the given FileId are deleted from the table before the new positions are inserted running |
| 54 | {{{#!sql |
| 55 | DELETE FROM Position WHERE FileId=YYMMDDNNN |
| 56 | }}} |
| 57 | |
| 58 | |
| 59 | == Table Creation == |
| 60 | |
| 61 | It is not very handy if the SQL table has to be created manually beforehand. Therefore, `calcsource` can automatically create the table. To do this, specify `--create`. The query which would be used to create the table can be printed with `--print-create` even when `--create` has not been specified. Tables are created only if the do not yet exist (`CREATE TABLE IF NOT EXISTS`). To ensure recreation of a table, the old table can be dropped with `--drop`. As any insert operation would fail if the required table is dropped and no new one is created, `--drop` always implies `--create`. |
| 62 | |
| 63 | The table is created as |
| 64 | |
| 65 | {{{!#sql |
| 66 | CREATE TABLE IF NOT EXISTS Position |
| 67 | ( |
| 68 | FileId INT UNSIGNED NOT NULL, |
| 69 | EvtNumber INT UNSIGNED NOT NULL, |
| 70 | X FLOAT NOT NULL, |
| 71 | Y FLOAT NOT NULL, |
| 72 | PRIMARY KEY (FileId, EvtNumber) |
| 73 | ) |
| 74 | DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci |
| 75 | }}} |
| 76 | |
| 77 | === Database Engine === |
| 78 | |
| 79 | The default database engine is to create the table with the default of the database. If a database engine (`ENGINE=`) should be forced for the table the `--engine ENGINE` option can be used. Similarly, the row-format (`ROW_FORMAT=`) can be defined using `--row-format FORMAT`. For example: |
| 80 | |
| 81 | {{{ |
| 82 | --engine InnoDB --row-format=COMPRESSED |
| 83 | }}} |
| 84 | |
| 85 | == Ignore duplicate entries == |
| 86 | |
| 87 | Usually, the `INSERT` query would fail if another row with the same primary key exists already. This can be avoided adding the `IGNORE` keyword to the `INSERT` query by `--ignore-errors`, which essentially ignores all errors and turns them into warnings which are printed after the query succeeded. |
| 88 | |
| 89 | If the `--update` option is given, column are updated with `ON DUPLICATE KEY UPDATE X=VALUES(X), Y=VALUES(Y)`. |
| 90 | |
| 91 | == Source position == |
| 92 | |
| 93 | Instead of obtaining the source position automatically, right-ascension and declination can be specified manually with `--ra` and `--dec`. |
| 94 | |
| 95 | == Focal Distance == |
| 96 | |
| 97 | For a correct calculation of X and Y, the focal distance has to be known. The default is 4889mm. It can be altered with `--focal-dist`. |
| 98 | |
| 99 | == Debugging == |
| 100 | |
| 101 | The `INSERT` query can be skipped with `--insert`. A dry run which guarantees that nothing in the database is altered can be done with `--dry-run` (note that this might produce subsequent errors). |
| 102 | |
| 103 | To print out the meta queries (DROP, CREATE, DELETE, SELECT), the option `--print-meta` exists. The longer `INSERT` query can be printed using `--print-insert`. |