8 #include <xercesc/dom/DOM.hpp>
9 #include <xercesc/parsers/XercesDOMParser.hpp>
10 #include <xercesc/util/PlatformUtils.hpp>
11 #include <xercesc/util/XMLString.hpp>
15 using namespace xercesc;
28 inline std::string
_toString(XMLCh
const* toTranscode) {
29 std::string
tmp(XMLString::transcode(toTranscode));
33 inline unsigned int _toUInt(XMLCh
const* toTranscode) {
34 std::istringstream iss(
_toString(toTranscode));
35 unsigned int returnValue;
40 inline double _toDouble(XMLCh
const* toTranscode) {
41 std::istringstream iss(
_toString(toTranscode));
48 XMLCh* buff = XMLString::transcode(temp.c_str());
54 inline std::string _toParenString(DOMNode
const& nodeToConvert) {
55 std::ostringstream oss;
57 DOMNodeList *childList = nodeToConvert.getChildNodes();
59 unsigned int numNodes = childList->getLength();
60 for (
unsigned int i = 0;
i < numNodes; ++
i) {
61 DOMNode *childNode = childList->item(
i);
62 if (childNode->getNodeType() != DOMNode::ELEMENT_NODE) {
65 DOMElement *
child =
static_cast<DOMElement *
>(childNode);
67 DOMNamedNodeMap *
attributes = child->getAttributes();
68 unsigned int numAttributes = attributes->getLength();
69 for (
unsigned int j = 0;
j < numAttributes; ++
j) {
70 DOMNode *attributeNode = attributes->item(
j);
71 if (attributeNode->getNodeType() != DOMNode::ATTRIBUTE_NODE) {
74 DOMAttr *attribute =
static_cast<DOMAttr *
>(attributeNode);
76 oss <<
"(" <<
_toString(child->getTagName()) <<
87 T& iHolder,
T const*& iPointer) {
97 SiteLocalConfigService::SiteLocalConfigService(
ParameterSet const& pset) :
98 m_url(
"/SITECONF/local/JobConfig/site-local-config.xml"),
100 m_fallbackDataCatalog(),
102 m_rfioType(
"castor"),
105 m_cacheTempDirPtr(0),
107 m_cacheMinFreePtr(0),
112 m_ttreeCacheSize(0U),
113 m_ttreeCacheSizePtr(0),
118 m_nativeProtocolsPtr(0) {
120 char*
tmp = getenv(
"CMS_PATH");
137 if(pset.
exists(
"debugLevel")) {
149 return "file:PoolFileCatalog.xml";
154 <<
"Did not find catalog in event-data section in " <<
m_url;
166 return "file:PoolFileCatalog.xml";
177 <<
"Valid site-local-config not found at " <<
m_url;
182 <<
"Did not find frontier-connect in calib-data section in " <<
m_url;
193 std::string complexstr =
"";
194 while ((serverurl =
m_frontierConnect.find(
"(serverurl=", nextparen)) != std::string::npos) {
199 complexstr.append(servlet);
208 static std::string
const proto =
"frontier://";
210 if (input.substr(0,proto.length()) == proto) {
228 if (endservlet == std::string::npos) {
229 endservlet = input.rfind(
'/', input.length());
231 std::string servlet = input.substr(startservlet, endservlet - startservlet);
232 if ((servlet !=
"") && (servlet.find_first_of(
":/)[]") == std::string::npos)) {
233 if (servlet ==
"cms_conditions_data") {
283 std::vector<std::string>
const*
290 XMLPlatformUtils::Initialize();
291 std::auto_ptr<XercesDOMParser>
parser(
new XercesDOMParser);
293 parser->setValidationScheme(XercesDOMParser::Val_Auto);
294 parser->setDoNamespaces(
false);
296 parser->parse(url.c_str());
297 DOMDocument*
doc = parser->getDocument();
330 DOMNodeList *sites = doc->getElementsByTagName(
_toDOMS(
"site"));
331 unsigned int numSites = sites->getLength();
332 for (
unsigned int i = 0;
i < numSites; ++
i) {
333 DOMElement *site =
static_cast<DOMElement *
>(sites->item(
i));
337 DOMNodeList *eventDataList = site->getElementsByTagName(
_toDOMS(
"event-data"));
338 if (eventDataList->getLength() > 0) {
339 DOMElement *eventData =
static_cast<DOMElement *
>(eventDataList->item(0));
341 DOMNodeList *catalogs = eventData->getElementsByTagName(
_toDOMS(
"catalog"));
343 if (catalogs->getLength() > 0) {
344 DOMElement *
catalog =
static_cast<DOMElement *
>(catalogs->item(0));
348 if (catalogs->getLength() > 1) {
349 DOMElement *
catalog =
static_cast<DOMElement *
>(catalogs->item(1));
353 DOMNodeList* rfiotypes = eventData->getElementsByTagName(
_toDOMS(
"rfiotype"));
355 if (rfiotypes->getLength() > 0) {
356 DOMElement* rfiotype =
static_cast<DOMElement *
>(rfiotypes->item(0));
364 DOMNodeList *calibDataList = site->getElementsByTagName(
_toDOMS(
"calib-data"));
366 if (calibDataList->getLength() > 0) {
367 DOMElement *calibData =
static_cast<DOMElement *
>(calibDataList->item(0));
368 DOMNodeList *frontierConnectList = calibData->getElementsByTagName(
_toDOMS(
"frontier-connect"));
370 if (frontierConnectList->getLength() > 0) {
371 DOMElement *
frontierConnect =
static_cast<DOMElement *
>(frontierConnectList->item(0));
378 DOMNodeList *sourceConfigList = site->getElementsByTagName(
_toDOMS(
"source-config"));
380 if (sourceConfigList->getLength() > 0) {
381 DOMElement *sourceConfig =
static_cast<DOMElement *
>(sourceConfigList->item(0));
382 DOMNodeList *cacheTempDirList = sourceConfig->getElementsByTagName(
_toDOMS(
"cache-temp-dir"));
384 if (cacheTempDirList->getLength() > 0) {
385 DOMElement *cacheTempDir =
static_cast<DOMElement *
>(cacheTempDirList->item(0));
390 DOMNodeList *cacheMinFreeList = sourceConfig->getElementsByTagName(
_toDOMS(
"cache-min-free"));
392 if (cacheMinFreeList->getLength() > 0) {
393 DOMElement *cacheMinFree =
static_cast<DOMElement *
>(cacheMinFreeList->item(0));
398 DOMNodeList *cacheHintList = sourceConfig->getElementsByTagName(
_toDOMS(
"cache-hint"));
400 if (cacheHintList->getLength() > 0) {
401 DOMElement *cacheHint =
static_cast<DOMElement *
>(cacheHintList->item(0));
406 DOMNodeList *readHintList = sourceConfig->getElementsByTagName(
_toDOMS(
"read-hint"));
408 if (readHintList->getLength() > 0) {
409 DOMElement *readHint =
static_cast<DOMElement *
>(readHintList->item(0));
414 DOMNodeList *ttreeCacheSizeList = sourceConfig->getElementsByTagName(
_toDOMS(
"ttree-cache-size"));
416 if (ttreeCacheSizeList->getLength() > 0) {
417 DOMElement *ttreeCacheSize =
static_cast<DOMElement *
>(ttreeCacheSizeList->item(0));
422 DOMNodeList *timeoutList = sourceConfig->getElementsByTagName(
_toDOMS(
"timeout-in-seconds"));
424 if (timeoutList->getLength() > 0) {
425 DOMElement *timeout =
static_cast<DOMElement *
>(timeoutList->item(0));
430 DOMNodeList *nativeProtocolsList = sourceConfig->getElementsByTagName(
_toDOMS(
"native-protocols"));
432 if (nativeProtocolsList->getLength() > 0) {
433 DOMElement *nativeProtocol =
static_cast<DOMElement *
>(nativeProtocolsList->item(0));
434 DOMNodeList *childList = nativeProtocol->getChildNodes();
436 XMLCh* prefixXMLCh =
_toDOMS(
"prefix");
437 unsigned int numNodes = childList->getLength();
438 for (
unsigned int i = 0;
i < numNodes; ++
i) {
439 DOMNode *childNode = childList->item(
i);
440 if (childNode->getNodeType() != DOMNode::ELEMENT_NODE) {
443 DOMElement *child =
static_cast<DOMElement *
>(childNode);
453 catch (xercesc::DOMException
const&
e) {
460 desc.
setComment(
"Service to translate logical file names to physical file names.");
471 descriptions.
add(
"SiteLocalConfigService", desc);
unsigned int const * m_timeoutPtr
std::string const fallbackDataCatalog(void) const
T getUntrackedParameter(std::string const &, T const &) const
std::string const * m_cacheTempDirPtr
std::string m_frontierConnect
void parse(std::string const &url)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
std::string m_fallbackDataCatalog
std::string const rfioType(void) const
double const * m_cacheMinFreePtr
double const * sourceCacheMinFree() const
std::string _toString(const XMLCh *toTranscode)
std::string const dataCatalog(void) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string m_cacheTempDir
unsigned int m_ttreeCacheSize
std::vector< std::string > const * m_nativeProtocolsPtr
std::string const lookupCalibConnect(std::string const &input) const
void setComment(std::string const &value)
std::string const * sourceCacheHint() const
unsigned int m_debugLevel
std::string const * sourceReadHint() const
std::vector< std::string > m_nativeProtocols
unsigned int debugLevel() const
std::string const * m_cacheHintPtr
std::string const * m_readHintPtr
unsigned int const * m_ttreeCacheSizePtr
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::string const * sourceCacheTempDir() const
std::vector< std::vector< double > > tmp
XMLCh * _toDOMS(std::string temp)
unsigned int const * sourceTimeout() const
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
std::string const frontierConnect(std::string const &servlet) const
std::vector< std::string > const * sourceNativeProtocols() const
unsigned int const * sourceTTreeCacheSize() const
std::string m_dataCatalog