EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairDbValidityRec.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairDbValidityRec.cxx
1 
2 #include "Detector.h"
3 #include "SimFlag.h"
4 #include "FairDbBinaryFile.h"
5 #include "FairDbResult.h"
6 #include "FairDbOutRowStream.h"
7 #include "FairDbValidityRec.h"
8 #include "ValRange.h"
9 #include "ValTimeStamp.h"
10 
11 #include "TString.h"
12 
13 #include <sstream>
14 #include <iostream>
15 
17 
18 
19 #include "FairDbResPtr.tpl"
21 
22 
23 ostream& operator<<(ostream& os, const FairDbValidityRec& vRec)
24 {
25 
26  const ValRange& range(vRec.GetValRange());
27 
28  ostringstream os2; //Use local to avoid manipulators from making permanent change to os.
29  os2 << "SeqNo: " << vRec.GetSeqNo()
30  << " AggNo: " << vRec.GetAggregateNo()
31  << " DbNo: " << vRec.GetDbNo();
32  if ( vRec.IsGap() ) { os2 << " (gap)"; }
33  os2 << " ValRange: |"
34  << hex << "0x" << range.GetDetectorMask() << "|"
35  << "0x" << range.GetSimMask() << "|"
36  << " " << range.GetTimeStart().AsString("s") << " .. "
37  << range.GetTimeEnd().AsString("s")
38  << " from: " << range.GetDataSource();
39  os << os2.str();
40  return os;
41 
42 }
43 
44 
46  const ValTimeStamp& endOther)
47 {
48 
51 
52  SetTimeWindow( start > startOther ? start : startOther,
53  end < endOther ? end : endOther );
54 }
55 
56 //.....................................................................
57 
58 FairDbValidityRec::FairDbValidityRec(Int_t dbNo,Bool_t isGap)
59  : FairDbTableRow(),
60  fAggregateNo(-2),
61  fCreationDate(),
62  fDbNo(dbNo),
63  fInsertDate(),
64  fIsGap(isGap),
65  fTask(0),
66  fSeqNo(0),
67  fTableProxy(0),
68  fValRange()
69 {
70 }
71 //.....................................................................
72 
74  : FairDbTableRow(from),
75  fAggregateNo(from.fAggregateNo),
76  fCreationDate(from.fCreationDate),
77  fDbNo(from.fDbNo),
78  fInsertDate(from.fInsertDate),
79  fIsGap(from.fIsGap),
80  fTask(from.fTask),
81  fSeqNo(from.fSeqNo),
82  fTableProxy(from.fTableProxy),
83  fValRange(from.fValRange)
84 
85 {
86  *this = from;
87 
88 }
89 //.....................................................................
90 
92  FairDb::Task task,
93  Int_t aggNo,
94  UInt_t seqNo,
95  Int_t dbNo,
96  Bool_t isGap,
98  fAggregateNo(aggNo),
99  fCreationDate(time),
100  fDbNo(dbNo),
101  fInsertDate(),
102  fIsGap(isGap),
103  fTask(task),
104  fSeqNo(seqNo),
105  fTableProxy(0),
106  fValRange(range)
107 {
108 
109 }
110 
111 //.....................................................................
112 
114 {
115 
116 }
117 
118 
120  const FairDbValidityRec* /* vrec */)
121 {
122 
123  ValTimeStamp start, end;
124  Int_t detMask, simMask;
125 
126 
127  fTableProxy = rs.GetTableProxy();
128  fDbNo = rs.GetDbNo();
129 
130 // Read data from row.
131 
132  rs >> fSeqNo >> start >> end >> detMask >> simMask >> fTask
134 
135  fIsGap = kFALSE;
136 
137  ValRange vr(detMask, simMask, start, end, "From Database");
138  fValRange = vr;
139 
140  cout
141  << "FairDbValidityRec for row " << rs.CurRowNum()
142  << ": " << fValRange.AsString()
143  << " seq num: " << fSeqNo
144  << " agg no: " << fAggregateNo
145  << " task: " << endl;
146 }
147 
148 
150 {
152  this->GetSeqNo(),
153  this->GetCreationDate());
154 
155 }
156 
157 std::string FairDbValidityRec::GetL2CacheName(UInt_t seqLo,
158  UInt_t seqHi,
159  ValTimeStamp ts)
160 {
161 
162  ostringstream oss;
163  oss << seqLo << "_";
164  if ( seqLo != seqHi ) { oss << seqHi << "_"; }
165  oss << ts.AsString("s");
166  std::string str(oss.str());
167  // Convert white space to underscore.
168  int i = str.size();
169  while ( i-- ) if ( str[i] == ' ' ) { str[i] = '_'; }
170  return str;
171 
172 }
173 
174 
176 {
177 
178  const ValRange& otherVR =other.GetValRange();
179 
180  return
181  ( other.GetTask() == fTask
182  && ( otherVR.GetDetectorMask() & fValRange.GetDetectorMask() )
183  && ( otherVR.GetSimMask() & fValRange.GetSimMask() )
184  && ( otherVR.GetTimeStart() >= fValRange.GetTimeEnd()
185  || otherVR.GetTimeEnd() <= fValRange.GetTimeStart() )
186  );
187 
188 }
189 
190 
192  const FairDb::Task& task) const
193 {
194 
195  ValTimeStamp ts = vc.GetTimeStamp();
196  const ValRange& vr = this->GetValRange();
197 
198  return
199  ( task == this->GetTask()
200  && ( vc.GetDetector() & vr.GetDetectorMask() )
201  && ( vc.GetSimFlag() & vr.GetSimMask() )
202  && ( ts >= vr.GetTimeEnd()
203  || ts < vr.GetTimeStart() )
204  );
205 
206 }
207 
208 
209 
211  const FairDb::Task& task) const
212 {
213 
214  cout << " FairDbValidityRec::IsCompatible : tasks:"
215  << task << "," << fTask
216  << " is compat: " << fValRange.IsCompatible(vc) << endl
217  << " range " << fValRange.AsString() << endl
218  << " context " << vc.AsString() << endl;
219 
220  return task == fTask && fValRange.IsCompatible(vc);
221 
222 }
223 
225  const ValTimeStamp& end)
226 {
229  start,
230  end,
232  fValRange = range;
233 
234 }
235 
236 
238  const FairDbValidityRec* /* vrec */) const
239 {
240 
241  ors << fSeqNo
243  << fValRange.GetTimeEnd()
245  << fValRange.GetSimMask()
246  << fTask
247  << fAggregateNo
248  << fCreationDate
249  << fInsertDate;
250 }
251 
253 {
254 
255  if ( file.IsReading() ) {
256  file >> fAggregateNo
257  >> fCreationDate
258  >> fDbNo
259  >> fInsertDate
260  >> fIsGap
261  >> fTask
262  >> fSeqNo
263  >> fValRange;
264  fTableProxy = 0;
265  } else if ( file.IsWriting() ) {
266  file << fAggregateNo
267  << fCreationDate
268  << fDbNo
269  << fInsertDate
270  << fIsGap
271  << fTask
272  << fSeqNo
273  << fValRange;
274  }
275 }
276 
277 
278 void FairDbValidityRec::Trim(const ValTimeStamp& queryTime,
279  const FairDbValidityRec& other)
280 {
281 
282  if ( fAggregateNo != other.fAggregateNo || other.IsGap() ) { return; }
283 
284 // If this record is not a gap then the other record can be ignore
285 // as it is of lower priority.
286 
287  if ( ! IsGap() ) { return; }
288 
291  ValTimeStamp startOther = other.GetValRange().GetTimeStart();
292  ValTimeStamp endOther = other.GetValRange().GetTimeEnd();
293 
294 // If entry brackets query date, then use it but with a validity that
295 // is trimmed by the current record.
296 
297  if ( startOther <= queryTime && endOther > queryTime ) {
298  if ( start < startOther ) { start = startOther; }
299  if ( end > endOther ) { end = endOther; }
300  *this = other;
301  SetTimeWindow(start,end);
302  }
303 
304 // It doesn't bracket, so use it to trim the window
305 
306  else {
307 
308  if ( endOther <= queryTime ) {
309  if ( start < endOther ) { SetTimeWindow(endOther,end); }
310  } else if ( startOther > queryTime ) {
311  if ( end > startOther ) { SetTimeWindow(start, startOther); }
312  }
313  }
314 
315 }
316