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/DOMDocument.hpp>
23 #include <xercesc/dom/DOMWriter.hpp>
30 using namespace xercesc;
33 template <
class T> XMLCh* transcode (
const T& fInput) {
36 return XMLString::transcode (ost.str().c_str());
39 const char* IOV_ID =
"IOV_ID";
40 const char* TAG_ID =
"TAG_ID";
42 std::string kind (
const HcalPedestals& fObject) {
return "HCAL_PEDESTALS_V2";}
43 std::string kind (
const HcalGains& fObject) {
return "HCAL Gains";}
44 std::string kind (
const HcalRawGains& fObject) {
return "HCAL Raw Gains";}
46 std::string extensionTableName (
const std::string& fKind) {
47 if (fKind ==
"HCAL_PEDESTALS_V2")
return "HCAL_PEDESTALS_V2";
48 if (fKind ==
"HCAL Gains")
return "HCAL_GAIN_PEDSTL_CALIBRATIONS";
49 if (fKind ==
"HCAL Raw Gains")
return "HCAL_RAW_GAINS";
57 template <
class T> DOMElement* newElement (DOMElement* fParent,
const T&
fName);
58 template <
class T> DOMElement* newValue (DOMElement* fParent,
const std::string& fName,
const T& fValue);
59 template <
class T>
void addAttribute (DOMElement* fElement,
const std::string& fName,
const T& fValue);
60 const DOMDocument* document ();
61 void streamOut (std::ostream& fOut);
64 DOMElement* makeHeader (DOMElement* fRoot,
const std::string& fExtensionName,
unsigned long fRun);
65 DOMElement* makeDataset (DOMElement* fRoot,
const std::string& fVersion);
66 DOMElement* makeElement (DOMElement* fRoot);
67 DOMElement* makeMaps (DOMElement* fRoot);
69 DOMElement* makeType (DOMElement* fHeader,
const std::string& fExtensionName);
70 DOMElement* makeRun (DOMElement* fHeader,
unsigned long fRun);
72 DOMElement* makeChId (DOMElement* fDataset,
DetId fId);
74 DOMElement* makeElementDataset (DOMElement* fElement,
int fXMLId,
DetId fDetId,
const std::string& fVersion,
const std::string& fKind,
unsigned long fRun);
75 DOMElement* makeElementIOV (DOMElement* fElement,
unsigned long long fIovBegin,
unsigned long long fIovEnd = 0);
76 DOMElement* makeElementTag (DOMElement* fElement,
const std::string& fTagName,
const std::string& fDetectorName,
const std::string& fComment =
"Automatically created by HcalDbXml");
78 DOMElement* makeMapTag (DOMElement* fMap);
79 DOMElement* makeMapIOV (DOMElement* fTag);
80 DOMElement* makeMapDataset (DOMElement* fIov,
int fXMLId);
83 DOMElement* makeData (DOMElement* fDataset);
86 void addData (DOMElement* fData,
const HcalPedestal& fItem);
88 void addData (DOMElement* fData,
const HcalGain& fItem);
89 void addData (DOMElement* fData,
const HcalRawGain& fItem);
100 XMLPlatformUtils::Initialize();
101 mDom = DOMImplementationRegistry::getDOMImplementation (transcode (
"Core"));
109 DOMElement* element =
mDoc->createElement (transcode (fName));
110 fParent->appendChild (element);
115 DOMElement* element =
newElement (fParent, fName);
116 DOMText*
text =
mDoc->createTextNode (transcode (fValue));
117 element->appendChild (text);
122 fElement->setAttribute (transcode (fName), transcode (fValue));
136 newValue (type,
"EXTENSION_TABLE_NAME", extensionTableName (fKind));
143 newValue (run,
"RUN_TYPE",
"HcalDbXml");
150 newValue (dataset,
"VERSION", fVersion);
155 DOMElement* channel =
newElement (fDataset,
"CHANNEL");
156 newValue (channel,
"EXTENSION_TABLE_NAME",
"HCAL_CHANNELS");
161 newValue (channel,
"Z", eta > 0 ? 1 : -1);
172 newValue (dataset,
"VERSION", fVersion);
181 newValue (iov,
"INTERVAL_OF_VALIDITY_BEGIN", fIovBegin);
183 newValue (iov,
"INTERVAL_OF_VALIDITY_END", fIovEnd);
188 DOMElement*
XMLDocument::makeElementTag (DOMElement* fElement,
const std::string& fTagName,
const std::string& fDetectorName,
const std::string& fComment) {
192 newValue (tag,
"TAG_NAME", fTagName);
193 newValue (tag,
"DETECTOR_NAME", fDetectorName);
194 newValue (tag,
"COMMENT_DESCRIPTION", fComment);
199 DOMElement* element =
newElement (fRoot,
"ELEMENTS");
221 DOMElement* element =
newElement (fIov,
"DATA_SET");
299 DOMWriter* domWriter =
mDom->createDOMWriter();
300 domWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
301 domWriter->writeNode (&formTaget, *(
root()));
306 template <
class T1,
class T2>
308 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
309 const T1* fObject1,
const T2* fObject2 = 0) {
310 if (!fObject1)
return false;
311 const std::string KIND = kind (*fObject1);
323 std::vector<DetId> detids = fObject1->getAllChannels ();
324 for (
unsigned iCh = 0; iCh < detids.size(); iCh++) {
325 DetId id = detids [iCh];
327 version << fTag <<
'_' << fGMTIOVBegin;
331 doc.
addData (data, *(fObject1->getValues (
id)));
333 if (fObject2) doc.
addData (data, *(fObject2->getValues (
id)));
336 std::cout <<
"dumpObject_-> ERROR: width is not available for cell # " <<
id.rawId() << std::endl;
347 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
349 return dumpObject_ (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, &fObject, &fError);
353 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
355 float dummyError = 0.0001;
356 std::cout <<
"HcalDbXml::dumpObject-> set default errors: 0.0001, 0.0001, 0.0001, 0.0001" << std::endl;
359 for (std::vector<DetId>::iterator channel = channels.begin ();
360 channel != channels.end ();
364 for (
int iCapId = 0; iCapId < 4; iCapId++) {
365 item.
setSigma (iCapId, iCapId, dummyError*dummyError);
367 widths.addValues(item);
369 return dumpObject (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, fObject, widths);
373 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
375 return dumpObject_ (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, &fObject, &fError);
379 unsigned fRun,
unsigned long fGMTIOVBegin,
unsigned long fGMTIOVEnd,
const std::string& fTag,
383 for (std::vector<DetId>::iterator channel = channels.begin (); channel != channels.end (); channel++)
388 return dumpObject (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, fObject, widths);
392 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")
bool addValues(const Item &myItem, bool h2mode_=false)
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)
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)
uint32_t rawId() const
get the raw id
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)
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)
std::auto_ptr< XERCES_CPP_NAMESPACE_QUALIFIER XercesDOMParser > parser
const std::string & getField2() const
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
DOMElement * makeChId(DOMElement *fDataset, DetId fId)
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)
DOMElement * makeMapDataset(DOMElement *fIov, int fXMLId)
int getField(int i) const
string root
initialization