Index: trunk/MagicSoft/Mars/datacenter/macros/fillcamera.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/fillcamera.C	(revision 9144)
+++ trunk/MagicSoft/Mars/datacenter/macros/fillcamera.C	(revision 9216)
@@ -50,4 +50,5 @@
 #include <iomanip>
 
+#include <TEnv.h>
 #include <TRegexp.h>
 #include <TObjectTable.h>
@@ -222,10 +223,16 @@
     TString psfy      = Form("%5.2f", pointspready);
     TString psfadd    = Form("%5.2f", TMath::Hypot(runheader2->GetPointSpreadX(), runheader2->GetPointSpread()));
+    Int_t mirr = runheader2->GetMirrorFraction();
     TString mirrfrac  = Form("%5.2f", runheader2->GetMirrorFraction());
+    if (mirr < 0 )
+        mirrfrac = "NULL";
     TString misx      = Form("%5.2f", misptx);
     TString misy      = Form("%5.2f", mispty);
     TString reflector = Form("%5.0i", reflvers);
     TString camera    = Form("%5.0i", camvers);
+    Int_t impact = runheader3->GetImpactMax();
     TString imax      = Form("%5.1f", runheader3->GetImpactMax());
+    if (impact < 0)
+        imax = "NULL";
     TString numphe    = Form("%5.1f", runheader3->GetNumPheFromDNSB());
     TString pmin      = Form("%5.1f", runheader3->GetShowerPhiMin());
@@ -257,4 +264,14 @@
 //    TString numtrig   = Form("%7.0i", TMath::Nint(h.GetBinContent(2)));
 
+    UInt_t nsumtrig = (UInt_t)tree2->Draw("Length$(MRawEvtHeader.fTrigPattern[0])","(MRawEvtHeader.fTrigPattern[0]==0xffffdfdf) || (MRawEvtHeader.fTrigPattern[0]==0xffffdede)","goff");
+    if (nsumtrig<0)
+    {
+        cout << "ERROR - Evaluating sumtrigger events in file: " << fname << endl;
+        return 2;
+    }
+    TString numsumtrig   = Form("%7.0i", nsumtrig);
+    if (nsumtrig==0)
+        numsumtrig = "0";
+
     // Determine observation mode, fake wobble means On mode with mispointing
     TString wobblemod="Wobble";
@@ -280,5 +297,9 @@
     // Get zbin
     Float_t zBin=TMath::Nint((1-((TMath::Cos(tmin*TMath::Pi()/180)+TMath::Cos(tmax*TMath::Pi()/180))/2))*100);
+    Float_t zBinmin=TMath::Nint((1-(TMath::Cos(tmin*TMath::Pi()/180)))*100);
+    Float_t zBinmax=TMath::Nint((1-(TMath::Cos(tmax*TMath::Pi()/180)))*100);
     Int_t zBin2=TMath::Nint(zBin);
+    Int_t zBin2Min=TMath::Nint(zBinmin);
+    Int_t zBin2Max=TMath::Nint(zBinmax);
 
     // Definition of keys
@@ -294,4 +315,5 @@
     Int_t viewconeangleokey;
     Int_t spectrumkey;
+    Int_t triggerkey;
 
     // Definition of variables to be filled in the db
@@ -317,4 +339,5 @@
         cout << "NumEvents       " << numevt    << endl;
         cout << "NumTriggers     " << numtrig   << endl;
+        cout << "NumSumTriggers  " << numsumtrig   << endl;
         cout << "NumPheFromDNSB  " << numphe    << endl;
         cout << "ViewconeAngleInner  " << coneanglei << endl;
@@ -359,4 +382,5 @@
         viewconeangleokey = serv.QueryKeyOfName("ViewconeAngleO", coneangleo.Data());
         spectrumkey    = 1;
+        triggerkey = nsumtrig == 0 ? 2 : 3;
         psfkey         = 1;
         spotsizekey    = 1;
@@ -398,4 +422,5 @@
         cout << "coneangleokey:  " << viewconeangleokey << endl;
         cout << "spectrumkey:    " << spectrumkey << endl;
+        cout << "triggerkey:     " << triggerkey << endl;
         cout << endl;
 
@@ -432,4 +457,5 @@
         cout << "NumEvents       " << numevt    << endl;
         cout << "NumTriggers     " << numtrig   << endl;
+        cout << "NumSumTriggers  " << numsumtrig   << endl;
         cout << "NumPheFromDNSB  " << numphe    << endl;
         cout << "ViewconeAngleInner  " << coneanglei << endl;
@@ -465,4 +491,6 @@
         spotsizekey    = serv.QueryKeyOfName("AddSpotSize", addspot);
         spectrumkey    = serv.QueryKeyOfName("Spectrum", slope);
+        triggerkey = nsumtrig == 0 ? 2 : 3;
+
 
         if (corsvers==0)
@@ -502,4 +530,5 @@
         cout << "coneangleokey:  " << viewconeangleokey << endl;
         cout << "spectrumkey:    " << spectrumkey << endl;
+        cout << "triggerkey:     " << triggerkey << endl;
         cout << endl;
 
@@ -555,5 +584,5 @@
             Form("fELowLim=%s, fEUppLim=%s, fSlopeSpec=%5.2f, "
                  "fImpactMax=%s, fNumSimulatedShowers=%d, fNumEvents=%d, "
-                 "fNumPheFromDNSB=%s, fZBin=%d, fThetaMin=%s, "
+                 "fNumPheFromDNSB=%s, fZBin=%d, fZBinMin=%d, fZBinMax=%d, fThetaMin=%s, "
                  "fThetaMax=%s, fPointSpread=%s, "
                  "fPedesMean=%s, fLow2HighGain=%s, "
@@ -561,5 +590,5 @@
                  elow.Data(), eupp.Data(), spectrum,
                  imax.Data(), numsimshow, numevents,
-                 numphe.Data(), zBin2, thetamin.Data(),
+                 numphe.Data(), zBin2, zBin2Min, zBin2Max, thetamin.Data(),
                  thetamax.Data(), psf.Data(),
                  ped.Data(), low2high.Data(),
@@ -571,7 +600,7 @@
                  "fReflectorVersionKEY=%d, fCameraVersionKEY=%d, "
                  "fObservationModeKEY=%d, fMCParticleKEY=%d, "
-                 "fSequenceFirst=0, fNumTriggers=%d, fViewconeAngleInner=%5.2f, fViewconeAngleOuter=%5.2f, "
+                 "fSequenceFirst=0, fNumTriggers=%d, fNumSumTriggers=%d, fViewconeAngleInner=%5.2f, fViewconeAngleOuter=%5.2f, "
                  "fAtmosphericModelKEY=%d, fAmplFadcKEY=%d, fAddSpotSizeKEY=%d, "
-                 "fPSFKEY=%d, fViewconeAngleOKEY=%d, fSpectrumKEY=%d ",
+                 "fPSFKEY=%d, fViewconeAngleOKEY=%d, fSpectrumKEY=%d, fTriggerFlagKEY=%d ",
                  enoise.Data(),
                  dnoise.Data(), RunNum,
@@ -579,7 +608,7 @@
                  reflectorkey, camerakey,
                  observationkey, particlekey,
-                 ntrig, coneai, coneao,
+                 ntrig, nsumtrig, coneai, coneao,
                  atmomodelkey, amplfadckey, spotsizekey,
-                 psfkey, viewconeangleokey, spectrumkey);
+                 psfkey, viewconeangleokey, spectrumkey, triggerkey);
 
         TString vars2 =
@@ -625,5 +654,5 @@
                 Form("fELowLim=%s, fEUppLim=%s, fSlopeSpec=%5.2f, "
                      "fImpactMax=%s, fNumSimulatedShowers=%d, fNumEvents=%d, "
-                     "fNumPheFromDNSB=%s, fZBin=%d, fThetaMin=%s, "
+                     "fNumPheFromDNSB=%s, fZBin=%d, fZBinMin=%d, fZBinMax=%d, fThetaMin=%s, "
                      "fThetaMax=%s, fPointSpread=%s, "
                      "fPedesMean=%s, fLow2HighGain=%s, "
@@ -631,5 +660,5 @@
                      elow.Data(), eupp.Data(), spectrum,
                      imax.Data(), numsimshow, numevents,
-                     numphe.Data(), zBin2, thetamin.Data(),
+                     numphe.Data(), zBin2, zBin2Min, zBin2Max, thetamin.Data(),
                      thetamax.Data(), psf.Data(),
                      ped.Data(), low2high.Data(),
@@ -641,7 +670,7 @@
                      "fReflectorVersionKEY=%d, fCameraVersionKEY=%d, "
                      "fObservationModeKEY=%d, fMCParticleKEY=%d, "
-                     "fSequenceFirst=0, fNumTriggers=%d, fViewconeAngleInner=%5.2f, fViewconeAngleOuter=%5.2f, "
+                     "fSequenceFirst=0, fNumTriggers=%d, fNumSumTriggers=%d, fViewconeAngleInner=%5.2f, fViewconeAngleOuter=%5.2f, "
                      "fAtmosphericModelKEY=%d, fAmplFadcKEY=%d, fAddSpotSizeKEY=%d, "
-                     "fPSFKEY=%d, fViewconeAngleOKEY=%d, fSpectrumKEY=%d ",
+                     "fPSFKEY=%d, fViewconeAngleOKEY=%d, fSpectrumKEY=%d, fTriggerFlagKEY=%d ",
                      enoise.Data(),
                      dnoise.Data(), RunNum,
@@ -649,7 +678,7 @@
                      reflectorkey, camerakey,
                      observationkey, particlekey,
-                     ntrig, coneai, coneao,
+                     ntrig, nsumtrig, coneai, coneao,
                      atmomodelkey, amplfadckey, spotsizekey,
-                     psfkey, viewconeangleokey, spectrumkey);
+                     psfkey, viewconeangleokey, spectrumkey, triggerkey);
 
             TString vars2 =
@@ -686,5 +715,5 @@
 //    delete row;
 
-    //link file geht nur für data files, cal und ped haben keine psf... müssen aber in alle verzeichnisse verlinkt werden
+    //link file geht nur fuer data files, cal und ped haben keine psf... muessen aber in alle verzeichnisse verlinkt werden
     //wieder mit if point 0.5/-1.0 else
 
@@ -717,5 +746,6 @@
     TString particle = (*row)[0];    //ParticleName abfragen
     TString spec     = (*row)[1];    //Spectrum.fSpectrum abfragen
-    TString obsmode;             //wird über obskey präzisiert
+    TString obsmode;             //wird ueber obskey praezisiert
+    TString trigmode;            //wird ueber triggerkey praezisiert
     TString mkdir;
     TString link;
@@ -778,4 +808,17 @@
     }
 
+    switch(triggerkey)
+    {
+    case 2:
+        obsmode += "";
+        break;
+    case 3:
+        obsmode += "SUM";
+        break;
+    default:
+        cout << "ERROR - TriggerFlagKEY wrong value" << endl;
+        return 2;
+    }
+
     if (observationkey!=1)
     {
@@ -858,8 +901,8 @@
 {
 //    TEnv env("mcsql.rc");
-//    TEnv env("sql.rc");
-
-//    MSQLMagic serv(env);
-    MSQLMagic serv("sql.rc");
+    TEnv env("sql.rc");
+
+    MSQLMagic serv(env);
+//    MSQLMagic serv("sql.rc");
     if (!serv.IsConnected())
     {
