17 #include <xercesc/util/XMLString.hpp> 18 #include <xercesc/dom/DOMElement.hpp> 19 #include <xercesc/dom/DOMText.hpp> 20 #include <xercesc/dom/DOMImplementation.hpp> 21 #include <xercesc/dom/DOMImplementationRegistry.hpp> 22 #include <xercesc/dom/DOMConfiguration.hpp> 23 #include <xercesc/dom/DOMDocument.hpp> 24 #include <xercesc/dom/DOMLSOutput.hpp> 25 #include <xercesc/dom/DOMLSSerializer.hpp> 36 template <
class T> XMLCh* transcode (
const T& fInput) {
39 return XMLString::transcode (ost.str().c_str());
42 const char* IOV_ID =
"IOV_ID";
43 const char* TAG_ID =
"TAG_ID";
50 if (fKind ==
"HCAL_PEDESTALS_V2")
return "HCAL_PEDESTALS_V2";
51 if (fKind ==
"HCAL Gains")
return "HCAL_GAIN_PEDSTL_CALIBRATIONS";
52 if (fKind ==
"HCAL Raw Gains")
return "HCAL_RAW_GAINS";
60 template <
class T> DOMElement* newElement (DOMElement* fParent,
const T& fName);
61 template <
class T> DOMElement* newValue (DOMElement* fParent,
const std::string& fName,
const T& fValue);
62 template <
class T>
void addAttribute (DOMElement* fElement,
const std::string& fName,
const T& fValue);
63 const DOMDocument* document ();
64 void streamOut (std::ostream& fOut);
67 DOMElement* makeHeader (DOMElement* fRoot,
const std::string& fExtensionName,
unsigned long fRun);
68 DOMElement* makeDataset (DOMElement* fRoot,
const std::string& fVersion);
69 DOMElement* makeElement (DOMElement* fRoot);
70 DOMElement* makeMaps (DOMElement* fRoot);
72 DOMElement* makeType (DOMElement* fHeader,
const std::string& fExtensionName);
73 DOMElement* makeRun (DOMElement* fHeader,
unsigned long fRun);
75 DOMElement* makeChId (DOMElement* fDataset,
DetId fId);
77 DOMElement* makeElementDataset (DOMElement* fElement,
int fXMLId,
DetId fDetId,
const std::string& fVersion,
const std::string& fKind,
unsigned long fRun);
78 DOMElement* makeElementIOV (DOMElement* fElement,
unsigned long long fIovBegin,
unsigned long long fIovEnd = 0);
79 DOMElement* makeElementTag (DOMElement* fElement,
const std::string& fTagName,
const std::string& fDetectorName,
const std::string& fComment =
"Automatically created by HcalDbXml");
81 DOMElement* makeMapTag (DOMElement* fMap);
82 DOMElement* makeMapIOV (DOMElement* fTag);
83 DOMElement* makeMapDataset (DOMElement* fIov,
int fXMLId);
86 DOMElement* makeData (DOMElement* fDataset);
89 void addData (DOMElement* fData,
const HcalPedestal& fItem);
91 void addData (DOMElement* fData,
const HcalGain& fItem);
92 void addData (DOMElement* fData,
const HcalRawGain& fItem);
104 mDom = DOMImplementationRegistry::getDOMImplementation (transcode (
"Core"));
112 DOMElement* element =
mDoc->createElement (transcode (fName));
113 fParent->appendChild (element);
118 DOMElement* element =
newElement (fParent, fName);
119 DOMText*
text =
mDoc->createTextNode (transcode (fValue));
120 element->appendChild (text);
125 fElement->setAttribute (transcode (fName), transcode (fValue));
139 newValue (type,
"EXTENSION_TABLE_NAME", extensionTableName (fKind));
146 newValue (run,
"RUN_TYPE",
"HcalDbXml");
153 newValue (dataset,
"VERSION", fVersion);
158 DOMElement* channel =
newElement (fDataset,
"CHANNEL");
159 newValue (channel,
"EXTENSION_TABLE_NAME",
"HCAL_CHANNELS");
164 newValue (channel,
"Z", eta > 0 ? 1 : -1);
175 newValue (dataset,
"VERSION", fVersion);
182 DOMElement* iov =
newElement (fElement,
"IOV");
184 newValue (iov,
"INTERVAL_OF_VALIDITY_BEGIN", fIovBegin);
186 newValue (iov,
"INTERVAL_OF_VALIDITY_END", fIovEnd);
195 newValue (tag,
"TAG_NAME", fTagName);
196 newValue (tag,
"DETECTOR_NAME", fDetectorName);
197 newValue (tag,
"COMMENT_DESCRIPTION", fComment);
202 DOMElement* element =
newElement (fRoot,
"ELEMENTS");
224 DOMElement* element =
newElement (fIov,
"DATA_SET");
302 DOMLSSerializer* domWriter =
mDom->createLSSerializer();
303 DOMConfiguration* dc = domWriter->getDomConfig();
304 dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
306 DOMLSOutput* outputDesc = ((DOMImplementationLS*)
mDom)->createLSOutput();
307 outputDesc->setByteStream(&formTarget);
309 domWriter->write (
root(), outputDesc);
314 template <
class T1,
class T2>
316 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
317 const T1* fObject1,
const T2* fObject2 = 0) {
318 if (!fObject1)
return false;
331 std::vector<DetId> detids = fObject1->getAllChannels ();
332 for (
unsigned iCh = 0; iCh < detids.size(); iCh++) {
333 DetId id = detids [iCh];
335 version << fTag <<
'_' << fGMTIOVBegin;
339 doc.
addData (data, *(fObject1->getValues (
id)));
341 if (fObject2) doc.
addData (data, *(fObject2->getValues (
id)));
344 std::cout <<
"dumpObject_-> ERROR: width is not available for cell # " <<
id.rawId() << std::endl;
355 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
357 return dumpObject_ (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, &fObject, &fError);
361 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
363 float dummyError = 0.0001;
364 std::cout <<
"HcalDbXml::dumpObject-> set default errors: 0.0001, 0.0001, 0.0001, 0.0001" << std::endl;
367 for (std::vector<DetId>::iterator channel = channels.begin ();
368 channel != channels.end ();
372 for (
int iCapId = 0; iCapId < 4; iCapId++) {
373 item.
setSigma (iCapId, iCapId, dummyError*dummyError);
375 widths.addValues(item);
377 return dumpObject (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, fObject, widths);
381 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
383 return dumpObject_ (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, &fObject, &fError);
387 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
391 for (std::vector<DetId>::iterator channel = channels.begin (); channel != channels.end (); channel++)
394 widths.addValues(item);
396 return dumpObject (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, fObject, widths);
400 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
DOMElement * makeElementTag(DOMElement *fElement, const std::string &fTagName, const std::string &fDetectorName, const std::string &fComment="Automatically created by HcalDbXml")
std::string strStatus() const
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
bool dumpObject(std::ostream &fOutput, unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string &fTag, unsigned fVersion, const HcalPedestals &fObject, const HcalPedestalWidths &fError)
void streamOut(std::ostream &fOut)
constexpr uint32_t rawId() const
get the raw id
DOMElement * makeDataset(DOMElement *fRoot, const std::string &fVersion)
float getValue(int fCapId) const
get value for capId = 0..3
float getValue(int fCapId) const
get value for capId = 0..3
DOMElement * makeMapIOV(DOMElement *fTag)
const std::string & getField3() const
DOMElement * makeElementIOV(DOMElement *fElement, unsigned long long fIovBegin, unsigned long long fIovEnd=0)
std::vector< DetId > getAllChannels() const
DOMElement * makeElementDataset(DOMElement *fElement, int fXMLId, DetId fDetId, const std::string &fVersion, const std::string &fKind, unsigned long fRun)
Abs< T >::type abs(const T &t)
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * doc
float getValue(int fCapId) const
get value for capId = 0..3
DOMElement * makeMapTag(DOMElement *fMap)
void addAttribute(DOMElement *fElement, const std::string &fName, const T &fValue)
void addData(DOMElement *fData, const HcalPedestal &fItem)
const DOMDocument * document()
DOMElement * makeElement(DOMElement *fRoot)
DOMElement * makeRun(DOMElement *fHeader, unsigned long fRun)
const std::string & getField2() const
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
DOMElement * makeChId(DOMElement *fDataset, DetId fId)
std::unique_ptr< XERCES_CPP_NAMESPACE_QUALIFIER XercesDOMParser > parser
DOMElement * makeMaps(DOMElement *fRoot)
DOMElement * makeType(DOMElement *fHeader, const std::string &fExtensionName)
DOMElement * makeData(DOMElement *fDataset, const HcalPedestal &fPed, const HcalPedestalWidth &fWidth)
DOMElement * makeHeader(DOMElement *fRoot, const std::string &fExtensionName, unsigned long fRun)
char data[epos_bytes_allocation]
const std::string & getFlavor() const
DOMElement * newElement(DOMElement *fParent, const T &fName)
DOMElement * newValue(DOMElement *fParent, const std::string &fName, const T &fValue)
void setSigma(int fCapId1, int fCapId2, float fSigma)
const HcalTopology * topo() const
DOMElement * makeMapDataset(DOMElement *fIov, int fXMLId)
int getField(int i) const