8 #include <xercesc/dom/DOM.hpp>
9 #include <xercesc/parsers/XercesDOMParser.hpp>
11 #include <xercesc/util/XMLString.hpp>
14 #include <boost/algorithm/string.hpp>
16 using namespace xercesc;
34 inline unsigned int _toUInt(XMLCh
const* toTranscode) {
35 std::istringstream iss(
_toString(toTranscode));
36 unsigned int returnValue;
41 inline bool _toBool(XMLCh
const* toTranscode) {
43 if ((value ==
"true") || (value ==
"1"))
48 inline double _toDouble(XMLCh
const* toTranscode) {
49 std::istringstream iss(
_toString(toTranscode));
56 XMLCh* buff = XMLString::transcode(temp.c_str());
62 inline std::string _toParenString(DOMNode
const& nodeToConvert) {
63 std::ostringstream oss;
65 DOMNodeList *childList = nodeToConvert.getChildNodes();
67 unsigned int numNodes = childList->getLength();
68 for (
unsigned int i = 0;
i < numNodes; ++
i) {
69 DOMNode *childNode = childList->item(
i);
70 if (childNode->getNodeType() != DOMNode::ELEMENT_NODE) {
73 DOMElement *
child =
static_cast<DOMElement *
>(childNode);
75 DOMNamedNodeMap *
attributes = child->getAttributes();
76 unsigned int numAttributes = attributes->getLength();
77 for (
unsigned int j = 0;
j < numAttributes; ++
j) {
78 DOMNode *attributeNode = attributes->item(
j);
79 if (attributeNode->getNodeType() != DOMNode::ATTRIBUTE_NODE) {
82 DOMAttr *attribute =
static_cast<DOMAttr *
>(attributeNode);
84 oss <<
"(" <<
_toString(child->getTagName()) <<
95 T& iHolder,
T const*& iPointer) {
106 const std::string SiteLocalConfigService::m_statisticsDefaultPort =
"3334";
108 SiteLocalConfigService::SiteLocalConfigService(
ParameterSet const& pset) :
109 m_url(
"/SITECONF/local/JobConfig/site-local-config.xml"),
111 m_fallbackDataCatalog(),
113 m_rfioType(
"castor"),
125 m_ttreeCacheSize(0U),
130 m_enablePrefetching(
false),
131 m_enablePrefetchingPtr(
nullptr),
134 m_statisticsDestination(),
138 char*
tmp = getenv(
"CMS_PATH");
160 if(pset.
exists(
"debugLevel")) {
179 return "file:PoolFileCatalog.xml";
184 <<
"Did not find catalog in event-data section in " <<
m_url;
196 return "file:PoolFileCatalog.xml";
207 <<
"Valid site-local-config not found at " <<
m_url;
212 <<
"Did not find frontier-connect in calib-data section in " <<
m_url;
224 while ((serverurl =
m_frontierConnect.find(
"(serverurl=", nextparen)) != std::string::npos) {
229 complexstr.append(servlet);
240 if (input.substr(0,proto.length()) == proto) {
258 if (endservlet == std::string::npos) {
259 endservlet = input.rfind(
'/', input.length());
261 std::string servlet = input.substr(startservlet, endservlet - startservlet);
262 if ((servlet !=
"") && (servlet.find_first_of(
":/)[]") == std::string::npos)) {
263 if (servlet ==
"cms_conditions_data") {
323 std::vector<std::string>
const*
328 struct addrinfo
const*
341 std::auto_ptr<XercesDOMParser>
parser(
new XercesDOMParser);
343 parser->setValidationScheme(XercesDOMParser::Val_Auto);
344 parser->setDoNamespaces(
false);
346 parser->parse(url.c_str());
347 DOMDocument*
doc = parser->getDocument();
380 DOMNodeList *
sites = doc->getElementsByTagName(
_toDOMS(
"site"));
381 unsigned int numSites = sites->getLength();
382 for (
unsigned int i = 0;
i < numSites; ++
i) {
383 DOMElement *site =
static_cast<DOMElement *
>(sites->item(
i));
390 DOMNodeList *eventDataList = site->getElementsByTagName(
_toDOMS(
"event-data"));
391 if (eventDataList->getLength() > 0) {
392 DOMElement *eventData =
static_cast<DOMElement *
>(eventDataList->item(0));
394 DOMNodeList *catalogs = eventData->getElementsByTagName(
_toDOMS(
"catalog"));
396 if (catalogs->getLength() > 0) {
397 DOMElement *
catalog =
static_cast<DOMElement *
>(catalogs->item(0));
401 if (catalogs->getLength() > 1) {
402 DOMElement *
catalog =
static_cast<DOMElement *
>(catalogs->item(1));
406 DOMNodeList* rfiotypes = eventData->getElementsByTagName(
_toDOMS(
"rfiotype"));
408 if (rfiotypes->getLength() > 0) {
409 DOMElement* rfiotype =
static_cast<DOMElement *
>(rfiotypes->item(0));
417 DOMNodeList *calibDataList = site->getElementsByTagName(
_toDOMS(
"calib-data"));
419 if (calibDataList->getLength() > 0) {
420 DOMElement *calibData =
static_cast<DOMElement *
>(calibDataList->item(0));
421 DOMNodeList *frontierConnectList = calibData->getElementsByTagName(
_toDOMS(
"frontier-connect"));
423 if (frontierConnectList->getLength() > 0) {
424 DOMElement *
frontierConnect =
static_cast<DOMElement *
>(frontierConnectList->item(0));
431 DOMNodeList *sourceConfigList = site->getElementsByTagName(
_toDOMS(
"source-config"));
433 if (sourceConfigList->getLength() > 0) {
434 DOMElement *sourceConfig =
static_cast<DOMElement *
>(sourceConfigList->item(0));
435 DOMNodeList *cacheTempDirList = sourceConfig->getElementsByTagName(
_toDOMS(
"cache-temp-dir"));
437 if (cacheTempDirList->getLength() > 0) {
438 DOMElement *cacheTempDir =
static_cast<DOMElement *
>(cacheTempDirList->item(0));
443 DOMNodeList *cacheMinFreeList = sourceConfig->getElementsByTagName(
_toDOMS(
"cache-min-free"));
445 if (cacheMinFreeList->getLength() > 0) {
446 DOMElement *cacheMinFree =
static_cast<DOMElement *
>(cacheMinFreeList->item(0));
451 DOMNodeList *cacheHintList = sourceConfig->getElementsByTagName(
_toDOMS(
"cache-hint"));
453 if (cacheHintList->getLength() > 0) {
454 DOMElement *cacheHint =
static_cast<DOMElement *
>(cacheHintList->item(0));
459 DOMNodeList *cloneCacheHintList = sourceConfig->getElementsByTagName(
_toDOMS(
"clone-cache-hint"));
461 if (cloneCacheHintList->getLength() > 0) {
462 DOMElement *cloneCacheHint =
static_cast<DOMElement *
>(cloneCacheHintList->item(0));
467 DOMNodeList *readHintList = sourceConfig->getElementsByTagName(
_toDOMS(
"read-hint"));
469 if (readHintList->getLength() > 0) {
470 DOMElement *readHint =
static_cast<DOMElement *
>(readHintList->item(0));
475 DOMNodeList *ttreeCacheSizeList = sourceConfig->getElementsByTagName(
_toDOMS(
"ttree-cache-size"));
477 if (ttreeCacheSizeList->getLength() > 0) {
478 DOMElement *ttreeCacheSize =
static_cast<DOMElement *
>(ttreeCacheSizeList->item(0));
483 DOMNodeList *timeoutList = sourceConfig->getElementsByTagName(
_toDOMS(
"timeout-in-seconds"));
485 if (timeoutList->getLength() > 0) {
486 DOMElement *timeout =
static_cast<DOMElement *
>(timeoutList->item(0));
491 DOMNodeList *statsDestList = sourceConfig->getElementsByTagName(
_toDOMS(
"statistics-destination"));
493 if (statsDestList->getLength() > 0) {
494 DOMElement *statsDest =
static_cast<DOMElement *
>(statsDestList->item(0));
498 DOMNodeList *prefetchingList = sourceConfig->getElementsByTagName(
_toDOMS(
"prefetching"));
500 if (prefetchingList->getLength() > 0) {
501 DOMElement *prefetching =
static_cast<DOMElement *
>(prefetchingList->item(0));
506 DOMNodeList *nativeProtocolsList = sourceConfig->getElementsByTagName(
_toDOMS(
"native-protocols"));
508 if (nativeProtocolsList->getLength() > 0) {
509 DOMElement *nativeProtocol =
static_cast<DOMElement *
>(nativeProtocolsList->item(0));
510 DOMNodeList *childList = nativeProtocol->getChildNodes();
512 XMLCh* prefixXMLCh =
_toDOMS(
"prefix");
513 unsigned int numNodes = childList->getLength();
514 for (
unsigned int i = 0;
i < numNodes; ++
i) {
515 DOMNode *childNode = childList->item(
i);
516 if (childNode->getNodeType() != DOMNode::ELEMENT_NODE) {
519 DOMElement *child =
static_cast<DOMElement *
>(childNode);
529 catch (xercesc::DOMException
const&
e) {
535 std::vector<std::string> inputStrings;
539 struct addrinfo *res;
540 struct addrinfo hints;
541 memset(&hints,
'\0',
sizeof(hints));
542 hints.ai_socktype = SOCK_DGRAM;
543 hints.ai_flags = AI_ADDRCONFIG;
544 hints.ai_family = AF_UNSPEC;
545 int e = getaddrinfo(host.c_str(), port.c_str(), &hints, &res);
556 desc.
setComment(
"Service to translate logical file names to physical file names.");
562 ->setComment(
"Provide an alternate cache hint for fast cloning.");
569 ->setComment(
"Request ROOT to asynchronously prefetch I/O during computation.");
571 ->setComment(
"Provide an alternate network destination for I/O statistics (must be in the form of host:port).");
573 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
std::string const * m_cloneCacheHintPtr
double const * sourceCacheMinFree() const
static const std::string m_statisticsDefaultPort
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_cloneCacheHint
struct addrinfo const * statisticsDestination() const
std::string m_cacheTempDir
unsigned int m_ttreeCacheSize
std::string const & siteName() const
std::vector< std::string > const * m_nativeProtocolsPtr
static std::string const input
std::string const lookupCalibConnect(std::string const &input) const
~SiteLocalConfigService()
void setComment(std::string const &value)
struct addrinfo * m_statisticsAddrInfo
std::string m_statisticsDestination
std::string const * sourceCacheHint() const
bool const * m_enablePrefetchingPtr
unsigned int m_debugLevel
std::string const * sourceReadHint() const
std::string const * sourceCloneCacheHint() const override
std::vector< std::string > m_nativeProtocols
unsigned int debugLevel() const
std::string const * m_cacheHintPtr
std::string const * m_readHintPtr
void computeStatisticsDestination()
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)
volatile std::atomic< bool > shutdown_flag false
std::string const frontierConnect(std::string const &servlet) const
std::vector< std::string > const * sourceNativeProtocols() const
unsigned int const * sourceTTreeCacheSize() const
bool enablePrefetching() const
std::string m_dataCatalog