ATLAS Offline Software
Loading...
Searching...
No Matches
LumiBlockRangeContainerConverter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
7
14
15#include "TROOT.h"
16
17#include <stdlib.h>
18
20 : m_reader(new Root::TGoodRunsListReader())
21 , m_writer(new Root::TGoodRunsListWriter())
22{
23}
24
25
31
32
34LumiBlockRangeContainerConverter::GetLumiBlockRangeContainer(const Root::TGoodRunsList& grl, std::map<TString,TString>& metadata, TString& version)
35{
36 metadata = grl.GetMetaData();
37 version = grl.GetVersion();
38 return this->GetLumiBlockRangeContainer( grl );
39}
40
41
44{
45 // xAOD::LumiBlockRangeContainer* iovc = new xAOD::LumiBlockRangeContainer();
48 piovComplete->setStore( piovCompleteAux );
49
50 Root::TGoodRun goodrun;
51 std::map<Int_t, Root::TGoodRun>::const_iterator it;
52 std::vector< Root::TLumiBlockRange >::const_iterator itlbr;
53 int RunNumber(-1), LumiBlockStart(-1), LumiBlockEnd(-1);
54
55 for(it = grl.begin(); it != grl.end(); ++it) {
56 RunNumber = it->first;
57 goodrun = it->second;
58 for(itlbr = goodrun.begin(); itlbr != goodrun.end(); ++itlbr) {
59 LumiBlockStart = itlbr->Begin();
60 LumiBlockEnd = itlbr->End();
62 piovComplete->push_back(iovr);
63 iovr->setStartRunNumber(RunNumber);
64 iovr->setStartLumiBlockNumber(LumiBlockStart);
65 iovr->setStopRunNumber(RunNumber);
66 iovr->setStopLumiBlockNumber(LumiBlockEnd);
67 iovr->setEventsExpected(0);
68 iovr->setEventsSeen(0);
69 // iovc->push_back(new LB_IOVRange(IOVTime(RunNumber, LumiBlockStart), IOVTime(RunNumber,LumiBlockEnd)));
70 }
71 }
72 // iovc->sort(xAOD::LumiBlockRangeContainer::SortIOVRangeByStart());
74 return piovComplete;
75}
76
77
80{
81 Root::TGoodRunsList* pgrl = this->GetGRLObject( xmlfile );
83 delete pgrl;
84 return iovc;
85}
86
87
90{
91 m_reader->SetXMLString( xmlstring );
92 (void) m_reader->Interpret();
93 return this->GetLumiBlockRangeContainer( m_reader->GetMergedGoodRunsList() );
94}
95
96
97void
98LumiBlockRangeContainerConverter::CreateXMLFile(const Root::TGRLCollection& grlcollection, const char* xmlfilename)
99{
100 m_writer->SetGRLCollection( grlcollection ) ;
101 m_writer->SetFilename( xmlfilename ) ;
102 m_writer->WriteXMLFile() ;
103}
104
105
106void
107LumiBlockRangeContainerConverter::CreateXMLFile(const Root::TGoodRunsList& grl, const TString& xmlfilename, const TString& prefix)
108{
109 m_writer->SetGoodRunsList( grl ) ;
110 TString xmlfile = ( xmlfilename.IsNull() ? prefix + grl.GetSuggestedName() + ".xml" : xmlfilename );
111 m_writer->SetFilename( xmlfile.Data() ) ;
112 m_writer->WriteXMLFile() ;
113}
114
115
116void
118 const TString& xmlfilename, const TString& prefix )
119{
120 Root::TGoodRunsList* pgrl = this->GetGRLObject(lbc,metadata,version);
121 m_writer->SetGoodRunsList( *pgrl ) ;
122 TString xmlfile = ( xmlfilename.IsNull() ? prefix+pgrl->GetSuggestedName()+".xml" : xmlfilename );
123 m_writer->SetFilename( xmlfile.Data() ) ;
124 m_writer->WriteXMLFile() ;
125 delete pgrl;
126}
127
128
129void
131{
132 m_writer->SetGRLCollection( grlcollection ) ;
133 m_writer->SetPrefix( prefix ) ;
134 m_writer->WriteXMLFiles() ;
135}
136
137
138const TString
140{
141 m_writer->SetGoodRunsList( grl ) ;
142 return m_writer->GetXMLString() ;
143}
144
145
146const TString
148{
149 m_writer->SetGRLCollection( grlcollection ) ;
150 return m_writer->GetXMLString() ;
151}
152
153
154const std::vector<TString>
156{
157 m_writer->SetGRLCollection( grlcollection ) ;
158 return m_writer->GetXMLStrings() ;
159}
160
161
162const TString
163LumiBlockRangeContainerConverter::GetXMLString( const xAOD::LumiBlockRangeContainer& lbc, const std::map<TString,TString>& metadata, const char* version )
164{
165 Root::TGoodRunsList* pgrl = this->GetGRLObject(lbc,metadata,version);
166 m_writer->SetGoodRunsList( *pgrl ) ;
167 TString xmlstring = m_writer->GetXMLString() ;
168 delete pgrl;
169 return xmlstring;
170}
171
172
174LumiBlockRangeContainerConverter::GetGRLObject( const xAOD::LumiBlockRangeContainer& lbc, const std::map<TString,TString>& metadata, const char* version ) const
175{
177 grl->SetVersion(version);
178 grl->SetMetaData(metadata);
179
180 if (!lbc.empty()) {
181 Root::TGoodRun goodrun;
182 int prev_runnbr(-1), cur_runnbr(-1), cur_lbstart(-1), cur_lbstop(-1);
183
184 for (const xAOD::LumiBlockRange* lbr : lbc) {
185 // for( xAOD::LumiBlockRangeContainer::const_iterator it=lbc.begin(); it != lbc.end(); ++it ) {
186 // const LB_IOVRange* iovr = (*it);
187 cur_runnbr = lbr->startRunNumber();
188 cur_lbstart = lbr->startLumiBlockNumber();
189 cur_lbstop = lbr->stopLumiBlockNumber();
190 // store previous run and reset
191 if (prev_runnbr!=cur_runnbr) {
192 if (prev_runnbr>=0) { (*grl)[prev_runnbr]=goodrun; }
193 goodrun.clear();
194 goodrun.SetRunNumber(cur_runnbr);
195 }
196 // store lumiblock range
197 goodrun.push_back( Root::TLumiBlockRange(cur_lbstart,cur_lbstop) ) ;
198 prev_runnbr = cur_runnbr;
199 } // loop over lbs
200 (*grl)[prev_runnbr]=goodrun; // also store last goodrun
201 } // lbc !empty
202
203
204 grl->Compress();
205 return grl;
206}
207
208
211{
212 m_reader->SetXMLFile( xmlfile );
213 (void) m_reader->Interpret();
214 return (new Root::TGoodRunsList( m_reader->GetMergedGoodRunsList() ));
215}
216
217
220{
221 m_reader->SetXMLString( xmlstring );
222 (void) m_reader->Interpret();
223 return (new Root::TGoodRunsList( m_reader->GetMergedGoodRunsList() ));
224}
225
226
229{
230 m_reader->SetXMLFile( xmlfile );
231 (void) m_reader->Interpret();
232 return (new Root::TGRLCollection( m_reader->GetMergedGRLCollection() ));
233}
234
235
238{
239 m_reader->SetXMLString( xmlstring );
240 (void) m_reader->Interpret();
241 return (new Root::TGRLCollection( m_reader->GetMergedGRLCollection() ));
242}
243
244
245const TString
247{
248 if (lbc.empty()) return "grl_empty";
249
250 Int_t beginrun(-1), endrun(-1), beginlb(-1), endlb(-1);
251
254
255 // cur_runnbr = (*i)->startRunNumber();
256 // cur_lbstart = (*i)->startLumiBlockNumber();
257 // cur_lbstop = (*i)->stopLumiBlockNumber();
258
259 beginrun = (*itb)->startRunNumber();
260 beginlb = (*itb)->startLumiBlockNumber();
261 endrun = (*ite)->stopRunNumber();
262 endlb = (*ite)->stopLumiBlockNumber();
263
264 return Form("grl_%d.%d-%d.%d",beginrun,beginlb,endrun,endlb);
265}
266
std::map< TString, TString > grlmetadatamap
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
void sort()
Sort the container.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition DataVector.h:847
bool empty() const noexcept
Returns true if the collection is empty.
void CreateXMLFiles(const Root::TGRLCollection &grlcollection, const char *prefix)
const TString GetSuggestedName(const xAOD::LumiBlockRangeContainer &lbc) const
Root::TGoodRunsList * GetGRLObject(const xAOD::LumiBlockRangeContainer &lbc, const grlmetadatamap &metadata=grlmetadatamap(), const char *version="") const
Root::TGoodRunsList * GetGRLObjectFromString(const TString &xmlstring)
xAOD::LumiBlockRangeContainer * GetLumiBlockRangeContainerFromString(const TString &xmlstring)
Root::TGRLCollection * GetGRLCollection(const char *xmlfile)
const std::vector< TString > GetXMLStrings(const Root::TGRLCollection &grlcollection)
const TString GetXMLString(const Root::TGoodRunsList &grl)
xAOD::LumiBlockRangeContainer * GetLumiBlockRangeContainer(const Root::TGoodRunsList &grl, std::map< TString, TString > &metadata, TString &version)
void CreateXMLFile(const Root::TGoodRunsList &grl, const TString &xmlfilename="", const TString &prefix="")
Root::TGRLCollection * GetGRLCollectionFromString(const TString &xmlstring)
void SetRunNumber(const Int_t &runnr)
Definition TGoodRun.h:43
TString GetSuggestedName() const
void setStopRunNumber(uint32_t value)
Set the run number of the stop time of the range.
void setEventsSeen(uint32_t value)
Set the number of seen/processed events in this luminosity block range.
void setStartRunNumber(uint32_t value)
Set the run number of the start time of the range.
void setEventsExpected(uint32_t value)
Set the number of expected events in this luminosity block range.
void setStartLumiBlockNumber(uint32_t value)
Set the luminosity block of the start time of the range.
void setStopLumiBlockNumber(uint32_t value)
Set the luminosity block of the stop time of the range.
Helper functor used to sort xAOD::LumiBlockRangeContainer-s.
static std::vector< std::string > xmlfile
Definition iLumiCalc.h:29
LumiBlockRange_v1 LumiBlockRange
Declare the latest version of the class.
LumiBlockRangeContainer_v1 LumiBlockRangeContainer
Declare the latest version of the container.
LumiBlockRangeAuxContainer_v1 LumiBlockRangeAuxContainer
Declare the latest version of the auxiliary container.