EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ValRange.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ValRange.cxx
1 
2 #include "ValRange.h"
3 #include "ValContext.h"
4 
5 
7 
8 //_____________________________________________________________________________
9 std::ostream& operator<<(std::ostream& os, const ValRange& vldr)
10 {
11  return os << vldr.AsString();
12 }
13 
14 //_____________________________________________________________________________
16  : fDetectorMask(0), fSimMask(0),
17  fTimeStart(), fTimeEnd(), fDataSource("unknown")
18 {
19  // Default constructor
20 }
21 //_____________________________________________________________________________
22 ValRange::ValRange(const Int_t detMask, const Int_t simMask,
23  const ValTimeStamp& tstart,
24  const ValTimeStamp& tend,
25  const TString& source)
26  : fDetectorMask(detMask), fSimMask(simMask),
27  fTimeStart(tstart), fTimeEnd(tend), fDataSource(source)
28 {
29  // normal constructor
30 }
31 
32 //_____________________________________________________________________________
34 {
35  // delete all the owned sub-objects
36 
37 }
38 
39 //_____________________________________________________________________________
40 const char* ValRange::AsString(Option_t* option) const
41 {
42  // Return the ValRange as a string
43  //
44  // Result is a pointer to a statically allocated string.
45  // User should copy this into their own buffer before calling
46  // this method again.
47  //
48  // option "a": give detector/simflag masks as alpha chars
49  // option "c": compact (single line)
50  // option "s": drop nsec part of times
51  // option "1": include only "start time"
52  // option "-": don't include "source" info
53 
54  static char newstring[255] = " ";
55 
56  TString opt = option;
57  opt.ToLower();
58 
59  Bool_t opt_a = opt.Contains("a");
60  Bool_t opt_c = opt.Contains("c");
61 
62  TString detbits;
63  if (opt_a) {
65  } else {
66  sprintf(newstring,"det %#4.4x",fDetectorMask);
67  detbits = newstring;
68  }
69 
70  TString simbits;
71  if (opt_a) {
73  } else {
74  sprintf(newstring,"sim %#4.4x",fSimMask);
75  simbits = newstring;
76  }
77 
78  // ValTimeStamp::AsString returns pointer to statically allocated string
79  // one needs to copy this before calling it again in same function call
80  static char timeopt[4] = "c ";
81  timeopt[0] = (opt.Contains("s")?'s':'c');
82  TString start_str = fTimeStart.AsString(timeopt);
83  TString end_str;
84  if ( ! opt.Contains("1")) {
85  end_str = fTimeEnd.AsString(timeopt);
86  if ( !opt_c ) { end_str.Prepend("\n\t "); }
87  else { end_str.Prepend(" "); }
88  }
89  if ( ! opt_c ) { start_str.Prepend("\n\t "); }
90 
91  TString source;
92  if ( ! opt.Contains("-")) {
93  source += (opt_c) ? " '" : "\n\t from source: ";
94  source += fDataSource;
95  source += (opt_c) ? "'" : "";
96  }
97 
98  sprintf(newstring,
99  "|%s|%s|%s%s%s",
100  (const char*)detbits,
101  (const char*)simbits,
102  (const char*)start_str,
103  (const char*)end_str,
104  (const char*)source);
105 
106  return newstring;
107 }
108 
109 //_____________________________________________________________________________
110 Bool_t ValRange::IsCompatible(const ValContext& vldc) const
111 {
112  // compare ValContext with this ValRange to see if the
113  // the tagged set is compatible
114 
115  Int_t detector = (Int_t)vldc.GetDetector();
116  Int_t simflag = (Int_t)vldc.GetSimFlag();
117 
118  // account for case where both ValContext and ValRange
119  // are using "kUnknown" which has no bits set
120  if ( ! (detector & fDetectorMask) &&
121  (detector != Detector::kUnknown ||
122  fDetectorMask != Detector::kUnknown ) ) { return kFALSE; }
123  if ( ! (simflag & fSimMask) &&
124  (simflag != SimFlag::kUnknown ||
125  fSimMask != SimFlag::kUnknown ) ) { return kFALSE; }
126 
127  // the start time is taken as inclusive, but the end time is exclusive
128 
129  if ( vldc.GetTimeStamp() < fTimeStart ) { return kFALSE; }
130  if ( vldc.GetTimeStamp() >= fTimeEnd ) { return kFALSE; }
131 
132  return kTRUE;
133 }
134 
135 //_____________________________________________________________________________
136 Bool_t ValRange::IsCompatible(const ValContext* vldc) const
137 {
138  // compare ValContext with this ValRange to see if the
139  // the tagged set is compatible
140 
141  return IsCompatible(*vldc);
142 }
143 
144 //_____________________________________________________________________________
145 void ValRange::Print(Option_t* option) const
146 {
147  // Print this object
148 
149  printf("%s\n",AsString(option));
150 }
151 
152 //_____________________________________________________________________________
153 void ValRange::TrimTo(const ValRange& vldr)
154 {
155  // Trim this range to the intersection (ie. more restricted)
156  // limits of it's initial value and that of the argument
157 
159  fSimMask &= vldr.fSimMask;
160  if (fTimeStart < vldr.fTimeStart) { fTimeStart = vldr.fTimeStart; }
161  if (fTimeEnd > vldr.fTimeEnd ) { fTimeEnd = vldr.fTimeEnd; }
162  if (!fDataSource.Contains(vldr.fDataSource)) {
163  fDataSource += ", ";
164  fDataSource += vldr.fDataSource;
165  }
166 }
167 
168 //_____________________________________________________________________________