/* * ProfilerDetComponent.cpp * * Created on: Oct 18, 2015 * Author: Hovanes Egiyan */ #include "ProfilerDetComponent.hh" #include "ProfilerDetector.hh" using namespace std; // Instantiate templated members that are not specialized template short ProfilerDetComponent::getAverageValue( const std::string pvLabel ); //template unsigned ProfilerDetComponent::getAverageValue( const std::string pvLabel ); //template double ProfilerDetComponent::getAverageValue( const std::string pvLabel ); template void ProfilerDetComponent::setAllChannels( const std::string pvLabel, const std::string rbLabel, const short value ); // constructor that does not call the constructor of subclasses since this class inherits // virtually. Cannot be used to instantiate a object of this class ProfilerDetComponent::ProfilerDetComponent( ProfilerDetector* det ) : MutexedClass(), ProfilerPlaneData( false ), pdcDetector( 0 ), pdcPV() { std::cout << " Entering good " << __FUNCTION__ << " with det = " << hex << showbase << det << dec << " name is " << getName() << " ." << std::endl; pdcDetector = det; return; } ProfilerDetComponent::ProfilerDetComponent( const ProfilerDetComponent& c ) : MutexedClass(c), ProfilerPlaneData( c ), pdcDetector( c.pdcDetector ), pdcPV( c.pdcPV ) { std::cout << " Entering copy " << __FUNCTION__ << std::endl; return; } ProfilerDetComponent::~ProfilerDetComponent() { return; } ProfilerDetComponent& ProfilerDetComponent::operator=( const ProfilerDetComponent& c ) { // ProfilerPlaneData::operator=( c ); MtxLock objLock( mcMutex ); pdcDetector = c.pdcDetector; pdcPV = c.pdcPV; return *this; } inline std::string ProfilerDetComponent::getDetectorName() const { return pdcDetector->getName(); } ProfilerPVs* ProfilerDetComponent::setPVs( ProfilerPVs* pv ) { { MtxLock objLock( mcMutex ); pdcPV = pv; } // Set the vector sizes // ProfilerPlaneData::defineAxis(); // ProfilerPlaneData::resizeVectors( pdcPV->getArrays().getNFIFO() ); // We request slice creation here since the number of slices is not necessarily equal to the // original value of ppdNumberOfSlices. For instance, in the simulation the number of slices // is actually the FIFO length. For that reason, ProfilerPlaneDate::createSlices was declared to // be purely virtual. this->createSlices(); return pdcPV; } // Returned the averaged value of the unsigned values. The // averaged value is over all plane channels associated // with this plane. template T ProfilerDetComponent::getAverageValue( const std::string pvLabel ) { double sum = 0.0; // Running sum variable // Loop over all the pulser board channels related to this display and // sum their values. for ( unsigned iChan = 1; iChan <= getChanNumber(); iChan++ ) { // Append the channel number after a colon to the label. stringstream ssAddr; ssAddr << iChan; std::string addr = ssAddr.str(); std::string label = pvLabel + ":" + addr; double currValue = pdcPV->getPV( label, SYNC, T() ); sum += currValue; } if ( getChanNumber() > 0 ) { return static_cast( round( sum / getChanNumber() ) ); } else { // If no pulser board channel is assigned to this pulser // that is a pretty bad error, throw an exception std::stringstream errStream; errStream << "ProfilerDetComponent::getAverageValue : ProfilerDetComponent object " << getName() << " does not have channels associated with it"; throw std::runtime_error( errStream.str() ); } } template void ProfilerDetComponent::setAllChannels( const std::string pvLabel, const std::string rbLabel, const T value ) { // MtxLock obLock(ppvMutex); // Set all PV directly involved in this profiler plane for ( unsigned iChan = 1; iChan <= getChanNumber(); iChan++ ) { // Append the channel number after a colon to the label. stringstream ssAddr; ssAddr << iChan; std::string addr = ssAddr.str(); std::string label = pvLabel + ":" + addr; std::string readbackLabel = rbLabel + ":" + addr; // cout << "Will write to " << label << " and check with " << readbackLabel << endl; pdcPV->setValue( label, value, SYNC ); // check if the pvSet succeeded, and write a message on the screen // if the readback did not match the setpoint. if ( rbLabel != "" && !pdcPV->gotReadback( value, readbackLabel ) ) { cout << "ProfilerDetComponent::setAllChannels : failed to set PV with label " << pvLabel << " for " << getName() << " to " << value << endl; } } return; }