2#include "rdbModel/Management/XercesBuilder.h"
3#include "rdbModel/Management/Manager.h"
4#include "rdbModel/Tables/Table.h"
5#include "rdbModel/Tables/Column.h"
6#include "rdbModel/Tables/Assertion.h"
7#include "rdbModel/Tables/Datatype.h"
8#include "rdbModel/Tables/Index.h"
9#include "rdbModel/Tables/Set.h"
10#include "rdbModel/Tables/Query.h"
11#include "rdbModel/Tables/InterRow.h"
12#include "rdbModel/Tables/Supersede.h"
13#include "rdbModel/Tables/InsertNew.h"
14#include "facilities/Util.h"
15#include "xmlBase/XmlParser.h"
16#include "xmlBase/Dom.h"
21#define SCHEMA_MAJOR_VERSION 2
22#define SCHEMA_MINOR_VERSION 0
24 using XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument;
25 using XERCES_CPP_NAMESPACE_QUALIFIER DOMElement;
36 m_doc = parser.
parse(filename.c_str());
38 return (m_doc == 0) ? 0xffffffff : 0;
46 if (m_doc == 0 )
return 0;
48 DOMElement* docElt = m_doc->getDocumentElement();
52 m_rdb->m_dbName = Dom::getAttribute(docElt,
"dbs");
53 m_rdb->m_majorVersion = 0;
54 m_rdb->m_minorVersion = 0;
56 std::string versionString = Dom::getAttribute(docElt,
"SchemaVersion");
57 if (!versionString.size()) {
58 versionString = Dom::getAttribute(docElt,
"DTDversion");
61 unsigned dotPos = versionString.find(
'.');
63 std::string minorStr = std::string(versionString, dotPos+1);
65 versionString.resize(dotPos);
72 std::cerr <<
"rdbModel::XercesBuilder: Bad version string " << std::endl;
74 m_rdb->m_CVSid = Dom::getAttribute(docElt,
"CVSid");
76 std::cerr <<
"Schema major version " << m_rdb->m_majorVersion
79 std::cerr <<
"Bye for now";
85 std::vector<DOMElement*> tables;
86 Dom::getChildrenByTagName(docElt,
"table", tables);
87 unsigned int nTable = tables.size();
88 unsigned int processed = 0;
90 for (
unsigned int iTable = 0; iTable < nTable; iTable++) {
91 Table* newTable = buildTable(tables[iTable]);
94 m_rdb->addTable(newTable);
98 return nTable - processed;
101 Table* XercesBuilder::buildTable(DOMElement* tableElt) {
105 newTable->m_name = Dom::getAttribute(tableElt,
"name");
106 newTable->m_version = Dom::getAttribute(tableElt,
"version");
107 newTable->m_comment = Dom::getAttribute(tableElt,
"comment");
109 std::vector<DOMElement* > children;
110 Dom::getChildrenByTagName(tableElt,
"col", children);
111 unsigned int nChild = children.size();
114 for (
unsigned int iCol = 0; iCol < nChild; iCol++) {
115 Column* newCol = buildColumn(children[iCol], newTable);
118 newTable->addColumn(newCol);
125 DOMElement* primaryKey =
126 Dom::findFirstChildByName(tableElt,
"primary");
127 if (primaryKey != 0) {
128 Index* newIndex = buildIndex(primaryKey,
true, newTable);
130 newIndex->m_myTable = newTable;
131 newTable->addIndex(newIndex);
134 newTable->setPrimaryKeyCol();
137 Dom::getChildrenByTagName(tableElt,
"index", children);
138 nChild = children.size();
140 for (
unsigned int iIndex = 0; iIndex < nChild; iIndex++) {
141 Index* newIndex = buildIndex(children[iIndex],
false, newTable);
143 newTable->addIndex(newIndex);
150 Dom::getChildrenByTagName(tableElt,
"assert", children);
151 nChild = children.size();
153 for (
unsigned int iAssert = 0; iAssert < nChild; iAssert++) {
154 Assertion* newAssert = buildAssertion(children[iAssert], newTable);
156 newTable->addAssert(newAssert);
161 newTable->setValidRow(
v);
163 DOMElement* iNewElt = Dom::findFirstChildByName(tableElt,
"insertNew");
165 newTable->m_iNew = buildInsertNew(iNewElt, newTable);
167 DOMElement* supElt = Dom::findFirstChildByName(tableElt,
"supersede");
169 newTable->m_sup = buildSupersede(supElt, newTable);
175 Column* XercesBuilder::buildColumn(DOMElement* e, Table* myTable) {
178 Column* newCol =
new Column(myTable);
180 newCol->m_name = Dom::getAttribute(e,
"name");
181 DOMElement* com = Dom::findFirstChildByName(e,
"comment");
182 newCol->m_comment = Dom::getTextContent(com);
184 DOMElement* src = Dom::findFirstChildByName(e,
"src");
186 newCol->m_null = (Dom::getAttribute(src,
"null") ==
"true");
187 newCol->m_stickyInsert =
188 (Dom::getAttribute(src,
"stickyInsert") ==
"true");
190 DOMElement* child = Dom::getFirstChildElement(src);
191 if (Dom::checkTagName(child,
"default")) {
193 newCol->m_default = Dom::getAttribute(child,
"value");
195 else if (Dom::checkTagName(child,
"from")) {
196 std::string agent = Dom::getAttribute(child,
"agent");
197 if (agent ==
"auto_increment") {
200 else if (agent ==
"now") {
203 else if (agent ==
"enduser") {
206 else if (agent ==
"service") {
208 std::string contents = Dom::getAttribute(child,
"contents");
209 if (contents ==
"service_name") {
212 else if (contents ==
"username") {
215 else if (contents ==
"insert_time") {
218 else if (contents ==
"update_time") {
226 DOMElement* dtype = Dom::findFirstChildByName(e,
"type");
227 newCol->m_type = buildDatatype(dtype);
232 Datatype* XercesBuilder::buildDatatype(DOMElement* e) {
235 Datatype* newType =
new Datatype;
236 newType->setType(Dom::getAttribute(e,
"typename"));
238 if (Dom::hasAttribute(e,
"size")) {
240 newType->m_outputSize = Dom::getIntAttribute(e,
"size");
243 std::cerr <<
"Error in rdb database description file" << std::endl;
244 std::cerr << ex.
getMsg() << std::endl;
245 std::cerr <<
"Ignoring column size specification " << std::endl;
246 newType->m_outputSize = -1;
249 else newType->m_outputSize = -1;
250 if ((newType->m_outputSize == -1) &&
252 if ((newType->m_outputSize == -1) &&
254 std::cerr <<
"Error in rdb database description file: " << std::endl;
255 std::cerr <<
"Missing size spec. for varchar field " << std::endl;
262 DOMElement*
restrict = Dom::getFirstChildElement(e);
265 DOMElement* rtype = Dom::getFirstChildElement(
restrict);
266 std::string tagname = Dom::getTagName(rtype);
268 (tagname != std::string(
"enum") ) ) {
269 std::cerr <<
"From rdbMode::XercesBuilder::buildDatatype" << std::endl;
270 std::cerr <<
"Bad enum type. Missing value list " << std::endl;
276 if (tagname == std::string(
"nonnegative")) {
278 if (newType->m_isInt) newType->m_minInt = 0;
280 else if (tagname == std::string(
"positive")) {
282 if (newType->m_isInt) newType->m_minInt = 1;
284 else if (tagname == std::string(
"interval")) {
285 newType->setInterval(Dom::getAttribute(rtype,
"min"),
286 Dom::getAttribute(rtype,
"max"));
288 else if (tagname == std::string(
"file")) {
291 else if (tagname == std::string(
"enum")) {
293 Enum* newEnum =
new Enum();
294 newEnum->m_required =
295 (Dom::getAttribute(rtype,
"use") ==
"require");
296 if (!(newEnum->m_required) &&
300 std::cerr <<
"From rdbMode::XercesBuilder::buildDatatype"
302 std::cerr <<
"Bad enum type. List must be 'required' " << std::endl;
307 std::string enums = Dom::getAttribute(rtype,
"values");
309 unsigned int start = 0;
310 std::string::size_type blankLoc = enums.find(std::string(
" "), start);
312 while (blankLoc != std::string::npos) {
313 newEnum->m_choices.push_back(enums.substr(start, blankLoc-start));
314 start = blankLoc + 1;
315 blankLoc = enums.find(std::string(
" "), start);
317 newEnum->m_choices.push_back(enums.substr(start));
318 newType->m_enum = newEnum;
324 std::cerr <<
"From rdbMode::XercesBuilder::buildDatatype"
326 std::cerr <<
"Bad enum type. Missing value list " << std::endl;
334 Index* XercesBuilder::buildIndex(DOMElement* e,
bool primaryElt,
341 newIndex->m_primary =
true;
342 std::string col = newIndex->m_name = Dom::getAttribute(e,
"col");
343 newIndex->m_indexCols.push_back(newIndex->m_name);
344 Column* myCol = myTable->getColumnByName(col);
345 myCol->m_isPrimaryKey =
true;
348 newIndex->m_name = Dom::getAttribute(e,
"name");
350 std::string primaryVal =
351 Dom::getAttribute(e,
"primary");
352 newIndex->m_primary = (primaryVal ==
"yes");
355 std::string cols = Dom::getAttribute(e,
"cols");
358 if (newIndex->m_primary) {
359 Column* myCol = myTable->getColumnByName(cols);
360 myCol->m_isPrimaryKey =
true;
363 unsigned int start = 0;
364 std::string::size_type blankLoc = cols.find(std::string(
" "), start);
366 while (blankLoc != std::string::npos) {
367 newIndex->m_indexCols.push_back(cols.substr(start, blankLoc-start));
368 start = blankLoc + 1;
369 blankLoc = cols.find(std::string(
" "), start);
371 newIndex->m_indexCols.push_back(cols.substr(start));
377 Assertion* XercesBuilder::buildAssertion(DOMElement* e, Table* myTable) {
386 Assertion::Operator* op = buildOperator(opElt, myTable);
388 Assertion* newAssert =
new Assertion(op, myTable);
390 newAssert->setName(name);
395 Assertion::Operator* XercesBuilder::buildOperator(DOMElement* e,
399 std::string opName = Dom::getTagName(e);
401 if ((opName ==
"isNull") || (opName ==
"isEmpty")) {
403 DOMElement* child = Dom::getFirstChildElement(e);
405 std::string which = Dom::getAttribute(child,
"which");
409 return new Assertion::Operator(opType,
410 Dom::getAttribute(child,
"col"),
416 else if (opName ==
"compare") {
417 std::string relation = Dom::getAttribute(e,
"relation");
419 else if (relation ==
"greaterThan") {
422 else if (relation ==
"equal") opType =
OPTYPEequal;
423 else if (relation ==
"notEqual")
425 else if (relation ==
"lessOrEqual") {
428 else if (relation ==
"greaterOrEqual") {
431 DOMElement* child[2];
432 child[0] = Dom::getFirstChildElement(e);
433 child[1] = Dom::getSiblingElement(child[0]);
435 std::string compareArgs[2];
438 for (
unsigned iChild = 0; iChild < 2; iChild++) {
445 if (Dom::checkTagName(child[iChild],
"value")) {
447 compareArgs[iChild] =
448 Dom::getTextContent(child[iChild]);
451 compareArgs[iChild] =
452 Dom::getAttribute(child[iChild],
"col");
454 std::string which = Dom::getAttribute(child[iChild],
456 if (which == std::string(
"old")) {
458 }
else if (which == std::string(
"toBe")) {
464 Assertion::Operator* newOp =
465 new Assertion::Operator(opType, compareArgs[0], compareArgs[1],
466 valueType[0], valueType[1]);
467 if (!newOp->validCompareOp(myTable)) {
475 else if (opName ==
"exists") {
476 std::string tableName;
478 if (Dom::hasAttribute(e,
"tableName") ) {
480 Dom::getAttribute(e,
"tableName");
482 else tableName = myTable->getName();
483 DOMElement* child = Dom::getFirstChildElement(e);
484 Assertion::Operator* childOp = buildOperator(child, myTable);
485 return new Assertion::Operator(opType, tableName, childOp);
488 else if (opName ==
"or") opType =
OPTYPEor;
489 else if (opName ==
"and") opType =
OPTYPEand;
490 else if (opName ==
"not") opType =
OPTYPEnot;
493 std::vector<DOMElement*> children;
494 std::vector<Assertion::Operator*> childOps;
495 Dom::getChildrenByTagName(e,
"*", children);
496 unsigned nChild = children.size();
497 for (
unsigned iChild = 0; iChild < nChild; iChild++) {
498 Assertion::Operator* childOp = buildOperator(children[iChild], myTable);
500 childOps.push_back(childOp);
506 return new Assertion::Operator(opType, childOps);
509 Set* XercesBuilder::buildSet(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* e,
513 std::string destCol = Dom::getAttribute(e,
"destCol");
515 std::string destRow = Dom::getAttribute(e,
"destRow");
521 std::string srcValue;
522 std::string interp(
"");
523 DOMElement* srcElt = Dom::findFirstChildByName(e,
"*");
524 std::string tag = Dom::getTagName(srcElt);
525 if (tag == std::string(
"ask")) {
529 else if (tag == std::string(
"value") ) {
531 srcValue = Dom::getTextContent(srcElt);
532 interp = Dom::getAttribute(srcElt,
"interp");
535 std::string forceStr= Dom::getAttribute(srcElt,
"force");
536 bool force = (forceStr == std::string(
"true"));
537 srcValue = Dom::getAttribute(srcElt,
"col");
538 std::string which = Dom::getAttribute(srcElt,
"which");
546 return new Set(
t, destCol, destType, srcValue, srcType, interp);
551 XercesBuilder::buildSupersede(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* e,
559 std::string onlyIfStr = Dom::getAttribute(e,
"onlyIf");
560 Assertion* onlyIf =
t->getAssertionByName(onlyIfStr);
561 Supersede* super =
new Supersede(
t, onlyIf);
565 e = Dom::findFirstChildByName(e,
"*");
567 Set*
s = buildSet(e,
t);
569 e = Dom::getSiblingElement(e);
576 XercesBuilder::buildQuery(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* e,
579 std::string whereStr = Dom::getAttribute(e,
"assertRef");
580 Assertion* where =
t->getAssertionByName(whereStr);
582 Query*
q =
new Query(
t, 0, where);
583 e = Dom::findFirstChildByName(e,
"*");
585 q->addSelect(Dom::getTextContent(e));
586 e = Dom::getSiblingElement(e);
592 XercesBuilder::buildInsertNew(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* e,
596 std::string internalStr = Dom::getAttribute(e,
"internalCond");
597 Assertion* internal =
t->getAssertionByName(internalStr);
599 std::string officialStr = Dom::getAttribute(e,
"official");
600 Assertion* official =
t->getAssertionByName(officialStr);
602 InsertNew* in =
new InsertNew(
t, internal, official);
603 e = Dom::findFirstChildByName(e,
"*");
605 InterRow* ir = buildInterRow(e,
t);
608 e = Dom::getSiblingElement(e);
614 XercesBuilder::buildInterRow(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* e,
619 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* queryElt =
620 Dom::findFirstChildByName(e,
"*");
621 Query*
q = buildQuery(queryElt,
t);
623 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* sib =
624 Dom::getSiblingElement(queryElt);
625 bool quit = Dom::checkTagName(sib,
"quit");
627 InterRow* inter =
new InterRow(
t,
q, quit);
628 if (quit)
return inter;
632 Set*
s = buildSet(sib,
t);
634 sib = Dom::getSiblingElement(sib);
std::map< int, double >::value_type valType
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
#define SCHEMA_MAJOR_VERSION
static int stringToInt(const std::string &InStr)
Exception class used when converting from string to numeric type.
static Manager * getManager()
Assertion * getAssertionByName(const std::string &name) const
virtual unsigned int parseInput(const std::string &inputPath)
Base exception class for Dom.
virtual std::string getMsg()
static std::string getAttribute(const DOMElement *elt, const char *attName)
static DOMElement * getFirstChildElement(const DOMNode *parent)
Get first child which is an element node, if any.
DOMDocument * parse(const char *const filename, const std::string &docType=std::string(""))
Parse an xml file, returning document node if successful.
void doSchema(bool doit)
Call this method to turn on schema processing (else it's off)