/* * jlabSSPDIRCBoard.cpp * * Created on: June 16, 2014 * Author: * * This class provides a wrapper around accessing the shared memory on the ROCs */ #include #include #include "jlabSSPDIRCBoard.hh" using namespace std; static const char *dTempNamesArr[] = { "t_fpga", "t_reg0", "t_reg1", "v_pcb5", "v_pcb3", "v_vccint", "v_vccaux", "v_mgt1", "v_mgt1_2" }; vector jlabSSPDIRCBoard::dTempNames( dTempNamesArr, dTempNamesArr + sizeof(dTempNamesArr) / sizeof(char*) ); void jlabSSPDIRCBoard::Set_Data( vmeDIRC_Scalers locInputScalars ) { // ACQUIRE LOCK jlabMutexHolder locMutexHolder( &dMemoryMutex ); // Set Timers //index 16 is timer dScalarCountTimer_Readout1 = vector( 1, double( locInputScalars.counters[dSlotNumber][DIRC_MAX_CHAN] ) / 1.0E6 ); //input is in microseconds dScalarRateTimer_Readout1 = vector( 1, locInputScalars.rates[dSlotNumber][DIRC_MAX_CHAN] ); // cout << "[" << dSlotNumber << "," << fiberNumber << "]" << endl; GetFiberValues( locInputScalars ); // LOCK RELEASED ON FUNCTION EXIT (locMutexHolder destructor) } void jlabSSPDIRCBoard::GetFiberValues( vmeDIRC_Scalers locInputScalers ) { // cout << "Getting fiber " << desiredFiber << " for slot " << dSlotNumber << endl; // double countingRate = 0; // Check for the range of the slot number if ( dSlotNumber < 0 || dSlotNumber >= DIRC_MAX_SLOT ) return; // printf( "============================ DIRC slotNumber=%d \n", dSlotNumber ); uint64_t nWords = locInputScalers.counters[dSlotNumber][0]; uint64_t wordNumber = 0; volatile uint64_t length = locInputScalers.counters[dSlotNumber][wordNumber++]; while ( wordNumber < nWords ) { volatile uint64_t readFiberNumber = locInputScalers.counters[dSlotNumber][wordNumber++]; // printf( "fiber=%llu\n", readFiberNumber ); volatile unsigned int clock = locInputScalers.counters[dSlotNumber][wordNumber++]; double scale = 1.; if ( clock > 0 ) { scale = 125000000.0 / clock; } for ( unsigned fpgaChannel = 0; fpgaChannel < DIRC_MAX_SCALER_FIBER; fpgaChannel++ ) { //--- DIRC_MAX_SCALER_FIBER 192 // if ( (fpgaChannel % 6) == 0 ) printf( "\n" ); // Calculate EPICS asyn parameter channel number unsigned epicsChannel = GetEPICSChannelNumber( readFiberNumber, fpgaChannel ); // countingRate = locInputScalers.counters[dSlotNumber][wordNumber] * scale; dScalarCountMap_Readout1[epicsChannel] = vector( 1, double( locInputScalers.counters[dSlotNumber][wordNumber] ) ); dScalarRateMap_Readout1[epicsChannel] = vector( 1, locInputScalers.rates[dSlotNumber][wordNumber] ); // printf( "| %3u: %11.3f ", fpgaChannel, countingRate ); wordNumber++; } // printf( "\n" ) ; } // Now read the temperatures wordNumber = 0; nWords = locInputScalers.data[dSlotNumber][0]; length = locInputScalers.data[dSlotNumber][wordNumber++]; vector fiberIsPresent(dFiberTimoutCounter.size(), false); while ( wordNumber < nWords ) { volatile uint64_t readFiberNumber = locInputScalers.data[dSlotNumber][wordNumber++]; for ( unsigned dataElm = 0; dataElm < DIRC_MAX_DATA_FIBER; dataElm++ ) { if ( 0 <= readFiberNumber && readFiberNumber < dTempAndVoltArray[dataElm].size() ) { dTempAndVoltArray[dataElm][readFiberNumber] = locInputScalers.data[dSlotNumber][wordNumber]; fiberIsPresent[readFiberNumber] = true; } wordNumber++; } } for( unsigned iFiber = 0; iFiber < dFiberTimoutCounter.size(); iFiber++ ) { if( fiberIsPresent[iFiber] ) { dFiberTimoutCounter[iFiber] = 0; } else { dFiberTimoutCounter[iFiber]++; } } return; } vector jlabSSPDIRCBoard::GetScalers( uint32_t locChannel, string locScalarType, vector& locTimes, bool locOutputInHzFlag ) { vector locScalars; // ACQUIRE LOCK jlabMutexHolder locMutexHolder( &dMemoryMutex ); if ( locScalarType == "Readout1" ) { locTimes = locOutputInHzFlag ? dScalarRateTimer_Readout1 : dScalarCountTimer_Readout1; const map >& locScalarMap = locOutputInHzFlag ? dScalarRateMap_Readout1 : dScalarCountMap_Readout1; map >::const_iterator locIterator = locScalarMap.find( locChannel ); if ( locIterator != locScalarMap.end() ) locScalars = locIterator->second; } // LOCK RELEASED ON FUNCTION EXIT (locMutexHolder destructor) return locScalars; } double jlabSSPDIRCBoard::GetScaler( uint32_t locChannel, string locScalarType, bool locOutputInHzFlag ) { vector locScalars( 1 ); // ACQUIRE LOCK jlabMutexHolder locMutexHolder( &dMemoryMutex ); if ( locScalarType == "Readout1" ) { const map >& locScalarMap = locOutputInHzFlag ? dScalarRateMap_Readout1 : dScalarCountMap_Readout1; map >::const_iterator locIterator = locScalarMap.find( locChannel ); if ( locIterator != locScalarMap.end() ) locScalars = locIterator->second; } // LOCK RELEASED ON FUNCTION EXIT (locMutexHolder destructor) return locScalars[0]; } double jlabSSPDIRCBoard::GetTemperature( uint32_t fiber, uint32_t tempType ) { // cout << "Requested fiber " << fiber << " tempType " << tempType << endl; // The default value for non-existing fibers and temperatures is -999. double returnValue = -9999; // ACQUIRE LOCK jlabMutexHolder locMutexHolder( &dMemoryMutex ); if ( 0 <= tempType && tempType < dTempAndVoltArray.size() && 0 <= fiber && fiber < dTempAndVoltArray[tempType].size() ) { returnValue = dTempAndVoltArray[tempType][fiber] / dTempConversionConstant; } return returnValue; }