Index: trunk/FACT++/src/ftmctrl.cc
===================================================================
--- trunk/FACT++/src/ftmctrl.cc	(revision 11338)
+++ trunk/FACT++/src/ftmctrl.cc	(revision 11344)
@@ -722,6 +722,5 @@
             return true;
 
-        for (int i=0; i<40; i++)
-            data[i].fPrescaling = value;
+        data.SetPrescaling(value);
 
         // Maybe move to a "COMMIT" command?
@@ -837,10 +836,11 @@
         FTM::StaticData data(fStaticData);
 
-        data.Enable(FTM::StaticData::kPedestal, d[0]>0);
-        data.Enable(FTM::StaticData::kLPext,    d[1]>0);
-        data.Enable(FTM::StaticData::kLPint,    d[2]>0);
-
-        data.fTriggerSequence =
-            (uint16_t(d[0])<<10) | (uint16_t(d[2])<<5) | uint16_t(d[1]);
+        /*
+         data.Enable(FTM::StaticData::kPedestal, d[0]>0);
+         data.Enable(FTM::StaticData::kLPext,    d[1]>0);
+         data.Enable(FTM::StaticData::kLPint,    d[2]>0);
+         */
+
+        data.SetSequence(d[0], d[2], d[1]);
 
         //if (fStaticData.fTriggerSeq     !=data.fTriggerSequence ||
@@ -926,10 +926,8 @@
 
         for (int i=0; i<8; i++)
-        {
             if (reg[i]>0xffffffff)
                 return false;
 
-            data.fClockConditioner[i] = reg[i];
-        }
+        data.SetClockRegister(reg);
 
         CmdSendStatDat(data);
@@ -1966,4 +1964,25 @@
 
     map<uint16_t, boost::array<uint64_t, 8>> fClockCondSetup;
+
+    template<class V>
+    bool CheckConfigVal(const Configuration &conf, V max, const string &name, const string &sub)
+    {
+        if (!conf.HasDef(name, sub))
+        {
+            T::Error("Neither "+name+"default nor "+name+sub+" found.");
+            return false;
+        }
+
+        const V val = conf.GetDef<V>(name, sub);
+
+        if (val<=max)
+            return true;
+
+        ostringstream str;
+        str << name << sub << "=" << val << " exceeds allowed maximum of " << max << "!";
+        T::Error(str);
+
+        return false;
+    }
 
     int EvalConfiguration(const Configuration &conf)
@@ -2004,12 +2023,12 @@
             boost::array<uint64_t, 8> &arr = fClockCondSetup[*it];
 
-            arr[0] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R0.",  *it);
-            arr[1] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R1.",  *it);
-            arr[2] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R8.",  *it);
-            arr[3] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R9.",  *it);
-            arr[4] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R11.", *it);
-            arr[5] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R13.", *it);
-            arr[6] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R14.", *it);
-            arr[7] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R15.", *it);
+            arr[0] = conf.GetDef<Hex<uint32_t>>("clock-conditioner.R0.",  *it);
+            arr[1] = conf.GetDef<Hex<uint32_t>>("clock-conditioner.R1.",  *it);
+            arr[2] = conf.GetDef<Hex<uint32_t>>("clock-conditioner.R8.",  *it);
+            arr[3] = conf.GetDef<Hex<uint32_t>>("clock-conditioner.R9.",  *it);
+            arr[4] = conf.GetDef<Hex<uint32_t>>("clock-conditioner.R11.", *it);
+            arr[5] = conf.GetDef<Hex<uint32_t>>("clock-conditioner.R13.", *it);
+            arr[6] = conf.GetDef<Hex<uint32_t>>("clock-conditioner.R14.", *it);
+            arr[7] = conf.GetDef<Hex<uint32_t>>("clock-conditioner.R15.", *it);
 
             ostringstream out;
@@ -2018,4 +2037,127 @@
                 out << " " << setw(8) << arr[i];
             T::Message(out.str());
+        }
+
+        // ---------- Setup run types ---------
+        const vector<string> types = conf.Get<vector<string>>("run-type");
+        if (types.size()==0)
+            T::Warn("No run-types defined.");
+
+        T::Message("Defining run-types");
+        for (vector<string>::const_iterator it=types.begin();
+             it!=types.end(); it++)
+        {
+            if (fConfigs.count(*it)>0)
+            {
+                T::Error("Run-type "+*it+" defined twice.");
+                return 2;
+            }
+
+            FTM::StaticData data;
+
+            const uint16_t frq = conf.GetDef<uint16_t>("sampling-frequency.", *it);
+            if (fClockCondSetup.count(frq)==0)
+            {
+                T::Error("sampling-frequency."+*it+" - frequency not available.");
+                return 2;
+            }
+
+            data.SetClockRegister(fClockCondSetup[frq].data());
+
+            // Trigger sequence ped:lp1:lp2
+            // (data. is used here as an abbreviation for FTM::StaticData::
+            if (!CheckConfigVal<bool>    (conf, true,                     "enable-trigger.",             *it) ||
+                !CheckConfigVal<bool>    (conf, true,                     "enable-external-1.",          *it) ||
+                !CheckConfigVal<bool>    (conf, true,                     "enable-external-2.",          *it) ||
+                !CheckConfigVal<bool>    (conf, true,                     "enable-veto.",                *it) ||
+                !CheckConfigVal<bool>    (conf, true,                     "enable-clock-conditioner.",   *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxSequence,        "trigger-sequence-ped.",       *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxSequence,        "trigger-sequence-lp-ext.",    *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxSequence,        "trigger-sequence-lp-int.",    *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxTriggerInterval, "trigger-interval.",           *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxMultiplicity,    "multiplicity-physics.",       *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxMultiplicity,    "multiplicity-calib.",         *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxWindow,          "coincidence-window-physics.", *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxWindow,          "coincidence-window-calib.",   *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxDeadTime,        "dead-time.",                  *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxDelayTrigger,    "trigger-delay.",              *it) ||
+                !CheckConfigVal<uint16_t>(conf, data.kMaxDelayTimeMarker, "time-marker-delay.",          *it) ||
+                !CheckConfigVal<uint16_t>(conf, 0xffff,                   "ftu-report-interval.",        *it) ||
+                0)
+                return 2;
+
+            data.Enable(data.kTrigger,          conf.GetDef<bool>("enable-trigger.",           *it));
+            data.Enable(data.kExt1,             conf.GetDef<bool>("enable-external-1.",        *it));
+            data.Enable(data.kExt2,             conf.GetDef<bool>("enable-external-2.",        *it));
+            data.Enable(data.kVeto,             conf.GetDef<bool>("enable-veto.",              *it));
+            data.Enable(data.kClockConditioner, conf.GetDef<bool>("enable-clock-conditioner.", *it));
+
+            // [ms] Interval between two artificial triggers (no matter which type) minimum 1ms, 10 bit
+            data.fTriggerInterval     = conf.GetDef<uint16_t>("trigger-interval.",           *it);
+            data.fMultiplicityPhysics = conf.GetDef<uint16_t>("multiplicity-physics.",       *it);
+            data.fMultiplicityCalib   = conf.GetDef<uint16_t>("multiplicity-calib.",         *it);
+            data.fWindowPhysics       = conf.GetDef<uint16_t>("coincidence-window-physics.", *it); /// (4ns * x + 8ns)
+            data.fWindowCalib         = conf.GetDef<uint16_t>("coincidence-window-calib.",   *it); /// (4ns * x + 8ns)
+            data.fDelayTrigger        = conf.GetDef<uint16_t>("trigger-delay.",              *it); /// (4ns * x + 8ns)
+            data.fDelayTimeMarker     = conf.GetDef<uint16_t>("time-marker-delay.",          *it); /// (4ns * x + 8ns)
+            data.fDeadTime            = conf.GetDef<uint16_t>("dead-time.",                  *it); /// (4ns * x + 8ns)
+
+            data.SetPrescaling(conf.GetDef<uint16_t>("ftu-report-interval.", *it));
+
+            const uint16_t seqped = conf.GetDef<uint16_t>("trigger-sequence-ped.",       *it);
+            const uint16_t seqint = conf.GetDef<uint16_t>("trigger-sequence-lp-int.",    *it);
+            const uint16_t seqext = conf.GetDef<uint16_t>("trigger-sequence-lp-ext.",    *it);
+
+            data.SetSequence(seqped, seqint, seqext);
+
+            data.EnableAllFTU();
+            data.EnableAllPixel();
+
+            const vector<uint16_t> pat1 = conf.Vec<uint16_t>("disable-patch.default");
+            const vector<uint16_t> pat2 = conf.Vec<uint16_t>("disable-patch."+*it);
+
+            const vector<uint16_t> pix1 = conf.Vec<uint16_t>("disable-pixel.default");
+            const vector<uint16_t> pix2 = conf.Vec<uint16_t>("disable-pixel."+*it);
+
+            vector<uint16_t> pat, pix;
+            pat.insert(pat.end(), pat1.begin(), pat1.end());
+            pat.insert(pat.end(), pat2.begin(), pat2.end());
+            pix.insert(pix.end(), pix1.begin(), pix1.end());
+            pix.insert(pix.end(), pix2.begin(), pix2.end());
+
+            for (vector<uint16_t>::const_iterator ip=pat.begin(); ip!=pat.end(); ip++)
+            {
+                if (*ip>FTM::StaticData::kMaxPatchIdx)
+                {
+                    ostringstream str;
+                    str << "disable-patch.*=" << *ip << " exceeds allowed maximum of " << FTM::StaticData::kMaxPatchIdx << "!";
+                    T::Error(str);
+                    return 2;
+                }
+                data.DisableFTU(*ip);
+            }
+            for (vector<uint16_t>::const_iterator ip=pix.begin(); ip!=pix.end(); ip++)
+            {
+                if (*ip>FTM::StaticData::kMaxPixelIdx)
+                {
+                    ostringstream str;
+                    str << "disable-pixel.*=" << *ip << " exceeds allowed maximum of " << FTM::StaticData::kMaxPixelIdx << "!";
+                    T::Error(str);
+                    return 2;
+                }
+                data.EnablePixel(*ip, false);
+            }
+
+            fConfigs[*it] = data;
+
+            /*
+             threshold-A  data[n].fDAC[0] = val
+             threshold-B  data[n].fDAC[1] = val
+             threshold-C  data[n].fDAC[2] = val
+             threshold-D  data[n].fDAC[3] = val
+             threshold-H  data[n].fDAC[4] = val
+             */
+
+            // kMaxDAC = 0xfff,
         }
 
@@ -2148,13 +2290,34 @@
     po::options_description runtype("Run type configuration");
     runtype.add_options()
-        ("clock-conditioner.frequency", vars<uint16_t>(),      "Frequencies for which to setup the clock-conditioner")
-        ("clock-conditioner.R0.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R0 (replace * by the defined frequency)")
-        ("clock-conditioner.R1.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R1 (replace * by the defined frequency)")
-        ("clock-conditioner.R8.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R8 (replace * by the defined frequency)")
-        ("clock-conditioner.R9.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R9 (replace * by the defined frequency)")
-        ("clock-conditioner.R11.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R11 (replace * by the defined frequency)")
-        ("clock-conditioner.R13.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R13 (replace * by the defined frequency)")
-        ("clock-conditioner.R14.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R14 (replace * by the defined frequency)")
-        ("clock-conditioner.R15.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R15 (replace * by the defined frequency)")
+        ("clock-conditioner.frequency",  vars<uint16_t>(),      "Frequencies for which to setup the clock-conditioner")
+        ("clock-conditioner.R0.*",       var<Hex<uint32_t>>(),  "Clock-conditioner R0 (replace * by the defined frequency)")
+        ("clock-conditioner.R1.*",       var<Hex<uint32_t>>(),  "Clock-conditioner R1 (replace * by the defined frequency)")
+        ("clock-conditioner.R8.*",       var<Hex<uint32_t>>(),  "Clock-conditioner R8 (replace * by the defined frequency)")
+        ("clock-conditioner.R9.*",       var<Hex<uint32_t>>(),  "Clock-conditioner R9 (replace * by the defined frequency)")
+        ("clock-conditioner.R11.*",      var<Hex<uint32_t>>(),  "Clock-conditioner R11 (replace * by the defined frequency)")
+        ("clock-conditioner.R13.*",      var<Hex<uint32_t>>(),  "Clock-conditioner R13 (replace * by the defined frequency)")
+        ("clock-conditioner.R14.*",      var<Hex<uint32_t>>(),  "Clock-conditioner R14 (replace * by the defined frequency)")
+        ("clock-conditioner.R15.*",      var<Hex<uint32_t>>(),  "Clock-conditioner R15 (replace * by the defined frequency)")
+        ("run-type",                     vars<string>(),        "")
+        ("sampling-frequency.*",         var<uint16_t>(),       "")
+        ("enable-trigger.*",             var<bool>(),           "")
+        ("enable-external-1.*",          var<bool>(),           "")
+        ("enable-external-2.*",          var<bool>(),           "")
+        ("enable-veto.*",                var<bool>(),           "")
+        ("enable-clock-conditioner.*",   var<bool>(),           "")
+        ("trigger-interval.*",           var<uint16_t>(),       "")
+        ("trigger-sequence-ped.*",       var<uint16_t>(),       "")
+        ("trigger-sequence-lp-int.*",    var<uint16_t>(),       "")
+        ("trigger-sequence-lp-ext.*",    var<uint16_t>(),       "")
+        ("multiplicity-physics.*",       var<uint16_t>(),       "")
+        ("multiplicity-calib.*",         var<uint16_t>(),       "")
+        ("coincidence-window-physics.*", var<uint16_t>(),       "")
+        ("coincidence-window-calib.*",   var<uint16_t>(),       "")
+        ("dead-time.*",                  var<uint16_t>(),       "")
+        ("trigger-delay.*",              var<uint16_t>(),       "")
+        ("time-marker-delay.*",          var<uint16_t>(),       "")
+        ("diable-pixel.*",               vars<uint16_t>(),      "")
+        ("diable-patch.*",               vars<uint16_t>(),      "")
+        ("ftu-report-interval.*",        var<uint16_t>(),       "")
         ;
 
