/* * ProfilerDetector.cpp * Implementation of the base class for profiler detector * * Created on: Sep 29, 2015 * Author: Hovanes Egiyan */ #include "ProfilerDetector.hh" using namespace std; ProfilerDetector::ProfilerDetector( const std::string detName ) : MutexedClass(), pdName(detName), pdPlaneMap(), pdSimMap(), pdPV(0), pdReadyToProcess(false) { std::cout << " Entering good " << __FUNCTION__ << std::endl; MtxLock objLock(mcMutex); // Create the object that contains information sent from the SNL code. pdPV = new ProfilerPVs(); return; } // Destructor ProfilerDetector::~ProfilerDetector() { // Destroy all plane objects for ( map::iterator it = pdPlaneMap.begin(); it != pdPlaneMap.end(); it++ ) { std::string planeName = it->first; ProfilerPlaneV* planePtr = it->second; if( planePtr != 0 ) delete planePtr; pdPlaneMap.erase( planeName); } // Delete all plane simulators for( map::iterator it = pdSimMap.begin(); it != pdSimMap.end(); it++ ) { std::string simName = it->first; ProfilerPlaneSimulatorV* simPtr = it->second; if( simPtr != 0 ) delete simPtr; pdSimMap.erase( simName ); } // Destroy the object with the SNL PV info. if( pdPV != 0 ) delete pdPV; return; } // Connect and set monitor for the PVs needed for this detector void ProfilerDetector::assignPVs() { MtxLock obLock(mcMutex); pdPV->assignPVs(); // Start the threads for this detector that monitors the PVs // and sets the flags that have been registered when input PVs change. for (map::iterator it = pdPlaneMap.begin(); it != pdPlaneMap.end(); it++ ) { ProfilerPlaneV* plane = it->second; plane->startMainThread(); } // pdPlaneMap["x"]->startMainThread(); // // Start the treads for this detector that simulate the PVs. // for( map::iterator it = pdSimMap.begin(); it != pdSimMap.end(); it++ ) { // ProfilerPlaneSimulatorV* simPtr = it->second; // simPtr->startMainThread(); // } pdReadyToProcess = true; return; } // Specify which PVs will be used in this detector. The first parameter is the // state sequence ID, the second parameter is the reference to the structure // defined in the SNL code. This method the points the arrays in PV object for // this detector to the arrays in pvStruct in the argument, and then assigns the PV pointers // in all planes to the value of pdPV pointer for this detector. All planes end // up using the same structure, so care must be taken. void ProfilerDetector::usePVs( SS_ID ssID, ProfilerPVs::pvStruct& pvStruct ) { MtxLock obLock(mcMutex); pdPV->setSSID(ssID); // Set the SSID for this detector pdPV->getArrays() = pvStruct; // Set the pointers to this arrays in this detector. // Loop over all planes in this detector and set their PV object pointer to the // PV object pointer of this detector so that all planes and simulators within this detector use the // same PV arrays. for ( map::iterator it = pdPlaneMap.begin(); it != pdPlaneMap.end(); it++ ) { std::string planeName = it->first; ProfilerPlaneV* planePtr = it->second; if( planePtr != 0 ) { planePtr->setPVs(pdPV); } } // Loop over all simulators in this detector and set their PV object pointer to the // PV object pointer of this detector so that all planes and simulators within this detector use the // same PV arrays. for( map::iterator it = pdSimMap.begin(); it != pdSimMap.end(); it++ ) { std::string simName = it->first; ProfilerPlaneSimulatorV* simPtr = it->second; if( simPtr != 0 ) { simPtr->setPVs( pdPV ); } } return; } // Check if a plane planeID exists for this detector bool ProfilerDetector::planeExists( const std::string planeID ) const { if( pdPlaneMap.count(planeID) > 0 ) { return true; } else { return false; } } // Method to register the flag for synchronization with a new sequencer ID. void ProfilerDetector::registerFlag( const std::string planeID, const SS_ID ssID, const EV_ID flagID, const std::string flagName ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; if( isReady() ) plane->registerFlag( ssID, flagID, flagName ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::registerFlag : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // Check if plane with planeID is in simulation mode bool ProfilerDetector::isSimulation( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->isSimulation(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::isSimulation : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // Set flags for plane planeID from a map void ProfilerDetector::setFlags( const std::string planeID, const std::map >& f ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; if( isReady() ) plane->setFlags( f ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::setFlags : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // Set smoothing option for the profiler void ProfilerDetector::setSmoothOption( const std::string planeID, const short option ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; if( isReady() ) plane->setSmoothOption( option ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::setSmoothOption : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // Set smoothing option for the profiler void ProfilerDetector::setAccumulateOption( const std::string planeID, const short option ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; if( isReady() ) plane->setAccumulateOption( option ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::setAccumulateOption : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // reset scalers void ProfilerDetector::resetScalers( const std::string planeID, const short reset ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; if( isReady() ) plane->resetScalers( reset ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::resetScalers : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // Fir with Cauchy distribution void ProfilerDetector::fitWithCauchy( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; if( isReady() ) plane->fitWithCauchy(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::fitWithCauchy : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // Get flags that were registered for plane planeID map > ProfilerDetector::getFlags( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getFlags(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getFlags : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return mean value from the fit for plane planeID, waveform in slices void ProfilerDetector::getMean( const std::string planeID, double* meanArrayPtr ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; plane->getMean( meanArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getMean : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // return width value from the fit for plane planeID, waveform in slices void ProfilerDetector::getWidth( const std::string planeID, double* widthArrayPtr ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; plane->getWidth( widthArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getWidth : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // return amplitude value from the fit for plane planeID, waveform in slices void ProfilerDetector::getAmplitude( const std::string planeID, double* amplArrayPtr ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; plane->getAmplitude( amplArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getAmplitude : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // return signal integral value from the fit for plane planeID, waveform in slices void ProfilerDetector::getSignal( const std::string planeID, double* sigArrayPtr ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; plane->getSignal( sigArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSignal : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // return background level from the fit for plane planeID, waveform in slices void ProfilerDetector::getBkg( const std::string planeID, double* bkgArrayPtr ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; plane->getBkg( bkgArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getBkg : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // return integrated over fibers rate for plane planeID, waveform in slices void ProfilerDetector::getSum( const std::string planeID, double* sumArrayPtr ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; plane->getSummedSlices( sumArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSum : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } return; } // return mean value from the fit for plane planeID double ProfilerDetector::getTotalRate( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getTotalRate(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getTotalRate : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return mean value from the fit for plane planeID double ProfilerDetector::getSummedMean( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumMean(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedMean : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return width value from the fit for plane planeID double ProfilerDetector::getSummedWidth( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumWidth(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedWidth : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return amplitude value from the fit for plane planeID double ProfilerDetector::getSummedAmplitude( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumAmpl(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedAmplitude : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return signal integral value from the fit for plane planeID double ProfilerDetector::getSummedSignal( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumSignal(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedSignal : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return background level from the fit for plane planeID double ProfilerDetector::getSummedBkg( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumBkg(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedBkg : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return mean value error from the fit for plane planeID double ProfilerDetector::getSummedMeanErr( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumMeanErr(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedMeanErr : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return width value error from the fit for plane planeID double ProfilerDetector::getSummedWidthErr( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumWidthErr(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedWidthErr : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return amplitude value error from the fit for plane planeID double ProfilerDetector::getSummedAmplitudeErr( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumAmplErr(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedAmplitudeErr : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return signal integral value error from the fit for plane planeID double ProfilerDetector::getSummedSignalErr( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumSignalErr(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedSignalErr : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // return background level error from the fit for plane planeID double ProfilerDetector::getSummedBkgErr( const std::string planeID ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getSumBkgErr(); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getSummedBkgErr : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // Return x-axis for the profiler plane plane ID void ProfilerDetector::getAxis( const std::string planeID, double* axisArrayPtr ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getAxis( axisArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getAxis : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } } // Return y-axis (y-axis) for the profiler plane plane ID void ProfilerDetector::getValues( const std::string planeID, double* valueArrayPtr ) { if( planeExists( planeID) ) { ProfilerPlaneV* plane = pdPlaneMap[planeID]; return plane->getValues( valueArrayPtr ); } else { // throw an exception std::stringstream errStream; errStream << "ProfilerDetector::getValues : Profiler Plane object called " << planeID << " does not exists" << " for detector " << pdName ; throw std::runtime_error( errStream.str()); } }