17 #include <boost/algorithm/string.hpp>
33 inline std::string _toParenString(tinyxml2::XMLElement
const &nodeToConvert) {
34 std::ostringstream oss;
36 for (
auto child = nodeToConvert.FirstChildElement();
child !=
nullptr;
child =
child->NextSiblingElement()) {
37 for (
auto attribute =
child->FirstAttribute(); attribute !=
nullptr; attribute = attribute->Next()) {
38 oss <<
"(" <<
child->Name() << attribute->Name() <<
"=" << attribute->Value() <<
")";
45 static void overrideFromPSet(
char const *iName,
edm::ParameterSet const &iPSet,
T &iHolder,
T const *&iPointer) {
53 const char *safe(
const char *iCheck) {
54 if (iCheck ==
nullptr) {
62 const char *
tmp = std::getenv(
"CMS_PATH");
66 returnValue +=
"/SITECONF/local/JobConfig/site-local-config.xml";
78 : m_url(
pset.getUntrackedParameter<
std::
string>(
"siteLocalConfigFileUrl", defaultURL())),
84 m_cacheTempDirPtr(nullptr),
86 m_cacheMinFreePtr(nullptr),
88 m_cacheHintPtr(nullptr),
90 m_cloneCacheHintPtr(nullptr),
92 m_readHintPtr(nullptr),
94 m_ttreeCacheSizePtr(nullptr),
96 m_timeoutPtr(nullptr),
98 m_enablePrefetching(
false),
99 m_enablePrefetchingPtr(nullptr),
101 m_nativeProtocolsPtr(nullptr),
102 m_statisticsDestination(),
103 m_statisticsAddrInfo(nullptr),
104 m_statisticsInfoAvail(
false),
121 std::vector<std::string> tmpStatisticsInfo;
122 std::vector<std::string>
const *tmpStatisticsInfoPtr =
nullptr;
123 overrideFromPSet(
"overrideStatisticsInfo",
pset, tmpStatisticsInfo, tmpStatisticsInfoPtr);
124 if (tmpStatisticsInfoPtr) {
127 for (
auto &
entry : tmpStatisticsInfo) {
132 if (
pset.exists(
"debugLevel")) {
135 if (
pset.exists(
"overrideUseLocalConnectString")) {
138 if (
pset.exists(
"overrideLocalConnectPrefix")) {
141 if (
pset.exists(
"overrideLocalConnectSuffix")) {
158 static std::vector<std::string>
const tmp{
"file:PoolFileCatalog.xml"};
163 throw cms::Exception(
"Incomplete configuration") <<
"Did not find catalogs in event-data section in " <<
m_url;
171 throw cms::Exception(
"Incomplete configuration") <<
"Valid site-local-config not found at " <<
m_url;
176 <<
"Did not find frontier-connect in calib-data section in " <<
m_url;
179 if (servlet.empty()) {
188 while ((serverurl =
m_frontierConnect.find(
"(serverurl=", nextparen)) != std::string::npos) {
193 complexstr.append(servlet);
203 if (
input.substr(0, proto.length()) == proto) {
221 if (endservlet == std::string::npos) {
222 endservlet =
input.rfind(
'/',
input.length());
224 std::string servlet =
input.substr(startservlet, endservlet - startservlet);
225 if ((!servlet.empty()) && (servlet.find_first_of(
":/)[]") == std::string::npos)) {
226 if (servlet ==
"cms_conditions_data") {
276 tinyxml2::XMLDocument
doc;
277 auto loadErr =
doc.LoadFile(
url.c_str());
278 if (loadErr != tinyxml2::XML_SUCCESS) {
310 auto rootElement =
doc.RootElement();
312 for (
auto site = rootElement->FirstChildElement(
"site"); site !=
nullptr;
313 site = site->NextSiblingElement(
"site")) {
319 auto eventData = site->FirstChildElement(
"event-data");
321 auto catalog = eventData->FirstChildElement(
"catalog");
330 auto rfiotype = eventData->FirstChildElement(
"rfiotype");
332 m_rfioType = safe(rfiotype->Attribute(
"value"));
339 auto calibData = site->FirstChildElement(
"calib-data");
342 auto frontierConnect = calibData->FirstChildElement(
"frontier-connect");
347 auto localConnect = calibData->FirstChildElement(
"local-connect");
351 <<
"It is illegal to include both frontier-connect and local-connect in the same XML file";
354 auto connectString = localConnect->FirstChildElement(
"connectString");
365 auto sourceConfig = site->FirstChildElement(
"source-config");
368 auto cacheTempDir = sourceConfig->FirstChildElement(
"cache-temp-dir");
375 auto cacheMinFree = sourceConfig->FirstChildElement(
"cache-min-free");
383 auto cacheHint = sourceConfig->FirstChildElement(
"cache-hint");
390 auto cloneCacheHint = sourceConfig->FirstChildElement(
"clone-cache-hint");
392 if (cloneCacheHint) {
397 auto readHint = sourceConfig->FirstChildElement(
"read-hint");
400 m_readHint = safe(readHint->Attribute(
"value"));
404 auto ttreeCacheSize = sourceConfig->FirstChildElement(
"ttree-cache-size");
406 if (ttreeCacheSize) {
411 auto timeout = sourceConfig->FirstChildElement(
"timeout-in-seconds");
418 auto statsDest = sourceConfig->FirstChildElement(
"statistics-destination");
425 std::string tmpStatisticsInfo = safe(statsDest->Attribute(
"info"));
430 auto prefetching = sourceConfig->FirstChildElement(
"prefetching");
437 auto nativeProtocol = sourceConfig->FirstChildElement(
"native-protocols");
439 if (nativeProtocol) {
440 for (
auto child = nativeProtocol->FirstChildElement();
child !=
nullptr;
453 std::vector<std::string> inputStrings;
457 struct addrinfo *
res;
458 struct addrinfo hints;
459 memset(&hints,
'\0',
sizeof(hints));
460 hints.ai_socktype = SOCK_DGRAM;
461 hints.ai_flags = AI_ADDRCONFIG;
462 hints.ai_family = AF_UNSPEC;
463 int e = getaddrinfo(
host.c_str(),
port.c_str(), &hints, &
res);
473 desc.setComment(
"Service to translate logical file names to physical file names.");
477 "Specify the file containing the site local config. Empty string will load from default directory.");
479 desc.addOptionalUntracked<
double>(
"overrideSourceCacheMinFree");
481 desc.addOptionalUntracked<
std::string>(
"overrideSourceCloneCacheHintDir")
482 ->setComment(
"Provide an alternate cache hint for fast cloning.");
484 desc.addOptionalUntracked<std::vector<std::string> >(
"overrideSourceNativeProtocols");
485 desc.addOptionalUntracked<
unsigned int>(
"overrideSourceTTreeCacheSize");
486 desc.addOptionalUntracked<
unsigned int>(
"overrideSourceTimeout");
487 desc.addOptionalUntracked<
unsigned int>(
"debugLevel");
488 desc.addOptionalUntracked<
bool>(
"overridePrefetching")
489 ->setComment(
"Request ROOT to asynchronously prefetch I/O during computation.");
490 desc.addOptionalUntracked<
std::string>(
"overrideStatisticsDestination")
492 "Provide an alternate network destination for I/O statistics (must be in the form of host:port).");
493 desc.addOptionalUntracked<std::vector<std::string> >(
"overrideStatisticsInfo")
495 "Provide an alternate listing of statistics to send (comma separated list; current options are 'dn' or "
496 "'nodn'). If left blank, all information is snet (including DNs).");
497 desc.addOptionalUntracked<
bool>(
"overrideUseLocalConnectString");
500 descriptions.
add(
"SiteLocalConfigService",
desc);