ATLAS Offline Software
Loading...
Searching...
No Matches
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
30
31void
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
213Bool_t
214Root::TGoodRunsList::HasRun( Int_t runnr ) const
215{
216 return ( this->find(runnr)!=this->end() );
217}
218
219
220Bool_t
221Root::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
228Bool_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
241Bool_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
252void
253Root::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
276std::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
286std::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
296std::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
310std::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
324Bool_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
375Bool_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
389TString
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
412void
413Root::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
428void
430{
431 for (auto& [runno, run] : *this) run.Compress();
432}
433
ClassImp(Root::TGoodRunsList) Root
#define GEndl
Definition TMsgLogger.h:147
#define verb
static const Attributes_t empty
Bool_t IsEmpty() const
Definition TGoodRun.cxx:249
Int_t GetRunNumber() const
Definition TGoodRun.h:42
std::vector< int > GetRunlist() const
Bool_t HasTriggerInfo() const
void Summary(Bool_t verbose=kFALSE) const
void SetVersion(const TString &version)
Bool_t HasRun(Int_t runnr) const
Bool_t HasSameGRLInfo(const TGoodRunsList &other) const
const TString & GetVersion() const
std::vector< std::string > GetTriggerList() const
const Root::TGoodRunsList GetSumWith(const TGoodRunsList &other) const
const Root::TGoodRunsList GetPartNotIn(const TGoodRunsList &other) const
Bool_t HasOverlapWith(const TGoodRunsList &other, bool verb=false) const
Bool_t HasRunLumiBlock(Int_t runnr, Int_t lumiblocknr) const
const Root::TGoodRunsList GetPartOnlyIn(const TGoodRunsList &other) const
void SetMetaData(const std::map< TString, TString > &metadata)
void AddRunLumiBlock(Int_t runnr, Int_t lumiblocknr)
const std::map< TString, TString > & GetMetaData() const
std::vector< Root::TGoodRun > GetGoodRuns() const
void AddGRL(const TGoodRunsList &other)
std::vector< std::string > GetStreamList() const
std::map< TString, TString > m_metadata
Bool_t IsEmpty() const
const Root::TGoodRunsList GetOverlapWith(const TGoodRunsList &other) const
TString GetSuggestedName() const
STL class.
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
bool verbose
Definition hcg.cxx:73
@ kWARNING
Definition TMsgLogger.h:41
@ kDEBUG
Definition TMsgLogger.h:39
@ kINFO
Definition TMsgLogger.h:40
Definition run.py:1
STL namespace.