/* * PulserMap.cpp * * Created on: Aug 14, 2015 * Author: Hovanes Egiyan */ #include "PulserMap.hh" #include "PulserDetectorFCAL.hh" #include "PulserDetectorPS.hh" using namespace std; // Map of all detector objects instantiated map PulserMap::pmDetectorMap; volatile static int dummyInt = PulserMap::initDetectorMap(); // Create the detector and populate the detector map int PulserMap::initDetectorMap() { cout << "Creating FCAL" << endl; pmDetectorMap["FCAL"] = new PulserDetectorFCAL(); cout << "FCAL created" << endl; cout << "Creating PS" << endl; pmDetectorMap["PS"] = new PulserDetectorPS("U1-1-TOP:4"); cout << "PS created" << endl; cout << "Creating DIRC" << endl; pmDetectorMap["DIRC"] = new PulserDetectorPS("D2-5-MID:7"); cout << "DIRC created" << endl; cout << "Creating COMCAL" << endl; pmDetectorMap["COMCAL"] = new PulserDetectorPS("D2-5-MID:8"); cout << "COMCAL created" << endl; cout << "Creating ECAL" << endl; pmDetectorMap["ECAL"] = new PulserDetectorPS("D2-5-MID:8"); cout << "ECAL created" << endl; cout << "Creating RNDM" << endl; pmDetectorMap["RNDM"] = new PulserDetectorPS("U1-1-TOP:17"); cout << "RNDM created" << endl; return 0; } // Check if a detector called detName exists bool PulserMap::detectorExists( std::string detName ) { if( pmDetectorMap.count( detName ) > 0 ) { return true; } else { return false; } } // Check if a pulser with (detName, pulserID) exists bool PulserMap::pulserExists( std::string detName, std::string pulserID ) { if( detectorExists( detName ) ) { if( pmDetectorMap[detName]->pulserExists( pulserID ) ) { return true; } else { return false; } } else { return false; } } // Make all pulsers in all detectors use the same arrays void PulserMap::usePVs( const std::string detName, SS_ID ssID, PulserPVs::pvStruct& pvStr ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; det->usePVs( ssID, pvStr ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::usePVs : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str()); } return; } // Assign PVs for a particular pulser void PulserMap::assignPVs( const std::string detName ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; det->assignPVs(); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::assignPVs : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str()); } return; } //// Check if the input PVs for detector detName changed //bool PulserMap::inputsChanged( const std::string detName ) { // if( detectorExists( detName ) ) { // PulserDetector* det = pmDetectorMap[detName]; // return det->inputsChanged(); // } else { // // throw an exception // std::stringstream errStream; // errStream << "PulserMap::inputsChanged : Detector object " << detName << " does not exists" ; // throw std::runtime_error( errStream.str()); // } //} // // Register sync flag for state sequence ssID void PulserMap::registerFlag( const std::string detName, const SS_ID ssID, const EV_ID flagID ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; det->registerFlag( ssID, flagID ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::assignPVs : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str()); } return; } // Switch the state of the pulser based on the currently required state void PulserMap::switchState( const std::string detName, const std::string pulserID, const short state ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; det->switchState( pulserID, state ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::switchState : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } // Set the pulse width for the pulser void PulserMap::setWidth( const std::string detName, const std::string pulserID, const unsigned width ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; det->setWidth( pulserID, width ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::setWidth : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } // Set the pulsing frequency for the pulser void PulserMap::setFrequency( const std::string detName, const std::string pulserID, const double freq ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; det->setFrequency( pulserID, freq ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::setFrequency : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } // Set the number of pulses for the pulser void PulserMap::setNPulses( const std::string detName, const std::string pulserID, const unsigned n ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; det->setNPulses( pulserID, n ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::setNPulses : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } // Set the pulse delay for the pulser void PulserMap::setDelay( const std::string detName, const std::string pulserID, const unsigned delay ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; det->setDelay( pulserID, delay ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::setDelay : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } return; } short PulserMap::getStatus( const std::string detName, const std::string pulserID ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; return det->getStatus( pulserID ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::getStatus : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } unsigned PulserMap::getWidth( const std::string detName, const std::string pulserID ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; return det->getWidth( pulserID ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::getWidth : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } double PulserMap::getFrequency( const std::string detName, const std::string pulserID ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; return det->getFrequency( pulserID ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::getFrequency : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } unsigned PulserMap::getNPulses( const std::string detName, const std::string pulserID ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; return det->getNPulses( pulserID ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::getNPulses : Detector object " << detName << " does not exists" ; throw std::runtime_error( errStream.str() ); } } unsigned PulserMap::getDelay( const std::string detName, const std::string pulserID ) { if( detectorExists( detName ) ) { PulserDetector* det = pmDetectorMap[detName]; return det->getDelay( pulserID ); } else { // throw an exception std::stringstream errStream; errStream << "PulserMap::getDelay : 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 "PulserMap.h" void pulserUsePVs( const char* detName, SS_ID ssID, struct pvStructure* pvs) { PulserMap::usePVs( detName, ssID, *reinterpret_cast(pvs) ); return; } void pulserAssignPVs( const char* detName ) { PulserMap::assignPVs( detName ); return; } //short pulserInputsChanged( const char* detName ) { // return ( PulserMap::inputsChanged( detName ) ? 1 : 0 ) ; //} void pulserRegisterFlag( const char* detName, const SS_ID ssID, const EV_ID flagID ) { PulserMap::registerFlag( detName, ssID, flagID ); } void pulserSwitch( const char* detName, const char* pulserID, const short state ) { PulserMap::switchState( detName, pulserID, state ); return; } void pulserSetWidth( const char* detName, const char* pulserID, const unsigned width ) { PulserMap::setWidth( detName, pulserID, width ); return; } void pulserSetFrequency( const char* detName, const char* pulserID, const double freq ) { PulserMap::setFrequency( detName, pulserID, freq ); return; } void pulserSetNPulses( const char* detName, const char* pulserID, const unsigned n ) { PulserMap::setNPulses( detName, pulserID, n ); return; } void pulserSetDelay( const char* detName, const char* pulserID, const unsigned delay ) { PulserMap::setDelay( detName, pulserID, delay ); return; } short pulserGetStatus( const char* detName, const char* pulserID ) { return PulserMap::getStatus( detName, pulserID ); } unsigned pulserGetWidth( const char* detName, const char* pulserID ) { return PulserMap::getWidth( detName, pulserID ); } double pulserGetFrequency( const char* detName, const char* pulserID ) { return PulserMap::getFrequency( detName, pulserID ); } unsigned pulserGetNPulses( const char* detName, const char* pulserID ) { return PulserMap::getNPulses( detName, pulserID ); } unsigned pulserGetDelay( const char* detName, const char* pulserID ) { return PulserMap::getDelay( detName, pulserID ); } };