/* * ProfilerMap.cpp * * Created on: Sep 30, 2015 * Author: Hovanes Egiyan */ #include "ProfilerMap.hh" #include "ProfilerBPU.hh" using namespace std; // Map of all detector objects instantiated map ProfilerMap::pmDetectorMap; volatile static int dummyInt = ProfilerMap::initDetectorMap(); // Create the detector and populate the detector map int ProfilerMap::initDetectorMap() { cout << "Creating BPU" << endl; pmDetectorMap["bpu"] = new ProfilerBPU(); cout << "BPU created" << endl; return 0; } // Check if a detector called detName exists bool ProfilerMap::detectorExists( std::string detName ) { if( pmDetectorMap.count( detName ) > 0 ) { return true; } else { return false; } } // Check if a profiler plane with (detName, planeID) exists bool ProfilerMap::planeExists( std::string detName, std::string planeID ) { if( detectorExists( detName ) ) { if( pmDetectorMap[detName]->planeExists( planeID ) ) { return true; } else { return false; } } else { return false; } } // Make all profiler planes in all detectors use the same arrays void ProfilerMap::usePVs( const std::string detName, SS_ID ssID, ProfilerPVs::pvStruct& pvStr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->usePVs( ssID, pvStr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::usePVs : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str()); } return; } // Assign PVs for a particular profiler void ProfilerMap::assignPVs( const std::string detName ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->assignPVs(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::assignPVs : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str()); } return; } // Register sync flag for state sequence ssID void ProfilerMap::registerFlag( const std::string detName, std::string planeID, const SS_ID ssID, const EV_ID flagID, const std::string flagName ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->registerFlag( planeID, ssID, flagID, flagName ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::assignPVs : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str()); } return; } // Check if the plane is in simulation mode bool ProfilerMap::isSimulation( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->isSimulation( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::isSimulation : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } // Set the smoothing option void ProfilerMap::setSmoothOption( const std::string detName, const std::string planeID, const short option ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->setSmoothOption( planeID, option ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::setSmoothOption : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } // Set the accumulate option void ProfilerMap::setAccumulateOption( const std::string detName, const std::string planeID, const short option ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->setAccumulateOption( planeID, option ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::setSmoothOption : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } // Reset scalers void ProfilerMap::resetScalers( const std::string detName, const std::string planeID, const short reset ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->resetScalers( planeID, reset ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::resetScalers : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } // Reset scalers void ProfilerMap::fitWithCauchy( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->fitWithCauchy( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::fitWithCauchy : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } void ProfilerMap::getMean( const std::string detName, const std::string planeID, double* meanArrayPtr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->getMean( planeID, meanArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getMean : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } void ProfilerMap::getWidth( const std::string detName, const std::string planeID, double* widthArrayPtr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->getWidth( planeID, widthArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getWidth : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } void ProfilerMap::getAmplitude( const std::string detName, const std::string planeID, double* amplArrayPtr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->getAmplitude( planeID, amplArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getAmplitude : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } void ProfilerMap::getSignal( const std::string detName, const std::string planeID, double* sigArrayPtr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->getSignal( planeID, sigArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSignal : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } void ProfilerMap::getBkg( const std::string detName, const std::string planeID, double* bkgArrayPtr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->getBkg( planeID, bkgArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getBkg : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } void ProfilerMap::getSum( const std::string detName, const std::string planeID, double* sumArrayPtr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; det->getSum( planeID, sumArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSum : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } double ProfilerMap::getTotalRate( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getTotalRate( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getTotalRate : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedMean( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedMean( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedMean : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedWidth( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedWidth( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedWidth : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedAmplitude( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedAmplitude( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedAmplitude : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedSignal( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedSignal( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedSignal : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedBkg( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedBkg( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedBkg : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedMeanErr( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedMeanErr( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedMeanErr : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedWidthErr( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedWidthErr( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedWidthErr : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedAmplitudeErr( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedAmplitudeErr( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedAmplitudeErr : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedSignalErr( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedSignalErr( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedSignalErr : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double ProfilerMap::getSummedBkgErr( const std::string detName, const std::string planeID ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getSummedBkgErr( planeID ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getSummedBkgErr : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } void ProfilerMap::getValues( const std::string detName, const std::string planeID, double* valueArrayPtr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getValues( planeID, valueArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getValues : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } void ProfilerMap::getAxis( const std::string detName, const std::string planeID, double* axisArrayPtr ) { if( detectorExists( detName ) ) { ProfilerDetector* det = pmDetectorMap[detName]; return det->getAxis( planeID, axisArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerMap::getAxis : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } // Below are the implementation of the functions with C-linkage defined in a separate .h-file so // that the state code can call the methods of this class. extern "C" { #include "ProfilerMap.h" void profilerUsePVs( const char* detName, SS_ID ssID, struct pvStructure* pvs) { ProfilerMap::usePVs( detName, ssID, *reinterpret_cast(pvs) ); return; } void profilerAssignPVs( const char* detName ) { ProfilerMap::assignPVs( detName ); return; } void profilerRegisterFlag( const char* detName, const char* planeID, const SS_ID ssID, const EV_ID flagID, const char* flagName ) { ProfilerMap::registerFlag( detName, planeID, ssID, flagID, flagName ); } int profilerIsSimulation( const char* detName, const char* planeID ) { return ProfilerMap::isSimulation( detName, planeID ) == 0 ? 0 : 1; } void profilerSetSmoothOption( const char* detName, const char* planeID, const short opt ) { ProfilerMap::setSmoothOption( detName, planeID, opt ); return; } void profilerSetAccumulateOption( const char* detName, const char* planeID, const short opt ) { ProfilerMap::setAccumulateOption( detName, planeID, opt ); return; } void profilerResetScalers( const char* detName, const char* planeID, const short reset ) { ProfilerMap::resetScalers( detName, planeID, reset ); return; } void profilerFitWithCauchy( const char* detName, const char* planeID ){ ProfilerMap::fitWithCauchy( detName, planeID ); } void profilerGetMean( const char* detName, const char* planeID, double* meanArrayPtr ) { return ProfilerMap::getMean( detName, planeID, meanArrayPtr ); } void profilerGetWidth( const char* detName, const char* planeID, double* widthArrayPtr ) { return ProfilerMap::getWidth( detName, planeID, widthArrayPtr ); } void profilerGetAmplitude( const char* detName, const char* planeID, double* amplArrayPtr ) { return ProfilerMap::getAmplitude( detName, planeID, amplArrayPtr ); } void profilerGetSignal( const char* detName, const char* planeID, double* sigArrayPtr ) { return ProfilerMap::getSignal( detName, planeID, sigArrayPtr ); } void profilerGetBkg( const char* detName, const char* planeID, double* bkgArrayPtr ) { return ProfilerMap::getBkg( detName, planeID, bkgArrayPtr ); } void profilerGetSum( const char* detName, const char* planeID, double* sumArrayPtr ) { return ProfilerMap::getSum( detName, planeID, sumArrayPtr ); } double profilerGetTotalRate( const char* detName, const char* planeID ) { return ProfilerMap::getTotalRate( detName, planeID ); } double profilerGetSummedMean( const char* detName, const char* planeID ) { return ProfilerMap::getSummedMean( detName, planeID ); } double profilerGetSummedWidth( const char* detName, const char* planeID ) { return ProfilerMap::getSummedWidth( detName, planeID ); } double profilerGetSummedAmplitude( const char* detName, const char* planeID ) { return ProfilerMap::getSummedAmplitude( detName, planeID ); } double profilerGetSummedSignal( const char* detName, const char* planeID ) { return ProfilerMap::getSummedSignal( detName, planeID ); } double profilerGetSummedBkg( const char* detName, const char* planeID ) { return ProfilerMap::getSummedBkg( detName, planeID ); } double profilerGetSummedMeanErr( const char* detName, const char* planeID ) { return ProfilerMap::getSummedMeanErr( detName, planeID ); } double profilerGetSummedWidthErr( const char* detName, const char* planeID ) { return ProfilerMap::getSummedWidthErr( detName, planeID ); } double profilerGetSummedAmplitudeErr( const char* detName, const char* planeID ) { return ProfilerMap::getSummedAmplitudeErr( detName, planeID ); } double profilerGetSummedSignalErr( const char* detName, const char* planeID ) { return ProfilerMap::getSummedSignalErr( detName, planeID ); } double profilerGetSummedBkgErr( const char* detName, const char* planeID ) { return ProfilerMap::getSummedBkgErr( detName, planeID ); } void profilerGetValues( const char* detName, const char* planeID, double* valueArrayPtr ) { ProfilerMap::getValues( detName, planeID, valueArrayPtr ); } void profilerGetAxis( const char* detName, const char* planeID, double* axisArrayPtr ){ ProfilerMap::getAxis( detName, planeID, axisArrayPtr ); } };