Index: /trunk/FACT++/src/calcsource.cc
===================================================================
--- /trunk/FACT++/src/calcsource.cc	(revision 19068)
+++ /trunk/FACT++/src/calcsource.cc	(revision 19069)
@@ -1,4 +1,2 @@
-#include <boost/algorithm/string/join.hpp>
-
 #include "Database.h"
 
@@ -9,9 +7,4 @@
 
 #include <TROOT.h>
-#include <TSystem.h>
-#include <TFile.h>
-#include <TTree.h>
-#include <TLeaf.h>
-#include <TError.h>
 #include <TVector3.h>
 #include <TRotation.h>
@@ -21,32 +14,13 @@
 // ------------------------------------------------------------------------
 
-struct Map : pair<string, string>
-{
-    Map() { }
-};
-
-std::istream &operator>>(std::istream &in, Map &m)
-{
-    string txt;
-    in >> txt;
-
-    const auto p = txt.find_first_of('/');
-    if (p==string::npos)
-        throw runtime_error("Missing / in map argument.");
-    if (p!=txt.find_last_of('/'))
-        throw runtime_error("Only one / allowed in map argument.");
-
-    m.first  = txt.substr(0, p);
-    m.second = txt.substr(p+1);
-
-    return in;
-}
-
-
 void SetupConfiguration(Configuration &conf)
 {
-    po::options_description control("Root to Database");
+    po::options_description control("Calcsource options");
     control.add_options()
-        ("uri,u",          var<string>()->required(), "Database link as in\n\tuser:password@server[:port]/database.")
+        ("uri,u",          var<string>()
+#if BOOST_VERSION >= 104200
+         ->required()
+#endif
+         , "Database link as in\n\tuser:password@server[:port]/database.")
         //("source-key",     var<uint32_t>(5),                "")
         //("source-name",    var<string>(""),               "")
@@ -81,85 +55,56 @@
     cout <<
         "calcsource - Fill a table with source positions\n"
-//        "\n"
-//        "Usage: rootifysql [rootify.sql [rootify.root]] [-u URI] [-q query|-f file] [-i] [-o out] [-f] [-cN] [-t tree] [-vN]\n"
+        "\n"
+        "This tool is to calculate the source position in the camera and fill "
+        "it into a database table for all events which come from a single run. "
+        "The run is idetified by its FileId (YYMMDDXXX), where YYMMDD is "
+        "its date and XXX is the run-number. For this run the corresponding "
+        "source key `fSourceKey` is obtained from the RunInfo table "
+        "(--table.runinfo) and the corresponding fRightAscension and fDeclination "
+        "from the Source table (--table.source). If --ra and --dec was specified "
+        "by the user, this step is skipped and these two values are used instead."
+        "\n\n"
+        "Then for each event with the given FileId, its pointing position "
+        "(`Ra`, `Dec`), its time (`MJD`, `MilliSec`) and its event number "
+        "(`EvtNumber`) are requested from the table given by --table.events. "
+        "Based on this information and the focal distance (--focal-distance) the "
+        "`X` and `Y` coordinate of the source in the camera plane is calculated. "
+        "The result can then be filled into a database."
+        "\n\n"
+        "The table to be filled or updated should contain the following columns:\n"
+        "   - FileId INT UNSIGNED NOT NULL\n"
+        "   - EvtNumber INT UNSIGNED NOT NULL\n"
+        "   - X FLOAT NOT NULL\n"
+        "   - Y FLOAT NOT NULL\n"
+        "\n"
+        "If the table does not exist, it can be created automatically specifying "
+        "the --crate option. If a table already exists and it should be dropped "
+        "before creation, the --drop option can be used:\n"
+        "\n"
+        "   calcsource 170909009 --create\n"
+        "\n"
+        "Process the data from the run 009 from 09/09/2017. If no table exists "
+        "a table with the name given by --table.position is created.\n"
+        "\n"
+        "   calcsource 170909009 --create --drop\n"
+        "\n"
+        "Same as before, but if a table with the name given by --table.position "
+        "exists, it is dropped before.\n"
+        "\n"
+        "For each event, a new row is inserted. If existing rows should be updated, "
+        "use:\n"
+        "\n"
+        "   calcsource 170909009 --updated\n"
+        "\n"
+        "The --create option is compatible with that. The --drop option is ignored.\n"
+        "\n"
+        "For debugging purposes several print options and options to avoid irreversible "
+        "changes to the database exist."
+        "\n\n"
+        "Usage: calcsource YYMMDDXXX [-u URI] [options]\n"
         "\n"
         ;
     cout << endl;
 }
-
-enum BasicType_t
-{
-    kNone = 0,
-    kFloat,
-    kDouble,
-    kInt16,
-    kUInt16,
-    kInt32,
-    kUInt32,
-    kInt64,
-    kUInt64,
-};
-
-static const map<string, pair<BasicType_t, string>> ConvRoot =
-{
-    { "Float_t",   { kFloat,  "FLOAT"             } },
-    { "Double_t",  { kDouble, "DOUBLE"            } },
-    { "ULong64_t", { kUInt64, "BIGINT UNSIGNED"   } },
-    { "Long64_t",  { kInt64,  "BIGINT"            } },
-    { "UInt_t",    { kUInt32, "INT UNSIGNED"      } },
-    { "Int_t",     { kInt32,  "INT"               } },
-    { "UShort_t",  { kUInt16, "SMALLINT UNSIGNED" } },
-    { "Short_t",   { kInt16,  "SMALLINT"          } },
-};
-
-struct Container
-{
-    string branch; // branch name
-    string column; // column name
-    BasicType_t type;
-    void *ptr;
-
-    Container(const string &b, const string &c, const BasicType_t &t) : branch(b), column(c), type(t), ptr(0)
-    {
-        switch (t)
-        {
-        case kFloat:  ptr = new Float_t;   break;
-        case kDouble: ptr = new Double_t;  break;
-        case kInt16:  ptr = new Short_t;   break;
-        case kUInt16: ptr = new UShort_t;  break;
-        case kInt32:  ptr = new Int_t;     break;
-        case kUInt32: ptr = new UInt_t;    break;
-        case kInt64:  ptr = new Long64_t;  break;
-        case kUInt64: ptr = new ULong64_t; break;
-        case kNone:
-            break;
-        }
-    }
-    ~Container()
-    {
-        //::operator delete(ptr); // It seems root is deleting it already
-    }
-
-    string fmt() const
-    {
-        ostringstream str;
-
-        switch (type)
-        {
-        case kFloat:   str << setprecision(8) << *reinterpret_cast<Float_t*>(ptr); break;
-        case kDouble:  str << setprecision(16) << *reinterpret_cast<Double_t*>(ptr); break;
-        case kInt16:   str << *reinterpret_cast<Short_t*>(ptr); break;
-        case kUInt16:  str << *reinterpret_cast<UShort_t*>(ptr); break;
-        case kInt32:   str << *reinterpret_cast<Int_t*>(ptr); break;
-        case kUInt32:  str << *reinterpret_cast<UInt_t*>(ptr); break;
-        case kInt64:   str << *reinterpret_cast<Long64_t*>(ptr); break;
-        case kUInt64:  str << *reinterpret_cast<ULong64_t*>(ptr); break;
-        case kNone:
-            break;
-        }
-
-        return str.str();
-    }
-};
 
 class MRotation : public TRotation
@@ -172,12 +117,4 @@
 
 
-void ErrorHandlerAll(Int_t level, Bool_t abort, const char *location, const char *msg)
-{
-    if (string(msg).substr(0,24)=="no dictionary for class ")
-        return;
-
-    DefaultErrorHandler(level, abort, location, msg);
-}
-
 int main(int argc, const char* argv[])
 {
@@ -185,5 +122,4 @@
 
     gROOT->SetBatch();
-    SetErrorHandler(ErrorHandlerAll);
 
     Configuration conf(argv[0]);
