/* * ScanDetector.cpp * * Created on: Nov 26, 2014 * Author: Hovanes Egiyan */ #include "ScanDetector.hh" #include "ScanStream.hh" #include ClassImp(ScanDetector) using namespace std; // Default constructor ScanDetector::ScanDetector() : TObject(), detNumber(0), detName(""), detDescription(""), detUnit(""), detScanStreamPtr(0), detData() { return; } ScanDetector::ScanDetector( istream& inStream, ScanStream* scanStream ) : TObject(), detNumber(0), detName(""), detDescription(""), detUnit(""), detScanStreamPtr(scanStream), detData() { // Read 4 lines from the input stream and check if the first descriptors // match the token for individual attributes of the detectors for( int iLine = 0; iLine < 4; iLine ++ ) { string sLine; if( !getline(inStream, sLine) ) break; size_t colPosition = sLine.find( ":" ); // Find the first colon position string firstString = sLine.substr( 0, colPosition ); string secondString = sLine.substr( colPosition+1 ); // The rest of the string if( firstString.find("Detector") != std::string::npos ) { // Convert the string values to integer value to assign to the integer attribute stringstream ssAttributes; ssAttributes << secondString; int attribValue; ssAttributes >> attribValue; detNumber = attribValue; } else if (firstString.find("Name") != std::string::npos ) { detName = secondString; } else if (firstString.find("Description") != std::string::npos ) { detDescription = secondString; } else if (firstString.find("Unit") != std::string::npos ) { detUnit = secondString; } } return; } ScanDetector::~ScanDetector() { // TODO Auto-generated destructor stub } ScanDetector::ScanDetector( const ScanDetector& det ) : TObject(), detNumber(det.getNumber()), detName(det.getName()), detDescription(det.getDesciption()), detUnit(det.getUnit()), detScanStreamPtr(det.getScanStream()), detData(const_cast(det).getData()){ } ScanDetector& ScanDetector::operator=( const ScanDetector& det ) { if( this != &det ) { detNumber = det.detNumber; detName = det.detName; detDescription = det.detDescription; detUnit = det.detUnit; detScanStreamPtr = det.detScanStreamPtr; detData = det.detData; } return *this; } void ScanDetector::printData() { cout << "Detector " << detName << " has " << detData.size() << " data points: " << endl; for ( unsigned iPt = 0; iPt < detData.size(); iPt++ ) { cout << detData[iPt] << " " ; } cout << endl; return; } int ScanDetector::readData( istream& inStream ) { string sLine; if( getline(inStream, sLine) ) { vector stringVector; boost::split(stringVector, sLine, boost::is_any_of(" ")); detData.resize( stringVector.size() -1 ); // Last one is always empty, ignore it for( unsigned iPt = 0; iPt < stringVector.size() - 1; iPt++ ) { stringstream ssValue; ssValue << stringVector[iPt]; ssValue >> detData[iPt]; } } return detData.size(); }