#include <DetectorDescription/Parser/interface/DDLParser.h>
Public Types | |
typedef std::map< int, std::pair< std::string, std::string > > | FileNameHolder |
typedef xercesc_2_7::SAX2XMLReader | SAX2XMLReader |
Public Member Functions | |
void | dumpFileList (std::ostream &co) |
void | dumpFileList () |
Print out the list of files. | |
std::string | getCurrFileName () |
Report which file currently being processed (or last processed). | |
DDLSAX2FileHandler * | getDDLSAX2FileHandler () |
To get the parent this class allows access to the handler. | |
std::vector< std::string > | getFileList () |
Return list of files. | |
SAX2XMLReader * | getXMLParser () |
Get the SAX2Parser from the DDLParser. USE WITH CAUTION. Set your own handler, etc. | |
size_t | isFound (const std::string &filename) |
Is the file already known by the DDLParser? Returns 0 if not found, and index if found. | |
bool | isParsed (const std::string &filename) |
Is the file already parsed? | |
int | parse (const DDLDocumentProvider &dp) |
Parse all files. FIX - After deprecated stuff removed, make this void. | |
bool | parseOneFile (const std::string &filename) |
Process a single files. | |
~DDLParser () | |
Destructor terminates the XMLPlatformUtils (as required by Xerces). | |
Static Public Member Functions | |
static DDLParser * | instance () |
static void | setInstance (DDLParser *p) |
Protected Member Functions | |
DDLParser () | |
unique (and default) constructor | |
void | parseFile (const int &numtoproc) |
Parse File. Just to hold some common looking code. | |
Private Attributes | |
std::string | configFileName_ |
Configuration file name. Only necessary until deprecated methods removed. | |
std::string | currFileName_ |
Which file is currently being processed. | |
DDLSAX2Handler * | errHandler_ |
DDLSAX2ExpressionHandler * | expHandler_ |
DDLSAX2FileHandler * | fileHandler_ |
FileNameHolder | fileNames_ |
List of files to be processed, obtained from the DDLDocumentProvider. | |
int | nFiles_ |
Number of files + 1. | |
std::map< int, bool > | parsed_ |
Parse status of a given file. | |
SAX2XMLReader * | SAX2Parser_ |
SAX2XMLReader is one way of parsing. | |
Static Private Attributes | |
static DDLParser * | instance_ = 0 |
For Singleton behavior. |
DDLParser.h - description ------------------- begin: Mon Oct 22 2001 email: case@ucdhep.ucdavis.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 (DDLConfiguration) the 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.
Definition at line 58 of file DDLParser.h.
typedef std::map< int, std::pair<std::string, std::string> > DDLParser::FileNameHolder |
Definition at line 64 of file DDLParser.h.
typedef xercesc_2_7::SAX2XMLReader DDLParser::SAX2XMLReader |
Definition at line 62 of file DDLParser.h.
DDLParser::DDLParser | ( | ) | [protected] |
unique (and default) constructor
Constructor initializes XMLPlatformUtils (as required by Xerces.
Definition at line 67 of file DDLParser.cc.
References AlgoInit(), DCOUT_V, errHandler_, expHandler_, fileHandler_, and SAX2Parser_.
Referenced by instance().
00067 : nFiles_(0) 00068 { 00069 // Initialize the XML4C2 system 00070 00071 // in cleaning up try-catch blocks 2007-06-26 I decided to remove 00072 // this because of CMSSW rules. but keep the commented way I used to 00073 // do it... 00074 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! try 00075 // { 00076 XMLPlatformUtils::Initialize(); 00077 AlgoInit(); 00078 // } 00079 00080 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! catch (const XMLException& toCatch) 00081 // { 00082 // std::string e("\nDDLParser(): Error during initialization! Message:"); 00083 // e += std::string(StrX(toCatch.getMessage()).localForm()) + std::string ("\n"); 00084 // throw (DDException(e)); 00085 // } 00086 00087 SAX2Parser_ = XMLReaderFactory::createXMLReader(); 00088 00089 SAX2Parser_->setFeature(XMLUni::fgSAX2CoreValidation, false); // optional 00090 SAX2Parser_->setFeature(XMLUni::fgSAX2CoreNameSpaces, false); // optional 00091 // Specify other parser features, e.g. 00092 // SAX2Parser_->setFeature(XMLUni::fgXercesSchemaFullChecking, false); 00093 00094 expHandler_ = new DDLSAX2ExpressionHandler; 00095 fileHandler_ = new DDLSAX2FileHandler; 00096 errHandler_ = new DDLSAX2Handler; 00097 SAX2Parser_->setErrorHandler(errHandler_); 00098 SAX2Parser_->setContentHandler(fileHandler_); 00099 00100 // edm::LogInfo ("DDLParser") << "created SAX2XMLReader at memory " << SAX2Parser_ << std::endl; 00101 00102 DCOUT_V('P', "DDLParser::DDLParser(): new (and only) DDLParser"); 00103 }
DDLParser::~DDLParser | ( | ) |
Destructor terminates the XMLPlatformUtils (as required by Xerces).
Definition at line 59 of file DDLParser.cc.
References DCOUT_V.
00060 { 00061 // clean up and leave 00062 XMLPlatformUtils::Terminate(); 00063 DCOUT_V('P', "DDLParser::~DDLParser(): destruct DDLParser"); 00064 }
void DDLParser::dumpFileList | ( | std::ostream & | co | ) |
Print out the list of files.
Definition at line 238 of file DDLParser.cc.
References lat::endl(), fileNames_, and it.
00238 { 00239 edm::LogInfo ("DDLParser") << "File List:" << std::endl; 00240 for (FileNameHolder::const_iterator it = fileNames_.begin(); it != fileNames_.end(); ++it) 00241 edm::LogInfo ("DDLParser") << it->second.second << std::endl; 00242 }
std::string DDLParser::getCurrFileName | ( | ) |
Report which file currently being processed (or last processed).
Definition at line 410 of file DDLParser.cc.
References currFileName_.
Referenced by DDLSAX2FileHandler::endElement(), DDLSAX2ExpressionHandler::startElement(), DDLSAX2FileHandler::startElement(), and DDXMLElement::throwError().
00411 { 00412 return currFileName_; 00413 }
DDLSAX2FileHandler * DDLParser::getDDLSAX2FileHandler | ( | ) |
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 129 of file DDLParser.cc.
References fileHandler_.
Referenced by DDXMLElement::parent(), and DDXMLElement::throwError().
00129 { 00130 return fileHandler_; 00131 }
std::vector< std::string > DDLParser::getFileList | ( | void | ) |
Return list of files.
Definition at line 228 of file DDLParser.cc.
References fileNames_.
00229 { 00230 std::vector<std::string> flist; 00231 for (FileNameHolder::const_iterator fit = fileNames_.begin(); fit != fileNames_.end(); ++fit) 00232 { 00233 flist.push_back(fit->second.first); // was .second (mec: 2003:02:19 00234 } 00235 return flist; 00236 }
SAX2XMLReader * DDLParser::getXMLParser | ( | ) |
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.
I wanted to do this for the DDLConfiguration to do the parsing separately. Since these two classes are so connected I wonder if I should remove this, make DDLConfiguration a friend of this guy and let it access the SAX2XMLReader directly. FIX: Maybe Configuration should handle its own parser? Maybe I should destroy the parser and remake it as needed, this way validation can be turned on for the DDL after the CDL says what should be done.
by giving them access to the SAX2XMLReader. This may not be a good idea! The reason that I
Definition at line 127 of file DDLParser.cc.
References SAX2Parser_.
Referenced by FIPConfiguration::readConfig().
00127 { return SAX2Parser_; }
DDLParser * DDLParser::instance | ( | ) | [static] |
Definition at line 113 of file DDLParser.cc.
References DDLParser(), and instance_.
Referenced by DDLSAX2FileHandler::endElement(), FIPConfiguration::FIPConfiguration(), DDXMLElement::parent(), DDLSAX2ExpressionHandler::startElement(), DDLSAX2FileHandler::startElement(), testParser(), DDXMLElement::throwError(), and XMLIdealGeometryESSource::XMLIdealGeometryESSource().
00114 { 00115 00116 if ( instance_ == 0 ) { 00117 instance_ = new DDLParser(); 00118 } 00119 00120 return instance_; 00121 }
size_t DDLParser::isFound | ( | const std::string & | filename | ) |
Is the file already known by the DDLParser? Returns 0 if not found, and index if found.
Definition at line 133 of file DDLParser.cc.
References fileNames_, i, and it.
Referenced by isParsed(), parse(), and parseOneFile().
00134 { 00135 FileNameHolder::const_iterator it = fileNames_.begin(); 00136 size_t i = 1; 00137 bool foundFile = false; 00138 while (it != fileNames_.end() && !foundFile) // for (; it != fileNames_.end(); ++it) 00139 { 00140 if (it->second.first == filename) 00141 { 00142 foundFile = true; 00143 } 00144 else ++i; 00145 ++it; 00146 } 00147 if (foundFile) 00148 return i; 00149 return 0; 00150 }
bool DDLParser::isParsed | ( | const std::string & | filename | ) |
int DDLParser::parse | ( | const DDLDocumentProvider & | dp | ) |
Parse all files. FIX - After deprecated stuff removed, make this void.
Definition at line 250 of file DDLParser.cc.
References DCOUT, DDLDocumentProvider::doValidation(), DDLSAX2FileHandler::dumpElementTypeCounter(), expHandler_, DDLSAX2FileHandler::extractFileName(), fileHandler_, edm::fileIndex, fileNames_, DDLDocumentProvider::getFileList(), DDLDocumentProvider::getURLList(), i, isFound(), LogDebug, nFiles_, parsed_, parseFile(), SAX2Parser_, and size.
Referenced by testParser(), and XMLIdealGeometryESSource::XMLIdealGeometryESSource().
00251 { 00252 // edm::LogInfo ("DDLParser") << "Start Parsing. Validation is set to " << dp.doValidation() << "." << std::endl; 00253 edm::LogInfo ("DDLParser") << "Start Parsing. Validation is set off for the time being." << std::endl; 00254 // prep for pass 1 through DDD XML 00255 // // Since this block does nothing for CMSSW right now, I have taken it all out 00256 // This clean-up involves interface changes such as the removal of doValidation() everywhere (OR NOT 00257 // if I decide to keep it for other testing reasons.) 00258 if (dp.doValidation()) 00259 { 00260 // DCOUT_V('P', "WARNING: PARSER VALIDATION IS TURNED OFF REGARDLESS OF <Schema... ELEMENT"); 00261 SAX2Parser_->setFeature(XMLUni::fgSAX2CoreValidation, true); 00262 SAX2Parser_->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); 00263 // // SAX2Parser_->setFeature(XMLUni::fgXercesSchemaFullChecking, true); 00264 } 00265 else 00266 // { 00267 SAX2Parser_->setFeature(XMLUni::fgSAX2CoreValidation, false); 00268 SAX2Parser_->setFeature(XMLUni::fgSAX2CoreNameSpaces, false); 00269 // // SAX2Parser_->setFeature(XMLUni::fgXercesSchemaFullChecking, false); 00270 00271 // } 00272 00273 // This need be only done once, so might as well to it here. 00274 size_t fileIndex = 0; 00275 std::vector<std::string> fullFileName; 00276 00277 for (; fileIndex < (dp.getFileList()).size(); ++fileIndex) 00278 { 00279 std::string ts = dp.getURLList()[fileIndex]; 00280 std::string tf = dp.getFileList()[fileIndex]; 00281 if ( ts.size() > 0 ) { 00282 if ( ts[ts.size() - 1] == '/') { 00283 fullFileName.push_back( ts + tf ); 00284 } else { 00285 fullFileName.push_back( ts + "/" + tf ); 00286 } 00287 } else { 00288 fullFileName.push_back( tf ); 00289 } 00290 } 00291 00292 for (std::vector<std::string>::const_iterator fnit = fullFileName.begin(); 00293 fnit != fullFileName.end(); 00294 ++fnit) 00295 { 00296 size_t foundFile = isFound(expHandler_->extractFileName( *fnit )); 00297 00298 if (!foundFile) 00299 { 00300 pair <std::string, std::string> pss; 00301 pss.first = expHandler_->extractFileName( *fnit ); 00302 pss.second = *fnit; 00303 fileNames_[nFiles_++] = pss; 00304 parsed_[nFiles_ - 1]=false; 00305 } 00306 } 00307 00308 // Start processing the files found in the config file. 00309 00310 // PASS 1: This was added later (historically) to implement the DDD 00311 // requirement for Expressions. 00312 DCOUT('P', "DDLParser::parse(): PASS1: Just before setting Xerces content and error handlers... "); 00313 00314 00315 // in cleaning up try-catch blocks 2007-06-26 I decided to remove 00316 // this because of CMSSW rules. but keep the commented way I used to 00317 // do it... 00318 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! try 00319 // { 00320 SAX2Parser_->setContentHandler(expHandler_); 00321 for (size_t i = 0; i < fileNames_.size(); ++i) 00322 { 00323 // seal::SealTimer t("DDLParser: parsing expressions of file " +fileNames_[i].first); 00324 if (!parsed_[i]) 00325 { 00326 parseFile(i); 00327 } 00328 } 00329 expHandler_->dumpElementTypeCounter(); 00330 // } 00331 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! catch (const XMLException& toCatch) { 00332 // edm::LogInfo ("DDLParser") << "\nPASS1: XMLException while processing files... \n" 00333 // << "Exception message is: \n" 00334 // << StrX(toCatch.getMessage()) << "\n" ; 00335 // XMLPlatformUtils::Terminate(); 00336 // // FIX use this after DEPRECATED stuff removed: throw(DDException("See XML Exception above")); 00337 // return -1; 00338 // } 00339 // PASS 2: 00340 00341 DCOUT('P', "DDLParser::parse(): PASS2: Just before setting Xerces content and error handlers... "); 00342 00343 // in cleaning up try-catch blocks 2007-06-26 I decided to remove 00344 // this because of CMSSW rules. but keep the commented way I used to 00345 // do it... 00346 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! try 00347 // { 00348 SAX2Parser_->setContentHandler(fileHandler_); 00349 00350 // No need to validate (regardless of user's doValidation 00351 // because the files have already been validated on the first pass. 00352 // This optimization suggested by Martin Liendl. 00353 // SAX2Parser_->setFeature(StrX("https://xml.org/sax/features/validation"), false); // optional 00354 // SAX2Parser_->setFeature(StrX("https://xml.org/sax/features/namespaces"), false); // optional 00355 // SAX2Parser_->setFeature(StrX("https://apache.org/xml/features/validation/dynamic"), false); 00356 00357 00358 // Process files again. 00359 for (size_t i = 0; i < fileNames_.size(); ++i) 00360 { 00361 // seal::SealTimer t("DDLParser: parsing all elements of file " +fileNames_[i].first); 00362 parseFile(i); 00363 parsed_[i] = true; 00364 pair<std::string, std::string> namePair = fileNames_[i]; 00365 LogDebug ("DDLParser") << "Completed parsing file " << namePair.second << std::endl; 00366 } 00367 // } 00368 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! catch (const XMLException& toCatch) { 00369 // edm::LogError ("DDLParser") << "\nPASS2: XMLException while processing files... \n" 00370 // << "Exception message is: \n" 00371 // << StrX(toCatch.getMessage()) << "\n" ; 00372 // XMLPlatformUtils::Terminate(); 00373 // return -1; 00374 // } 00375 return 0; 00376 }
Parse File. Just to hold some common looking code.
Definition at line 378 of file DDLParser.cc.
References currFileName_, DCOUT, fileNames_, first, mergeAndRegister_online::fname, parsed_, SAX2Parser_, and edm::second().
Referenced by parse(), and parseOneFile().
00379 { 00380 00381 if (!parsed_[numtoproc]) 00382 { 00383 const std::string & fname = fileNames_[numtoproc].second; 00384 00385 // in cleaning up try-catch blocks 2007-06-26 I decided to remove 00386 // this because of CMSSW rules. but keep the commented way I used to 00387 // do it... 00388 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! try 00389 // { 00390 currFileName_ = fname; 00391 SAX2Parser_->parse(currFileName_.c_str()); 00392 // } 00393 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! catch (const XMLException& toCatch) 00394 // { 00395 // std::string e("\nWARNING: DDLParser::parseFile, File: '"); 00396 // e += currFileName_ + "'\n" 00397 // + "Exception message is: \n" 00398 // + std::string(StrX(toCatch.getMessage()).localForm()) + "\n"; 00399 // throw(DDException(e)); 00400 // } 00401 } 00402 else 00403 { 00404 DCOUT('P', "\nWARNING: File " + fileNames_[numtoproc].first 00405 + " has already been processed as " + fileNames_[numtoproc].second); 00406 } 00407 }
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 160 of file DDLParser.cc.
References currFileName_, DCOUT, DCOUT_V, lat::endl(), expHandler_, DDLSAX2FileHandler::extractFileName(), fileHandler_, EgammaValidation_cff::filename, fileNames_, edm::FileInPath::fullPath(), isFound(), LogDebug, nFiles_, parsed_, parseFile(), SAX2Parser_, and edm::second().
00161 { 00162 00163 std::string filename = expHandler_->extractFileName(fullname); 00164 edm::FileInPath fp(fullname); 00165 std::string absoluteFileName = fp.fullPath(); 00166 size_t foundFile = isFound(filename); 00167 if (!foundFile) 00168 { 00169 int fIndex = foundFile; 00170 pair <std::string, std::string> pss; 00171 pss.first = filename; 00172 pss.second = absoluteFileName; //url+filename; 00173 fIndex = nFiles_; 00174 fileNames_[nFiles_] = pss; 00175 ++nFiles_; 00176 parsed_[fIndex]=false; 00177 00178 currFileName_ = fileNames_[fIndex].second; 00179 00180 // in cleaning up try-catch blocks 2007-06-26 I decided to remove 00181 // this because of CMSSW rules. but keep the commented way I used to 00182 // do it... 00183 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! try 00184 // { 00185 SAX2Parser_->setContentHandler(expHandler_); 00186 LogDebug ("DDLParser") << "ParseOneFile() Parsing: " << fileNames_[fIndex].second << std::endl; 00187 parseFile ( fIndex ); 00188 00189 // } 00190 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! catch (const XMLException& toCatch) { 00191 // edm::LogError ("DDLParser") << "\nDDLParser::ParseOneFile, PASS1: XMLException while processing files... \n" 00192 // << "Exception message is: \n" 00193 // << StrX(toCatch.getMessage()) << "\n" ; 00194 // XMLPlatformUtils::Terminate(); 00195 // throw (DDException(" See XMLException above. ")); 00196 // } 00197 00198 // PASS 2: 00199 00200 DCOUT_V('P', "DDLParser::ParseOneFile(): PASS2: Just before setting Xerces content and error handlers... "); 00201 00202 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! try 00203 // { 00204 00205 SAX2Parser_->setContentHandler(fileHandler_); 00206 00207 parseFile ( fIndex ); 00208 parsed_[fIndex] = true; 00209 00210 // } 00211 // DO NOT UNCOMMENT FOR ANY RELEASE; ONLY FOR DEBUGGING! catch (const XMLException& toCatch) { 00212 // edm::LogError ("DDLParser") << "\nDDLParser::ParseOneFile, PASS2: XMLException while processing files... \n" 00213 // << "Exception message is: \n" 00214 // << StrX(toCatch.getMessage()) << "\n" ; 00215 // XMLPlatformUtils::Terminate(); 00216 // throw (DDException(" See XMLException above.")); 00217 // } 00218 } 00219 else // was found and is parsed... 00220 { 00221 DCOUT('P', " WARNING: DDLParser::ParseOneFile() file " + filename 00222 + " was already parsed as " + fileNames_[foundFile].second); 00223 return true; 00224 } 00225 return false; 00226 }
std::string DDLParser::configFileName_ [private] |
Configuration file name. Only necessary until deprecated methods removed.
Definition at line 155 of file DDLParser.h.
std::string DDLParser::currFileName_ [private] |
Which file is currently being processed.
Definition at line 158 of file DDLParser.h.
Referenced by getCurrFileName(), parseFile(), and parseOneFile().
DDLSAX2Handler* DDLParser::errHandler_ [private] |
DDLSAX2ExpressionHandler* DDLParser::expHandler_ [private] |
DDLSAX2FileHandler* DDLParser::fileHandler_ [private] |
Definition at line 163 of file DDLParser.h.
Referenced by DDLParser(), getDDLSAX2FileHandler(), parse(), and parseOneFile().
FileNameHolder DDLParser::fileNames_ [private] |
List of files to be processed, obtained from the DDLDocumentProvider.
Definition at line 146 of file DDLParser.h.
Referenced by dumpFileList(), getFileList(), isFound(), parse(), parseFile(), and parseOneFile().
DDLParser * DDLParser::instance_ = 0 [static, private] |
int DDLParser::nFiles_ [private] |
Number of files + 1.
Definition at line 152 of file DDLParser.h.
Referenced by parse(), and parseOneFile().
std::map<int, bool> DDLParser::parsed_ [private] |
Parse status of a given file.
Definition at line 149 of file DDLParser.h.
Referenced by isParsed(), parse(), parseFile(), and parseOneFile().
SAX2XMLReader* DDLParser::SAX2Parser_ [private] |
SAX2XMLReader is one way of parsing.
Definition at line 161 of file DDLParser.h.
Referenced by DDLParser(), getXMLParser(), parse(), parseFile(), and parseOneFile().