| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Context.cc

Go to the documentation of this file.
00001 
00002 // $Id: Context.cc,v 1.3 2007/03/07 22:49:11 tagg Exp $
00003 //
00004 // Context
00005 //
00006 // Author:  N. Tagg
00007 //          2008/3/7 bv@bnl.gov, remove ROOT dependency
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     // Default constructor (unknown detector, simflag, timestamp=now)
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(); // instead of opfx
00064         os << c.AsString();
00065     }
00066     // instead of os.osfx()
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     // Return true if this was initialized by default ctor
00089     // we can only test site, detector, simflag
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 // Operators.
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     // Honest, this makes sense...
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 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:15:31 2011 for Context by doxygen 1.4.7