ATLAS Offline Software
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 
10 #include "GoodRunsLists/TGoodRun.h"
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 
28 {
29  if (m_reader!=0) { delete m_reader; m_reader=0; }
30  if (m_writer!=0) { delete m_writer; m_writer=0; }
31 }
32 
33 
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();
84 }
85 
86 
87 void
88 LumiBlockCollectionConverter::CreateXMLFile(const Root::TGRLCollection& grlcollection, const char* xmlfilename)
89 {
90  m_writer->SetGRLCollection( grlcollection ) ;
91  m_writer->SetFilename( xmlfilename ) ;
93 }
94 
95 
96 void
97 LumiBlockCollectionConverter::CreateXMLFile(const Root::TGoodRunsList& grl, const TString& xmlfilename, const TString& prefix)
98 {
100  TString xmlfile = ( xmlfilename.IsNull() ? prefix + grl.GetSuggestedName() + ".xml" : xmlfilename );
101  m_writer->SetFilename( xmlfile.Data() ) ;
103 }
104 
105 
106 void
108  const TString& xmlfilename, const TString& prefix )
109 {
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 
119 void
121 {
122  m_writer->SetGRLCollection( grlcollection ) ;
125 }
126 
127 
128 const TString
130 {
132  return m_writer->GetXMLString() ;
133 }
134 
135 
136 const TString
138 {
139  m_writer->SetGRLCollection( grlcollection ) ;
140  return m_writer->GetXMLString() ;
141 }
142 
143 
144 const std::vector<TString>
146 {
147  m_writer->SetGRLCollection( grlcollection ) ;
148  return m_writer->GetXMLStrings() ;
149 }
150 
151 
152 const TString
153 LumiBlockCollectionConverter::GetXMLString( const LumiBlockCollection& lbc, const std::map<TString,TString>& metadata, const char* version )
154 {
156  m_writer->SetGoodRunsList( *pgrl ) ;
157  TString xmlstring = m_writer->GetXMLString() ;
158  delete pgrl;
159  return xmlstring;
160 }
161 
162 
164 LumiBlockCollectionConverter::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();
204 }
205 
206 
209 {
210  m_reader->SetXMLString( xmlstring );
211  (void) m_reader->Interpret();
213 }
214 
215 
218 {
219  m_reader->SetXMLFile( xmlfile );
220  (void) m_reader->Interpret();
222 }
223 
224 
227 {
228  m_reader->SetXMLString( xmlstring );
229  (void) m_reader->Interpret();
231 }
232 
233 
234 const 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 
TGoodRunsList.h
TLumiBlockRange.h
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Root::TGoodRun
Definition: TGoodRun.h:27
Root
Definition: GoodRunsListSelectorTool.h:30
TGRLCollection.h
LumiBlockCollectionConverter::CreateXMLFile
void CreateXMLFile(const Root::TGoodRunsList &grl, const TString &xmlfilename="", const TString &prefix="")
Definition: LumiBlockCollectionConverter.cxx:97
IOVTime::event
uint32_t event() const noexcept
Definition: IOVTime.h:106
LumiBlockCollectionConverter::GetXMLString
const TString GetXMLString(const Root::TGoodRunsList &grl)
Definition: LumiBlockCollectionConverter.cxx:129
Root::TGoodRun::SetRunNumber
void SetRunNumber(const Int_t &runnr)
Definition: TGoodRun.h:53
LumiBlockCollectionConverter::GetLumiBlockCollection
LumiBlockCollection * GetLumiBlockCollection(const Root::TGoodRunsList &grl, std::map< TString, TString > &metadata, TString &version)
Definition: LumiBlockCollectionConverter.cxx:35
IOVRange::start
const IOVTime & start() const
Definition: IOVRange.h:38
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
LumiBlockCollection
LumiBlockCollection
Definition: LumiBlockTPCnv.cxx:25
LumiBlockCollectionConverter::GetGRLCollectionFromString
Root::TGRLCollection * GetGRLCollectionFromString(const TString &xmlstring)
Definition: LumiBlockCollectionConverter.cxx:226
skel.it
it
Definition: skel.GENtoEVGEN.py:396
LumiBlockCollection::SortIOVRangeByStart
Definition: LumiBlockCollection.h:42
Root::TGoodRunsListReader::SetXMLString
void SetXMLString(const TString &xmlstring)
Definition: TGoodRunsListReader.h:50
LumiBlockCollection.h
collisions.grl
grl
Definition: collisions.py:25
LumiBlockCollectionConverter::GetGRLObjectFromString
Root::TGoodRunsList * GetGRLObjectFromString(const TString &xmlstring)
Definition: LumiBlockCollectionConverter.cxx:208
python.checkMetadata.metadata
metadata
Definition: checkMetadata.py:175
IOVRange::stop
const IOVTime & stop() const
Definition: IOVRange.h:39
LB_IOVRange.h
grl
Definition: ZLumiScripts/grid/grl.py:1
IOVTime
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
Definition: IOVTime.h:33
DeMoUpdate.endrun
int endrun
Definition: DeMoUpdate.py:463
Root::TGoodRunsListWriter::WriteXMLFile
Bool_t WriteXMLFile()
Definition: TGoodRunsListWriter.cxx:110
Root::TGoodRunsListWriter::GetXMLString
const TString & GetXMLString()
Definition: TGoodRunsListWriter.cxx:194
LumiBlockCollectionConverter::m_reader
Root::TGoodRunsListReader * m_reader
Definition: LumiBlockCollectionConverter.h:70
LumiBlockCollectionConverter::GetGRLObject
Root::TGoodRunsList * GetGRLObject(const LumiBlockCollection &lbc, const grlmetadatamap &metadata=grlmetadatamap(), const char *version="") const
Definition: LumiBlockCollectionConverter.cxx:164
LumiBlockCollectionConverter::~LumiBlockCollectionConverter
virtual ~LumiBlockCollectionConverter()
Definition: LumiBlockCollectionConverter.cxx:27
LumiBlockCollection
Definition: LumiBlockCollection.h:21
Root::TGoodRunsListWriter::SetFilename
void SetFilename(const TString &dataCardName)
Definition: TGoodRunsListWriter.h:63
TGoodRun.h
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
Root::TGoodRunsListWriter::SetGRLCollection
void SetGRLCollection(const TGRLCollection &grlvec)
Definition: TGoodRunsListWriter.h:61
LumiBlockCollectionConverter::GetXMLStrings
const std::vector< TString > GetXMLStrings(const Root::TGRLCollection &grlcollection)
Definition: LumiBlockCollectionConverter.cxx:145
DataVector::rbegin
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
Root::TGRLCollection
Definition: TGRLCollection.h:29
EventInfoWrite.RunNumber
RunNumber
Definition: EventInfoWrite.py:50
Root::TGoodRunsListWriter::WriteXMLFiles
Bool_t WriteXMLFiles()
Definition: TGoodRunsListWriter.cxx:81
DataVector< LB_IOVRange >::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Standard const_reverse_iterator.
Definition: DataVector.h:846
LumiBlockCollectionConverter::GetSuggestedName
const TString GetSuggestedName(const LumiBlockCollection &lbc) const
Definition: LumiBlockCollectionConverter.cxx:235
LumiBlockCollectionConverter::m_writer
Root::TGoodRunsListWriter * m_writer
Definition: LumiBlockCollectionConverter.h:71
Root::TGoodRunsListWriter::SetPrefix
void SetPrefix(const TString &prefix)
Definition: TGoodRunsListWriter.h:64
IOVTime::run
uint32_t run() const noexcept
Definition: IOVTime.h:105
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Root::TGoodRunsList
Definition: TGoodRunsList.h:31
TGoodRunsListReader.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
get_generator_info.version
version
Definition: get_generator_info.py:33
DataVector::sort
void sort()
Sort the container.
Root::TGoodRunsListWriter::SetGoodRunsList
void SetGoodRunsList(const TGoodRunsList &goodrunslist)
Definition: TGoodRunsListWriter.h:62
LumiBlockCollectionConverter::GetGRLCollection
Root::TGRLCollection * GetGRLCollection(const char *xmlfile)
Definition: LumiBlockCollectionConverter.cxx:217
LumiBlockCollectionConverter.h
Root::TGoodRunsListReader::Interpret
Bool_t Interpret()
Definition: TGoodRunsListReader.cxx:71
LumiBlockCollectionConverter::CreateXMLFiles
void CreateXMLFiles(const Root::TGRLCollection &grlcollection, const char *prefix)
Definition: LumiBlockCollectionConverter.cxx:120
Root::TLumiBlockRange
Definition: TLumiBlockRange.h:26
Root::TGoodRunsListWriter::GetXMLStrings
const std::vector< TString > & GetXMLStrings()
Definition: TGoodRunsListWriter.cxx:165
LumiBlockCollectionConverter::GetLumiBlockCollectionFromString
LumiBlockCollection * GetLumiBlockCollectionFromString(const TString &xmlstring)
Definition: LumiBlockCollectionConverter.cxx:79
Root::TGoodRunsListReader::GetMergedGRLCollection
const TGRLCollection GetMergedGRLCollection(const Root::BoolOperation &operation=OR) const
Definition: TGoodRunsListReader.cxx:332
grlmetadatamap
std::map< TString, TString > grlmetadatamap
Definition: LumiBlockCollectionConverter.h:29
LumiBlockCollectionConverter::LumiBlockCollectionConverter
LumiBlockCollectionConverter()
Definition: LumiBlockCollectionConverter.cxx:20
LB_IOVRange
Definition: LB_IOVRange.h:16
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
TGoodRunsListWriter.h
Root::TGoodRunsListReader::GetMergedGoodRunsList
const TGoodRunsList GetMergedGoodRunsList(const Root::BoolOperation &operation=OR) const
Definition: TGoodRunsListReader.cxx:318
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Root::TGoodRunsList::GetSuggestedName
TString GetSuggestedName() const
Definition: TGoodRunsList.cxx:390
Root::TGoodRunsListReader::SetXMLFile
void SetXMLFile(const TString &xmlfile)
Definition: TGoodRunsListReader.h:51