CMS 3D CMS Logo

SiStripDbParams.cc
Go to the documentation of this file.
1 
5 #include <iostream>
6 
7 using namespace sistrip;
8 
9 // -----------------------------------------------------------------------------
10 //
12  : usingDb_(false),
13  confdb_(null_),
14  user_(null_),
15  passwd_(null_),
16  path_(null_),
17  usingDbCache_(false),
18  sharedMemory_(""),
19  tnsAdmin_(""),
20  partitions_(),
21  outputModuleXml_("/tmp/module.xml"),
22  outputDcuInfoXml_("/tmp/dcuinfo.xml"),
23  outputFecXml_("/tmp/fec.xml"),
24  outputFedXml_("/tmp/fed.xml") {
25  ;
26 }
27 
28 // -----------------------------------------------------------------------------
29 //
31  : usingDb_(input.usingDb()),
32  confdb_(input.confdb()),
33  user_(input.user()),
34  passwd_(input.passwd()),
35  path_(input.path()),
36  usingDbCache_(input.usingDbCache()),
37  sharedMemory_(input.sharedMemory()),
38  tnsAdmin_(input.tnsAdmin()),
39  partitions_(input.partitions().begin(), input.partitions().end()),
40  outputModuleXml_(input.outputModuleXml()),
41  outputDcuInfoXml_(input.outputDcuInfoXml()),
42  outputFecXml_(input.outputFecXml()),
43  outputFedXml_(input.outputFedXml()) {
44  ;
45 }
46 
47 // -----------------------------------------------------------------------------
48 //
50  usingDb_ = input.usingDb();
51  confdb_ = input.confdb();
52  user_ = input.user();
53  passwd_ = input.passwd();
54  path_ = input.path();
55  confdb(confdb_);
56  usingDbCache_ = input.usingDbCache();
57  sharedMemory_ = input.sharedMemory();
58  tnsAdmin_ = input.tnsAdmin();
59  partitions_.clear();
60  partitions_ = SiStripPartitions(input.partitions().begin(), input.partitions().end());
61  outputModuleXml_ = input.outputModuleXml();
62  outputDcuInfoXml_ = input.outputDcuInfoXml();
63  outputFecXml_ = input.outputFecXml();
64  outputFedXml_ = input.outputFedXml();
65  return *this;
66 }
67 
68 // -----------------------------------------------------------------------------
69 //
71  if (!(usingDb_ == input.usingDb() && confdb_ == input.confdb() && user_ == input.user() &&
72  passwd_ == input.passwd() && path_ == input.path() && usingDbCache_ == input.usingDbCache() &&
73  sharedMemory_ == input.sharedMemory() && tnsAdmin_ == input.tnsAdmin() &&
74  outputModuleXml_ == input.outputModuleXml() && outputDcuInfoXml_ == input.outputDcuInfoXml() &&
75  outputFecXml_ == input.outputFecXml() && outputFedXml_ == input.outputFedXml())) {
76  return false;
77  }
78  if (partitionsSize() != input.partitionsSize()) {
79  return false;
80  }
81  // SiStripPartitions::const_iterator ii = input.partitions().begin();
82  // SiStripPartitions::const_iterator jj = input.partitions().end();
83  // SiStripPartitions::const_iterator iter = partitions_.begin();
84  // for ( ; ii != jj; ++ii ) {
85  // if ( ii->first != iter->first || ii->second != iter->second ) { return false; }
86  // iter++;
87  // }
88  // return true;
89  return partitions_ == input.partitions_;
90 }
91 
92 // -----------------------------------------------------------------------------
93 //
94 bool SiStripDbParams::operator!=(const SiStripDbParams& input) const { return !(*this == input); }
95 
96 // -----------------------------------------------------------------------------
97 //
99 
100 // -----------------------------------------------------------------------------
101 //
103  usingDb_ = false;
104  confdb_ = null_;
105  user_ = null_;
106  passwd_ = null_;
107  path_ = null_;
108  usingDbCache_ = false;
109  sharedMemory_ = "";
110  tnsAdmin_ = "";
111  partitions_.clear();
112  confdb(confdb_);
113  outputModuleXml_ = "/tmp/module.xml";
114  outputDcuInfoXml_ = "/tmp/dcuinfo.xml";
115  outputFecXml_ = "/tmp/fec.xml";
116  outputFedXml_ = "/tmp/fed.xml";
117 }
118 
119 // -----------------------------------------------------------------------------
120 //
122  if (in.partitionName().empty()) {
123  std::stringstream ss;
124  ss << "[SiStripDbParams::" << __func__ << "]"
125  << " Attempting to add partition with null name!";
126  //edm::LogWarning(mlConfigDb_) << ss.str();
127  }
128 
129  SiStripPartitions::const_iterator iter = partitions_.find(in.partitionName());
130  if (iter == partitions_.end()) {
131  partitions_[in.partitionName()] = in;
132  if (in.partitionName() != SiStripPartition::defaultPartitionName_) {
133  std::stringstream ss;
134  ss << "[SiStripDbParams::" << __func__ << "]"
135  << " Added new partition with name \"" << in.partitionName() << "\"";
136  //ss << std::endl << partitions_[in.partitionName()];
137  ss << " (Currently have " << partitions_.size() << " partitions in cache...)";
138  LogTrace(mlConfigDb_) << ss.str();
139  }
140  } else {
141  std::stringstream ss;
142  ss << "[SiStripDbParams::" << __func__ << "]"
143  << " Partition with name \"" << in.partitionName() << "\" already found!"
144  << " Not adding to cache...";
145  edm::LogWarning(mlConfigDb_) << ss.str();
146  }
147 }
148 
149 // -----------------------------------------------------------------------------
150 //
152  // "Common" configurables
153  usingDb_ = cfg.getUntrackedParameter<bool>("UsingDb", false);
154  usingDbCache_ = cfg.getUntrackedParameter<bool>("UsingDbCache", false);
155  sharedMemory_ = cfg.getUntrackedParameter<std::string>("SharedMemory", "");
156  tnsAdmin_ = cfg.getUntrackedParameter<std::string>("TNS_ADMIN", "");
157  confdb(cfg.getUntrackedParameter<std::string>("ConfDb", ""));
158 
159  // Check if top-level PSet (containing partition-level Psets) exists
160  std::string partitions = "Partitions";
161  std::vector<std::string> str = cfg.getParameterNamesForType<edm::ParameterSet>(false);
162  std::vector<std::string>::const_iterator istr = std::find(str.begin(), str.end(), partitions);
163  if (istr != str.end()) {
164  // Retrieve top-level PSet containing partition-level Psets
165  edm::ParameterSet psets = cfg.getUntrackedParameter<edm::ParameterSet>(partitions);
166 
167  // Extract names of partition-level PSets
168  std::vector<std::string> names = psets.getParameterNamesForType<edm::ParameterSet>(false);
169 
170  // Iterator through PSets names, retrieve PSet for each partition and extract info
171  std::vector<std::string>::iterator iname = names.begin();
172  std::vector<std::string>::iterator jname = names.end();
173  for (; iname != jname; ++iname) {
176  tmp.pset(pset);
177  addPartition(tmp);
178  }
179  }
180 
181  // Ensure at least one "default" partition
182  if (partitions_.empty()) {
184  }
185 
186  // Set output XML files
187  outputModuleXml_ = cfg.getUntrackedParameter<std::string>("OutputModuleXml", "/tmp/module.xml");
188  outputDcuInfoXml_ = cfg.getUntrackedParameter<std::string>("OutputDcuInfoXml", "/tmp/dcuinfo.xml");
189  outputFecXml_ = cfg.getUntrackedParameter<std::string>("OutputFecXml", "/tmp/fec.xml");
190  outputFedXml_ = cfg.getUntrackedParameter<std::string>("OutputFedXml", "/tmp/fed.xml");
191 }
192 
193 // -----------------------------------------------------------------------------
194 //
196  confdb_ = confdb;
197  size_t ipass = confdb.find('/');
198  size_t ipath = confdb.find('@');
199  if (ipass != std::string::npos && ipath != std::string::npos) {
200  user_ = confdb.substr(0, ipass);
201  passwd_ = confdb.substr(ipass + 1, ipath - ipass - 1);
202  path_ = confdb.substr(ipath + 1, confdb.size());
203  } else {
204  user_ = null_;
205  passwd_ = null_;
206  path_ = null_;
207  }
208 }
209 
210 // -----------------------------------------------------------------------------
211 //
213  if (!user.empty() && !passwd.empty() && !path.empty() && user != null_ && passwd != null_ && path != null_) {
214  user_ = user;
215  passwd_ = passwd;
216  path_ = path;
217  } else {
218  user_ = null_;
219  passwd_ = null_;
220  path_ = null_;
221  }
222  confdb_ = user_ + "/" + passwd_ + "@" + path_;
223 }
224 
225 // -----------------------------------------------------------------------------
226 //
227 SiStripDbParams::SiStripPartitions::const_iterator SiStripDbParams::partition(std::string partition_name) const {
228  SiStripDbParams::SiStripPartitions::const_iterator ii = partitions().begin();
229  SiStripDbParams::SiStripPartitions::const_iterator jj = partitions().end();
230  for (; ii != jj; ++ii) {
231  if (partition_name == ii->second.partitionName()) {
232  return ii;
233  }
234  }
235  return partitions().end();
236 }
237 
238 // -----------------------------------------------------------------------------
239 //
240 SiStripDbParams::SiStripPartitions::iterator SiStripDbParams::partition(std::string partition_name) {
241  SiStripDbParams::SiStripPartitions::iterator ii = partitions().begin();
242  SiStripDbParams::SiStripPartitions::iterator jj = partitions().end();
243  for (; ii != jj; ++ii) {
244  if (partition_name == ii->second.partitionName()) {
245  return ii;
246  }
247  }
248  return partitions().end();
249 }
250 
251 // -----------------------------------------------------------------------------
252 //
253 std::vector<std::string> SiStripDbParams::partitionNames() const {
254  std::vector<std::string> partitions;
255  SiStripPartitions::const_iterator ii = partitions_.begin();
256  SiStripPartitions::const_iterator jj = partitions_.end();
257  for (; ii != jj; ++ii) {
258  if (std::find(partitions.begin(), partitions.end(), ii->second.partitionName()) == partitions.end()) {
259  if (!ii->second.partitionName().empty()) {
260  partitions.push_back(ii->second.partitionName());
261  }
262  } else {
263  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
264  << " Partition " << ii->second.partitionName()
265  << " already found! Not adding to vector...";
266  }
267  }
268  return partitions;
269 }
270 
271 // -----------------------------------------------------------------------------
272 //
273 std::vector<std::string> SiStripDbParams::partitionNames(std::string input) const {
274  std::istringstream ss(input);
275  std::vector<std::string> partitions;
276  std::string delimiter = ":";
278  while (getline(ss, token, ':')) {
279  if (!token.empty()) {
280  partitions.push_back(token);
281  }
282  }
283  return partitions;
284 }
285 
286 // -----------------------------------------------------------------------------
287 //
288 std::string SiStripDbParams::partitionNames(const std::vector<std::string>& partitions) const {
289  std::stringstream ss;
290  std::vector<std::string>::const_iterator ii = partitions.begin();
291  std::vector<std::string>::const_iterator jj = partitions.end();
292  bool first = true;
293  for (; ii != jj; ++ii) {
294  if (!ii->empty()) {
295  first ? ss << *ii : ss << ":" << *ii;
296  first = false;
297  }
298  }
299  return ss.str();
300 }
301 
302 // -----------------------------------------------------------------------------
303 //
304 void SiStripDbParams::print(std::stringstream& ss) const {
305  ss << " Using database account : " << std::boolalpha << usingDb_ << std::noboolalpha << std::endl;
306  ss << " Using XML files : " << std::boolalpha << !usingDb_ << std::noboolalpha << std::endl;
307  ss << " Using database cache : " << std::boolalpha << usingDbCache_ << std::noboolalpha << std::endl;
308  if (usingDbCache_) {
309  ss << " Shared memory name : " << std::boolalpha << sharedMemory_ << std::noboolalpha << std::endl;
310  }
311 
312  if (!usingDbCache_) {
313  if (usingDb_) {
314  ss << " Database account (ConfDb) : " << user_ + "/******@" + path_ << std::endl;
315  }
316 
317  ss << " Number of partitions : " << partitions_.size();
318  if (partitions_.empty()) {
319  if (!usingDbCache_) {
320  ss << " (Empty!)";
321  } else {
322  ss << " (Using database cache!)";
323  }
324  }
325  ss << std::endl;
326 
327  uint16_t cntr = 0;
328  SiStripPartitions::const_iterator ii = partitions_.begin();
329  SiStripPartitions::const_iterator jj = partitions_.end();
330  for (; ii != jj; ++ii) {
331  cntr++;
332  ss << " Partition #" << cntr << " (out of " << partitions_.size() << "):" << std::endl;
333  ii->second.print(ss, usingDb_);
334  }
335 
336  if (!usingDb_) {
337  ss << " Output \"module.xml\" file : " << outputModuleXml_ << std::endl
338  << " Output \"dcuinfo.xml\" file : " << outputDcuInfoXml_ << std::endl
339  << " Output \"fec.xml\" file(s) : " << outputFecXml_ << std::endl
340  << " Output \"fed.xml\" file(s) : " << outputFedXml_ << std::endl;
341  }
342  }
343 }
344 
345 // -----------------------------------------------------------------------------
346 //
347 std::ostream& operator<<(std::ostream& os, const SiStripDbParams& params) {
348  std::stringstream ss;
349  params.print(ss);
350  os << ss.str();
351  return os;
352 }
353 
354 // -----------------------------------------------------------------------------
355 //
356 std::vector<std::string> SiStripDbParams::inputModuleXmlFiles() const {
357  std::vector<std::string> files;
358  SiStripPartitions::const_iterator ii = partitions_.begin();
359  SiStripPartitions::const_iterator jj = partitions_.end();
360  for (; ii != jj; ++ii) {
361  files.insert(files.end(), ii->second.inputModuleXml());
362  }
363  return files;
364 }
365 
366 // -----------------------------------------------------------------------------
367 //
368 std::vector<std::string> SiStripDbParams::inputDcuInfoXmlFiles() const {
369  std::vector<std::string> files;
370  SiStripPartitions::const_iterator ii = partitions_.begin();
371  SiStripPartitions::const_iterator jj = partitions_.end();
372  for (; ii != jj; ++ii) {
373  files.insert(files.end(), ii->second.inputDcuInfoXml());
374  }
375  return files;
376 }
377 
378 // -----------------------------------------------------------------------------
379 //
380 std::vector<std::string> SiStripDbParams::inputFecXmlFiles() const {
381  std::vector<std::string> files;
382  SiStripPartitions::const_iterator ii = partitions_.begin();
383  SiStripPartitions::const_iterator jj = partitions_.end();
384  for (; ii != jj; ++ii) {
385  files.insert(files.end(), ii->second.inputFecXml().begin(), ii->second.inputFecXml().end());
386  }
387  return files;
388 }
389 
390 // -----------------------------------------------------------------------------
391 //
392 std::vector<std::string> SiStripDbParams::inputFedXmlFiles() const {
393  std::vector<std::string> files;
394  SiStripPartitions::const_iterator ii = partitions_.begin();
395  SiStripPartitions::const_iterator jj = partitions_.end();
396  for (; ii != jj; ++ii) {
397  files.insert(files.end(), ii->second.inputFedXml().begin(), ii->second.inputFedXml().end());
398  }
399  return files;
400 }
std::string path() const
std::string passwd() const
static const std::string defaultPartitionName_
std::string tnsAdmin_
std::map< std::string, SiStripPartition > SiStripPartitions
std::vector< std::string > inputModuleXmlFiles() const
Definition: confdb.py:1
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const_iterator_range partitions() const
SiStripDbParams & operator=(const SiStripDbParams &)
const std::string names[nVars_]
std::string user() const
sistrip classes
#define LogTrace(id)
std::string outputDcuInfoXml_
static std::string const input
Definition: EdmProvDump.cc:50
static const char mlConfigDb_[]
T getUntrackedParameter(std::string const &, T const &) const
SiStripPartitions::const_iterator partition(std::string partition_name) const
void print(std::stringstream &) const
std::string outputFecXml_
std::string outputModuleXml_
std::string user_
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
std::vector< std::string > partitionNames() const
std::string outputFedXml_
std::string passwd_
Container class for database partition parameters.
std::vector< std::string > inputFedXmlFiles() const
std::string sharedMemory_
bool operator==(const SiStripDbParams &) const
std::string path_
std::string confdb() const
ii
Definition: cuy.py:589
std::vector< std::string > inputDcuInfoXmlFiles() const
Container class for database connection parameters.
std::string & path_
bool operator!=(const SiStripDbParams &) const
size_type partitionsSize() const
void pset(const edm::ParameterSet &)
std::string confdb_
Log< level::Warning, false > LogWarning
void addPartition(const SiStripPartition &)
#define str(s)
tmp
align.sh
Definition: createJobs.py:716
std::vector< std::string > inputFecXmlFiles() const
SiStripPartitions partitions_
std::ostream & operator<<(std::ostream &os, const SiStripDbParams &params)
static const char null_[]
Definition: Constants.h:22