/* * jlabDiscBoard.cpp * * Created on: June 16, 2014 * Author: * * This class provides a wrapper around accessing the shared memory on the ROCs */ #include "jlabDiscBoard.hh" void jlabDiscBoard::Set_Data(vmeDSC_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, double(locInputScalars.counters2[dSlotNumber][16])/1.0E6); //input is in microseconds dScalarRateTimer_Trigger1 = vector(1, locInputScalars.rates2[dSlotNumber][16]); 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, double(locInputScalars.counters2[dSlotNumber][locChannel])); dScalarRateMap_Trigger1[locChannel] = vector(1, locInputScalars.rates2[dSlotNumber][locChannel]); dScalarCountMap_Trigger2[locChannel] = vector(1, 0.0); dScalarRateMap_Trigger2[locChannel] = vector(1, 0.0); dThresholds["Readout1"][locChannel] = locInputScalars.thresholds[dSlotNumber][locChannel]; dThresholds["Trigger1"][locChannel] = locInputScalars.thresholds2[dSlotNumber][locChannel]; } // LOCK RELEASED ON FUNCTION EXIT (locMutexHolder destructor) } vector jlabDiscBoard::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 jlabDiscBoard::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]; } double jlabDiscBoard::GetThreshold(const unsigned chanNumb, const string threshType) { // ACQUIRE LOCK jlabMutexHolder locMutexHolder(&dMemoryMutex); map >::const_iterator locTypeIterator = dThresholds.find(threshType); if(locTypeIterator == dThresholds.end()) return -1.0; const map& locTypeMap = locTypeIterator->second; map::const_iterator locChannelIterator = locTypeMap.find(chanNumb); if(locChannelIterator == locTypeMap.end()) return 0.0; return locChannelIterator->second; } // Get a vector of thresholds for a particular type of thresholds vector jlabDiscBoard::GetThresholds( const string threshType ) { vector locThresholds; // ACQUIRE LOCK jlabMutexHolder locMutexHolder(&dMemoryMutex); map >::const_iterator locTypeIterator = dThresholds.find(threshType); if(locTypeIterator == dThresholds.end()) return locThresholds; const map& locTypeMap = locTypeIterator->second; map::const_iterator locChannelIterator = locTypeMap.begin(); for(; locChannelIterator != locTypeMap.end(); ++locChannelIterator) locThresholds.push_back(locChannelIterator->second); return locThresholds; }