00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "Context/Context.h"
00012 #include <iostream>
00013 #include <sstream>
00014
00015
00016 Context::Context()
00017 : mSite(Site::kUnknown)
00018 , mSimFlag(SimFlag::kUnknown)
00019 , mTimeStamp(0,0)
00020 , mDetId(DetectorId::kUnknown)
00021 {
00022
00023 }
00024
00025
00026 Context::Context(Site::Site_t site,
00027 SimFlag::SimFlag_t flag,
00028 const TimeStamp& time,
00029 DetectorId::DetectorId_t det)
00030 : mSite(site)
00031 , mSimFlag(flag)
00032 , mTimeStamp(time)
00033 , mDetId(det)
00034 {
00035 }
00036
00037
00038 Context::Context(const Context& other)
00039 {
00040 *this = other;
00041 }
00042
00043 Context& Context::operator=(const Context& rhs)
00044 {
00045 if (this == &rhs) return *this;
00046
00047 mSite = rhs.GetSite();
00048 mSimFlag = rhs.GetSimFlag();
00049 mTimeStamp = rhs.GetTimeStamp();
00050 mDetId = rhs.GetDetId();
00051
00052 return *this;
00053 }
00054
00055
00056 std::ostream& operator<<(std::ostream& os, const Context& c)
00057 {
00058 os << c.AsString();
00059 return os;
00060
00062 if (os.good()) {
00063 if (os.tie()) os.tie()->flush();
00064 os << c.AsString();
00065 }
00066
00067 if (os.flags() & std::ios::unitbuf) os.flush();
00068 return os;
00069 }
00070
00071
00072 std::string Context::AsString(const char* option) const
00073 {
00075
00076 std::stringstream ss;
00077 ss << Site::AsString(mSite) << ", "
00078 << SimFlag::AsString(mSimFlag) << ", "
00079 << mTimeStamp.AsString(option) << ", "
00080 << DetectorId::AsString(mDetId);
00081
00082 return ss.str();
00083 }
00084
00085
00086 bool Context::IsValid() const
00087 {
00088
00089
00090
00091 if( (mTimeStamp.GetSec()>0)
00092 && mSimFlag !=SimFlag::kUnknown
00093 && mSite != Site::kUnknown
00094 )
00095 return false;
00096 return true;
00097 }
00098
00099
00100
00101
00102 bool operator==(const Context& lhs, const Context& rhs)
00103 {
00104 if (lhs.GetTimeStamp()==rhs.GetTimeStamp())
00105 if (lhs.GetSimFlag() == rhs.GetSimFlag())
00106 if (lhs.GetSite() == rhs.GetSite() )
00107 if (lhs.GetDetId() == rhs.GetDetId())
00108 return true;
00109
00110 return false;
00111 }
00112
00113 bool operator!=(const Context& lhs, const Context& rhs)
00114 {
00115 if (lhs.GetTimeStamp()!=rhs.GetTimeStamp()) return true;
00116 if (lhs.GetSimFlag() != rhs.GetSimFlag()) return true;
00117 if (lhs.GetSite() != rhs.GetSite() ) return true;
00118 if (lhs.GetDetId() != rhs.GetDetId()) return true;
00119 return false;
00120 }
00121
00122 bool operator< (const Context& lhs, const Context& rhs)
00123 {
00124
00125 if (lhs.GetTimeStamp() < rhs.GetTimeStamp()) return true;
00126 if (lhs.GetTimeStamp() == rhs.GetTimeStamp()) {
00127 if (lhs.GetSite() < rhs.GetSite()) return true;
00128 if (lhs.GetSite() == rhs.GetSite()) {
00129 if (lhs.GetDetId() < rhs.GetDetId()) return true;
00130 }
00131 }
00132 return false;
00133 }
00134
00135 bool operator> (const Context& lhs, const Context& rhs)
00136 {
00137 return !(lhs<rhs) && !(lhs==rhs);
00138 }
00139
00140 bool operator<=(const Context& lhs, const Context& rhs)
00141 {
00142 return (lhs<rhs) || (lhs==rhs);
00143 }
00144
00145 bool operator>=(const Context& lhs, const Context& rhs)
00146 {
00147 return !(lhs<rhs);
00148 }