/* * jlabDiscBoard.cpp * * Created on: June 16, 2014 * Author: * * This class provides a wrapper around accessing the shared memory on the ROCs */ #include "jlabFADC250Board.hh" void jlabFADC250Board::Set_Data(F250_Scalers locInputScalars) { // ACQUIRE LOCK jlabMutexHolder locMutexHolder(&dMemoryMutex); // Set Timers //index 16 is timer dScalarCountTimer_Readout1 = vector(1, double(locInputScalars.counters[dSlotNumber][16])/1.0E6); //input is in microseconds dScalarRateTimer_Readout1 = vector(1, locInputScalars.rates[dSlotNumber][16]); dScalarCountTimer_Readout2 = vector(1, 0.0); dScalarRateTimer_Readout2 = vector(1, 0.0); dScalarCountTimer_Trigger1 = vector(1, 0.0); dScalarRateTimer_Trigger1 = vector(1, 0.0); dScalarCountTimer_Trigger2 = vector(1, 0.0); dScalarRateTimer_Trigger2 = vector(1, 0.0); for(uint32_t locChannel = 0; locChannel < dNumChannels; ++locChannel) { dScalarCountMap_Readout1[locChannel] = vector(1, double(locInputScalars.counters[dSlotNumber][locChannel])); dScalarRateMap_Readout1[locChannel] = vector(1, locInputScalars.rates[dSlotNumber][locChannel]); dScalarCountMap_Readout2[locChannel] = vector(1, 0.0); dScalarRateMap_Readout2[locChannel] = vector(1, 0.0); dScalarCountMap_Trigger1[locChannel] = vector(1, 0.0); dScalarRateMap_Trigger1[locChannel] = vector(1, 0.0); dScalarCountMap_Trigger2[locChannel] = vector(1, 0.0); dScalarRateMap_Trigger2[locChannel] = vector(1, 0.0); } // LOCK RELEASED ON FUNCTION EXIT (locMutexHolder destructor) } vector jlabFADC250Board::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; } else if(locScalarType == "Readout2") { locTimes = locOutputInHzFlag ? dScalarRateTimer_Readout2 : dScalarCountTimer_Readout2; const map >& locScalarMap = locOutputInHzFlag ? dScalarRateMap_Readout2 : dScalarCountMap_Readout2; map >::const_iterator locIterator = locScalarMap.find(locChannel); if(locIterator != locScalarMap.end()) locScalars = locIterator->second; } else if(locScalarType == "Trigger1") { locTimes = locOutputInHzFlag ? dScalarRateTimer_Trigger1 : dScalarCountTimer_Trigger1; const map >& locScalarMap = locOutputInHzFlag ? dScalarRateMap_Trigger1 : dScalarCountMap_Trigger1; map >::const_iterator locIterator = locScalarMap.find(locChannel); if(locIterator != locScalarMap.end()) locScalars = locIterator->second; } else if(locScalarType == "Trigger2") { locTimes = locOutputInHzFlag ? dScalarRateTimer_Trigger2 : dScalarCountTimer_Trigger2; const map >& locScalarMap = locOutputInHzFlag ? dScalarRateMap_Trigger2 : dScalarCountMap_Trigger2; map >::const_iterator locIterator = locScalarMap.find(locChannel); if(locIterator != locScalarMap.end()) locScalars = locIterator->second; } // LOCK RELEASED ON FUNCTION EXIT (locMutexHolder destructor) return locScalars; } double jlabFADC250Board::GetScaler(uint32_t locChannel, string locScalarType, bool locOutputInHzFlag) { vector locScalars; // 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; } else if(locScalarType == "Readout2") { const map >& locScalarMap = locOutputInHzFlag ? dScalarRateMap_Readout2 : dScalarCountMap_Readout2; map >::const_iterator locIterator = locScalarMap.find(locChannel); if(locIterator != locScalarMap.end()) locScalars = locIterator->second; } else if(locScalarType == "Trigger1") { const map >& locScalarMap = locOutputInHzFlag ? dScalarRateMap_Trigger1 : dScalarCountMap_Trigger1; map >::const_iterator locIterator = locScalarMap.find(locChannel); if(locIterator != locScalarMap.end()) locScalars = locIterator->second; } else if(locScalarType == "Trigger2") { const map >& locScalarMap = locOutputInHzFlag ? dScalarRateMap_Trigger2 : dScalarCountMap_Trigger2; map >::const_iterator locIterator = locScalarMap.find(locChannel); if(locIterator != locScalarMap.end()) locScalars = locIterator->second; } // LOCK RELEASED ON FUNCTION EXIT (locMutexHolder destructor) return locScalars[0]; }