TVldRange.cxx

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////
00002 // $Id: TVldRange.cxx,v 1.1 2011/01/18 05:49:20 finch Exp $
00003 //
00004 // TVldRange
00005 //
00006 // TVldRange is delimits/identifies the allowed "context" values
00007 // associated with the associated DBI returned information
00008 //
00009 // Author:  R. Hatcher 2000.05.03
00010 //
00011 ////////////////////////////////////////////////////////////////////////////
00012 
00013 #include "TVldRange.hxx"
00014 #include "TVldContext.hxx"
00015 
00016 #include <TSK_DBI_Log.hxx>
00017 #include <MsgFormat.h>
00018 using std::endl;
00019 //CVSID("$Id: TVldRange.cxx,v 1.1 2011/01/18 05:49:20 finch Exp $");
00020 
00021 ClassImp(TVldRange)
00022 
00023 //_____________________________________________________________________________
00024 std::ostream& operator<<(std::ostream& os, const TVldRange& vldr)
00025 {
00026   return os << vldr.AsString();
00027 }
00028 
00029 //_____________________________________________________________________________
00030 TVldRange::TVldRange()
00031    : fDetectorMask(0), fSimMask(0),
00032      fTimeStart(), fTimeEnd(), fDataSource("unknown")
00033 {
00034    // Default constructor
00035 }
00036 //_____________________________________________________________________________
00037 TVldRange::TVldRange(const Int_t detMask, const Int_t simMask,
00038                          const TVldTimeStamp &tstart,
00039                          const TVldTimeStamp &tend,
00040                          const TString &source)
00041    : fDetectorMask(detMask), fSimMask(simMask),
00042      fTimeStart(tstart), fTimeEnd(tend), fDataSource(source)
00043 {
00044    // normal constructor
00045 }
00046 
00047 //_____________________________________________________________________________
00048 TVldRange::~TVldRange()
00049 {
00050    // delete all the owned sub-objects
00051 
00052 }
00053 
00054 //_____________________________________________________________________________
00055 const char* TVldRange::AsString(Option_t *option) const
00056 {
00057    // Return the TVldRange as a string
00058    //
00059    // Result is a pointer to a statically allocated string.
00060    // User should copy this into their own buffer before calling
00061    // this method again.
00062    //
00063    // option "a": give detector/simflag masks as alpha chars
00064    // option "c": compact (single line)
00065    // option "s": drop nsec part of times
00066    // option "1": include only "start time"
00067    // option "-": don't include "source" info
00068 
00069    static char newstring[255] = " ";
00070 
00071    TString opt = option;
00072    opt.ToLower();
00073 
00074    Bool_t opt_a = opt.Contains("a");
00075    Bool_t opt_c = opt.Contains("c");
00076 
00077    TString detbits;
00078    if (opt_a) {
00079      detbits = DbiDetector::MaskToString(fDetectorMask);
00080    }
00081    else {
00082       sprintf(newstring,"det %#4.4x",fDetectorMask);
00083       detbits = newstring;
00084    }
00085 
00086    TString simbits;
00087    if (opt_a) {
00088      simbits = DbiSimFlag::MaskToString(fSimMask);
00089    }
00090    else {
00091       sprintf(newstring,"sim %#4.4x",fSimMask);
00092       simbits = newstring;
00093    }
00094 
00095    // TVldTimeStamp::AsString returns pointer to statically allocated string
00096    // one needs to copy this before calling it again in same function call
00097    static char timeopt[4] = "c  ";
00098    timeopt[0] = (opt.Contains("s")?'s':'c');
00099    TString start_str = fTimeStart.AsString(timeopt);
00100    TString end_str;
00101    if ( ! opt.Contains("1")) {
00102       end_str = fTimeEnd.AsString(timeopt);
00103       if ( !opt_c ) end_str.Prepend("\n\t ");
00104       else          end_str.Prepend(" ");
00105    }
00106    if ( ! opt_c ) start_str.Prepend("\n\t ");
00107 
00108    TString source;
00109    if ( ! opt.Contains("-")) {
00110       source +=  (opt_c) ? " '" : "\n\t from source: ";
00111       source += fDataSource;
00112       source +=  (opt_c) ? "'" : "";
00113    }
00114 
00115    sprintf(newstring,
00116               "|%s|%s|%s%s%s",
00117               (const char*)detbits,
00118               (const char*)simbits,
00119               (const char*)start_str,
00120               (const char*)end_str,
00121               (const char*)source);
00122 
00123    return newstring;
00124 }
00125 
00126 //_____________________________________________________________________________
00127 Bool_t TVldRange::IsCompatible(const TVldContext &vldc) const
00128 {
00129    // compare TVldContext with this TVldRange to see if the
00130    // the tagged set is compatible
00131 
00132    Int_t detector = (Int_t)vldc.GetDetector();
00133    Int_t simflag  = (Int_t)vldc.GetSimFlag();
00134 
00135    // account for case where both TVldContext and TVldRange
00136    // are using "kUnknown" which has no bits set
00137    if ( ! (detector & fDetectorMask) &&
00138         (detector      != DbiDetector::kUnknown ||
00139          fDetectorMask != DbiDetector::kUnknown    ) ) return kFALSE;
00140    if ( ! (simflag  & fSimMask) &&
00141         (simflag  != DbiSimFlag::kUnknown ||
00142          fSimMask != DbiSimFlag::kUnknown   ) ) return kFALSE;
00143 
00144    // the start time is taken as inclusive, but the end time is exclusive
00145 
00146    if ( vldc.GetTimeStamp() <  fTimeStart ) return kFALSE;
00147    if ( vldc.GetTimeStamp() >= fTimeEnd   ) return kFALSE;
00148 
00149    return kTRUE;
00150 }
00151 
00152 //_____________________________________________________________________________
00153 Bool_t TVldRange::IsCompatible(const TVldContext *vldc) const
00154 {
00155    // compare TVldContext with this TVldRange to see if the
00156    // the tagged set is compatible
00157 
00158    return IsCompatible(*vldc);
00159 }
00160 
00161 //_____________________________________________________________________________
00162 void TVldRange::Print(Option_t *option) const
00163 {
00164    // Print this object
00165 
00166    printf("%s\n",AsString(option));
00167 }
00168 
00169 //_____________________________________________________________________________
00170 void TVldRange::TrimTo(const TVldRange& vldr)
00171 {
00172    // Trim this range to the intersection (ie. more restricted)
00173    // limits of it's initial value and that of the argument
00174 
00175    fDetectorMask &= vldr.fDetectorMask;
00176    fSimMask      &= vldr.fSimMask;
00177    if (fTimeStart < vldr.fTimeStart) fTimeStart = vldr.fTimeStart;
00178    if (fTimeEnd   > vldr.fTimeEnd  ) fTimeEnd   = vldr.fTimeEnd;
00179    if (!fDataSource.Contains(vldr.fDataSource)) {
00180       fDataSource   += ", ";
00181       fDataSource   += vldr.fDataSource;
00182    }
00183 }
00184 
00185 //_____________________________________________________________________________
00186 

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1