Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

VldRange.cxx

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

Generated on Thu Nov 1 15:54:05 2007 for loon by  doxygen 1.3.9.1