CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
DDLParser Class Reference

DDLParser is the main class of Detector Description Language Parser. More...

#include <DDLParser.h>

Public Types

typedef std::map< int, std::pair< std::string, std::string > > FileNameHolder
 
typedef XERCES_CPP_NAMESPACE::SAX2XMLReader SAX2XMLReader
 

Public Member Functions

void clearFiles ()
 Clear the file list - see Warning! More...
 
 DDLParser (DDCompactView &cpv)
 Constructor MUST associate a DDCompactView storage. More...
 
 DDLParser ()=delete
 
DDLSAX2FileHandlergetDDLSAX2FileHandler ()
 To get the parent this class allows access to the handler. More...
 
SAX2XMLReadergetXMLParser ()
 Get the SAX2Parser from the DDLParser. USE WITH CAUTION. Set your own handler, etc. More...
 
int parse (const DDLDocumentProvider &dp)
 Parse all files. Return is meaningless. More...
 
void parse (const std::vector< unsigned char > &ablob, unsigned int bsize)
 
bool parseOneFile (const std::string &filename)
 Process a single files. More...
 
 ~DDLParser ()
 Destructor terminates the XMLPlatformUtils (as required by Xerces) More...
 

Private Member Functions

std::string const extractFileName (const std::string &fullname)
 
std::string const getNameSpace (const std::string &fname)
 
size_t isFound (const std::string &filename)
 Is the file already known by the DDLParser? Returns 0 if not found, and index if found. More...
 
bool isParsed (const std::string &filename)
 Is the file already parsed? More...
 
void parseFile (const int &numtoproc)
 Parse File. Just to hold some common looking code. More...
 

Private Attributes

DDCompactViewcpv_
 reference to storage More...
 
std::string currFileName_
 Which file is currently being processed. More...
 
DDLElementRegistryelementRegistry_
 
DDLSAX2HandlererrHandler_
 
DDLSAX2ExpressionHandlerexpHandler_
 
DDLSAX2FileHandlerfileHandler_
 
FileNameHolder fileNames_
 List of files to be processed, obtained from the DDLDocumentProvider. More...
 
size_t nFiles_
 Number of files + 1. More...
 
std::map< int, bool > parsed_
 Parse status of a given file. More...
 
SAX2XMLReaderSAX2Parser_
 SAX2XMLReader is one way of parsing. More...
 

Detailed Description

DDLParser is the main class of Detector Description Language Parser.

Author
Michael Case

DDLParser.h - description

begin: Mon Oct 22 2001 email: case@.nosp@m.ucdh.nosp@m.ep.uc.nosp@m.davi.nosp@m.s.edu

Singleton which controls the parsing of XML files (DDL). It guarantees that a given filename will only be parsed once regardless of its path. It now relies on a DDLDocumentProvider class which provides a list of file names and URLs to be parsed.

It uses the Xerces C++ Parser from the Apache Group straight-forwardly. One main thing to note is that only one DDLParser can ever be made. This allows for sub-components of the parser to easily find out information from the parser during run-time.

There is an interface to parse just one file. If one uses this method and does not use the default DDLDocumentProvider user is responsible for also setting the DDRootDef.

Modification: 2003-02-13: Michael Case, Stepan Wynhoff and Martin Liendl 2003-02-24: same. DDLParser will use DDLDocumentProvider (abstract). One of these and will be defaulted to DDLConfiguration. This will read the "configuration.xml" file provided and will be used by the Parser to "get" the files. 2005-11-13: Michael Case removed some of the un-necessary methods that were deprecated. 2010-01 to 2010-04 sometime: Michael Case removed singleton-ness. MUST have a DDCompactView to refer to and no more default constructor at the moment. 2010-07-29: removed DDLConfiguration; use FIPConfiguration, it is easier. for CMSSW Framework example see XMLIdealGeometryESSource (different DDLDocumentProvider completely

Definition at line 63 of file DDLParser.h.

Member Typedef Documentation

◆ FileNameHolder

typedef std::map<int, std::pair<std::string, std::string> > DDLParser::FileNameHolder

Definition at line 67 of file DDLParser.h.

◆ SAX2XMLReader

typedef XERCES_CPP_NAMESPACE::SAX2XMLReader DDLParser::SAX2XMLReader

Definition at line 65 of file DDLParser.h.

Constructor & Destructor Documentation

◆ DDLParser() [1/2]

DDLParser::DDLParser ( DDCompactView cpv)

Constructor MUST associate a DDCompactView storage.

Definition at line 22 of file DDLParser.cc.

References elementRegistry_, errHandler_, expHandler_, fileHandler_, SAX2Parser_, and cms::concurrency::xercesInitialize().

22  : cpv_(cpv), nFiles_(0) {
24  SAX2Parser_ = XMLReaderFactory::createXMLReader();
25 
26  SAX2Parser_->setFeature(XMLUni::fgSAX2CoreValidation, false); // optional
27  SAX2Parser_->setFeature(XMLUni::fgSAX2CoreNameSpaces, false); // optional
28 
33  SAX2Parser_->setErrorHandler(errHandler_);
34  SAX2Parser_->setContentHandler(fileHandler_);
35 }
DDLSAX2FileHandler * fileHandler_
Definition: DDLParser.h:154
SAX2XMLReader * SAX2Parser_
SAX2XMLReader is one way of parsing.
Definition: DDLParser.h:151
void xercesInitialize()
Definition: Xerces.cc:18
DDLSAX2FileHandler is the SAX2 Handler for XML files found in the configuration file.
DDLSAX2ExpressionHandler is the first pass SAX2 Handler for XML files found in the configuration file...
DDLSAX2ExpressionHandler * expHandler_
Definition: DDLParser.h:155
DDLSAX2Handler * errHandler_
Definition: DDLParser.h:156
DDLElementRegistry * elementRegistry_
Definition: DDLParser.h:153
size_t nFiles_
Number of files + 1.
Definition: DDLParser.h:145
DDLSAX2Handler inherits from Xerces C++ DefaultHandler.
The main class for processing parsed elements.
DDCompactView & cpv_
reference to storage
Definition: DDLParser.h:136

◆ DDLParser() [2/2]

DDLParser::DDLParser ( )
delete

◆ ~DDLParser()

DDLParser::~DDLParser ( void  )

Destructor terminates the XMLPlatformUtils (as required by Xerces)

Definition at line 38 of file DDLParser.cc.

References elementRegistry_, errHandler_, expHandler_, fileHandler_, and cms::concurrency::xercesTerminate().

38  {
39  // clean up and leave
40  delete expHandler_;
41  delete fileHandler_;
42  delete errHandler_;
43  delete elementRegistry_;
45 }
void xercesTerminate()
Definition: Xerces.cc:23
DDLSAX2FileHandler * fileHandler_
Definition: DDLParser.h:154
DDLSAX2ExpressionHandler * expHandler_
Definition: DDLParser.h:155
DDLSAX2Handler * errHandler_
Definition: DDLParser.h:156
DDLElementRegistry * elementRegistry_
Definition: DDLParser.h:153

Member Function Documentation

◆ clearFiles()

void DDLParser::clearFiles ( void  )

Clear the file list - see Warning!

This could result in mangled geometry if the Core has not been cleared.

Definition at line 208 of file DDLParser.cc.

References fileNames_, and parsed_.

208  {
209  fileNames_.clear();
210  parsed_.clear();
211 }
std::map< int, bool > parsed_
Parse status of a given file.
Definition: DDLParser.h:142
FileNameHolder fileNames_
List of files to be processed, obtained from the DDLDocumentProvider.
Definition: DDLParser.h:139

◆ extractFileName()

std::string const DDLParser::extractFileName ( const std::string &  fullname)
private

Definition at line 213 of file DDLParser.cc.

Referenced by parse(), and parseOneFile().

213  {
214  return (fullname.substr(fullname.rfind('/') + 1));
215 }

◆ getDDLSAX2FileHandler()

DDLSAX2FileHandler * DDLParser::getDDLSAX2FileHandler ( void  )

To get the parent this class allows access to the handler.

In order to retrieve the name of the parent element from DDLSAX2Handlers.

Definition at line 53 of file DDLParser.cc.

References fileHandler_.

53 { return fileHandler_; }
DDLSAX2FileHandler * fileHandler_
Definition: DDLParser.h:154

◆ getNameSpace()

std::string const DDLParser::getNameSpace ( const std::string &  fname)
private

Definition at line 217 of file DDLParser.cc.

References alignmentValidation::fname, dqmiolumiharvest::j, runTheMatrix::ret, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by parse(), and parseOneFile().

217  {
218  size_t j = 0;
219  std::string ret = "";
220  while (j < fname.size() && fname[j] != '.')
221  ++j;
222  if (j < fname.size() && fname[j] == '.')
223  ret = fname.substr(0, j);
224  return ret;
225 }
ret
prodAgent to be discontinued
string fname
main script

◆ getXMLParser()

SAX2XMLReader * DDLParser::getXMLParser ( void  )

Get the SAX2Parser from the DDLParser. USE WITH CAUTION. Set your own handler, etc.

This method allows external "users" to use the current DDLParser on their own. by giving them access to the SAX2XMLReader. This may not be a good idea! The reason that I

Definition at line 51 of file DDLParser.cc.

References SAX2Parser_.

Referenced by FIPConfiguration::readConfig().

51 { return SAX2Parser_; }
SAX2XMLReader * SAX2Parser_
SAX2XMLReader is one way of parsing.
Definition: DDLParser.h:151

◆ isFound()

size_t DDLParser::isFound ( const std::string &  filename)
private

Is the file already known by the DDLParser? Returns 0 if not found, and index if found.

Definition at line 55 of file DDLParser.cc.

References corrVsCorr::filename, fileNames_, mps_fire::i, and ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it.

Referenced by isParsed(), parse(), and parseOneFile().

55  {
56  FileNameHolder::const_iterator it = fileNames_.begin();
57  size_t i = 1;
58  bool foundFile = false;
59  while (it != fileNames_.end() && !foundFile) {
60  if (it->second.first == filename) {
61  foundFile = true;
62  } else
63  ++i;
64  ++it;
65  }
66  if (foundFile)
67  return i;
68  return 0;
69 }
FileNameHolder fileNames_
List of files to be processed, obtained from the DDLDocumentProvider.
Definition: DDLParser.h:139

◆ isParsed()

bool DDLParser::isParsed ( const std::string &  filename)
private

Is the file already parsed?

Definition at line 71 of file DDLParser.cc.

References corrVsCorr::filename, newFWLiteAna::found, isFound(), and parsed_.

71  {
72  size_t found = isFound(filename);
73  if (found)
74  return parsed_[found];
75  return false;
76 }
std::map< int, bool > parsed_
Parse status of a given file.
Definition: DDLParser.h:142
size_t isFound(const std::string &filename)
Is the file already known by the DDLParser? Returns 0 if not found, and index if found.
Definition: DDLParser.cc:55

◆ parse() [1/2]

int DDLParser::parse ( const DDLDocumentProvider dp)

Parse all files. Return is meaningless.

Definition at line 123 of file DDLParser.cc.

References cms::cuda::assert(), DDLSAX2FileHandler::createDDConstants(), currFileName_, Calorimetry_cff::dp, expHandler_, extractFileName(), fileHandler_, fileNames_, getNameSpace(), mps_fire::i, isFound(), LogDebug, nFiles_, parsed_, parseFile(), SAX2Parser_, DDLSAX2Handler::setNameSpace(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by output(), and testParser().

123  {
124  edm::LogInfo("DDLParser") << "Start Parsing. Validation is set off for the time being." << std::endl;
125  // prep for pass 1 through DDD XML
126  SAX2Parser_->setFeature(XMLUni::fgSAX2CoreValidation, false);
127  SAX2Parser_->setFeature(XMLUni::fgSAX2CoreNameSpaces, false);
128 
129  // This need be only done once, so might as well to it here.
130  size_t fileIndex = 0;
131  std::vector<std::string> fullFileName;
132  const std::vector<std::string>& fileList = dp.getFileList();
133  const std::vector<std::string>& urlList = dp.getURLList();
134 
135  for (; fileIndex < fileList.size(); ++fileIndex) {
136  std::string ts = urlList[fileIndex];
137  std::string tf = fileList[fileIndex];
138  if (!ts.empty()) {
139  if (ts[ts.size() - 1] == '/') {
140  fullFileName.emplace_back(ts + tf);
141  } else {
142  fullFileName.emplace_back(ts + "/" + tf);
143  }
144  } else {
145  fullFileName.emplace_back(tf);
146  }
147  }
148 
149  for (const auto& fnit : fullFileName) {
150  size_t foundFile = isFound(extractFileName(fnit));
151 
152  if (!foundFile) {
153  pair<std::string, std::string> pss;
154  pss.first = extractFileName(fnit);
155  pss.second = fnit;
156  fileNames_[nFiles_++] = pss;
157  parsed_[nFiles_ - 1] = false;
158  }
159  }
160 
161  // Start processing the files found in the config file.
162  assert(fileNames_.size() == nFiles_);
163 
164  // PASS 1: This was added later (historically) to implement the DDD
165  // requirement for Expressions.
166 
167  SAX2Parser_->setContentHandler(expHandler_);
168  for (size_t i = 0; i < nFiles_; ++i) {
169  if (!parsed_[i]) {
170  currFileName_ = fileNames_[i].second;
172  parseFile(i);
173  }
174  }
176 
177  // PASS 2:
178 
179  SAX2Parser_->setContentHandler(fileHandler_);
180 
181  // No need to validate (regardless of user's doValidation
182  // because the files have already been validated on the first pass.
183  // This optimization suggested by Martin Liendl.
184 
185  // Process files again.
186  for (size_t i = 0; i < nFiles_; ++i) {
187  if (!parsed_[i]) {
188  currFileName_ = fileNames_[i].second;
190  parseFile(i);
191  parsed_[i] = true;
192  pair<std::string, std::string> namePair = fileNames_[i];
193  LogDebug("DDLParser") << "Completed parsing file " << namePair.second << std::endl;
194  }
195  }
196  return 0;
197 }
std::map< int, bool > parsed_
Parse status of a given file.
Definition: DDLParser.h:142
std::pair< ALIstring, ALIstring > pss
Definition: Fit.h:25
DDLSAX2FileHandler * fileHandler_
Definition: DDLParser.h:154
SAX2XMLReader * SAX2Parser_
SAX2XMLReader is one way of parsing.
Definition: DDLParser.h:151
std::string currFileName_
Which file is currently being processed.
Definition: DDLParser.h:148
FileNameHolder fileNames_
List of files to be processed, obtained from the DDLDocumentProvider.
Definition: DDLParser.h:139
assert(be >=bs)
std::string const extractFileName(const std::string &fullname)
Definition: DDLParser.cc:213
size_t isFound(const std::string &filename)
Is the file already known by the DDLParser? Returns 0 if not found, and index if found.
Definition: DDLParser.cc:55
DDLSAX2ExpressionHandler * expHandler_
Definition: DDLParser.h:155
void createDDConstants() const
creates all DDConstant from the evaluator which has been already &#39;filled&#39; in the first scan of the do...
Log< level::Info, false > LogInfo
void parseFile(const int &numtoproc)
Parse File. Just to hold some common looking code.
Definition: DDLParser.cc:199
size_t nFiles_
Number of files + 1.
Definition: DDLParser.h:145
virtual void setNameSpace(const std::string &nms)
std::string const getNameSpace(const std::string &fname)
Definition: DDLParser.cc:217
#define LogDebug(id)

◆ parse() [2/2]

void DDLParser::parse ( const std::vector< unsigned char > &  ablob,
unsigned int  bsize 
)

Definition at line 116 of file DDLParser.cc.

References DDLSAX2FileHandler::createDDConstants(), expHandler_, and SAX2Parser_.

116  {
117  char* dummy(nullptr);
118  MemBufInputSource mbis(&*ablob.begin(), bsize, dummy);
119  SAX2Parser_->parse(mbis);
121 }
SAX2XMLReader * SAX2Parser_
SAX2XMLReader is one way of parsing.
Definition: DDLParser.h:151
DDLSAX2ExpressionHandler * expHandler_
Definition: DDLParser.h:155
void createDDConstants() const
creates all DDConstant from the evaluator which has been already &#39;filled&#39; in the first scan of the do...

◆ parseFile()

void DDLParser::parseFile ( const int &  numtoproc)
private

Parse File. Just to hold some common looking code.

Definition at line 199 of file DDLParser.cc.

References currFileName_, fileNames_, alignmentValidation::fname, parsed_, SAX2Parser_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by parse(), and parseOneFile().

199  {
200  if (!parsed_[numtoproc]) {
201  const std::string& fname = fileNames_[numtoproc].second;
202 
204  SAX2Parser_->parse(currFileName_.c_str());
205  }
206 }
std::map< int, bool > parsed_
Parse status of a given file.
Definition: DDLParser.h:142
SAX2XMLReader * SAX2Parser_
SAX2XMLReader is one way of parsing.
Definition: DDLParser.h:151
std::string currFileName_
Which file is currently being processed.
Definition: DDLParser.h:148
FileNameHolder fileNames_
List of files to be processed, obtained from the DDLDocumentProvider.
Definition: DDLParser.h:139
string fname
main script

◆ parseOneFile()

bool DDLParser::parseOneFile ( const std::string &  filename)

Process a single files.

This method allows a user to add to an existing DDD by parsing a new XML file. Ideally, these would be in addition to an existing DDD configuration which was processed using Parse(...).
The idea is based on whether users decide that the configuration will only hold "standard geometry files" and that any ancillary parameter files, filters and so forth will be unknown to the main configuration file. For me, this seems to go against the principle of knowing what files are relevant because now, there is no central way to find out (externally) what XML files generate the DDD in memory.

On the other hand, if on any run, a dumpFileList is run, then the user will at least know what files were used from where in a given run.

2007-04-06: filename is now relative to src directory of checkout (or share). edm:FileInPath used internally.

Definition at line 80 of file DDLParser.cc.

References DDLSAX2FileHandler::createDDConstants(), currFileName_, expHandler_, extractFileName(), fileHandler_, corrVsCorr::filename, fileNames_, personalPlayback::fp, getNameSpace(), isFound(), LogDebug, nFiles_, parsed_, parseFile(), SAX2Parser_, DDLSAX2Handler::setNameSpace(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CompareDDCompactViews::beginRun().

80  {
82  edm::FileInPath fp(fullname);
83  std::string absoluteFileName = fp.fullPath();
84  size_t foundFile = isFound(filename);
85  if (!foundFile) {
86  pair<std::string, std::string> pss;
87  pss.first = filename;
88  pss.second = absoluteFileName; //url+filename;
89  int fIndex = nFiles_;
91  ++nFiles_;
92  parsed_[fIndex] = false;
93 
94  currFileName_ = fileNames_[fIndex].second;
95 
96  SAX2Parser_->setContentHandler(expHandler_);
98 
99  LogDebug("DDLParser") << "ParseOneFile() Parsing: " << fileNames_[fIndex].second << std::endl;
100  parseFile(fIndex);
102  // PASS 2:
103 
104  SAX2Parser_->setContentHandler(fileHandler_);
106  parseFile(fIndex);
107  parsed_[fIndex] = true;
108  } else // was found and is parsed...
109  {
110  return true;
111  }
112  return false;
113 }
std::map< int, bool > parsed_
Parse status of a given file.
Definition: DDLParser.h:142
std::pair< ALIstring, ALIstring > pss
Definition: Fit.h:25
DDLSAX2FileHandler * fileHandler_
Definition: DDLParser.h:154
SAX2XMLReader * SAX2Parser_
SAX2XMLReader is one way of parsing.
Definition: DDLParser.h:151
std::string currFileName_
Which file is currently being processed.
Definition: DDLParser.h:148
FileNameHolder fileNames_
List of files to be processed, obtained from the DDLDocumentProvider.
Definition: DDLParser.h:139
std::string const extractFileName(const std::string &fullname)
Definition: DDLParser.cc:213
size_t isFound(const std::string &filename)
Is the file already known by the DDLParser? Returns 0 if not found, and index if found.
Definition: DDLParser.cc:55
DDLSAX2ExpressionHandler * expHandler_
Definition: DDLParser.h:155
void createDDConstants() const
creates all DDConstant from the evaluator which has been already &#39;filled&#39; in the first scan of the do...
void parseFile(const int &numtoproc)
Parse File. Just to hold some common looking code.
Definition: DDLParser.cc:199
size_t nFiles_
Number of files + 1.
Definition: DDLParser.h:145
virtual void setNameSpace(const std::string &nms)
std::string const getNameSpace(const std::string &fname)
Definition: DDLParser.cc:217
#define LogDebug(id)

Member Data Documentation

◆ cpv_

DDCompactView& DDLParser::cpv_
private

reference to storage

Definition at line 136 of file DDLParser.h.

◆ currFileName_

std::string DDLParser::currFileName_
private

Which file is currently being processed.

Definition at line 148 of file DDLParser.h.

Referenced by parse(), parseFile(), and parseOneFile().

◆ elementRegistry_

DDLElementRegistry* DDLParser::elementRegistry_
private

Definition at line 153 of file DDLParser.h.

Referenced by DDLParser(), and ~DDLParser().

◆ errHandler_

DDLSAX2Handler* DDLParser::errHandler_
private

Definition at line 156 of file DDLParser.h.

Referenced by DDLParser(), and ~DDLParser().

◆ expHandler_

DDLSAX2ExpressionHandler* DDLParser::expHandler_
private

Definition at line 155 of file DDLParser.h.

Referenced by DDLParser(), parse(), parseOneFile(), and ~DDLParser().

◆ fileHandler_

DDLSAX2FileHandler* DDLParser::fileHandler_
private

Definition at line 154 of file DDLParser.h.

Referenced by DDLParser(), getDDLSAX2FileHandler(), parse(), parseOneFile(), and ~DDLParser().

◆ fileNames_

FileNameHolder DDLParser::fileNames_
private

List of files to be processed, obtained from the DDLDocumentProvider.

Definition at line 139 of file DDLParser.h.

Referenced by clearFiles(), isFound(), parse(), parseFile(), and parseOneFile().

◆ nFiles_

size_t DDLParser::nFiles_
private

Number of files + 1.

Definition at line 145 of file DDLParser.h.

Referenced by parse(), and parseOneFile().

◆ parsed_

std::map<int, bool> DDLParser::parsed_
private

Parse status of a given file.

Definition at line 142 of file DDLParser.h.

Referenced by clearFiles(), isParsed(), parse(), parseFile(), and parseOneFile().

◆ SAX2Parser_

SAX2XMLReader* DDLParser::SAX2Parser_
private

SAX2XMLReader is one way of parsing.

Definition at line 151 of file DDLParser.h.

Referenced by DDLParser(), getXMLParser(), parse(), parseFile(), and parseOneFile().