Changeset 16834 for trunk/FACT++


Ignore:
Timestamp:
06/14/13 10:54:35 (12 years ago)
Author:
tbretz
Message:
Changed the time for an update of the EVENTS service to a number whihc is not a mutiple of 1s, to avoid coincidences with interleaved events (just cosmetics); added a fix which ensures that the replacement of the calibration in runClose is not affecting events which are currenly processed in another thread; use make_shared where possible.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/EventBuilderWrapper.h

    r16745 r16834  
    493493        // Keep a copy of the currently valid drs calibration
    494494        // and associate it to the run control structure
    495         evt.runCtrl->calib = shared_ptr<DrsCalibration>(new DrsCalibration(DataCalib::GetCalibration()));
     495        evt.runCtrl->calib = make_shared<DrsCalibration>(DataCalib::GetCalibration());
    496496
    497497        /*
     
    631631
    632632        // If a Drs Calibration has just been finished, all following events
    633         // should also be processed with this calibration
     633        // should also be processed with this calibration.
     634        // Note that this is a generally dangerous operation. Here, the previous
     635        // DRS calibration shared_ptr gets freed and if it is the last in use,
     636        // the memory will vanish. If another thread accesses that pointer,
     637        // it _must_ make a copy of the shared_ptr first to ensure that
     638        // the memory will stay in scope until the end of its operation.
    634639        const DrsCalibration &cal = DataCalib::GetCalibration();
    635640        if (!run.calib || run.calib->fStep != cal.fStep || run.calib->fRoi!=cal.fRoi)
    636             run.calib = shared_ptr<DrsCalibration>(new DrsCalibration(cal));
     641            run.calib = make_shared<DrsCalibration>(cal);
    637642    }
    638643
     
    903908            // (Is that necessray, or would a simple offset correct do well already?)
    904909
     910            // This is a very important step. Making a copy of the shared pointer ensures
     911            // that another thread (here: runClose) can set a new shared_ptr with new
     912            // data without this thread being affected. If we just did run.calib->Apply
     913            // the shared_pointer in use here might vanash during the processing, the
     914            // memory is freed and we access invalid memory. It is not important
     915            // which memory we acces (the old or the new one) because it is just for
     916            // display purpose anyway.
     917            const shared_ptr<DrsCalibration> cal = run.calib;
     918
    905919            // There seems to be a problem using std::array... maybe the size is too big?
    906920            // array<float, (1440+160)*1024> vec2;
    907921            vector<float> vec((1440+160)*roi);
    908             run.calib->Apply(vec.data(), event->Adc_Data, start, roi);
     922            cal->Apply(vec.data(), event->Adc_Data, start, roi);
    909923
    910924            // ------------------- Appy DRS-step correction --------------------------
     
    940954            // ------------------ Update dim service (statistics) ---------------------
    941955
    942             if (fQueueEventData.empty() && now>fLastDimEventData+boost::posix_time::seconds(3))
     956            if (fQueueEventData.empty() && now>fLastDimEventData+boost::posix_time::microseconds(3141593))
    943957            {
    944958                fQueueEventData.emplace(evt.time, evt.trgTyp, evt.trgTyp==0 ? fMaxEvent.second : stats);
Note: See TracChangeset for help on using the changeset viewer.