Index: trunk/FACT++/gui/FactGui.h
===================================================================
--- trunk/FACT++/gui/FactGui.h	(revision 11693)
+++ trunk/FACT++/gui/FactGui.h	(revision 11701)
@@ -402,4 +402,5 @@
     DimStampedInfo fDimFadRoi;
     DimStampedInfo fDimFadDac;
+    DimStampedInfo fDimFadDrsCalibration;
     DimStampedInfo fDimFadStatus;
     DimStampedInfo fDimFadStatistics1;
@@ -1139,33 +1140,78 @@
     void DisplayEventData()
     {
+        if (!fEventData)
+            return;
+
 #ifdef HAVE_ROOT
 	TCanvas *c = fAdcDataCanv->GetCanvas();
 
-	TH1 *h = dynamic_cast<TH1*>(c->FindObject("EventData"));
-	if (h && h->GetNbinsX()!=fEventData->Roi)
-	{
-	    delete h;
-	    h = 0;
+        TH1 *hf = dynamic_cast<TH1*>(c->FindObject("Frame"));
+        TH1 *h  = dynamic_cast<TH1*>(c->FindObject("EventData"));
+	TH1 *d0 = dynamic_cast<TH1*>(c->FindObject("DrsCalib0"));
+	TH1 *d1 = dynamic_cast<TH1*>(c->FindObject("DrsCalib1"));
+        TH1 *d2 = dynamic_cast<TH1*>(c->FindObject("DrsCalib2"));
+
+	if (hf && hf->GetNbinsX()!=fEventData->Roi)
+        {
+            delete hf;
+            delete h;
+            delete d0;
+            delete d1;
+            delete d2;
+	    hf = 0;
+        }
+
+	if (!hf)
+        {
+            c->cd();
+
+            const int roi = fEventData->Roi>0 ? fEventData->Roi : 1;
+
+            hf = new TH1F("Frame", "", roi, -0.5, roi-0.5);
+            hf->SetDirectory(0);
+            hf->SetBit(kCanDelete);
+	    hf->SetStats(kFALSE);
+	    hf->SetYTitle("Voltage [mV]");
+	    hf->GetXaxis()->CenterTitle();
+	    hf->GetYaxis()->CenterTitle();
+	    hf->SetMinimum(-1026);
+	    hf->SetMaximum(1025);
+
+            h = new TH1F("EventData", "", roi, -0.5, roi-0.5);
+            h->SetDirectory(0);
+            h->SetBit(kCanDelete);
+	    h->SetMarkerStyle(kFullDotMedium);
+	    h->SetMarkerColor(kBlue);
+
+            d0 = new TH1F("DrsCalib0", "", roi, -0.5, roi-0.5);
+	    d0->SetDirectory(0);
+            d0->SetBit(kCanDelete);
+	    d0->SetMarkerStyle(kFullDotSmall);
+	    d0->SetMarkerColor(kRed);
+	    d0->SetLineColor(kRed);
+
+            d1 = new TH1F("DrsCalib1", "", roi, -0.5, roi-0.5);
+	    d1->SetDirectory(0);
+            d1->SetBit(kCanDelete);
+	    d1->SetMarkerStyle(kFullDotSmall);
+	    d1->SetMarkerColor(kMagenta);
+	    d1->SetLineColor(kMagenta);
+
+            d2 = new TH1F("DrsCalib2", "", roi, -0.5, roi-0.5);
+            d2->SetDirectory(0);
+            d2->SetBit(kCanDelete);
+	    d2->SetMarkerStyle(kFullDotSmall);
+	    d2->SetMarkerColor(kGreen);
+	    d2->SetLineColor(kGreen);
+
+            hf->Draw("PL");
+            d0->Draw("PEX0same");
+	    d1->Draw("PEX0same");
+	    d2->Draw("PEX0same");
+            h->Draw("PLsame");
+
+            gPad = NULL;
 	}
 
-	if (!h)
-	{
-	    c->cd();
-
-            const int roi = fEventData->Roi>0 ? fEventData->Roi : 1;
-
-	    TH1D hist("EventData", "", roi, -0.5, roi-0.5);
-	    hist.SetStats(kFALSE);
-	    //hist->SetBit(TH1::kNoTitle);
-	    hist.SetMarkerStyle(kFullDotMedium);
-	    hist.SetMarkerColor(kBlue);
-	    hist.SetYTitle("Voltage [mV]");
-	    hist.GetXaxis()->CenterTitle();
-	    hist.GetYaxis()->CenterTitle();
-	    hist.SetMinimum(-1026);
-	    hist.SetMaximum(1025);
-	    h = hist.DrawCopy("PL");
-	    h->SetDirectory(0);
-	}
 
         const uint32_t p =
@@ -1178,41 +1224,76 @@
         str << "EventNum = " << fEventData->EventNum;
         str << "   TriggerNum = " << fEventData->TriggerNum;
-        str << "   Trigger type = " << fEventData->TriggerType;
-        str << "   Board time = " << fEventData->BoardTime[fAdcBoard->value()+fAdcCrate->value()*10];
+        str << "   TriggerType = " << fEventData->TriggerType;
+        str << "   BoardTime = " << fEventData->BoardTime[fAdcBoard->value()+fAdcCrate->value()*10];
         str << "   (" << Time(fEventData->PCTime, fEventData->PCUsec) << ")";
-        h->SetTitle(str.str().c_str());
+        hf->SetTitle(str.str().c_str());
         str.str("");
         str << "ADC Pipeline (start cell: " << fEventData->StartPix[p] << ")";
-	h->SetXTitle(str.str().c_str());
-
-	// str.str("");
-	// str << "Crate=" << crate << " Board=" << board << " Channel=" << channel << " [" << d.time() << "]" << endl;
-	// hist->SetTitle(str.str().c_str());
-
-	for (int i=0; i<fEventData->Roi; i++)
-	    h->SetBinContent(i+1, reinterpret_cast<float*>(fEventData->Adc_Data)[p*fEventData->Roi+i]);
+	hf->SetXTitle(str.str().c_str());
+
+        const int16_t start = fEventData->StartPix[p];
+        if (start<0)
+        {
+            d0->Reset();
+            d1->Reset();
+            d2->Reset();
+        }
+        for (int i=0; i<fEventData->Roi; i++)
+        {
+            h->SetBinContent(i+1, reinterpret_cast<float*>(fEventData->Adc_Data)[p*fEventData->Roi+i]);
+            if (start<0)
+                continue;
+
+            if (fDrsRuns[0]>0)
+            {
+                d0->SetBinContent(i+1, fDrsCalibration[1440*1024*0 + p*1024+(start+i)%1024]);
+                d0->SetBinError(i+1,   fDrsCalibration[1440*1024*1 + p*1024+(start+i)%1024]);
+
+                cout << i << ": " << fDrsCalibration[1440*1024*0 + p*1024+(start+i)%1024] <<  " " << fDrsCalibration[1440*1024*1 + p*1024+(start+i)%1024] << endl;
+
+            }
+            if (fDrsRuns[1]>0)
+            {
+                d1->SetBinContent(i+1, fDrsCalibration[1440*1024*2 + p*1024+(start+i)%1024]);
+                d1->SetBinError(i+1,   fDrsCalibration[1440*1024*3 + p*1024+(start+i)%1024]);
+            }
+            if (fDrsRuns[2]>0)
+            {
+                d2->SetBinContent(i+1, fDrsCalibration[1440*1024*4 + p*1024 + i]);
+                d2->SetBinError(i+1,   fDrsCalibration[1440*1024*5 + p*1024 + i]);
+            }
+        }
 
         if (fAdcDynamicScale->isChecked())
         {
-            h->SetMinimum(-1111);
-            h->SetMaximum(-1111);
+            h->SetMinimum();
+            h->SetMaximum();
+
+            hf->SetMinimum(h->GetMinimum());
+            hf->SetMaximum(h->GetMaximum());
         }
         if (fAdcManualScale->isChecked())
 	{
             if (h->GetMinimumStored()==-1111)
+            {
                 h->SetMinimum(-1026);
+                hf->SetMinimum(-1026);
+            }
             if (h->GetMaximumStored()==-1111)
+            {
                 h->SetMaximum(1025);
-        }
+                hf->SetMaximum(1025);
+            }
+        }
+
         if (fAdcAutoScale->isChecked())
         {
-            const double min = h->GetMinimumStored();
-            const double max = h->GetMaximumStored();
-
             h->SetMinimum();
             h->SetMaximum();
 
-            h->SetMinimum(h->GetMinimum()<min || min==-1111 ? h->GetMinimum() : min);
-            h->SetMaximum(h->GetMaximum()>max || max==-1111 ? h->GetMaximum() : max);
+            if (h->GetMinimum()<hf->GetMinimum())
+                hf->SetMinimum(h->GetMinimum());
+            if (h->GetMaximum()>hf->GetMaximum())
+                hf->SetMaximum(h->GetMaximum());
         }
 
@@ -1247,4 +1328,34 @@
         fEventData = reinterpret_cast<EVENT*>(new char[d.size()]);
         memcpy(fEventData, d.ptr<void>(), d.size());
+
+        DisplayEventData();
+    }
+
+    uint32_t fDrsRuns[3];
+    vector<float> fDrsCalibration;
+
+    void handleFadDrsCalibration(const DimData &d)
+    {
+        if (d.size()==0)
+        {
+            fDrsRuns[0] = 0;
+            fDrsRuns[1] = 0;
+            fDrsRuns[2] = 0;
+            fDrsCalibration.assign(1024*1440*6, 0);
+            DisplayEventData();
+            return;
+        }
+
+        if (!CheckSize(d, 1024*1440*6*sizeof(float)+3*sizeof(uint32_t)))
+            // Do WHAT?
+            return;
+
+        const uint32_t *run = d.ptr<uint32_t>();
+        fDrsRuns[0] = run[0];
+        fDrsRuns[1] = run[1];
+        fDrsRuns[2] = run[2];
+
+        const float *dat = d.ptr<float>(sizeof(uint32_t)*3);
+        fDrsCalibration.assign(dat, dat+1024*1440*6);
 
         DisplayEventData();
@@ -2387,4 +2498,7 @@
             return PostInfoHandler(&FactGui::handleFadDac);
 
+        if (getInfo()==&fDimFadDrsCalibration)
+            return PostInfoHandler(&FactGui::handleFadDrsCalibration);
+
         if (getInfo()==&fDimFadPrescaler)
             return PostInfoHandler(&FactGui::handleFadPrescaler);
@@ -2807,24 +2921,23 @@
         const double tm = Time().RootTime();
 
-        TH1F h("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
-        h.SetDirectory(0);
-//        h.SetBit(TH1::kCanRebin);
-        h.SetStats(kFALSE);
+        TH1F *h=new TH1F("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
+        h->SetDirectory(0);
+        h->SetBit(kCanDelete);
+        h->SetStats(kFALSE);
 //        h.SetMinimum(0);
 //        h.SetMaximum(1);
-        h.SetXTitle("Time");
-        h.SetYTitle(ytitle);
-        h.GetXaxis()->CenterTitle();
-	h.GetYaxis()->CenterTitle();
-        h.GetXaxis()->SetTimeDisplay(true);
-        h.GetXaxis()->SetTimeFormat("%Mh%S'");
-	h.GetXaxis()->SetLabelSize(0.025);
-	h.GetYaxis()->SetLabelSize(0.025);
-        h.GetYaxis()->SetTitleOffset(1.2);
+        h->SetXTitle("Time");
+        h->SetYTitle(ytitle);
+        h->GetXaxis()->CenterTitle();
+	h->GetYaxis()->CenterTitle();
+        h->GetXaxis()->SetTimeDisplay(true);
+        h->GetXaxis()->SetTimeFormat("%Mh%S'");
+	h->GetXaxis()->SetLabelSize(0.025);
+	h->GetYaxis()->SetLabelSize(0.025);
+        h->GetYaxis()->SetTitleOffset(1.2);
 	//        h.GetYaxis()->SetTitleSize(1.2);
-
-	TH1 *cpy = h.DrawCopy();
-	cpy->SetDirectory(0);
-        return cpy;
+        h->Draw();
+
+        return h;
     }
 #endif
@@ -2863,9 +2976,10 @@
         fDimFadRoi             ("FAD_CONTROL/REGION_OF_INTEREST", (void*)NULL, 0, this),
         fDimFadDac             ("FAD_CONTROL/DAC",                (void*)NULL, 0, this),
+        fDimFadDrsCalibration  ("FAD_CONTROL/DRS_CALIBRATION",    (void*)NULL, 0, this),
         fDimFadStatus          ("FAD_CONTROL/STATUS",             (void*)NULL, 0, this),
         fDimFadStatistics1     ("FAD_CONTROL/STATISTICS1",        (void*)NULL, 0, this),
         fDimFadStatistics2     ("FAD_CONTROL/STATISTICS2",        (void*)NULL, 0, this),
         //-
-	fEventData(0),
+	fEventData(0), fDrsCalibration(1440*1024*6),
 	fTimeStamp1(0),
 	fTriggerCounter0(0),
