Index: /trunk/FACT++/src/EventBuilderWrapper.h
===================================================================
--- /trunk/FACT++/src/EventBuilderWrapper.h	(revision 16833)
+++ /trunk/FACT++/src/EventBuilderWrapper.h	(revision 16834)
@@ -493,5 +493,5 @@
         // Keep a copy of the currently valid drs calibration
         // and associate it to the run control structure
-        evt.runCtrl->calib = shared_ptr<DrsCalibration>(new DrsCalibration(DataCalib::GetCalibration()));
+        evt.runCtrl->calib = make_shared<DrsCalibration>(DataCalib::GetCalibration());
 
         /*
@@ -631,8 +631,13 @@
 
         // If a Drs Calibration has just been finished, all following events
-        // should also be processed with this calibration
+        // should also be processed with this calibration.
+        // Note that this is a generally dangerous operation. Here, the previous
+        // DRS calibration shared_ptr gets freed and if it is the last in use,
+        // the memory will vanish. If another thread accesses that pointer,
+        // it _must_ make a copy of the shared_ptr first to ensure that
+        // the memory will stay in scope until the end of its operation.
         const DrsCalibration &cal = DataCalib::GetCalibration();
         if (!run.calib || run.calib->fStep != cal.fStep || run.calib->fRoi!=cal.fRoi)
-            run.calib = shared_ptr<DrsCalibration>(new DrsCalibration(cal));
+            run.calib = make_shared<DrsCalibration>(cal);
     }
 
@@ -903,8 +908,17 @@
             // (Is that necessray, or would a simple offset correct do well already?)
 
+            // This is a very important step. Making a copy of the shared pointer ensures
+            // that another thread (here: runClose) can set a new shared_ptr with new
+            // data without this thread being affected. If we just did run.calib->Apply
+            // the shared_pointer in use here might vanash during the processing, the
+            // memory is freed and we access invalid memory. It is not important
+            // which memory we acces (the old or the new one) because it is just for
+            // display purpose anyway.
+            const shared_ptr<DrsCalibration> cal = run.calib;
+
             // There seems to be a problem using std::array... maybe the size is too big?
             // array<float, (1440+160)*1024> vec2;
             vector<float> vec((1440+160)*roi);
-            run.calib->Apply(vec.data(), event->Adc_Data, start, roi);
+            cal->Apply(vec.data(), event->Adc_Data, start, roi);
 
             // ------------------- Appy DRS-step correction --------------------------
@@ -940,5 +954,5 @@
             // ------------------ Update dim service (statistics) ---------------------
 
-            if (fQueueEventData.empty() && now>fLastDimEventData+boost::posix_time::seconds(3))
+            if (fQueueEventData.empty() && now>fLastDimEventData+boost::posix_time::microseconds(3141593))
             {
                 fQueueEventData.emplace(evt.time, evt.trgTyp, evt.trgTyp==0 ? fMaxEvent.second : stats);
