28 # define LIBXML_ATTR_ALLOC_SIZE(x)
30 #include <libxml/encoding.h>
31 #include <libxml/xmlwriter.h>
34 #define MY_ENCODING "ISO-8859-1"
43 , m_logger (
"TGoodRunsListWriter" )
45 , m_individuals(false)
52 , m_dataCardName( dataCardName )
53 , m_logger (
"TGoodRunsListWriter" )
55 , m_individuals(false)
73 m_individuals =
false;
76 m_xmlstringVec.clear();
83 if (m_grlvec.IsEmpty()) {
84 m_logger <<
kWARNING <<
"GoodRunsList is empty - nothing to write. Return false." <<
GEndl;
89 TString olddatacardname=m_dataCardName;
92 std::vector< Root::TGoodRunsList >::const_iterator litr = m_grlvec.begin();
93 for (
int i=0; litr!=m_grlvec.end(); ++litr, ++
i) {
97 m_dataCardName = m_prefix + Form(
"merged_%d_",
i) + litr->GetSuggestedName() +
".xml" ;
98 (void) this->WriteXMLFile();
103 m_dataCardName=olddatacardname;
112 if (m_grlvec.IsEmpty()) {
113 m_logger <<
kWARNING <<
"GoodRunsList is empty - nothing to write to <" << m_dataCardName <<
">. Return false." <<
GEndl;
116 if (m_dataCardName.IsNull()) {
117 m_logger <<
kINFO <<
"Output filename not set. Will be generated automatically." <<
GEndl;
129 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error creating the xml writer" <<
GEndl;
134 this->WriteLumiRangeCollection(
writer);
140 rc = xmlTextWriterEndDocument(
writer);
142 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterEndDocument" <<
GEndl;
146 xmlFreeTextWriter(
writer);
148 xmlSaveFormatFile(m_dataCardName.Data(),
doc, 1);
151 m_logger <<
kINFO <<
"GoodRunsList stored as : " << m_dataCardName <<
GEndl;
155 m_logger <<
kWARNING <<
"GoodRunsLists package compiled without libxml2" <<
GEndl;
156 m_logger <<
kWARNING <<
"can not write out GoodRunsList" <<
GEndl;
164 const std::vector<TString>&
167 m_xmlstringVec.clear();
169 if (m_grlvec.IsEmpty()) {
170 m_logger <<
kWARNING <<
"GoodRunsList is empty - nothing to write. Return false." <<
GEndl;
171 return m_xmlstringVec;
178 std::vector< Root::TGoodRunsList >::const_iterator litr = m_grlvec.begin();
179 for (
int i=0; litr!=m_grlvec.end(); ++litr, ++
i) {
183 m_xmlstringVec.push_back( this->GetXMLString() );
189 return m_xmlstringVec;
198 if (m_grlvec.IsEmpty()) {
199 m_logger <<
kWARNING <<
"GoodRunsList is empty - nothing to write. Return false." <<
GEndl;
211 buf = xmlBufferCreate();
213 m_logger <<
kWARNING <<
"testXmlwriterMemory: Error creating the xml buffer" <<
GEndl;
219 writer = xmlNewTextWriterMemory(buf, 0);
221 m_logger <<
kWARNING <<
"testXmlwriterMemory: Error creating the xml writer" <<
GEndl;
226 this->WriteLumiRangeCollection(
writer);
232 rc = xmlTextWriterEndDocument(
writer);
234 m_logger <<
kWARNING <<
"testXmlwriterMemory: Error at xmlTextWriterEndDocument" <<
GEndl;
238 xmlFreeTextWriter(
writer);
239 m_xmlstring = (
const char *) buf->content;
244 m_logger <<
kWARNING <<
"GoodRunsLists package compiled without libxml2" <<
GEndl;
245 m_logger <<
kWARNING <<
"can not write out GoodRunsList" <<
GEndl;
263 rc = xmlTextWriterStartDocument(
writer, NULL, NULL, NULL);
265 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterStartDocument" <<
GEndl;
270 xmlTextWriterWriteDTD(
writer, (
xmlChar *)
"LumiRangeCollection", NULL,
271 (
xmlChar *)
"http://atlas-runquery.cern.ch/LumiRangeCollection.dtd", NULL);
277 tmp = ConvertInput(
"This document is created by GoodRunsListWriter.",
MY_ENCODING);
278 rc = xmlTextWriterWriteComment(
writer,
tmp);
280 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterWriteComment" <<
GEndl;
283 if (
tmp != NULL) xmlFree(
tmp);
287 rc = xmlTextWriterStartElement(
writer, BAD_CAST
"LumiRangeCollection");
289 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterStartElement" <<
GEndl;
298 this->WriteNamedLumiRange(
writer);
302 std::vector< Root::TGoodRunsList >::const_iterator litr = m_grlvec.begin();
303 for (; litr!=m_grlvec.end(); ++litr) {
305 this->WriteNamedLumiRange(
writer);
308 m_grl = this->GetMergedGoodRunsList();
309 this->WriteNamedLumiRange(
writer);
314 rc = xmlTextWriterEndElement(
writer);
316 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterEndElement" <<
GEndl;
322 m_logger <<
kWARNING <<
"GoodRunsLists package compiled without libxml2" <<
GEndl;
323 m_logger <<
kWARNING <<
"can not write out GoodRunsList" <<
GEndl;
335 if (m_dataCardName.IsNull()) {
336 m_dataCardName = m_prefix +
"merged_" + m_grl.GetSuggestedName() +
".xml" ;
343 rc = xmlTextWriterStartElement(
writer, BAD_CAST
"NamedLumiRange");
345 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterStartElement" <<
GEndl;
352 this->WriteElement(
writer,
"Name",m_grl.GetName());
354 if (m_grl.GetVersion().Length()>0) {
355 this->WriteElement(
writer,
"Version",m_grl.GetVersion().Data());
356 }
else { m_logger <<
kINFO <<
"<Version> written to xml file <" << m_dataCardName <<
"> is empty." <<
GEndl; }
358 if (!m_grl.GetMetaData().empty()) {
359 std::map<TString,TString>::const_iterator mitr = m_grl.GetMetaData().begin();
360 for (; mitr!=m_grl.GetMetaData().
end(); ++mitr)
361 this->WriteElement(
writer,
"Metadata",mitr->second.Data(),
"Name",mitr->first.Data());
362 }
else { m_logger <<
kINFO <<
"<Metadata> written to xml file <" << m_dataCardName <<
"> is empty." <<
GEndl; }
364 std::map<Int_t,Root::TGoodRun>::const_iterator gitr = m_grl.begin();
365 for (; gitr!=m_grl.end(); ++gitr)
366 this->WriteLumiBlockCollection(
writer,gitr->second);
369 rc = xmlTextWriterEndElement(
writer);
371 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterEndElement" <<
GEndl;
377 m_logger <<
kWARNING <<
"GoodRunsLists package compiled without libxml2" <<
GEndl;
378 m_logger <<
kWARNING <<
"can not write out GoodRunsList" <<
GEndl;
394 rc = xmlTextWriterStartElement(
writer, BAD_CAST
"LumiBlockCollection");
396 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterStartElement" <<
GEndl;
404 std::vector<TLumiBlockRange>::const_iterator litr = goodrun.begin();
405 for (; litr!=goodrun.end(); ++litr)
406 if (!litr->IsEmpty()) {
407 if (litr->End()!=2147483647)
408 this->WriteElement(
writer,
"LBRange",0,
"Start",Form(
"%d",litr->Begin()),
"End",Form(
"%d",litr->End()));
410 this->WriteElement(
writer,
"LBRange",0,
"Start",Form(
"%d",litr->Begin()));
415 rc = xmlTextWriterEndElement(
writer);
417 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterEndElement" <<
GEndl;
423 m_logger <<
kWARNING <<
"GoodRunsLists package compiled without libxml2" <<
GEndl;
424 m_logger <<
kWARNING <<
"can not write out GoodRunsList" <<
GEndl;
435 const char* atr1,
const char* val1,
const char* atr2,
const char* val2)
441 rc = xmlTextWriterStartElement(
writer, BAD_CAST (
name));
443 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterStartElement" <<
GEndl;
447 if ((atr1!=0) && (val1!=0)) {
448 rc = xmlTextWriterWriteAttribute(
writer, BAD_CAST (atr1), BAD_CAST (val1));
450 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterWriteAttribute" <<
GEndl;
455 if ((atr2!=0) && (val2!=0)) {
456 rc = xmlTextWriterWriteAttribute(
writer, BAD_CAST (atr2), BAD_CAST (val2));
458 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterWriteAttribute" <<
GEndl;
464 rc = xmlTextWriterWriteString(
writer, BAD_CAST (
value));
466 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterWriteString" <<
GEndl;
471 rc = xmlTextWriterEndElement(
writer);
473 m_logger <<
kWARNING <<
"testXmlwriterDoc: Error at xmlTextWriterEndElement" <<
GEndl;
479 m_logger <<
kWARNING <<
"GoodRunsLists package compiled without libxml2" <<
GEndl;
480 m_logger <<
kWARNING <<
"can not write out GoodRunsList" <<
GEndl;
509 xmlCharEncodingHandlerPtr
handler;
522 out_size =
size * 2 - 1;
523 out = (
unsigned char *) xmlMalloc((
size_t) out_size);
528 if ((ret < 0) || (
temp -
size + 1)) {
530 m_logger <<
kWARNING <<
"ConvertInput: conversion wasn't successful." <<
GEndl;
532 m_logger <<
kWARNING <<
"ConvertInput: conversion wasn't successful. Converted: " <<
temp <<
" octets." <<
GEndl;
538 out = (
unsigned char *) xmlRealloc(
out, out_size + 1);
547 m_logger <<
kWARNING <<
"GoodRunsLists package compiled without libxml2" <<
GEndl;
548 m_logger <<
kWARNING <<
"can not write out GoodRunsList" <<
GEndl;