#include <ContextRange.h>
Collaboration diagram for ContextRange:
Public Member Functions | |
ContextRange () | |
ContextRange (const int siteMask, const int simMask, const TimeStamp &tstart, const TimeStamp &tend) | |
virtual | ~ContextRange () |
std::string | AsString (const char *option="") const |
bool | IsCompatible (const Context &cx) const |
bool | IsCompatible (const Context *cx) const |
int | GetSiteMask () const |
int | GetSimMask () const |
TimeStamp | GetTimeStart () const |
TimeStamp | GetTimeEnd () const |
void | TrimTo (const ContextRange &other) |
Trim this range to the intersection (ie. | |
void | SetTimeStart (const TimeStamp &tstart) |
void | SetTimeEnd (const TimeStamp &tend) |
void | SetSiteMask (const int siteMask) |
void | SetSimMask (const int simMask) |
Protected Attributes | |
int | mSiteMask |
Which sites. | |
int | mSimMask |
TimeStamp | mTimeStart |
or's of data/mc conditions | |
TimeStamp | mTimeEnd |
Friends | |
bool | operator== (const ContextRange &lhs, const ContextRange &rhs) |
bool | operator!= (const ContextRange &lhs, const ContextRange &rhs) |
bool | operator< (const ContextRange &lhs, const ContextRange &rhs) |
bool | operator<= (const ContextRange &lhs, const ContextRange &rhs) |
bool | operator> (const ContextRange &lhs, const ContextRange &rhs) |
bool | operator>= (const ContextRange &lhs, const ContextRange &rhs) |
Created on: 2000.05.03
Add comparison operators according to start time to build ContextRange indexed map. If you have another need for a more meaningful comparison, go ahead and change it. 2010/03/01 Zhe Wang
Definition at line 34 of file ContextRange.h.
ContextRange::ContextRange | ( | ) |
Definition at line 22 of file ContextRange.cc.
00023 : mSiteMask(0) 00024 , mSimMask(0) 00025 , mTimeStart(0,0) 00026 , mTimeEnd(0,0) 00027 { 00028 // Default constructor 00029 }
ContextRange::ContextRange | ( | const int | siteMask, | |
const int | simMask, | |||
const TimeStamp & | tstart, | |||
const TimeStamp & | tend | |||
) |
Definition at line 32 of file ContextRange.cc.
00036 : mSiteMask(siteMask), mSimMask(simMask), 00037 mTimeStart(tstart), mTimeEnd(tend) 00038 { 00039 // normal constructor 00040 }
ContextRange::~ContextRange | ( | ) | [virtual] |
std::string ContextRange::AsString | ( | const char * | option = "" |
) | const |
Definition at line 50 of file ContextRange.cc.
00051 { 00052 // Return the ContextRange as a string 00053 // 00054 // Result is a pointer to a statically allocated string. 00055 // User should copy this into their own buffer before calling 00056 // this method again. 00057 // 00058 // option "a": give site/simflag masks as alpha chars 00059 // option "c": compact (single line) 00060 // option "s": drop nsec part of times 00061 00062 std::string opt = option; 00063 std::transform(opt.begin(),opt.end(),opt.begin(),::tolower); 00064 00065 bool opt_a = (opt.find("a") != std::string::npos); 00066 bool opt_c = (opt.find("c") != std::string::npos); 00067 bool opt_s = (opt.find("s") != std::string::npos); 00068 00069 static std::string out; 00070 out="|"; 00071 00072 if (opt_a) 00073 out += Site::StringFromMask(mSiteMask); 00074 else { 00075 out += "site "; 00076 char buffer[1024] = {0}; 00077 snprintf(buffer,1024,"%#4.4x",mSiteMask); 00078 out += buffer; 00079 } 00080 00081 out += "|"; 00082 00083 if (opt_a) 00084 out += SimFlag::StringFromMask(mSimMask); 00085 else { 00086 out += "sim "; 00087 char buffer[1024] = {0}; 00088 snprintf(buffer,1024,"%#4.4x",mSiteMask); 00089 out += buffer; 00090 } 00091 00092 // TimeStamp::AsString returns pointer to statically allocated string 00093 // one needs to copy this before calling it again in same function call 00094 static char timeopt[4] = "c "; 00095 timeopt[0] = (opt_s ? 's' : 'c'); 00096 if(opt_c) out += "|"; 00097 else out += "\n\t"; 00098 00099 out += mTimeStart.AsString(timeopt); 00100 00101 if(opt_c) out += "|"; 00102 else out += "\n\t"; 00103 00104 out += mTimeEnd.AsString(timeopt); 00105 00106 return out; 00107 }
bool ContextRange::IsCompatible | ( | const Context & | cx | ) | const |
Definition at line 110 of file ContextRange.cc.
00111 { 00112 // compare Context with this ContextRange to see if the 00113 // the tagged set is compatible 00114 00115 int site = (int)cx.GetSite(); 00116 int simflag = (int)cx.GetSimFlag(); 00117 00118 // account for case where both Context and ContextRange 00119 // are using "kUnknown" which has no bits set 00120 if ( ! (site & mSiteMask) && 00121 (site != Site::kUnknown || 00122 mSiteMask != Site::kUnknown ) ) return false; 00123 if ( ! (simflag & mSimMask) && 00124 (simflag != SimFlag::kUnknown || 00125 mSimMask != SimFlag::kUnknown ) ) return false; 00126 00127 // the start time is taken as inclusive, but the end time is exclusive 00128 00129 if ( cx.GetTimeStamp() < mTimeStart ) return false; 00130 if ( cx.GetTimeStamp() >= mTimeEnd ) return false; 00131 00132 return true; 00133 }
bool ContextRange::IsCompatible | ( | const Context * | cx | ) | const |
Definition at line 136 of file ContextRange.cc.
00137 { 00138 // compare Context with this ContextRange to see if the 00139 // the tagged set is compatible 00140 assert(cx); 00141 return IsCompatible(*cx); 00142 }
int ContextRange::GetSiteMask | ( | ) | const [inline] |
int ContextRange::GetSimMask | ( | ) | const [inline] |
TimeStamp ContextRange::GetTimeStart | ( | ) | const [inline] |
TimeStamp ContextRange::GetTimeEnd | ( | ) | const [inline] |
void ContextRange::TrimTo | ( | const ContextRange & | other | ) |
Trim this range to the intersection (ie.
more restricted) limits of it's initial value and that of the argument
Definition at line 146 of file ContextRange.cc.
00147 { 00148 // Trim this range to the intersection (ie. more restricted) 00149 // limits of it's initial value and that of the argument 00150 00151 mSiteMask &= cx.mSiteMask; 00152 mSimMask &= cx.mSimMask; 00153 if (mTimeStart < cx.mTimeStart) mTimeStart = cx.mTimeStart; 00154 if (mTimeEnd > cx.mTimeEnd ) mTimeEnd = cx.mTimeEnd; 00155 }
void ContextRange::SetTimeStart | ( | const TimeStamp & | tstart | ) | [inline] |
void ContextRange::SetTimeEnd | ( | const TimeStamp & | tend | ) | [inline] |
void ContextRange::SetSiteMask | ( | const int | siteMask | ) | [inline] |
void ContextRange::SetSimMask | ( | const int | simMask | ) | [inline] |
bool operator== | ( | const ContextRange & | lhs, | |
const ContextRange & | rhs | |||
) | [friend] |
bool operator!= | ( | const ContextRange & | lhs, | |
const ContextRange & | rhs | |||
) | [friend] |
bool operator< | ( | const ContextRange & | lhs, | |
const ContextRange & | rhs | |||
) | [friend] |
bool operator<= | ( | const ContextRange & | lhs, | |
const ContextRange & | rhs | |||
) | [friend] |
bool operator> | ( | const ContextRange & | lhs, | |
const ContextRange & | rhs | |||
) | [friend] |
bool operator>= | ( | const ContextRange & | lhs, | |
const ContextRange & | rhs | |||
) | [friend] |
int ContextRange::mSiteMask [protected] |
int ContextRange::mSimMask [protected] |
Definition at line 71 of file ContextRange.h.
TimeStamp ContextRange::mTimeStart [protected] |
TimeStamp ContextRange::mTimeEnd [protected] |
Definition at line 73 of file ContextRange.h.