TSK_DBI_Context.cxx
Go to the documentation of this file.00001 #include "TSK_DBI_Context.hxx"
00002 #include <ctime>
00003
00004 const int TSK_DBI_Context::Invalid = 0xDEADBEEF;
00005
00006 ClassImp(TSK_DBI_Context)
00007
00008 TSK_DBI_Context::~TSK_DBI_Context() {}
00009
00010 TSK_DBI_Context::TSK_DBI_Context()
00011 : fRun(Invalid), fSubRun(Invalid), fEvent(Invalid),
00012 fSpill(Invalid), fTimeStamp(Invalid), fDataMC(1){}
00013
00014 TSK_DBI_Context::TSK_DBI_Context(int run, int subRun, int event,
00015 int spill, int stamp,int dataMC)
00016 : fRun(run), fSubRun(subRun), fEvent(event),
00017 fSpill(spill), fTimeStamp(stamp), fDataMC(dataMC) {}
00018
00019 int TSK_DBI_Context::GetRun() const {return fRun;}
00020 int TSK_DBI_Context::GetSubRun() const {return fSubRun;}
00021 int TSK_DBI_Context::GetEvent() const {return fEvent;}
00022 int TSK_DBI_Context::GetSpill() const {return fSpill;}
00023 bool TSK_DBI_Context::IsMC() const {
00024 if(fDataMC == 4)
00025 return true;
00026 return false;
00027 }
00028
00029 int TSK_DBI_Context::GetTimeStamp() const {return fTimeStamp;}
00030
00031 std::string TSK_DBI_Context::GetTimeStampString() const {
00032 std::time_t t = GetTimeStamp();
00033 char buf[256];
00034 std::strftime(buf,sizeof(buf),"'%Y-%m-%d %H:%M:%S'",std::gmtime(&t));
00035 return std::string(buf);
00036 }
00037
00038 void TSK_DBI_Context::SetRun(int v) {fRun = v;}
00039 void TSK_DBI_Context::SetSubRun(int v) {fSubRun = v;}
00040 void TSK_DBI_Context::SetEvent(int v) {fEvent = v;}
00041 void TSK_DBI_Context::SetSpill(int v) {fSpill = v;}
00042 void TSK_DBI_Context::SetTimeStamp(int v) {fTimeStamp = v;}
00043 void TSK_DBI_Context::SetDataMC(int dataMC){fDataMC = dataMC;}
00044
00045 bool TSK_DBI_Context::Valid() const {
00046 if (GetRun()!=TSK_DBI_Context::Invalid) return true;
00047 if (GetSubRun()!=TSK_DBI_Context::Invalid) return true;
00048 if (GetEvent()!=TSK_DBI_Context::Invalid) return true;
00049 if (GetSpill()!=TSK_DBI_Context::Invalid) return true;
00050 if (GetTimeStamp()!=TSK_DBI_Context::Invalid) return true;
00051 if (fDataMC!=TSK_DBI_Context::Invalid) return true;
00052 return false;
00053 }
00054
00055 std::ostream& operator<<(std::ostream& s, const TSK_DBI_Context& c) {
00056 s << "<";
00057 bool valid = false;
00058 if (c.GetRun()!=TSK_DBI_Context::Invalid) {
00059 if (valid) s << " ";
00060 s << "R: " << c.GetRun();
00061 valid = true;
00062 }
00063 if (c.GetSubRun()!=TSK_DBI_Context::Invalid) {
00064 if (valid) s << " ";
00065 s << "SR: " << c.GetSubRun();
00066 valid = true;
00067 }
00068 if (c.GetEvent()!=TSK_DBI_Context::Invalid) {
00069 if (valid) s << " ";
00070 s << "E: " << c.GetEvent();
00071 valid = true;
00072 }
00073 if (c.GetSpill()!=TSK_DBI_Context::Invalid) {
00074 if (valid) s << " ";
00075 s << "S: " << c.GetSpill();
00076 valid = true;
00077 }
00078 if (c.GetTimeStamp()!=TSK_DBI_Context::Invalid) {
00079 if (valid) s << " ";
00080 std::time_t t = c.GetTimeStamp();
00081 char buf[64];
00082 std::strftime(buf,sizeof(buf),"%y/%m/%d %X %Z",std::gmtime(&t));
00083 s << "T: " << buf;
00084 valid = true;
00085 }
00086 if (valid) {
00087 if (c.IsMC()) s << " MC";
00088 else s << " DET";
00089 }
00090 else {
00091 s << "Invalid Context";
00092 }
00093 s << ">";
00094 return s;
00095 }