ATLAS Offline Software
Loading...
Searching...
No Matches
LumiBlockCollectionConverter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
8
15
16#include "TROOT.h"
17
18#include <stdlib.h>
19
21 : m_reader(new Root::TGoodRunsListReader())
22 , m_writer(new Root::TGoodRunsListWriter())
23{
24}
25
26
32
33
35LumiBlockCollectionConverter::GetLumiBlockCollection(const Root::TGoodRunsList& grl, std::map<TString,TString>& metadata, TString& version)
36{
37 metadata = grl.GetMetaData();
38 version = grl.GetVersion();
39 return this->GetLumiBlockCollection( grl );
40}
41
42
45{
47
48 Root::TGoodRun goodrun;
49 std::map<Int_t, Root::TGoodRun>::const_iterator it;
50 std::vector< Root::TLumiBlockRange >::const_iterator itlbr;
51 int RunNumber(-1), LumiBlockStart(-1), LumiBlockEnd(-1);
52
53 for(it = grl.begin(); it != grl.end(); ++it) {
54 RunNumber = it->first;
55 goodrun = it->second;
56 for(itlbr = goodrun.begin(); itlbr != goodrun.end(); ++itlbr) {
57 LumiBlockStart = itlbr->Begin();
58 LumiBlockEnd = itlbr->End();
59 iovc->push_back(new LB_IOVRange(IOVTime(RunNumber, LumiBlockStart), IOVTime(RunNumber,LumiBlockEnd)));
60 }
61 }
63
64 return iovc;
65}
66
67
70{
71 Root::TGoodRunsList* pgrl = this->GetGRLObject( xmlfile );
72 LumiBlockCollection* iovc = this->GetLumiBlockCollection( *pgrl );
73 delete pgrl;
74 return iovc;
75}
76
77
80{
81 m_reader->SetXMLString( xmlstring );
82 (void) m_reader->Interpret();
83 return this->GetLumiBlockCollection( m_reader->GetMergedGoodRunsList() );
84}
85
86
87void
88LumiBlockCollectionConverter::CreateXMLFile(const Root::TGRLCollection& grlcollection, const char* xmlfilename)
89{
90 m_writer->SetGRLCollection( grlcollection ) ;
91 m_writer->SetFilename( xmlfilename ) ;
92 m_writer->WriteXMLFile() ;
93}
94
95
96void
97LumiBlockCollectionConverter::CreateXMLFile(const Root::TGoodRunsList& grl, const TString& xmlfilename, const TString& prefix)
98{
99 m_writer->SetGoodRunsList( grl ) ;
100 TString xmlfile = ( xmlfilename.IsNull() ? prefix + grl.GetSuggestedName() + ".xml" : xmlfilename );
101 m_writer->SetFilename( xmlfile.Data() ) ;
102 m_writer->WriteXMLFile() ;
103}
104
105
106void
108 const TString& xmlfilename, const TString& prefix )
109{
110 Root::TGoodRunsList* pgrl = this->GetGRLObject(lbc,metadata,version);
111 m_writer->SetGoodRunsList( *pgrl ) ;
112 TString xmlfile = ( xmlfilename.IsNull() ? prefix+pgrl->GetSuggestedName()+".xml" : xmlfilename );
113 m_writer->SetFilename( xmlfile.Data() ) ;
114 m_writer->WriteXMLFile() ;
115 delete pgrl;
116}
117
118
119void
121{
122 m_writer->SetGRLCollection( grlcollection ) ;
123 m_writer->SetPrefix( prefix ) ;
124 m_writer->WriteXMLFiles() ;
125}
126
127
128const TString
130{
131 m_writer->SetGoodRunsList( grl ) ;
132 return m_writer->GetXMLString() ;
133}
134
135
136const TString
138{
139 m_writer->SetGRLCollection( grlcollection ) ;
140 return m_writer->GetXMLString() ;
141}
142
143
144const std::vector<TString>
146{
147 m_writer->SetGRLCollection( grlcollection ) ;
148 return m_writer->GetXMLStrings() ;
149}
150
151
152const TString
153LumiBlockCollectionConverter::GetXMLString( const LumiBlockCollection& lbc, const std::map<TString,TString>& metadata, const char* version )
154{
155 Root::TGoodRunsList* pgrl = this->GetGRLObject(lbc,metadata,version);
156 m_writer->SetGoodRunsList( *pgrl ) ;
157 TString xmlstring = m_writer->GetXMLString() ;
158 delete pgrl;
159 return xmlstring;
160}
161
162
164LumiBlockCollectionConverter::GetGRLObject( const LumiBlockCollection& lbc, const std::map<TString,TString>& metadata, const char* version ) const
165{
167 grl->SetVersion(version);
168 grl->SetMetaData(metadata);
169
170 if (!lbc.empty()) {
171 Root::TGoodRun goodrun;
172 int prev_runnbr(-1), cur_runnbr(-1), cur_lbstart(-1), cur_lbstop(-1);
173
174 for( LumiBlockCollection::const_iterator it=lbc.begin(); it != lbc.end(); ++it ) {
175 const LB_IOVRange* iovr = (*it);
176 cur_runnbr = iovr->start().run();
177 cur_lbstart = iovr->start().event();
178 cur_lbstop = iovr->stop().event();
179 // store previous run and reset
180 if (prev_runnbr!=cur_runnbr) {
181 if (prev_runnbr>=0) { (*grl)[prev_runnbr]=goodrun; }
182 goodrun.clear();
183 goodrun.SetRunNumber(cur_runnbr);
184 }
185 // store lumiblock range
186 goodrun.push_back( Root::TLumiBlockRange(cur_lbstart,cur_lbstop) ) ;
187 prev_runnbr = cur_runnbr;
188 } // loop over lbs
189 (*grl)[prev_runnbr]=goodrun; // also store last goodrun
190 } // lbc !empty
191
192
193 grl->Compress();
194 return grl;
195}
196
197
200{
201 m_reader->SetXMLFile( xmlfile );
202 (void) m_reader->Interpret();
203 return (new Root::TGoodRunsList( m_reader->GetMergedGoodRunsList() ));
204}
205
206
209{
210 m_reader->SetXMLString( xmlstring );
211 (void) m_reader->Interpret();
212 return (new Root::TGoodRunsList( m_reader->GetMergedGoodRunsList() ));
213}
214
215
218{
219 m_reader->SetXMLFile( xmlfile );
220 (void) m_reader->Interpret();
221 return (new Root::TGRLCollection( m_reader->GetMergedGRLCollection() ));
222}
223
224
227{
228 m_reader->SetXMLString( xmlstring );
229 (void) m_reader->Interpret();
230 return (new Root::TGRLCollection( m_reader->GetMergedGRLCollection() ));
231}
232
233
234const TString
236{
237 if (lbc.empty()) return "grl_empty";
238
239 Int_t beginrun(-1), endrun(-1), beginlb(-1), endlb(-1);
240
243
244 beginrun = (*itb)->start().run();
245 beginlb = (*itb)->start().event();
246 endrun = (*ite)->stop().run();
247 endlb = (*ite)->stop().event();
248
249 return Form("grl_%d.%d-%d.%d",beginrun,beginlb,endrun,endlb);
250}
251
std::map< TString, TString > grlmetadatamap
LumiBlockCollection
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_iterator end() const noexcept
Return a const_iterator pointing past 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.
const IOVTime & stop() const
Definition IOVRange.h:39
const IOVTime & start() const
Definition IOVRange.h:38
Basic time unit for IOVSvc.
Definition IOVTime.h:33
uint32_t event() const noexcept
Definition IOVTime.h:106
uint32_t run() const noexcept
Definition IOVTime.h:105
Root::TGoodRunsList * GetGRLObject(const LumiBlockCollection &lbc, const grlmetadatamap &metadata=grlmetadatamap(), const char *version="") const
LumiBlockCollection * GetLumiBlockCollectionFromString(const TString &xmlstring)
LumiBlockCollection * GetLumiBlockCollection(const Root::TGoodRunsList &grl, std::map< TString, TString > &metadata, TString &version)
Root::TGoodRunsList * GetGRLObjectFromString(const TString &xmlstring)
Root::TGRLCollection * GetGRLCollection(const char *xmlfile)
const std::vector< TString > GetXMLStrings(const Root::TGRLCollection &grlcollection)
void CreateXMLFile(const Root::TGoodRunsList &grl, const TString &xmlfilename="", const TString &prefix="")
const TString GetXMLString(const Root::TGoodRunsList &grl)
const TString GetSuggestedName(const LumiBlockCollection &lbc) const
Root::TGRLCollection * GetGRLCollectionFromString(const TString &xmlstring)
void CreateXMLFiles(const Root::TGRLCollection &grlcollection, const char *prefix)
void SetRunNumber(const Int_t &runnr)
Definition TGoodRun.h:43
TString GetSuggestedName() const
static std::vector< std::string > xmlfile
Definition iLumiCalc.h:29