CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDLSAX2ConfigHandler.cc
Go to the documentation of this file.
1 /***************************************************************************
2  DDLSAX2ConfigHandler.cc - description
3  -------------------
4  begin : Mon Oct 22 2001
5  email : case@ucdhep.ucdavis.edu
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * DDDParser sub-component of DDD *
11  * *
12  ***************************************************************************/
13 
16 
20 
21 #include <iostream>
22 
24  : doValidation_(false),
25  files_(),
26  urls_(),
27  schemaLocation_(),
28  cpv_(cpv)
29 {}
30 
32 {}
33 
34 // ---------------------------------------------------------------------------
35 // DDLSAX2Handler: Implementation of the SAX DocumentHandler interface
36 //
37 // This is kind-of sneaky-cheating. Basically it ignores all elements except
38 // File elements, and displays attributes up to the name attribute because that
39 // is the only one it cares about at this time. Later we would need a mechanism
40 // to exclude and include sections based on the configuration if we proceed with
41 // that level of selectivity.
42 //
43 // The file name is passed back to DDLParser via SetDDLFileName in order to
44 // process this list of files later.
45 // ---------------------------------------------------------------------------
46 void
47 DDLSAX2ConfigHandler::startElement( const XMLCh* const uri,
48  const XMLCh* const localname,
49  const XMLCh* const qname,
50  const Attributes& attrs )
51 {
52 
53  ++elementCount_;
54  attrCount_ += attrs.getLength();
55 
56  std::string myelemname(StrX(qname).localForm());
57  DCOUT_V('P', "DetectorDescription/Parser/interface/DDLSAX2ConfigHandler::startElement" << myelemname << " started...");
58 
59  unsigned int numAtts = attrs.getLength();
60  unsigned int i = 0;
61  if (myelemname == "File")
62  {
63  std::string name="", url="";
64  while ( i < numAtts )
65  {
66  std::string myattname(StrX(attrs.getLocalName(i)).localForm());
67  std::string myvalue(StrX(attrs.getValue(i)).localForm());
68 
69  if (myattname == "name")
70  name=myvalue;
71  if (myattname == "url")
72  url=myvalue;
73  ++i;
74  }
75  DCOUT('P', "file name = " << name << " and url = " << url);
76  files_.push_back(name);
77  urls_.push_back(url);
78  }
79  else if (myelemname == "Root")
80  {
81  std::string fileName="", logicalPartName="";
82  while ( i < numAtts )
83  {
84  std::string myattname(StrX(attrs.getLocalName(i)).localForm());
85  std::string myvalue(StrX(attrs.getValue(i)).localForm());
86 
87  if (myattname == "fileName")
88  fileName = myvalue;
89  if (myattname == "logicalPartName")
90  logicalPartName = myvalue;
91  ++i;
92  }
93 
94  fileName = fileName.substr(0, fileName.find("."));
95  // std::cout << fileName << ":" << logicalPartName << " is the ROOT" << std::endl;
96  DDLogicalPart root(DDName(logicalPartName,fileName));
97  DDRootDef::instance().set(root);//DDName(logicalPartName, fileName));
99  // DDCompactView cpv;
100  //DDName rt(DDName(logicalPartName, fileName));
101  cpv_.setRoot(root);
102  DCOUT_V('P', std::string("DetectorDescription/Parser/interface/DDLSAX2ConfigHandler::startElement. Setting DDRoot LogicalPart=") + logicalPartName + std::string(" in ") + fileName);
103 
104  }
105  else if (myelemname == "Schema")
106  {
107  while ( i < numAtts )
108  {
109  std::string myattname(StrX(attrs.getLocalName(i)).localForm());
110  std::string myvalue(StrX(attrs.getValue(i)).localForm());
111  if (myattname == "schemaLocation")
112  schemaLocation_ = myvalue;
113  else if (myattname == "validation")
114  doValidation_ = (myvalue == "true" ? true : false);
115  ++i;
116  }
117  }
118  // std::cout << "DetectorDescription/Parser/interface/DDLSAX2ConfigHandler::startElement " << myelemname << " completed..." << std::endl;
119 }
120 
121 const std::vector<std::string>&
123 {
124  return files_;
125 }
126 
127 const std::vector<std::string>&
129 {
130  return urls_;
131 }
132 
133 const std::string
135 {
136  return schemaLocation_;
137 }
138 
139 const bool
141 {
142  return doValidation_;
143 }
int i
Definition: DBlmapReader.cc:9
const std::string getSchemaLocation() const
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:14
std::vector< std::string > files_
type of data representation of DDCompactView
Definition: DDCompactView.h:77
unsigned int elementCount_
void setRoot(const DDLogicalPart &root)
don&#39;t use : interface not stable ....
static value_type & instance()
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
std::vector< std::string > urls_
const std::vector< std::string > & getURLs() const
Definition: StrX.h:32
DDLSAX2ConfigHandler(DDCompactView &cpv)
unsigned int attrCount_
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
const std::vector< std::string > & getFileNames() const
const bool doValidation() const
volatile std::atomic< bool > shutdown_flag false
XERCES_CPP_NAMESPACE::Attributes Attributes
#define DCOUT(M_v_Y, M_v_S)
Definition: DDdebug.h:53