UniqueID.cpp

00001 #include "UniqueID.h"
00002 #include "LogicErrors.h"
00003 
00004 #include <sstream>
00005 
00006 using namespace std;
00007 using namespace Sct;
00008 
00009 namespace SctData {
00010 
00011 UniqueID::UniqueID(){
00012 }
00013 
00014 UniqueID& UniqueID::operator=(const UniqueID& other){
00015   runNumber=other.runNumber;
00016   scanNumber=other.scanNumber;
00017   module=other.module;
00018   nameAsString=other.nameAsString;
00019   return *this;
00020 }
00021 
00022 bool UniqueID::operator==(const UniqueID& other) const{
00023   return (runNumber==other.runNumber &&
00024       scanNumber==other.scanNumber &&
00025       module==other.module &&
00026       nameAsString==other.nameAsString);
00027 }
00028 
00029 bool UniqueID::operator!=(const UniqueID& other) const{
00030   return (!(*this==other));
00031 }
00032 
00033 
00034 UniqueID::UniqueID(string idAsString) : nameAsString(idAsString) {
00035     unsigned int dot = nameAsString.find('.');
00036     if (dot == nameAsString.npos) throw InvalidArgumentError("UniqueID can parse " + nameAsString + " - no run number", __FILE__, __LINE__);
00037     std::string temp = nameAsString.substr(0, dot);
00038     std::istringstream iss(temp);
00039     iss >> runNumber;
00040 
00041     unsigned int dot2 = nameAsString.find('.', ++dot);
00042     if (dot2 == nameAsString.npos) throw InvalidArgumentError("UniqueID can parse " + nameAsString + " - no scan number", __FILE__, __LINE__);
00043     temp = nameAsString.substr(dot, dot2-dot);
00044     std::istringstream iss2(temp);
00045     iss2 >> scanNumber;
00046 
00047     module = nameAsString.substr(++dot2);
00048 }
00049 
00050 UniqueID::UniqueID(unsigned int runNumber, unsigned int scanNumber, string module)
00051     : runNumber(runNumber), scanNumber(scanNumber), module(module) {
00052     ostringstream oss;
00053     oss << runNumber << "." << scanNumber << "." << module;
00054     nameAsString = oss.str();
00055 }
00056 
00057 UniqueID UniqueID::getUniqueID() const {
00058     return nameAsString;
00059 }
00060 
00061 
00062 UniqueID::operator string () const {
00063     return nameAsString;
00064 }
00065 
00066 string UniqueID::getModule() const {
00067     return module;
00068 }
00069 
00070 unsigned int UniqueID::getRunNumber() const {
00071     return runNumber;
00072 }
00073 
00074 unsigned int UniqueID::getScanNumber() const {
00075     return scanNumber;
00076 }
00077 
00078 }
00079 
00080 std::ostream& operator<<(std::ostream& os, const Sct::UniqueID& id){
00081   os << (string)id;
00082   return os;
00083 }
00084 
00085 std::istream& operator>>(std::istream& is, Sct::UniqueID& id){
00086   std::string parseMe;
00087   is >> parseMe;
00088   id=UniqueID(parseMe);
00089   return is;
00090 }
00091 

Generated on Mon Feb 6 14:01:37 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6