17 #include <boost/algorithm/string.hpp> 32 inline std::string _toParenString(tinyxml2::XMLElement
const &nodeToConvert) {
33 std::ostringstream oss;
35 for (
auto child = nodeToConvert.FirstChildElement();
child !=
nullptr;
child =
child->NextSiblingElement()) {
36 for (
auto attribute =
child->FirstAttribute(); attribute !=
nullptr; attribute = attribute->Next()) {
37 oss <<
"(" <<
child->Name() << attribute->Name() <<
"=" << attribute->Value() <<
")";
44 static void overrideFromPSet(
char const *iName,
edm::ParameterSet const &iPSet,
T &iHolder,
T const *&iPointer) {
52 const char *safe(
const char *iCheck) {
53 if (iCheck ==
nullptr) {
61 const char *
tmp = std::getenv(
"SITECONFIG_PATH");
65 returnValue +=
"/JobConfig/site-local-config.xml";
77 : m_url(
pset.getUntrackedParameter<
std::
string>(
"siteLocalConfigFileUrl", defaultURL())),
78 m_trivialDataCatalogs(),
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),
122 std::vector<std::string> tmpStatisticsInfo;
123 std::vector<std::string>
const *tmpStatisticsInfoPtr =
nullptr;
124 overrideFromPSet(
"overrideStatisticsInfo",
pset, tmpStatisticsInfo, tmpStatisticsInfoPtr);
125 if (tmpStatisticsInfoPtr) {
128 for (
auto &
entry : tmpStatisticsInfo) {
133 if (
pset.exists(
"debugLevel")) {
136 if (
pset.exists(
"overrideUseLocalConnectString")) {
139 if (
pset.exists(
"overrideLocalConnectPrefix")) {
142 if (
pset.exists(
"overrideLocalConnectSuffix")) {
156 static std::vector<std::string>
const tmp{
"file:PoolFileCatalog.xml"};
162 ex <<
"Did not find catalogs in event-data section in " <<
m_url;
163 ex.
addContext(
"edm::SiteLocalConfigService::trivialDataCatalogs()");
173 ex <<
"Incomplete configuration. Valid site-local-config not found at " <<
m_url;
174 ex.
addContext(
"edm::SiteLocalConfigService::dataCatalogs()");
179 ex <<
"Did not find catalogs in data-access section in " <<
m_url;
180 ex.
addContext(
"edm::SiteLocalConfigService::dataCatalogs()");
188 char *
tmp = std::getenv(
"SITECONFIG_PATH");
189 if (
tmp ==
nullptr) {
190 throw cms::Exception(
"SiteLocalConfigService") <<
"SITECONFIG_PATH is not set!";
197 if (aDataCatalog.
subSite.empty())
198 filename_storage = siteconfig_path;
201 filename_storage = siteconfig_path +
"/..";
204 if (aDataCatalog.
subSite.empty())
205 filename_storage = siteconfig_path +
"/../" + aDataCatalog.
storageSite;
208 filename_storage = siteconfig_path +
"/../../" + aDataCatalog.
storageSite;
210 filename_storage /=
"storage.json";
212 filename_storage = std::filesystem::canonical(filename_storage);
215 ex <<
"Fail to convert path to the storage description, " << filename_storage.string()
216 <<
", to the canonical absolute path" 218 ex.
addContext(
"edm::SiteLocalConfigService::storageDescriptionPath()");
221 return filename_storage;
226 throw cms::Exception(
"Incomplete configuration") <<
"Valid site-local-config not found at " <<
m_url;
231 <<
"Did not find frontier-connect in calib-data section in " <<
m_url;
234 if (servlet.empty()) {
243 while ((serverurl =
m_frontierConnect.find(
"(serverurl=", nextparen)) != std::string::npos) {
248 complexstr.append(servlet);
258 if (
input.substr(0, proto.length()) == proto) {
276 if (endservlet == std::string::npos) {
277 endservlet =
input.rfind(
'/',
input.length());
279 std::string servlet =
input.substr(startservlet, endservlet - startservlet);
280 if ((!servlet.empty()) && (servlet.find_first_of(
":/)[]") == std::string::npos)) {
281 if (servlet ==
"cms_conditions_data") {
335 if (tmp_site.empty())
346 tinyxml2::XMLDocument
doc;
347 auto loadErr =
doc.LoadFile(
url.c_str());
348 if (loadErr != tinyxml2::XML_SUCCESS) {
382 auto rootElement =
doc.RootElement();
384 for (
auto site = rootElement->FirstChildElement(
"site");
site !=
nullptr;
385 site =
site->NextSiblingElement(
"site")) {
386 auto subSite =
site->FirstChildElement(
"subsite");
393 auto subSite_first_child = subSite->FirstChild();
394 if (subSite_first_child) {
396 ex <<
"Invalid site-local-config.xml. Subsite node has children!";
397 ex.
addContext(
"edm::SiteLocalConfigService::parse()");
404 auto eventData =
site->FirstChildElement(
"event-data");
406 auto catalog = eventData->FirstChildElement(
"catalog");
415 auto rfiotype = eventData->FirstChildElement(
"rfiotype");
417 m_rfioType = safe(rfiotype->Attribute(
"value"));
430 auto dataAccess =
site->FirstChildElement(
"data-access");
433 auto catalog = dataAccess->FirstChildElement(
"catalog");
449 auto calibData =
site->FirstChildElement(
"calib-data");
452 auto frontierConnect = calibData->FirstChildElement(
"frontier-connect");
457 auto localConnect = calibData->FirstChildElement(
"local-connect");
461 <<
"It is illegal to include both frontier-connect and local-connect in the same XML file";
464 auto connectString = localConnect->FirstChildElement(
"connectString");
473 auto sourceConfig =
site->FirstChildElement(
"source-config");
476 auto cacheTempDir = sourceConfig->FirstChildElement(
"cache-temp-dir");
483 auto cacheMinFree = sourceConfig->FirstChildElement(
"cache-min-free");
491 auto cacheHint = sourceConfig->FirstChildElement(
"cache-hint");
498 auto cloneCacheHint = sourceConfig->FirstChildElement(
"clone-cache-hint");
500 if (cloneCacheHint) {
505 auto readHint = sourceConfig->FirstChildElement(
"read-hint");
508 m_readHint = safe(readHint->Attribute(
"value"));
512 auto ttreeCacheSize = sourceConfig->FirstChildElement(
"ttree-cache-size");
514 if (ttreeCacheSize) {
519 auto timeout = sourceConfig->FirstChildElement(
"timeout-in-seconds");
526 auto statsDest = sourceConfig->FirstChildElement(
"statistics-destination");
533 std::string tmpStatisticsInfo = safe(statsDest->Attribute(
"info"));
538 auto prefetching = sourceConfig->FirstChildElement(
"prefetching");
545 auto nativeProtocol = sourceConfig->FirstChildElement(
"native-protocols");
547 if (nativeProtocol) {
548 for (
auto child = nativeProtocol->FirstChildElement();
child !=
nullptr;
560 std::vector<std::string> inputStrings;
564 struct addrinfo *
res;
565 struct addrinfo hints;
566 memset(&hints,
'\0',
sizeof(hints));
567 hints.ai_socktype = SOCK_DGRAM;
568 hints.ai_flags = AI_ADDRCONFIG;
569 hints.ai_family = AF_UNSPEC;
570 int e = getaddrinfo(
host.c_str(),
port.c_str(), &hints, &
res);
580 desc.setComment(
"Service to translate logical file names to physical file names.");
584 "Specify the file containing the site local config. Empty string will load from default directory.");
586 desc.addOptionalUntracked<
double>(
"overrideSourceCacheMinFree");
588 desc.addOptionalUntracked<
std::string>(
"overrideSourceCloneCacheHintDir")
589 ->setComment(
"Provide an alternate cache hint for fast cloning.");
591 desc.addOptionalUntracked<std::vector<std::string> >(
"overrideSourceNativeProtocols");
592 desc.addOptionalUntracked<
unsigned int>(
"overrideSourceTTreeCacheSize");
593 desc.addOptionalUntracked<
unsigned int>(
"overrideSourceTimeout");
594 desc.addOptionalUntracked<
unsigned int>(
"debugLevel");
595 desc.addOptionalUntracked<
bool>(
"overridePrefetching")
596 ->setComment(
"Request ROOT to asynchronously prefetch I/O during computation.");
597 desc.addOptionalUntracked<
std::string>(
"overrideStatisticsDestination")
599 "Provide an alternate network destination for I/O statistics (must be in the form of host:port).");
600 desc.addOptionalUntracked<std::vector<std::string> >(
"overrideStatisticsInfo")
602 "Provide an alternate listing of statistics to send (comma separated list; current options are 'dn' or " 603 "'nodn'). If left blank, all information is snet (including DNs).");
604 desc.addOptionalUntracked<
bool>(
"overrideUseLocalConnectString");
607 descriptions.
add(
"SiteLocalConfigService",
desc);
unsigned int const * m_timeoutPtr
~SiteLocalConfigService() override
std::string const * m_cacheTempDirPtr
std::string m_frontierConnect
void parse(std::string const &url)
std::string m_subSiteName
static void fillDescriptions(ConfigurationDescriptions &descriptions)
struct addrinfo const * statisticsDestination() const override
double const * m_cacheMinFreePtr
std::string const * m_cloneCacheHintPtr
std::vector< edm::CatalogAttributes > m_dataCatalogs
bool exists(std::string const ¶meterName) const
checks if a parameter exists
static const std::string m_statisticsDefaultPort
std::vector< std::string > const & trivialDataCatalogs() const override
std::string const * sourceCacheHint() const override
std::string const * sourceReadHint() const override
std::string m_cloneCacheHint
unsigned int const * sourceTimeout() const override
std::string m_cacheTempDir
void getCatalog(tinyxml2::XMLElement const &cat, std::string site, std::string subSite)
std::string const & subSiteName() const override
unsigned int m_ttreeCacheSize
std::vector< std::string > const * sourceNativeProtocols() const override
std::vector< std::string > const * m_nativeProtocolsPtr
std::string const * sourceCacheTempDir() const override
static std::string const input
std::string const & localConnectPrefix() const override
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > m_trivialDataCatalogs
std::string m_localConnectPrefix
std::string m_statisticsDestination
edm::propagate_const< struct addrinfo * > m_statisticsAddrInfo
bool const * m_enablePrefetchingPtr
std::string const rfioType(void) const override
unsigned int m_debugLevel
std::string const frontierConnect(std::string const &servlet) const
std::filesystem::path const storageDescriptionPath(edm::CatalogAttributes const &aDataCatalog) const override
std::string m_localConnectSuffix
std::set< std::string > m_statisticsInfo
bool useLocalConnectString() const override
std::vector< std::string > m_nativeProtocols
unsigned int const * sourceTTreeCacheSize() const override
std::string const & localConnectSuffix() const override
def split(sequence, size)
std::string const * m_cacheHintPtr
std::string const * m_readHintPtr
void computeStatisticsDestination()
unsigned int debugLevel() const override
unsigned int const * m_ttreeCacheSizePtr
SiteLocalConfigService(ParameterSet const &pset)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void addContext(std::string const &context)
std::set< std::string > const * statisticsInfo() const override
static const char kEmptyString[1]
double const * sourceCacheMinFree() const override
std::vector< edm::CatalogAttributes > const & dataCatalogs() const override
bool m_useLocalConnectString
bool m_statisticsInfoAvail
std::string const * sourceCloneCacheHint() const override
std::string const lookupCalibConnect(std::string const &input) const override
bool enablePrefetching() const override
std::string const & siteName() const override