ATLAS Offline Software
TGoodRunsList.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <iostream>
6 
9 
10 
12 
13 
15  : TGoodRunsList("noname")
16 {
17 }
18 
19 
21  : std::map<Int_t,TGoodRun>()
22  , TNamed(name,"notitle")
23 {
24 }
25 
26 
28 {
29 }
30 
31 void
33 {
34  // ensure version and name are identical
35  Bool_t same = this->HasSameGRLInfo(other);
36  if (m_checkGRLInfo || other.GetCheckGRLInfo()) {
37  if (!same) {
38  TMsgLogger m_logger("TGoodRunsList");
39  m_logger << kWARNING << "Incompatible NamedLumiRanges: " << GEndl;
40  this->Summary(kFALSE);
41  other.Summary(kFALSE);
42  m_logger << kWARNING << "Not adding GoodRunsList." << GEndl;
43  return;
44  }
45  }
46 
47  // merge metadata
48  for (const auto& othermditem : other.GetMetaData()) {
49  auto thismditem = m_metadata.find(othermditem.first);
50  if (thismditem == m_metadata.end()) {
51  m_metadata.insert(othermditem);
52  } else {
53  auto& nameStr = othermditem.first;
54  auto& thisvaluestr = thismditem->second;
55  if (thisvaluestr != othermditem.second) {
56  if (nameStr == "RunList") {
57  thisvaluestr += ",";
58  } else {
59  thisvaluestr += " | ";
60  }
61  thisvaluestr += othermditem.second;
62  }
63  }
64  }
65 
66  const TGoodRunsList& diffgrl = this->GetPartOnlyIn(other);
67 
68  std::map<Int_t,Root::TGoodRun>::const_iterator itr;
69  // Store diffgrl goodrunslist
70  for (itr = diffgrl.begin(); itr!=diffgrl.end(); ++itr) {
71  if (this->find(itr->first)!=this->end()) { // overlapping runnumbers
72  Root::TGoodRun grun = itr->second.GetSumWith( this->find(itr->first)->second ) ;
73  if (!grun.IsEmpty()) (*this)[itr->first] = grun;
74  } else if (!itr->second.IsEmpty()) { // store rest directly
75  (*this)[itr->first] = itr->second;
76  }
77  }
78 
79  return;
80 }
81 
84 {
85  Root::TGoodRunsList overlapgrl;
86  overlapgrl.SetName("Overlap of GRLs");
87 
88  // ensure version and metadata are identical
89  Bool_t same = this->HasSameGRLInfo(other);
90  if (m_checkGRLInfo || other.GetCheckGRLInfo()) {
91  if (!same) {
92  TMsgLogger m_logger("TGoodRunsList");
93  m_logger << kWARNING << "Incompatible NamedLumiRanges: " << GEndl;
94  this->Summary(kFALSE);
95  other.Summary(kFALSE);
96  m_logger << kWARNING << "Returning empty GoodRunsList." << GEndl;
97  return overlapgrl;
98  }
99  }
100  if (same) {
101  overlapgrl.SetName(this->GetName());
102  overlapgrl.SetVersion(this->GetVersion());
103  overlapgrl.SetMetaData(this->GetMetaData());
104  }
105 
106  // Store goodruns
107  std::map<Int_t,Root::TGoodRun>::const_iterator itr = this->begin();
108  for (; itr!=this->end(); ++itr) {
109  if (other.find(itr->first)!=other.end()) { // check runnumbers
110  Root::TGoodRun grun = itr->second.GetOverlapWith( other.find(itr->first)->second ) ;
111  if (!grun.IsEmpty()) {
112  grun.Sort(); // sort lumiblock ranges before storage
113  overlapgrl[itr->first] = grun;
114  }
115  }
116  }
117 
118  return overlapgrl;
119 }
120 
121 
124 {
125  Root::TGoodRunsList sumgrl;
126  sumgrl.SetName("Sum of GRLs"/*this->GetName()*/);
127 
128  // ensure version and metadata are identical
129  Bool_t same = this->HasSameGRLInfo(other);
130  if (m_checkGRLInfo || other.GetCheckGRLInfo()) {
131  if (!same) {
132  TMsgLogger m_logger("TGoodRunsList");
133  m_logger << kWARNING << "Incompatible NamedLumiRanges: " << GEndl;
134  this->Summary(kFALSE);
135  other.Summary(kFALSE);
136  m_logger << kWARNING << "Returning empty GoodRunsList." << GEndl;
137  return sumgrl;
138  }
139  }
140  if (same) {
141  sumgrl.SetName(this->GetName());
142  sumgrl.SetVersion(this->GetVersion());
143  sumgrl.SetMetaData(this->GetMetaData());
144  }
145 
146  std::map<Int_t,Root::TGoodRun>::const_iterator itr;
147  // Store this goodruns
148  for (itr = this->begin(); itr!=this->end(); ++itr) {
149  if (other.find(itr->first)!=other.end()) { // check runnumbers
150  Root::TGoodRun grun = itr->second.GetSumWith( other.find(itr->first)->second ) ;
151  if (!grun.IsEmpty()) sumgrl[itr->first] = grun;
152  } else if (!itr->second.IsEmpty()) { // store difference
153  sumgrl[itr->first] = itr->second;
154  }
155  }
156  // Store remaining other goodruns
157  for (itr = other.begin(); itr!=other.end(); ++itr) {
158  if (sumgrl.find(itr->first)==sumgrl.end() && !itr->second.IsEmpty()) { // check for remaining runnumbers
159  sumgrl[itr->first] = itr->second;
160  }
161  }
162 
163  return sumgrl;
164 }
165 
166 
169 {
170  return other.GetPartNotIn(*this);
171 }
172 
173 
176 {
177  Root::TGoodRunsList notinother;
178  notinother.SetName("Difference of GRLs");
179 
180  // ensure version and metadata are identical
181  Bool_t same = this->HasSameGRLInfo(other);
182  if (m_checkGRLInfo || other.GetCheckGRLInfo()) {
183  if (!same) {
184  TMsgLogger m_logger("TGoodRunsList");
185  m_logger << kWARNING << "Incompatible NamedLumiRanges: " << GEndl;
186  this->Summary(kFALSE);
187  other.Summary(kFALSE);
188  m_logger << kWARNING << "Returning empty GoodRunsList." << GEndl;
189  return notinother;
190  }
191  }
192  if (same) {
193  notinother.SetName(this->GetName());
194  notinother.SetVersion(this->GetVersion());
195  notinother.SetMetaData(this->GetMetaData());
196  }
197 
198  std::map<Int_t,Root::TGoodRun>::const_iterator itr;
199  // How to store this goodrun ?
200  for (itr = this->begin(); itr!=this->end(); ++itr) {
201  if (other.find(itr->first)!=other.end()) { // check runnumbers
202  Root::TGoodRun notinrun = itr->second.GetPartNotIn( other.find(itr->first)->second ) ;
203  if (!notinrun.IsEmpty()) notinother[itr->first] = notinrun;
204  } else if (!itr->second.IsEmpty()) { // store difference
205  notinother[itr->first] = itr->second;
206  }
207  }
208 
209  return notinother;
210 }
211 
212 
213 Bool_t
215 {
216  return ( this->find(runnr)!=this->end() );
217 }
218 
219 
220 Bool_t
221 Root::TGoodRunsList::HasRunLumiBlock( Int_t runnr, Int_t lumiblocknr ) const
222 {
223  const auto run = this->find(runnr);
224  return ( run!=this->end() && run->second.HasLB( lumiblocknr ) );
225 }
226 
227 
228 Bool_t
230 {
231  std::map<TString,TString>::const_iterator itr = m_metadata.begin();
232  for (; itr!=m_metadata.end(); ++itr) {
233  TString triggername = itr->first;
234  triggername.ToLower();
235  if (triggername.BeginsWith("trigger") && itr->second.Length()>0) return kTRUE;
236  }
237  return kFALSE;
238 }
239 
240 
241 Bool_t
243 {
244  const Root::TGoodRunsList overlapgrl = this->GetOverlapWith(other);
245  bool isEmpty = overlapgrl.IsEmpty();
246  if (!isEmpty && verb) overlapgrl.Summary(true);
247 
248  return !isEmpty;
249 }
250 
251 
252 void
253 Root::TGoodRunsList::Summary(Bool_t verbose /*= kFALSE*/) const
254 {
255  // TNamed print
256  Print();
257 
258  TMsgLogger m_logger("TGoodRunsList");
259  // Versioning and metadata info
260  m_logger << kINFO << "Version: " << m_version << GEndl;
261  std::map<TString,TString>::const_iterator titr = m_metadata.begin();
262  for (titr = m_metadata.begin(); titr!=m_metadata.end(); ++titr)
263  m_logger << kINFO << "Metadata: " << (titr->first) << " : " << (titr->second) << GEndl;
264 
265  m_logger << kINFO << "Number of runs: " << this->size() << GEndl;
266 
267  // Info about runs
268  if (verbose) {
269  std::map<Int_t,Root::TGoodRun>::const_iterator itr = this->begin();
270  std::map<Int_t,Root::TGoodRun>::const_iterator end = this->end();
271  for (; itr!=end; ++itr) itr->second.Summary();
272  }
273 }
274 
275 
276 std::vector<int>
278 {
279  std::vector<int> runlist;
280  for (const auto& [runno, run] : *this) runlist.push_back(runno);
281 
282  return runlist;
283 }
284 
285 
286 std::vector<Root::TGoodRun>
288 {
289  std::vector<Root::TGoodRun> runlist;
290  for (const auto& [runno, run] : *this) runlist.push_back(run);
291 
292  return runlist;
293 }
294 
295 
296 std::vector<std::string>
298 {
299  std::vector<std::string> triggerchains;
300 
301  for (const auto& [key, value] : m_metadata) {
302  TString triggername = key;
303  triggername.ToLower();
304  if (triggername.BeginsWith("trigger") && value.Length()>0) triggerchains.push_back(value.Data());
305  }
306  return triggerchains;
307 }
308 
309 
310 std::vector<std::string>
312 {
313  std::vector<std::string> streamlist;
314 
315  for (const auto& [key, value] : m_metadata) {
316  TString streamname = key;
317  streamname.ToLower();
318  if (streamname.BeginsWith("stream") && value.Length()>0) streamlist.push_back(value.Data());
319  }
320  return streamlist;
321 }
322 
323 
324 Bool_t
326 {
327  TMsgLogger m_logger("TGoodRunsList");
328  Bool_t same(kTRUE);
329 
331  same = same && (TString(this->GetName())==TString(other.GetName())) ;
332  if (!same) {
333  m_logger << kDEBUG << "Incompatible names: <" << this->GetName() << "> <" << other.GetName() << ">" << GEndl;
334  return kFALSE;
335  }
337  same = same && (this->GetVersion()==other.GetVersion()) ;
338  if (!same) {
339  m_logger << kDEBUG << "Incompatible versions: <" << this->GetVersion() << "> <" << other.GetVersion() << ">" << GEndl;
340  return kFALSE;
341  }
344  std::map<TString,TString>::const_iterator mitr = this->GetMetaData().find("RQTSVNVersion");
345  std::map<TString,TString>::const_iterator oitr = other.GetMetaData().find("RQTSVNVersion");
346  if ( mitr==this->GetMetaData().end() && oitr==other.GetMetaData().end() ) {
347  ; // ok, RQ version missing from both grls
348  } else if ( mitr!=this->GetMetaData().end() && oitr!=other.GetMetaData().end() ) {
349  same = same && ( mitr->second==oitr->second );
350  if (!same) { m_logger << kDEBUG << "Incompatible run query versions: " << mitr->first
351  << " : <" << mitr->second << "> <" << oitr->second << ">" << GEndl; }
352  } else { same=kFALSE; } // version is missing from one grl
353 
354 /*
356  same = same && (this->GetMetaData().size()==other.GetMetaData().size()) ;
357  if (!same) {
358  m_logger << kDEBUG << "Incompatible metadata sizes: <" << this->GetMetaData().size() << "> <" << other.GetMetaData().size() << ">" << GEndl;
359  return kFALSE;
360  }
362  std::map<TString,TString>::const_iterator mitr = this->GetMetaData().begin();
363  for(; mitr!=this->GetMetaData().end() && same; ++mitr) {
364  if (other.GetMetaData().find(mitr->first)!=other.GetMetaData().end()) {
365  same = same && ( mitr->second==(other.GetMetaData().find(mitr->first))->second );
366  if (!same) { m_logger << kDEBUG << "Incompatible metadata: " << mitr->first
367  << " : <" << mitr->second << "> <" << (other.GetMetaData().find(mitr->first))->second << ">" << GEndl; }
368  } else same=kFALSE;
369  }
370 */
371  return same;
372 }
373 
374 
375 Bool_t
377 {
378  if (this->empty()) return kTRUE;
379 
380  Bool_t isEmpty(kTRUE);
381  std::map< Int_t, TGoodRun >::const_iterator litr = this->begin();
382  for (; litr!=this->end() && isEmpty; ++litr)
383  isEmpty = isEmpty && litr->second.IsEmpty();
384 
385  return isEmpty;
386 }
387 
388 
389 TString
391 {
392  if (this->IsEmpty()) return "grl_empty";
393 
394  Int_t beginrun(-1), endrun(-1), beginlb(-1), endlb(-1);
395 
396  Root::TGoodRun begingr = this->begin()->second;
397  Root::TGoodRun endgr = this->rbegin()->second;
398 
399  if (!begingr.IsEmpty()) {
400  beginrun = begingr.GetRunNumber();
401  beginlb = begingr.begin()->Begin();
402  }
403  if (!endgr.IsEmpty()) {
404  endrun = endgr.GetRunNumber();
405  endlb = endgr.rbegin()->End();
406  }
407 
408  return Form("grl_%d.%d-%d.%d",beginrun,beginlb,endrun,endlb);
409 }
410 
411 
412 void
413 Root::TGoodRunsList::AddRunLumiBlock( Int_t runnr, Int_t lumiblocknr )
414 {
415  if (runnr<0 || lumiblocknr<0) return;
416  if (this->HasRunLumiBlock(runnr,lumiblocknr)) return;
417 
418  std::map< Int_t, TGoodRun >::iterator itr = this->find(runnr);
419  if (itr==this->end()) {
420  this->insert( std::pair< Int_t, TGoodRun >(runnr,Root::TGoodRun(runnr)) );
421  itr = this->find(runnr);
422  }
423 
424  itr->second.AddLB(lumiblocknr);
425 }
426 
427 
428 void
430 {
431  for (auto& [runno, run] : *this) run.Compress();
432 }
433 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TGoodRunsList.h
Root::kWARNING
@ kWARNING
Definition: TMsgLogger.h:51
Root::TGoodRun
Definition: TGoodRun.h:27
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Root::TGoodRun::Sort
void Sort()
Definition: TGoodRun.cxx:193
Root::TGoodRunsList::GetGoodRuns
std::vector< Root::TGoodRun > GetGoodRuns() const
Definition: TGoodRunsList.cxx:287
Root::TGoodRunsList::HasSameGRLInfo
Bool_t HasSameGRLInfo(const TGoodRunsList &other) const
Definition: TGoodRunsList.cxx:325
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
Root::TGoodRunsList::AddRunLumiBlock
void AddRunLumiBlock(Int_t runnr, Int_t lumiblocknr)
Definition: TGoodRunsList.cxx:413
athena.value
value
Definition: athena.py:124
ClassImp
ClassImp(Root::TGoodRunsList) Root
Definition: TGoodRunsList.cxx:11
python.selector.AtlRunQuerySelectorLhcOlc.runlist
runlist
Definition: AtlRunQuerySelectorLhcOlc.py:607
MuonValidation_CreateSlides_config.Summary
list Summary
Definition: MuonValidation_CreateSlides_config.py:34
python.TrigEgammaFastCaloHypoTool.same
def same(val, tool)
Definition: TrigEgammaFastCaloHypoTool.py:12
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
GEndl
#define GEndl
Definition: TMsgLogger.h:151
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Root::kDEBUG
@ kDEBUG
Definition: TMsgLogger.h:49
Root::TGoodRunsList::GetSumWith
const Root::TGoodRunsList GetSumWith(const TGoodRunsList &other) const
Definition: TGoodRunsList.cxx:123
verb
#define verb
Definition: TileRawChannel2Bytes5.cxx:15
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Root::TGoodRunsList::GetPartNotIn
const Root::TGoodRunsList GetPartNotIn(const TGoodRunsList &other) const
Definition: TGoodRunsList.cxx:175
DeMoUpdate.endrun
int endrun
Definition: DeMoUpdate.py:463
Root::TGoodRunsList::TGoodRunsList
TGoodRunsList()
Root::TGoodRun::IsEmpty
Bool_t IsEmpty() const
Definition: TGoodRun.cxx:251
Root::kINFO
@ kINFO
Definition: TMsgLogger.h:50
Root::TGoodRunsList::IsEmpty
Bool_t IsEmpty() const
Definition: TGoodRunsList.cxx:376
Root::TGoodRunsList::Compress
void Compress()
Definition: TGoodRunsList.cxx:429
Root::TGoodRunsList::SetMetaData
void SetMetaData(const std::map< TString, TString > &metadata)
Definition: TGoodRunsList.h:59
Root::TGoodRunsList::GetTriggerList
std::vector< std::string > GetTriggerList() const
Definition: TGoodRunsList.cxx:297
run
Definition: run.py:1
Root::TGoodRunsList::SetVersion
void SetVersion(const TString &version)
Definition: TGoodRunsList.h:57
beamspotman.runnr
runnr
Definition: beamspotman.py:724
Root::TGoodRunsList::HasRun
Bool_t HasRun(Int_t runnr) const
Definition: TGoodRunsList.cxx:214
Root::TGoodRunsList::GetPartOnlyIn
const Root::TGoodRunsList GetPartOnlyIn(const TGoodRunsList &other) const
Definition: TGoodRunsList.cxx:168
Root::TGoodRunsList::Summary
void Summary(Bool_t verbose=kFALSE) const
Definition: TGoodRunsList.cxx:253
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Root::TGoodRunsList::GetRunlist
std::vector< int > GetRunlist() const
Definition: TGoodRunsList.cxx:277
Root::TGoodRunsList
Definition: TGoodRunsList.h:31
Root::TGoodRunsList::~TGoodRunsList
virtual ~TGoodRunsList()
Definition: TGoodRunsList.cxx:27
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
Root::TGoodRunsList::AddGRL
void AddGRL(const TGoodRunsList &other)
Definition: TGoodRunsList.cxx:32
dqm_persistency::Print
void Print(const PParameter *param, TDirectory *topdir, Option_t *opt="")
Definition: dqm_persistency_impl.cxx:161
TMsgLogger.h
Root::TGoodRun::GetRunNumber
Int_t GetRunNumber() const
Definition: TGoodRun.h:52
Root::TGoodRunsList::HasTriggerInfo
Bool_t HasTriggerInfo() const
Definition: TGoodRunsList.cxx:229
PURW_create_actual_mu_profile.runno
runno
Definition: PURW_create_actual_mu_profile.py:59
Root::TMsgLogger
Definition: TMsgLogger.h:52
Root::TGoodRunsList::HasOverlapWith
Bool_t HasOverlapWith(const TGoodRunsList &other, bool verb=false) const
Definition: TGoodRunsList.cxx:242
Root::TGoodRunsList::GetStreamList
std::vector< std::string > GetStreamList() const
Definition: TGoodRunsList.cxx:311
Root::TGoodRunsList::HasRunLumiBlock
Bool_t HasRunLumiBlock(Int_t runnr, Int_t lumiblocknr) const
Definition: TGoodRunsList.cxx:221
Root::TGoodRunsList::GetSuggestedName
TString GetSuggestedName() const
Definition: TGoodRunsList.cxx:390
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Root::TGoodRunsList::GetOverlapWith
const Root::TGoodRunsList GetOverlapWith(const TGoodRunsList &other) const
Definition: TGoodRunsList.cxx:83