ATLAS Offline Software
Loading...
Searching...
No Matches
TGRLCollection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8
9#include <algorithm>
10
12
13
14Root::TGRLCollection::TGRLCollection( Bool_t checkGRLInfo )
15 : std::vector<TGoodRunsList>()
16 , TObject()
17 , m_checkGRLInfo( checkGRLInfo )
18{
19}
20
21
26
27
28void
30{
31 this->clear();
32 m_checkGRLInfo=kFALSE;
33}
34
35
36void
37Root::TGRLCollection::SetVersion( const TString& version )
38{
39 std::vector<TGoodRunsList>::iterator itr = this->begin();
40 std::vector<TGoodRunsList>::iterator end = this->end();
41 for (; itr!=end; ++itr) itr->SetVersion(version);
42}
43
44
45void
46Root::TGRLCollection::SetMetaData( const std::map<TString,TString>& metadata )
47{
48 std::vector<TGoodRunsList>::iterator itr = this->begin();
49 std::vector<TGoodRunsList>::iterator end = this->end();
50 for (; itr!=end; ++itr) itr->SetMetaData(metadata);
51}
52
53void
54Root::TGRLCollection::Summary (Bool_t verbose /*= kFALSE*/) const
55{
56 std::vector<TGoodRunsList>::const_iterator itr = this->begin();
57 std::vector<TGoodRunsList>::const_iterator end = this->end();
58
59 for (; itr!=end; ++itr)
60 itr->Summary(verbose) ;
61}
62
63
64Bool_t
65Root::TGRLCollection::HasRun( const Int_t& runnr ) const
66{
67 std::vector<TGoodRunsList>::const_iterator itr = this->begin();
68 std::vector<TGoodRunsList>::const_iterator end = this->end();
69
70 Bool_t pass(kFALSE);
71 for (; itr!=end && !pass; ++itr)
72 pass = itr->HasRun(runnr);
73
74 return pass;
75}
76
77
78Bool_t
79Root::TGRLCollection::HasRunLumiBlock( const Int_t& runnr, const Int_t& lumiblocknr ) const
80{
81 std::vector<TGoodRunsList>::const_iterator itr = this->begin();
82 std::vector<TGoodRunsList>::const_iterator end = this->end();
83
84 Bool_t pass(kFALSE);
85 for (; itr!=end && !pass; ++itr)
86 pass = itr->HasRunLumiBlock(runnr,lumiblocknr);
87
88 return pass;
89}
90
91
92Bool_t
94{
95 if (this->empty()) return kTRUE;
96
97 Bool_t isEmpty(kTRUE);
98 std::vector< TGoodRunsList >::const_iterator litr = this->begin();
99 for (; litr!=this->end() && isEmpty; ++litr)
100 isEmpty = isEmpty && litr->IsEmpty();
101
102 return isEmpty;
103}
104
105
108{
109 // nothing interpreted. Return empty grl.
110 if (this->empty()) return Root::TGoodRunsList();
111
112 // set first goodrunslist
113 std::vector<Root::TGoodRunsList>::const_iterator itr = this->begin();
115 if (this->size()==1) {
116 grl.Compress();
117 return grl;
118 }
119
120 TMsgLogger mylogger( "TGRLCollection" );
121 mylogger << kINFO << "Now merging GRLs." << GEndl;
122
123 // check version and metadata when merging goodrunslists?
124 grl.SetCheckGRLInfo(m_checkGRLInfo);
125
126 if (!m_checkGRLInfo)
127 mylogger << kINFO << "Metadata and other info not required to be identical between GRLs." << GEndl;
128
129 // start AND-ing or OR-ring with following goodrunslists
130 for (++itr; itr!=this->end(); ++itr) {
131 switch (operation) {
132 case OR :
133 if ( grl.HasOverlapWith(*itr,false/*verbose*/) ) { // MB 22-june: LB splitting across files, turn off warning.
134 //mylogger << kWARNING << "Merging GRLs with overlapping lumi-blocks! Overlapping LBs rejected." << GEndl;
135 //mylogger << kWARNING << "IMPORTANT : Check your analysis for possible duplicate events!" << GEndl;
136 }
137 grl.AddGRL( *itr );
138 break;
139 case AND :
140 grl = grl.GetOverlapWith(*itr);
141 break;
142 }
143 }
144
145 grl.Compress(); // cleanup, safe space
146 return grl;
147}
148
149
152{
153 // invalid idx. Return empty grl.
154 if (idx>=this->size()) return Root::TGoodRunsList();
155
156 return (*this)[idx];
157}
158
159
162{
163 if (this->empty() /*|| this->size()==1*/) return *this; // nothing to merge, return this
164
165 TMsgLogger mylogger( "TGRLCollection" );
166 mylogger << kINFO << "Now merging GRLs where possible. Metadata required to be identical." << GEndl;
167
168 Root::TGRLCollection mergevec;
169
170 std::vector<TGoodRunsList>::const_iterator itr = this->begin();
171 std::vector<TGoodRunsList>::const_iterator end = this->end();
172 std::vector<TGoodRunsList>::iterator mitr;
173
174 for (; itr!=end; ++itr) {
175 bool matchFound(false);
176 for (mitr=mergevec.begin(); mitr!=mergevec.end() && !matchFound ; ++mitr) {
177 if (mitr->HasSameGRLInfo(*itr)) {
178 matchFound = true;
179 switch (operation) {
180 case OR :
181 if ( mitr->HasOverlapWith(*itr,false/*verbose*/) ) { // // MB 22-june: LB splitting across files, turn off warning.
182 //mylogger << kWARNING << "Merging GRLs with overlapping lumi-blocks! Overlapping LBs rejected." << GEndl;
183 //mylogger << kWARNING << "IMPORTANT : Check your analysis for possible duplicate events!" << GEndl;
184 }
185 mitr->AddGRL( *itr );
186 break;
187 case AND :
188 *mitr = mitr->GetOverlapWith( *itr );
189 break;
190 }
191 mitr->Compress(); // safe space
192 }
193 }
194 if (!matchFound) {
195 mergevec.push_back(*itr);
196 mergevec.rbegin()->Compress(); // safe space
197 }
198 }
199
200 return mergevec;
201}
202
203
204std::vector<Root::TGoodRunsList>::iterator
205Root::TGRLCollection::find( const TString& name )
206{
207 Bool_t found(false);
208
209 std::vector<TGoodRunsList>::iterator itr = this->begin();
210 std::vector<TGoodRunsList>::iterator end = this->end();
211
212 for (; itr!=end; ++itr) {
213 found = ( name==TString(itr->GetName()) ) ;
214 if (found) break;
215 }
216
217 return itr;
218}
219
220
221std::vector<Root::TGoodRunsList>::const_iterator
222Root::TGRLCollection::find( const TString& name ) const
223{
224 Bool_t found(false);
225
226 std::vector<TGoodRunsList>::const_iterator itr = this->begin();
227 std::vector<TGoodRunsList>::const_iterator end = this->end();
228
229 for (; itr!=end; ++itr) {
230 found = ( name==TString(itr->GetName()) ) ;
231 if (found) break;
232 }
233
234 return itr;
235}
236
237
238Bool_t
239Root::TGRLCollection::HasGoodRunsList( const TString& name ) const
240{
241 return (this->find(name)!=this->end());
242}
243
244
247{
248 Root::TGRLCollection overlapvec;
249
250 std::vector<TGoodRunsList>::const_iterator itr = this->begin();
251 for (; itr!=this->end(); ++itr) {
252 Root::TGoodRunsList overlapgrl = itr->GetOverlapWith(other);
253 overlapgrl.SetName(itr->GetName());
254 overlapgrl.SetVersion(itr->GetVersion());
255 overlapgrl.SetMetaData(itr->GetMetaData());
256 overlapgrl.Compress();
257 overlapvec.push_back(overlapgrl); // also push_back if empty!
258 }
259
260 return overlapvec;
261}
262
263
264
ClassImp(Root::TGRLCollection) Root
#define GEndl
Definition TMsgLogger.h:147
static const Attributes_t empty
const TGoodRunsList GetMergedGoodRunsList(const Root::BoolOperation &operation=OR) const
const TGoodRunsList GetGoodRunsList(unsigned int idx) const
void SetVersion(const TString &version)
void SetMetaData(const std::map< TString, TString > &metadata)
Bool_t HasRun(const Int_t &runnr) const
Bool_t HasRunLumiBlock(const Int_t &runnr, const Int_t &lumiblocknr) const
const Root::TGRLCollection GetOverlapWith(const TGoodRunsList &other) const
void Summary(Bool_t verbose=kFALSE) const
const Root::TGRLCollection GetMergedGRLCollection(const Root::BoolOperation &operation=OR) const
TGRLCollection(Bool_t checkGRLInfo=kFALSE)
Bool_t HasGoodRunsList(const TString &name) const
std::vector< TGoodRunsList >::iterator find(const TString &name)
void SetVersion(const TString &version)
void SetMetaData(const std::map< TString, TString > &metadata)
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
bool verbose
Definition hcg.cxx:73
@ kINFO
Definition TMsgLogger.h:40
STL namespace.