// // DoCalibrate.cpp // extern "C" { #include "messages.h" int get_flag (int, int); } #include "DoCalibrate.h" #include "afx.h" #include "LogFile.h" #include #include // ========================================== // constructor // ========================================== DoCalibrate::DoCalibrate (DetPlane* det_plane) : _chanList(&det_plane->chanList) { _nLoops = det_plane->nLoops (); _nChan = det_plane->nChan (); _eventLength = det_plane->eventLength (); _hitType = det_plane->hitType (); _linkNr = det_plane->link (); _dspNr = det_plane->dspNr (); } // ================================================= // collectData (certain number of events // ================================================= int DoCalibrate::collectData (int evtsReq, unsigned int* hitList, int crtl_block) { int i, chan, *data; int bit, word, shift, skip_boundary; int eventsLeft = 0; int eventsCollected = 0; // logFile << " Do calibrate collect Data " << endl; // logFile << " start events requested: " << evtsReq << " length\\chan " // << _eventLength << " " << _nChan << endl; while ( eventsCollected < evtsReq ) { // ------------------------------- // get new events // ------------------------------- if ( eventsLeft == 0 ) { do_calibrate ( _nLoops, 1, crtl_block); data = do_dataTransfer (_linkNr, _dspNr, 2); if ( data == 0 ) return eventsCollected; eventsLeft = ( data[1] - 12 ) / _eventLength; /* logFile << eventsLeft << " " << _eventLength << " " << data[1] << " " << hex << data[12] << dec << endl; logFile << " data " << hex; for ( int i = 0; i < 5; i++ ) logFile << data[12 + i] << " "; logFile << dec << endl; */ data += 12; // Begin off data (skip Header) } // ------------------------------------- // decode next event // ------------------------------------- skip_boundary = NHEAD_WORDS; for ( i = 0; i < _chanList->_nr_of_chan; i++ ) { chan = _chanList->_chanList[i]; bit = NHEAD_WORDS + chan + (chan / 128) * SKIP_CHIP_BOUNDARY; word = bit / 32; shift = 31 - bit % 32; if ( ( (data[word] >> shift) & 0x1) == _hitType ) { hitList[chan] += 1; } } // ----------------------------- // end of an event // ----------------------------- ++eventsCollected; --eventsLeft; data += _eventLength; // next event } // end of collecting all events return eventsCollected; } // ================================================= // collectData (certain number of events // ================================================= int DoCalibrate::collectData (int evtsMax, int evtsReq, unsigned int* hitList, int crtl_block) { int i, chan, *data; int bit, word, shift, skip_boundary; int eventsLeft = 0; int eventsCollected = 0; // logFile << " Do calibrate collect Data " << endl; // logFile << " start events requested: " << evtsReq << " length\\chan " // << _eventLength << " " << _nChan << endl; int numberOfHits = 0; double averageHits = 0.0; while ( eventsCollected < evtsMax ) { // ------------------------------- // get new events // ------------------------------- if ( eventsLeft == 0 ) { do_calibrate ( _nLoops, 1, crtl_block); data = do_dataTransfer (_linkNr, _dspNr, 2); if ( data == 0 ) return eventsCollected; eventsLeft = ( data[1] - 12 ) / _eventLength; /* logFile << eventsLeft << " " << _eventLength << " " << data[1] << " " << hex << data[12] << dec << endl; logFile << " data " << hex; for ( int i = 0; i < 5; i++ ) logFile << data[12 + i] << " "; logFile << dec << endl; */ data += 12; // Begin off data (skip Header) } // ------------------------------------- // decode next event // ------------------------------------- skip_boundary = NHEAD_WORDS; for ( i = 0; i < _chanList->_nr_of_chan; i++ ) { chan = _chanList->_chanList[i]; bit = NHEAD_WORDS + chan + (chan / 128) * SKIP_CHIP_BOUNDARY; word = bit / 32; shift = 31 - bit % 32; if ( ( (data[word] >> shift) & 0x1) == _hitType ) { hitList[chan] += 1; numberOfHits ++; } } // ----------------------------- // end of an event // ----------------------------- ++eventsCollected; --eventsLeft; data += _eventLength; // next event // check for the average number of hits per channel if ( eventsCollected % 1000 == 0 ) { averageHits = (double) numberOfHits / (double) _chanList->_nr_of_chan; if ( averageHits > (double) evtsReq ) evtsMax = 0; } } // end of collecting all events return eventsCollected; }