00001 #include "UniqueID.h"
00002 #include "Sct/LogicErrors.h"
00003
00004 #include <sstream>
00005
00006 using namespace std;
00007 using namespace Sct;
00008
00009 namespace SctData {
00010
00011 UniqueID::UniqueID(string uniqueID) : uniqueID(uniqueID) {
00012 int dot = uniqueID.find('.');
00013 if (dot == uniqueID.npos) throw InvalidArgumentError("UniqueID can parse " + uniqueID + " - no run number", __FILE__, __LINE__);
00014 std::string temp = uniqueID.substr(0, dot);
00015 std::istringstream iss(temp);
00016 iss >> runNumber;
00017
00018 int dot2 = uniqueID.find('.', ++dot);
00019 if (dot2 == uniqueID.npos) throw InvalidArgumentError("UniqueID can parse " + uniqueID + " - no scan number", __FILE__, __LINE__);
00020 temp = uniqueID.substr(dot, dot2-dot);
00021 std::istringstream iss2(temp);
00022 iss2 >> scanNumber;
00023
00024 module = uniqueID.substr(++dot2);
00025 }
00026
00027 UniqueID::UniqueID(unsigned int runNumber, unsigned int scanNumber, string module)
00028 : runNumber(runNumber), scanNumber(scanNumber), module(module) {
00029 ostringstream oss;
00030 oss << runNumber << "." << scanNumber << "." << module;
00031 uniqueID = oss.str();
00032 }
00033
00034 string UniqueID::getUniqueID() const {
00035 return uniqueID;
00036 }
00037
00038
00039 UniqueID::operator string () const {
00040 return getUniqueID();
00041 }
00042
00043 string UniqueID::getModule() const {
00044 return module;
00045 }
00046
00047 unsigned int UniqueID::getRunNumber() const {
00048 return runNumber;
00049 }
00050
00051 unsigned int UniqueID::getScanNumber() const {
00052 return scanNumber;
00053 }
00054
00055 }