File indexing completed on 2024-04-06 12:23:17
0001
0002 #include "OnlineDB/SiStripConfigDb/interface/SiStripDbParams.h"
0003 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <iostream>
0006
0007 using namespace sistrip;
0008
0009
0010
0011 SiStripDbParams::SiStripDbParams()
0012 : usingDb_(false),
0013 confdb_(null_),
0014 user_(null_),
0015 passwd_(null_),
0016 path_(null_),
0017 usingDbCache_(false),
0018 sharedMemory_(""),
0019 tnsAdmin_(""),
0020 partitions_(),
0021 outputModuleXml_("/tmp/module.xml"),
0022 outputDcuInfoXml_("/tmp/dcuinfo.xml"),
0023 outputFecXml_("/tmp/fec.xml"),
0024 outputFedXml_("/tmp/fed.xml") {
0025 ;
0026 }
0027
0028
0029
0030 SiStripDbParams::SiStripDbParams(const SiStripDbParams& input)
0031 : usingDb_(input.usingDb()),
0032 confdb_(input.confdb()),
0033 user_(input.user()),
0034 passwd_(input.passwd()),
0035 path_(input.path()),
0036 usingDbCache_(input.usingDbCache()),
0037 sharedMemory_(input.sharedMemory()),
0038 tnsAdmin_(input.tnsAdmin()),
0039 partitions_(input.partitions().begin(), input.partitions().end()),
0040 outputModuleXml_(input.outputModuleXml()),
0041 outputDcuInfoXml_(input.outputDcuInfoXml()),
0042 outputFecXml_(input.outputFecXml()),
0043 outputFedXml_(input.outputFedXml()) {
0044 ;
0045 }
0046
0047
0048
0049 SiStripDbParams& SiStripDbParams::operator=(const SiStripDbParams& input) {
0050 usingDb_ = input.usingDb();
0051 confdb_ = input.confdb();
0052 user_ = input.user();
0053 passwd_ = input.passwd();
0054 path_ = input.path();
0055 confdb(confdb_);
0056 usingDbCache_ = input.usingDbCache();
0057 sharedMemory_ = input.sharedMemory();
0058 tnsAdmin_ = input.tnsAdmin();
0059 partitions_.clear();
0060 partitions_ = SiStripPartitions(input.partitions().begin(), input.partitions().end());
0061 outputModuleXml_ = input.outputModuleXml();
0062 outputDcuInfoXml_ = input.outputDcuInfoXml();
0063 outputFecXml_ = input.outputFecXml();
0064 outputFedXml_ = input.outputFedXml();
0065 return *this;
0066 }
0067
0068
0069
0070 bool SiStripDbParams::operator==(const SiStripDbParams& input) const {
0071 if (!(usingDb_ == input.usingDb() && confdb_ == input.confdb() && user_ == input.user() &&
0072 passwd_ == input.passwd() && path_ == input.path() && usingDbCache_ == input.usingDbCache() &&
0073 sharedMemory_ == input.sharedMemory() && tnsAdmin_ == input.tnsAdmin() &&
0074 outputModuleXml_ == input.outputModuleXml() && outputDcuInfoXml_ == input.outputDcuInfoXml() &&
0075 outputFecXml_ == input.outputFecXml() && outputFedXml_ == input.outputFedXml())) {
0076 return false;
0077 }
0078 if (partitionsSize() != input.partitionsSize()) {
0079 return false;
0080 }
0081
0082
0083
0084
0085
0086
0087
0088
0089 return partitions_ == input.partitions_;
0090 }
0091
0092
0093
0094 bool SiStripDbParams::operator!=(const SiStripDbParams& input) const { return !(*this == input); }
0095
0096
0097
0098 SiStripDbParams::~SiStripDbParams() { reset(); }
0099
0100
0101
0102 void SiStripDbParams::reset() {
0103 usingDb_ = false;
0104 confdb_ = null_;
0105 user_ = null_;
0106 passwd_ = null_;
0107 path_ = null_;
0108 usingDbCache_ = false;
0109 sharedMemory_ = "";
0110 tnsAdmin_ = "";
0111 partitions_.clear();
0112 confdb(confdb_);
0113 outputModuleXml_ = "/tmp/module.xml";
0114 outputDcuInfoXml_ = "/tmp/dcuinfo.xml";
0115 outputFecXml_ = "/tmp/fec.xml";
0116 outputFedXml_ = "/tmp/fed.xml";
0117 }
0118
0119
0120
0121 void SiStripDbParams::addPartition(const SiStripPartition& in) {
0122 if (in.partitionName().empty()) {
0123 std::stringstream ss;
0124 ss << "[SiStripDbParams::" << __func__ << "]"
0125 << " Attempting to add partition with null name!";
0126
0127 }
0128
0129 SiStripPartitions::const_iterator iter = partitions_.find(in.partitionName());
0130 if (iter == partitions_.end()) {
0131 partitions_[in.partitionName()] = in;
0132 if (in.partitionName() != SiStripPartition::defaultPartitionName_) {
0133 std::stringstream ss;
0134 ss << "[SiStripDbParams::" << __func__ << "]"
0135 << " Added new partition with name \"" << in.partitionName() << "\"";
0136
0137 ss << " (Currently have " << partitions_.size() << " partitions in cache...)";
0138 LogTrace(mlConfigDb_) << ss.str();
0139 }
0140 } else {
0141 std::stringstream ss;
0142 ss << "[SiStripDbParams::" << __func__ << "]"
0143 << " Partition with name \"" << in.partitionName() << "\" already found!"
0144 << " Not adding to cache...";
0145 edm::LogWarning(mlConfigDb_) << ss.str();
0146 }
0147 }
0148
0149
0150
0151 void SiStripDbParams::pset(const edm::ParameterSet& cfg) {
0152
0153 usingDb_ = cfg.getUntrackedParameter<bool>("UsingDb", false);
0154 usingDbCache_ = cfg.getUntrackedParameter<bool>("UsingDbCache", false);
0155 sharedMemory_ = cfg.getUntrackedParameter<std::string>("SharedMemory", "");
0156 tnsAdmin_ = cfg.getUntrackedParameter<std::string>("TNS_ADMIN", "");
0157 confdb(cfg.getUntrackedParameter<std::string>("ConfDb", ""));
0158
0159
0160 std::string partitions = "Partitions";
0161 std::vector<std::string> str = cfg.getParameterNamesForType<edm::ParameterSet>(false);
0162 std::vector<std::string>::const_iterator istr = std::find(str.begin(), str.end(), partitions);
0163 if (istr != str.end()) {
0164
0165 edm::ParameterSet psets = cfg.getUntrackedParameter<edm::ParameterSet>(partitions);
0166
0167
0168 std::vector<std::string> names = psets.getParameterNamesForType<edm::ParameterSet>(false);
0169
0170
0171 std::vector<std::string>::iterator iname = names.begin();
0172 std::vector<std::string>::iterator jname = names.end();
0173 for (; iname != jname; ++iname) {
0174 edm::ParameterSet pset = psets.getUntrackedParameter<edm::ParameterSet>(*iname);
0175 SiStripPartition tmp;
0176 tmp.pset(pset);
0177 addPartition(tmp);
0178 }
0179 }
0180
0181
0182 if (partitions_.empty()) {
0183 addPartition(SiStripPartition());
0184 }
0185
0186
0187 outputModuleXml_ = cfg.getUntrackedParameter<std::string>("OutputModuleXml", "/tmp/module.xml");
0188 outputDcuInfoXml_ = cfg.getUntrackedParameter<std::string>("OutputDcuInfoXml", "/tmp/dcuinfo.xml");
0189 outputFecXml_ = cfg.getUntrackedParameter<std::string>("OutputFecXml", "/tmp/fec.xml");
0190 outputFedXml_ = cfg.getUntrackedParameter<std::string>("OutputFedXml", "/tmp/fed.xml");
0191 }
0192
0193
0194
0195 void SiStripDbParams::confdb(const std::string& confdb) {
0196 confdb_ = confdb;
0197 size_t ipass = confdb.find('/');
0198 size_t ipath = confdb.find('@');
0199 if (ipass != std::string::npos && ipath != std::string::npos) {
0200 user_ = confdb.substr(0, ipass);
0201 passwd_ = confdb.substr(ipass + 1, ipath - ipass - 1);
0202 path_ = confdb.substr(ipath + 1, confdb.size());
0203 } else {
0204 user_ = null_;
0205 passwd_ = null_;
0206 path_ = null_;
0207 }
0208 }
0209
0210
0211
0212 void SiStripDbParams::confdb(const std::string& user, const std::string& passwd, const std::string& path) {
0213 if (!user.empty() && !passwd.empty() && !path.empty() && user != null_ && passwd != null_ && path != null_) {
0214 user_ = user;
0215 passwd_ = passwd;
0216 path_ = path;
0217 } else {
0218 user_ = null_;
0219 passwd_ = null_;
0220 path_ = null_;
0221 }
0222 confdb_ = user_ + "/" + passwd_ + "@" + path_;
0223 }
0224
0225
0226
0227 SiStripDbParams::SiStripPartitions::const_iterator SiStripDbParams::partition(std::string partition_name) const {
0228 SiStripDbParams::SiStripPartitions::const_iterator ii = partitions().begin();
0229 SiStripDbParams::SiStripPartitions::const_iterator jj = partitions().end();
0230 for (; ii != jj; ++ii) {
0231 if (partition_name == ii->second.partitionName()) {
0232 return ii;
0233 }
0234 }
0235 return partitions().end();
0236 }
0237
0238
0239
0240 SiStripDbParams::SiStripPartitions::iterator SiStripDbParams::partition(std::string partition_name) {
0241 SiStripDbParams::SiStripPartitions::iterator ii = partitions().begin();
0242 SiStripDbParams::SiStripPartitions::iterator jj = partitions().end();
0243 for (; ii != jj; ++ii) {
0244 if (partition_name == ii->second.partitionName()) {
0245 return ii;
0246 }
0247 }
0248 return partitions().end();
0249 }
0250
0251
0252
0253 std::vector<std::string> SiStripDbParams::partitionNames() const {
0254 std::vector<std::string> partitions;
0255 SiStripPartitions::const_iterator ii = partitions_.begin();
0256 SiStripPartitions::const_iterator jj = partitions_.end();
0257 for (; ii != jj; ++ii) {
0258 if (std::find(partitions.begin(), partitions.end(), ii->second.partitionName()) == partitions.end()) {
0259 if (!ii->second.partitionName().empty()) {
0260 partitions.push_back(ii->second.partitionName());
0261 }
0262 } else {
0263 edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
0264 << " Partition " << ii->second.partitionName()
0265 << " already found! Not adding to vector...";
0266 }
0267 }
0268 return partitions;
0269 }
0270
0271
0272
0273 std::vector<std::string> SiStripDbParams::partitionNames(std::string input) const {
0274 std::istringstream ss(input);
0275 std::vector<std::string> partitions;
0276 std::string delimiter = ":";
0277 std::string token;
0278 while (getline(ss, token, ':')) {
0279 if (!token.empty()) {
0280 partitions.push_back(token);
0281 }
0282 }
0283 return partitions;
0284 }
0285
0286
0287
0288 std::string SiStripDbParams::partitionNames(const std::vector<std::string>& partitions) const {
0289 std::stringstream ss;
0290 std::vector<std::string>::const_iterator ii = partitions.begin();
0291 std::vector<std::string>::const_iterator jj = partitions.end();
0292 bool first = true;
0293 for (; ii != jj; ++ii) {
0294 if (!ii->empty()) {
0295 first ? ss << *ii : ss << ":" << *ii;
0296 first = false;
0297 }
0298 }
0299 return ss.str();
0300 }
0301
0302
0303
0304 void SiStripDbParams::print(std::stringstream& ss) const {
0305 ss << " Using database account : " << std::boolalpha << usingDb_ << std::noboolalpha << std::endl;
0306 ss << " Using XML files : " << std::boolalpha << !usingDb_ << std::noboolalpha << std::endl;
0307 ss << " Using database cache : " << std::boolalpha << usingDbCache_ << std::noboolalpha << std::endl;
0308 if (usingDbCache_) {
0309 ss << " Shared memory name : " << std::boolalpha << sharedMemory_ << std::noboolalpha << std::endl;
0310 }
0311
0312 if (!usingDbCache_) {
0313 if (usingDb_) {
0314 ss << " Database account (ConfDb) : " << user_ + "/******@" + path_ << std::endl;
0315 }
0316
0317 ss << " Number of partitions : " << partitions_.size();
0318 if (partitions_.empty()) {
0319 if (!usingDbCache_) {
0320 ss << " (Empty!)";
0321 } else {
0322 ss << " (Using database cache!)";
0323 }
0324 }
0325 ss << std::endl;
0326
0327 uint16_t cntr = 0;
0328 SiStripPartitions::const_iterator ii = partitions_.begin();
0329 SiStripPartitions::const_iterator jj = partitions_.end();
0330 for (; ii != jj; ++ii) {
0331 cntr++;
0332 ss << " Partition #" << cntr << " (out of " << partitions_.size() << "):" << std::endl;
0333 ii->second.print(ss, usingDb_);
0334 }
0335
0336 if (!usingDb_) {
0337 ss << " Output \"module.xml\" file : " << outputModuleXml_ << std::endl
0338 << " Output \"dcuinfo.xml\" file : " << outputDcuInfoXml_ << std::endl
0339 << " Output \"fec.xml\" file(s) : " << outputFecXml_ << std::endl
0340 << " Output \"fed.xml\" file(s) : " << outputFedXml_ << std::endl;
0341 }
0342 }
0343 }
0344
0345
0346
0347 std::ostream& operator<<(std::ostream& os, const SiStripDbParams& params) {
0348 std::stringstream ss;
0349 params.print(ss);
0350 os << ss.str();
0351 return os;
0352 }
0353
0354
0355
0356 std::vector<std::string> SiStripDbParams::inputModuleXmlFiles() const {
0357 std::vector<std::string> files;
0358 SiStripPartitions::const_iterator ii = partitions_.begin();
0359 SiStripPartitions::const_iterator jj = partitions_.end();
0360 for (; ii != jj; ++ii) {
0361 files.insert(files.end(), ii->second.inputModuleXml());
0362 }
0363 return files;
0364 }
0365
0366
0367
0368 std::vector<std::string> SiStripDbParams::inputDcuInfoXmlFiles() const {
0369 std::vector<std::string> files;
0370 SiStripPartitions::const_iterator ii = partitions_.begin();
0371 SiStripPartitions::const_iterator jj = partitions_.end();
0372 for (; ii != jj; ++ii) {
0373 files.insert(files.end(), ii->second.inputDcuInfoXml());
0374 }
0375 return files;
0376 }
0377
0378
0379
0380 std::vector<std::string> SiStripDbParams::inputFecXmlFiles() const {
0381 std::vector<std::string> files;
0382 SiStripPartitions::const_iterator ii = partitions_.begin();
0383 SiStripPartitions::const_iterator jj = partitions_.end();
0384 for (; ii != jj; ++ii) {
0385 files.insert(files.end(), ii->second.inputFecXml().begin(), ii->second.inputFecXml().end());
0386 }
0387 return files;
0388 }
0389
0390
0391
0392 std::vector<std::string> SiStripDbParams::inputFedXmlFiles() const {
0393 std::vector<std::string> files;
0394 SiStripPartitions::const_iterator ii = partitions_.begin();
0395 SiStripPartitions::const_iterator jj = partitions_.end();
0396 for (; ii != jj; ++ii) {
0397 files.insert(files.end(), ii->second.inputFedXml().begin(), ii->second.inputFedXml().end());
0398 }
0399 return files;
0400 }