CMS 3D CMS Logo

SiStripConfigDb.cc
Go to the documentation of this file.
1 
6 #include <iostream>
7 #include <fstream>
8 
9 using namespace sistrip;
10 
11 // -----------------------------------------------------------------------------
12 //
13 std::atomic<uint32_t> SiStripConfigDb::cntr_{0};
14 
15 // -----------------------------------------------------------------------------
16 //
17 std::atomic<bool> SiStripConfigDb::allowCalibUpload_{false};
18 
19 // -----------------------------------------------------------------------------
20 //
22  : factory_(nullptr),
23  dbCache_(nullptr),
24  dbParams_(),
25  // Local cache
26  connections_(),
27  devices_(),
28  feds_(),
29  dcuDetIds_(),
30  analyses_(),
31  apvDevices_(),
32  muxDevices_(),
33  dcuDevices_(),
34  lldDevices_(),
35  pllDevices_(),
36  dohDevices_(),
37  typedDevices_(),
38  fedIds_(),
39  // Misc
40  usingStrips_(true),
41  openConnection_(false) {
42  auto count = ++cntr_;
43  edm::LogVerbatim(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
44  << " Constructing database service..."
45  << " (Class instance: " << count << ")";
46 
47  // Set DB connection parameters
48  dbParams_.reset();
50  //edm::LogVerbatim(mlConfigDb_) << dbParams_;
51 
52  // Open connection
54 }
55 
56 // -----------------------------------------------------------------------------
57 //
60  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
61  << " Destructing object...";
62  --cntr_;
63 }
64 
65 // -----------------------------------------------------------------------------
66 //
74  i2cAddr_(sistrip::invalid_),
75  fedId_(sistrip::invalid_),
78  reset();
79 }
80 
81 // -----------------------------------------------------------------------------
82 //
90  i2cAddr_ = sistrip::invalid_;
91  fedId_ = sistrip::invalid_;
94 }
95 
96 // -----------------------------------------------------------------------------
97 //
99  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
100  << " Opening connection to database...";
101 
102  // Check if connection already exists
103  if (openConnection_) {
104  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
105  << " Connection already open!";
106  return;
107  }
108  openConnection_ = true;
109 
110  // Establish database connection
111  if (dbParams_.usingDb()) {
112  if (dbParams_.usingDbCache()) {
114  } else {
115  usingDatabase();
116  }
117  } else {
118  usingXmlFiles();
119  }
120 
121  std::stringstream ss;
122  ss << "[SiStripConfigDb::" << __func__ << "]"
123  << " Database connection parameters: " << std::endl
124  << dbParams_;
125  edm::LogVerbatim(mlConfigDb_) << ss.str();
126 
127  // Clear local caches
128  clearLocalCache();
129 
130  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
131  << " Opened connection to database!";
132 }
133 
134 // -----------------------------------------------------------------------------
135 //
137  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
138  << " Closing connection to database...";
139 
140  // Check if connection exists
141  if (!openConnection_) {
142  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
143  << " No connection open!";
144  return;
145  }
146  openConnection_ = false;
147 
148  // Clear local caches
149  clearLocalCache();
150 
151  try {
152  if (factory_) {
153  delete factory_;
154  }
155  } catch (...) {
156  handleException(__func__, "Attempting to delete DeviceFactory object...");
157  }
158  factory_ = nullptr;
159 
160  try {
161  if (dbCache_) {
162  delete dbCache_;
163  }
164  } catch (...) {
165  handleException(__func__, "Attempting to delete DbClient object...");
166  }
167  dbCache_ = nullptr;
168 
169  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
170  << " Closed connection to database...";
171 }
172 
173 // -----------------------------------------------------------------------------
174 //
176  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
177  << " Clearing local caches...";
178 
182  clearDcuDetIds();
184 
185  typedDevices_.clear();
186  fedIds_.clear();
187 }
188 
189 // -----------------------------------------------------------------------------
190 //
191 DeviceFactory* const SiStripConfigDb::deviceFactory(std::string method_name) const {
192  if (factory_) {
193  return factory_;
194  } else {
195  if (!method_name.empty()) {
196  stringstream ss;
197  ss << "[SiStripConfigDb::" << __func__ << "]"
198  << " NULL pointer to DeviceFactory requested by"
199  << " method SiStripConfigDb::" << method_name << "()!";
200  edm::LogWarning(mlConfigDb_) << ss.str();
201  }
202  return nullptr;
203  }
204 }
205 
206 // -----------------------------------------------------------------------------
207 //
208 DbClient* const SiStripConfigDb::databaseCache(std::string method_name) const {
209  if (dbCache_) {
210  return dbCache_;
211  } else {
212  if (!method_name.empty()) {
213  stringstream ss;
214  ss << "[SiStripConfigDb::" << __func__ << "]"
215  << " NULL pointer to DbClient requested by"
216  << " method SiStripConfigDb::" << method_name << "()!";
217  edm::LogWarning(mlConfigDb_) << ss.str();
218  }
219  return nullptr;
220  }
221 }
222 
223 // -----------------------------------------------------------------------------
224 //
226  // Retrieve connection params from CONFDB env. var. and override .cfg values
227  std::string user = "";
228  std::string passwd = "";
229  std::string path = "";
230  DbAccess::getDbConfiguration(user, passwd, path);
231  if (!user.empty() && !passwd.empty() && !path.empty()) {
232  std::stringstream ss;
233  ss << "[SiStripConfigDb::" << __func__ << "]"
234  << " Setting \"user/passwd@path\" to \"" << user << "/" << passwd << "@" << path
235  << "\" using 'CONFDB' environmental variable";
236  if (dbParams_.user() != null_ || dbParams_.passwd() != null_ || dbParams_.path() != null_) {
237  ss << " (Overwriting existing value of \"" << dbParams_.user() << "/" << dbParams_.passwd() << "@"
238  << dbParams_.path() << "\" read from .cfg file)";
239  }
240  edm::LogVerbatim(mlConfigDb_) << ss.str() << std::endl;
241  dbParams_.confdb(user, passwd, path);
242 
243  } else if (dbParams_.user() != null_ && dbParams_.passwd() != null_ && dbParams_.path() != null_) {
244  std::stringstream ss;
245  ss << "[SiStripConfigDb::" << __func__ << "]"
246  << " Setting \"user/passwd@path\" to \"" << dbParams_.user() << "/" << dbParams_.passwd() << "@"
247  << dbParams_.path() << "\" using 'ConfDb' configurable read from .cfg file";
248  edm::LogVerbatim(mlConfigDb_) << ss.str();
249 
250  } else {
251  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
252  << " Unable to retrieve 'user/passwd@path' parameters"
253  << " from 'CONFDB' environmental variable or .cfg file"
254  << " (present value is \"" << user << "/" << passwd << "@" << path
255  << "\"). Aborting connection to database...";
256  return;
257  }
258 
259  // Check TNS_ADMIN environmental variable
260  std::string pattern = "TNS_ADMIN";
261  std::string tns_admin = "/afs/cern.ch/project/oracle/admin";
262  if (std::getenv(pattern.c_str()) != nullptr) {
263  tns_admin = std::getenv(pattern.c_str());
264  edm::LogVerbatim(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
265  << " TNS_ADMIN is set to: \"" << tns_admin << "\"";
266  } else {
267  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
268  << " TNS_ADMIN is not set!"
269  << " Trying to use /afs and setting to: \"" << tns_admin << "\"";
270  }
271 
272  // Retrieve TNS_ADMIN from .cfg file and override
273  if (!dbParams_.tnsAdmin().empty()) {
274  std::stringstream ss;
275  ss << "[SiStripConfigDb::" << __func__ << "]"
276  << " Overriding TNS_ADMIN value using cfg file!" << std::endl
277  << " Original value : \"" << tns_admin << "\"!" << std::endl
278  << " New value : \"" << dbParams_.tnsAdmin() << "\"!";
279  tns_admin = dbParams_.tnsAdmin();
280  edm::LogVerbatim(mlConfigDb_) << ss.str();
281  }
282 
283  // Remove trailing slash and set TNS_ADMIN
284  if (tns_admin.empty()) {
285  tns_admin = ".";
286  }
287  std::string slash = tns_admin.substr(tns_admin.size() - 1, 1);
288  if (slash == sistrip::dir_) {
289  tns_admin = tns_admin.substr(0, tns_admin.size() - 1);
290  }
291  setenv(pattern.c_str(), tns_admin.c_str(), 1);
292 
293  // Check if database is found in tnsnames.ora file
294  std::string filename(tns_admin + "/tnsnames.ora");
295  std::ifstream tnsnames_ora(filename.c_str());
296  bool ok = false;
297  if (tnsnames_ora.is_open()) {
299  while (!tnsnames_ora.eof()) {
300  getline(tnsnames_ora, line);
301  if (!dbParams_.path().empty() && line.find(dbParams_.path()) != std::string::npos) {
302  ok = true;
303  }
304  }
305  } else {
306  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
307  << " Cannot open file \"" << filename << "\"";
308  }
309 
310  if (ok) {
311  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
312  << " Found database account \"" << dbParams_.path() << "\" in file \"" << filename << "\"!";
313  } else {
314  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
315  << " Cannot find database account \"" << dbParams_.path() << "\" in file \""
316  << filename << "\""
317  << " Aborting connection to database...";
318  return;
319  }
320 
321  // Create device factory object
322  try {
323  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
324  << " Creating DeviceFactory object...";
325  factory_ = new DeviceFactory(dbParams_.user(), dbParams_.passwd(), dbParams_.path());
326  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
327  << " Created DeviceFactory object!";
328  } catch (...) {
329  std::stringstream ss;
330  ss << "Failed to connect to database using parameters '" << dbParams_.user() << "/" << dbParams_.passwd() << "@"
331  << dbParams_.path() << "' and partitions '" << dbParams_.partitionNames(dbParams_.partitionNames()) << "'";
332  handleException(__func__, ss.str());
333  return;
334  }
335 
336  // Check for valid pointer to DeviceFactory
337  if (deviceFactory(__func__)) {
338  std::stringstream ss;
339  ss << "[SiStripConfigDb::" << __func__ << "]"
340  << " DeviceFactory created at address 0x" << std::hex << std::setw(8) << std::setfill('0') << factory_
341  << std::dec << ", using database account with parameters '" << dbParams_.user() << "/" << dbParams_.passwd()
342  << "@" << dbParams_.path();
343  LogTrace(mlConfigDb_) << ss.str();
344  } else {
345  edm::LogError(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
346  << " NULL pointer to DeviceFactory!"
347  << " Unable to connect to database using connection parameters '" << dbParams_.user()
348  << "/" << dbParams_.passwd() << "@" << dbParams_.path() << "' and partitions '"
350  return;
351  }
352 
353  try {
354  deviceFactory(__func__)->setUsingDb(dbParams_.usingDb());
355  } catch (...) {
356  handleException(__func__, "Attempted to 'setUsingDb'");
357  }
358 
359  // Retrieve partition name from ENV_CMS_TK_PARTITION env. var. and override .cfg value
360  std::string partition = "ENV_CMS_TK_PARTITION";
361  if (std::getenv(partition.c_str()) != nullptr) {
362  std::stringstream ss;
363  ss << "[SiStripConfigDb::" << __func__ << "]"
364  << " Setting \"partitions\" to \"" << std::getenv(partition.c_str())
365  << "\" using 'ENV_CMS_TK_PARTITION' environmental variable";
366  if (!dbParams_.partitionNames().empty()) {
367  ss << " (Overwriting existing value of \"" << dbParams_.partitionNames(dbParams_.partitionNames())
368  << "\" read from .cfg file)";
369  }
370  edm::LogVerbatim(mlConfigDb_) << ss.str() << std::endl;
371 
372  // Build partitions from env. var.
373  std::vector<std::string> partitions = dbParams_.partitionNames(std::getenv(partition.c_str()));
374  if (!partitions.empty()) {
376  std::vector<std::string>::iterator ii = partitions.begin();
377  std::vector<std::string>::iterator jj = partitions.end();
378  for (; ii != jj; ++ii) {
379  SiStripPartition partition(*ii);
380  dbParams_.addPartition(partition);
381  }
382  }
383 
384  } else if (!dbParams_.partitionNames().empty()) {
385  std::stringstream ss;
386  ss << "[SiStripConfigDb::" << __func__ << "]"
387  << " Setting \"partitions\" to \"" << dbParams_.partitionNames(dbParams_.partitionNames())
388  << "\" using 'PartitionName' configurables read from .cfg file";
389  edm::LogVerbatim(mlConfigDb_) << ss.str();
390  } else {
391  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
392  << " Unable to retrieve 'partition' parameter"
393  << " from 'CONFDB' environmental variable or .cfg file!"
394  << " Aborting connection to database...";
395  return;
396  }
397 
398  // Check if should use current state, run number or versions
399  SiStripDbParams::SiStripPartitions::iterator ip = dbParams_.partitions().begin();
400  SiStripDbParams::SiStripPartitions::iterator jp = dbParams_.partitions().end();
401  for (; ip != jp; ++ip) {
402  ip->second.update(this);
403  }
404 }
405 
406 // -----------------------------------------------------------------------------
407 //
409  // Reset all DbParams except for those concerning database cache
411  temp = dbParams_;
412  dbParams_.reset();
413  dbParams_.usingDb(temp.usingDb());
414  dbParams_.usingDbCache(temp.usingDbCache());
415  dbParams_.sharedMemory(temp.sharedMemory());
416 
417  // Add default partition
419 
420  // Check shared memory name from .cfg file
421  if (dbParams_.sharedMemory().empty()) {
422  std::stringstream ss;
423  ss << "[SiStripConfigDb::" << __func__ << "]"
424  << " Empty string for shared memory name!"
425  << " Cannot accept shared memory!";
426  edm::LogError(mlConfigDb_) << ss.str();
427  return;
428  }
429 
430  // Create database cache object
431  try {
432  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
433  << " Creating DbClient object...";
434  dbCache_ = new DbClient(dbParams_.sharedMemory());
435  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
436  << " Created DbClient object...";
437  } catch (...) {
438  std::stringstream ss;
439  ss << "Failed to connect to database cache using shared memory name: '" << dbParams_.sharedMemory() << "'!";
440  handleException(__func__, ss.str());
441  return;
442  }
443 
444  // Check for valid pointer to DbClient object
445  if (databaseCache(__func__)) {
446  std::stringstream ss;
447  ss << "[SiStripConfigDb::" << __func__ << "]"
448  << " DbClient object created at address 0x" << std::hex << std::setw(8) << std::setfill('0') << dbCache_
449  << std::dec << " using shared memory name '" << dbParams_.sharedMemory() << "'";
450  LogTrace(mlConfigDb_) << ss.str();
451  } else {
452  edm::LogError(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
453  << " NULL pointer to DbClient object!"
454  << " Unable to connect to database cache using shared memory name '"
455  << dbParams_.sharedMemory() << "'";
456  return;
457  }
458 
459  // Try retrieve descriptions from Database Client
460  try {
461  databaseCache(__func__)->parse();
462  } catch (...) {
463  handleException(__func__, "Attempted to called DbClient::parse() method");
464  }
465 }
466 
467 // -----------------------------------------------------------------------------
468 //
470  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
471  << " Using XML description files...";
472 
473  // Create device factory object
474  try {
475  factory_ = new DeviceFactory();
476  } catch (...) {
477  handleException(__func__, "Attempting to create DeviceFactory for use with xml files");
478  }
479 
480  // Check for valid pointer to DeviceFactory
481  if (deviceFactory(__func__)) {
482  std::stringstream ss;
483  ss << "[SiStripConfigDb::" << __func__ << "]"
484  << " DeviceFactory created at address 0x" << std::hex << std::setw(8) << std::setfill('0') << factory_
485  << std::dec << ", using XML description files";
486  LogTrace(mlConfigDb_) << ss.str();
487  } else {
488  edm::LogError(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
489  << " NULL pointer to DeviceFactory!"
490  << " Unable to connect to database!";
491  return;
492  }
493 
494  try {
495  deviceFactory(__func__)->setUsingDb(dbParams_.usingDb());
496  } catch (...) {
497  handleException(__func__, "Attempted to 'setUsingDb'");
498  }
499 
500  // Iterate through partitions
501  SiStripDbParams::SiStripPartitions::const_iterator ip = dbParams_.partitions().begin();
502  SiStripDbParams::SiStripPartitions::const_iterator jp = dbParams_.partitions().end();
503  for (; ip != jp; ++ip) {
504  // Input module.xml file
505  if (ip->second.inputModuleXml().empty()) {
506  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
507  << " NULL path to input 'module.xml' file!";
508  } else {
509  if (checkFileExists(ip->second.inputModuleXml())) {
510  try {
511  deviceFactory(__func__)->addConnectionFileName(ip->second.inputModuleXml());
512  } catch (...) {
513  handleException(__func__);
514  }
515  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
516  << " Added input 'module.xml' file: " << ip->second.inputModuleXml();
517  } else {
518  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
519  << " No 'module.xml' file found at " << ip->second.inputModuleXml();
520  ip->second.inputModuleXml() = "";
521  }
522  }
523 
524  // Input dcuinfo.xml file
525  if (ip->second.inputDcuInfoXml().empty()) {
526  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
527  << " NULL path to input 'dcuinfo.xml' file!";
528  } else {
529  if (checkFileExists(ip->second.inputDcuInfoXml())) {
530  try {
531  deviceFactory(__func__)->addTkDcuInfoFileName(ip->second.inputDcuInfoXml());
532  } catch (...) {
533  handleException(__func__);
534  }
535  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
536  << " Added 'dcuinfo.xml' file: " << ip->second.inputDcuInfoXml();
537  } else {
538  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
539  << " No 'dcuinfo.xml' file found at " << ip->second.inputDcuInfoXml();
540  ip->second.inputDcuInfoXml() = "";
541  }
542  }
543 
544  // Input FEC xml files
545  if (ip->second.inputFecXml().empty()) {
546  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
547  << " NULL paths to input 'fec.xml' files!";
548  } else {
549  for (const auto& iter : ip->second.inputFecXml()) {
550  if (iter.empty()) {
551  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
552  << " NULL path to input 'fec.xml' file!";
553  } else {
554  if (checkFileExists(iter)) {
555  try {
556  deviceFactory(__func__)->addFecFileName(iter);
557  } catch (...) {
558  handleException(__func__);
559  }
560  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
561  << " Added 'fec.xml' file: " << iter;
562  } else {
563  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
564  << " No 'fec.xml' file found at " << iter;
565  }
566  }
567  }
568  }
569 
570  // Input FED xml files
571  if (ip->second.inputFedXml().empty()) {
572  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
573  << " NULL paths to input 'fed.xml' files!";
574  } else {
575  for (const auto& iter : ip->second.inputFedXml()) {
576  if (iter.empty()) {
577  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
578  << " NULL path to input 'fed.xml' file!";
579  } else {
580  if (checkFileExists(iter)) {
581  try {
582  deviceFactory(__func__)->addFedFileName(iter);
583  } catch (...) {
584  handleException(__func__);
585  }
586  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
587  << " Added 'fed.xml' file: " << iter;
588  } else {
589  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
590  << " No 'fed.xml' file found at " << iter;
591  }
592  }
593  }
594  }
595  }
596 
597  // Output module.xml file
598  if (dbParams_.outputModuleXml().empty()) {
599  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
600  << " NULL path to output 'module.xml' file!"
601  << " Setting to '/tmp/module.xml'...";
602  dbParams_.outputModuleXml() = "/tmp/module.xml";
603  } else {
604  try {
605  ConnectionFactory* factory = deviceFactory(__func__);
606  factory->setOutputFileName(dbParams_.outputModuleXml());
607  } catch (...) {
608  handleException(__func__, "Problems setting output 'module.xml' file!");
609  }
610  }
611 
612  // Output dcuinfo.xml file
613  if (dbParams_.outputDcuInfoXml().empty()) {
614  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
615  << " NULL path to output 'dcuinfo.xml' file!"
616  << " Setting to '/tmp/dcuinfo.xml'...";
617  dbParams_.outputModuleXml() = "/tmp/dcuinfo.xml";
618  } else {
619  try {
620  TkDcuInfoFactory* factory = deviceFactory(__func__);
621  factory->setOutputFileName(dbParams_.outputDcuInfoXml());
622  } catch (...) {
623  handleException(__func__, "Problems setting output 'dcuinfo.xml' file!");
624  }
625  }
626 
627  // Output fec.xml file
628  if (dbParams_.outputFecXml().empty()) {
629  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
630  << " NULL path to output 'fec.xml' file!"
631  << " Setting to '/tmp/fec.xml'...";
632  dbParams_.outputFecXml() = "/tmp/fec.xml";
633  } else {
634  try {
635  FecDeviceFactory* factory = deviceFactory(__func__);
636  factory->setOutputFileName(dbParams_.outputFecXml());
637  } catch (...) {
638  handleException(__func__, "Problems setting output 'fec.xml' file!");
639  }
640  }
641 
642  // Output fed.xml file
643  if (dbParams_.outputFedXml().empty()) {
644  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
645  << " NULL path to output 'fed.xml' file!"
646  << " Setting to '/tmp/fed.xml'...";
647  dbParams_.outputFedXml() = "/tmp/fed.xml";
648  } else {
649  try {
650  Fed9U::Fed9UDeviceFactory* factory = deviceFactory(__func__);
651  factory->setOutputFileName(dbParams_.outputFedXml());
652  } catch (...) {
653  handleException(__func__, "Problems setting output 'fed.xml' file!");
654  }
655  }
656 }
657 
658 // -----------------------------------------------------------------------------
659 //
660 void SiStripConfigDb::handleException(const std::string& method_name, const std::string& extra_info) const {
661  std::stringstream ss;
662  try {
663  throw; // rethrow caught exception to be dealt with below
664  }
665 
666  catch (const cms::Exception& e) {
667  ss << " Caught cms::Exception in method " << method_name << " with message: " << std::endl << e.what();
668  if (!extra_info.empty()) {
669  ss << "Additional info: " << extra_info << std::endl;
670  }
671  //throw e; // rethrow cms::Exception
672  }
673 
674  catch (const oracle::occi::SQLException& e) {
675  ss << " Caught oracle::occi::SQLException in method " << method_name << " with message: " << std::endl
676  << e.getMessage();
677  if (!extra_info.empty()) {
678  ss << "Additional info: " << extra_info << std::endl;
679  }
680  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
681  }
682 
683  catch (const FecExceptionHandler& e) {
684  ss << " Caught FecExceptionHandler exception in method " << method_name << " with message: " << std::endl
685  << const_cast<FecExceptionHandler&>(e).what();
686  if (!extra_info.empty()) {
687  ss << "Additional info: " << extra_info << std::endl;
688  }
689  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
690  }
691 
692  // catch ( const Fed9UDeviceFactoryException& e ) {
693  // ss << " Caught Fed9UDeviceFactoryException exception in method "
694  // << method_name << " with message: " << std::endl
695  // << e.what();
696  // if ( extra_info != "" ) { ss << "Additional info: " << extra_info << std::endl; }
697  // //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
698  // }
699 
700  catch (const ICUtils::ICException& e) {
701  ss << " Caught ICUtils::ICException in method " << method_name << " with message: " << std::endl << e.what();
702  if (!extra_info.empty()) {
703  ss << "Additional info: " << extra_info << std::endl;
704  }
705  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
706  }
707 
708  catch (const exception& e) {
709  ss << " Caught std::exception in method " << method_name << " with message: " << std::endl << e.what();
710  if (!extra_info.empty()) {
711  ss << "Additional info: " << extra_info << std::endl;
712  }
713  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
714  }
715 
716  catch (...) {
717  ss << " Caught unknown exception in method " << method_name << " (No message) " << std::endl;
718  if (!extra_info.empty()) {
719  ss << "Additional info: " << extra_info << std::endl;
720  }
721  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
722  }
723 
724  // Message
725  edm::LogError(mlConfigDb_) << ss.str();
726 }
727 
728 // -----------------------------------------------------------------------------
729 //
731  fstream fs;
732  fs.open(path.c_str(), ios::in);
733  if (!fs.is_open()) {
734  return false;
735  }
736  fs.close();
737  return true;
738 }
739 
740 // -----------------------------------------------------------------------------
741 //
743  runs.clear();
744 
745  // Check DF pointer
746  DeviceFactory* const df = deviceFactory(__func__);
747  if (!df) {
748  edm::LogError(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
749  << " NULL pointer to DeviceFactory object!";
750  return;
751  }
752 
753  // Retrieve runs
754  tkRunVector all;
755  all = df->getAllRuns();
756 
757  // Iterate through tkRunVector
758  tkRunVector::const_iterator ii = all.begin();
759  tkRunVector::const_iterator jj = all.end();
760  for (; ii != jj; ++ii) {
761  // Check TkRun pointer
762  if (*ii) {
763  // Retrieve run type
764  uint16_t type = (*ii)->getModeId((*ii)->getMode());
766  if (type == 1) {
768  } else if (type == 2) {
770  } else if (type == 3) {
772  } else if (type == 33) {
774  } else if (type == 4) {
776  } else if (type == 5) {
778  } else if (type == 6) {
780  } else if (type == 7) {
782  } else if (type == 10) {
784  } else if (type == 8) {
786  } else if (type == 12) {
788  } else if (type == 13) {
790  } else if (type == 14) {
792  } else if (type == 15) {
794  } else if (type == 16) {
796  } else if (type == 17) {
798  } else if (type == 18) {
800  } else if (type == 19) {
802  } else if (type == 20) {
804  } else if (type == 21) {
806  } else if (type == 0) {
808  } else {
810  }
811 
812  // Store run details
813  Run r;
814  r.type_ = temp;
815  r.partition_ = (*ii)->getPartitionName();
816  r.number_ = (*ii)->getRunNumber();
817  runs.push_back(r);
818 
819  } else {
820  edm::LogWarning(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
821  << " NULL pointer to TkRun object!";
822  }
823  }
824 }
825 
826 // -----------------------------------------------------------------------------
827 //
830  std::string optional_partition) const {
831  out.clear();
832 
833  // Check partition name (if not empty string)
834  if (!optional_partition.empty()) {
835  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partition(optional_partition);
836  if (iter == dbParams_.partitions().end()) {
837  edm::LogWarning(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
838  << " Partition name not found!";
839  return;
840  }
841  }
842 
843  // Iterate through runs
844  Runs::const_iterator ii = in.begin();
845  Runs::const_iterator jj = in.end();
846  for (; ii != jj; ++ii) {
847  // Check partition name
848  if (ii->partition_ == optional_partition || optional_partition.empty()) {
849  // Check run type
850  if (ii->type_ != sistrip::UNKNOWN_RUN_TYPE && ii->type_ != sistrip::UNDEFINED_RUN_TYPE) {
851  // Check run number
852  if (ii->number_) {
853  bool found = false;
854  if (out.find(ii->type_) != out.end()) {
855  Runs::const_iterator irun = out[ii->type_].begin();
856  Runs::const_iterator jrun = out[ii->type_].end();
857  while (!found && irun != jrun) {
858  if (irun->number_ == ii->number_) {
859  found = true;
860  }
861  ++irun;
862  }
863  }
864  // Check if run number already found
865  if (!found) {
866  out[ii->type_].push_back(*ii);
867  } else {
868  // edm::LogWarning(mlConfigDb_)
869  // << "[SiStripPartition::" << __func__ << "]"
870  // << " Run number already found!";
871  }
872  } else {
873  // edm::LogWarning(mlConfigDb_)
874  // << "[SiStripPartition::" << __func__ << "]"
875  // << " NULL run number!";
876  }
877  } else {
878  // edm::LogWarning(mlConfigDb_)
879  // << "[SiStripPartition::" << __func__ << "]"
880  // << " Unexpected run type!";
881  }
882  } else {
883  // edm::LogWarning(mlConfigDb_)
884  // << "[SiStripPartition::" << __func__ << "]"
885  // << " Partition name does not match!";
886  }
887  }
888 }
889 
890 // -----------------------------------------------------------------------------
891 //
894  sistrip::RunType optional_type) const {
895  out.clear();
896 
897  // Iterate through runs
898  Runs::const_iterator ii = in.begin();
899  Runs::const_iterator jj = in.end();
900  for (; ii != jj; ++ii) {
901  // Check partition name
902  if (!ii->partition_.empty()) {
903  // Check run type
904  if (ii->type_ == optional_type || optional_type == sistrip::UNDEFINED_RUN_TYPE) {
905  // Check run number
906  if (ii->number_) {
907  bool found = false;
908  if (out.find(ii->partition_) != out.end()) {
909  Runs::const_iterator irun = out[ii->partition_].begin();
910  Runs::const_iterator jrun = out[ii->partition_].end();
911  while (!found && irun != jrun) {
912  if (irun->number_ == ii->number_) {
913  found = true;
914  }
915  ++irun;
916  }
917  }
918  // Check if run number already found
919  if (!found) {
920  out[ii->partition_].push_back(*ii);
921  } else {
922  // edm::LogWarning(mlConfigDb_)
923  // << "[SiStripPartition::" << __func__ << "]"
924  // << " Run number already found!";
925  }
926  } else {
927  // edm::LogWarning(mlConfigDb_)
928  // << "[SiStripPartition::" << __func__ << "]"
929  // << " NULL run number!";
930  }
931  } else {
932  // edm::LogWarning(mlConfigDb_)
933  // << "[SiStripPartition::" << __func__ << "]"
934  // << " Run type does not match!";
935  }
936  } else {
937  // edm::LogWarning(mlConfigDb_)
938  // << "[SiStripPartition::" << __func__ << "]"
939  // << " NULL value for partition!";
940  }
941  }
942 }
943 
944 // -----------------------------------------------------------------------------
945 //
946 void SiStripConfigDb::partitions(std::list<std::string>& partitions) const {
947  partitions.clear();
948 
949  // Check DF pointer
950  DeviceFactory* const df = deviceFactory(__func__);
951  if (!df) {
952  edm::LogError(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
953  << " NULL pointer to DeviceFactory object!";
954  return;
955  }
956 
957  partitions = df->getAllPartitionNames();
958 }
sistrip::CALIBRATION_SCAN
Definition: ConstantsForRunType.h:87
sistrip::PHYSICS_ZS
Definition: ConstantsForRunType.h:86
sistrip::null_
static const char null_[]
Definition: Constants.h:22
SiStripDbParams::partitionNames
std::vector< std::string > partitionNames() const
Definition: SiStripDbParams.cc:253
sistrip::DAQ_SCOPE_MODE
Definition: ConstantsForRunType.h:83
SiStripConfigDb::clearAnalysisDescriptions
void clearAnalysisDescriptions(std::string partition="")
Definition: AnalysisDescriptions.cc:337
SiStripConfigDb::handleException
void handleException(const std::string &method_name, const std::string &extra_info="") const
Definition: SiStripConfigDb.cc:660
sistrip::CALIBRATION
Definition: ConstantsForRunType.h:73
SiStripConfigDb::cntr_
static std::atomic< uint32_t > cntr_
Definition: SiStripConfigDb.h:413
SiStripConfigDb::Runs
std::vector< Run > Runs
Definition: SiStripConfigDb.h:187
MessageLogger.h
SiStripConfigDb::factory_
DeviceFactory * factory_
Definition: SiStripConfigDb.h:355
sistrip::VPSP_SCAN
Definition: ConstantsForRunType.h:82
sistrip::FAST_CABLING
Definition: ConstantsForRunType.h:89
funct::false
false
Definition: Factorize.h:29
sistrip::APV_TIMING
Definition: ConstantsForRunType.h:75
SiStripConfigDb::openDbConnection
void openDbConnection()
Definition: SiStripConfigDb.cc:98
SiStripPartition
Container class for database partition parameters.
Definition: SiStripPartition.h:24
SiStripConfigDb::Run
Definition: SiStripConfigDb.h:179
SiStripConfigDb::fedIds_
FedIds fedIds_
Definition: SiStripConfigDb.h:402
SiStripConfigDb::RunsByPartition
std::map< std::string, Runs > RunsByPartition
Definition: SiStripConfigDb.h:191
sistrip::dir_
static const char dir_[]
Definition: ConstantsForDqm.h:17
sistrip::OPTO_SCAN
Definition: ConstantsForRunType.h:74
SiStripConfigDb::openConnection_
bool openConnection_
Definition: SiStripConfigDb.h:410
SiStripConfigDb::allowCalibUpload_
static std::atomic< bool > allowCalibUpload_
Definition: SiStripConfigDb.h:415
SiStripDbParams::tnsAdmin
std::string tnsAdmin() const
Definition: SiStripDbParams.h:176
SiStripConfigDb::~SiStripConfigDb
~SiStripConfigDb()
Definition: SiStripConfigDb.cc:58
SiStripConfigDb::dbParams_
SiStripDbParams dbParams_
Definition: SiStripConfigDb.h:361
sistrip::RunType
RunType
Definition: ConstantsForRunType.h:70
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:26
SiStripConfigDb::clearDcuDetIds
void clearDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:270
SiStripConfigDb::clearFedDescriptions
void clearFedDescriptions(std::string partition="")
Definition: FedDescriptions.cc:268
sistrip::ccuAddr_
static const char ccuAddr_[]
Definition: ConstantsForGranularity.h:55
sistrip::FINE_DELAY
Definition: ConstantsForRunType.h:85
sistrip::mlConfigDb_
static const char mlConfigDb_[]
Definition: ConstantsForLogger.h:16
SiStripDbParams::partition
SiStripPartitions::const_iterator partition(std::string partition_name) const
Definition: SiStripDbParams.cc:227
SiStripConfigDb::partitions
void partitions(std::list< std::string > &) const
Definition: SiStripConfigDb.cc:946
SiStripConfigDb::SiStripPartition
friend class SiStripPartition
Definition: SiStripConfigDb.h:95
SiStripConfigDb::RunsByType
std::map< sistrip::RunType, Runs > RunsByType
Definition: SiStripConfigDb.h:189
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
SiStripConfigDb::clearFedConnections
void clearFedConnections(std::string partition="")
Definition: FedConnections.cc:269
SiStripConfigDb::SiStripConfigDb
SiStripConfigDb(const edm::ParameterSet &, const edm::ActivityRegistry &)
Definition: SiStripConfigDb.cc:21
sistrip::FED_CABLING
Definition: ConstantsForRunType.h:81
SiStripConfigDb::deviceFactory
DeviceFactory *const deviceFactory(std::string method_name="") const
Definition: SiStripConfigDb.cc:191
SiStripConfigDb::closeDbConnection
void closeDbConnection()
Definition: SiStripConfigDb.cc:136
sistrip::FINE_DELAY_TTC
Definition: ConstantsForRunType.h:78
edm::ActivityRegistry
Definition: ActivityRegistry.h:133
SiStripConfigDb::usingXmlFiles
void usingXmlFiles()
Definition: SiStripConfigDb.cc:469
sistrip::fecCrate_
static const char fecCrate_[]
Definition: ConstantsForGranularity.h:52
SiStripDbParams::user
std::string user() const
Definition: SiStripDbParams.h:171
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
SiStripDbParams::clearPartitions
void clearPartitions()
Definition: SiStripDbParams.h:192
SiStripConfigDb::usingDatabaseCache
void usingDatabaseCache()
Definition: SiStripConfigDb.cc:408
SiStripDbParams::sharedMemory
std::string sharedMemory() const
Definition: SiStripDbParams.h:175
sistrip::fecSlot_
static const char fecSlot_[]
Definition: ConstantsForGranularity.h:53
SiStripDbParams::outputModuleXml
std::string outputModuleXml() const
Definition: SiStripDbParams.h:187
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripConfigDb::DeviceAddress::DeviceAddress
DeviceAddress()
Definition: SiStripConfigDb.cc:67
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
funct::true
true
Definition: Factorize.h:173
sistrip::ccuChan_
static const char ccuChan_[]
Definition: ConstantsForGranularity.h:56
SiStripConstants.h
sistrip::lldChan_
static const char lldChan_[]
Definition: ConstantsForGranularity.h:39
edm::ParameterSet
Definition: ParameterSet.h:47
sistrip::CALIBRATION_DECO
Definition: ConstantsForRunType.h:93
SiStripDbParams::usingDb
bool usingDb() const
Definition: SiStripDbParams.h:169
SiStripDbParams::path
std::string path() const
Definition: SiStripDbParams.h:173
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
sistrip::QUITE_FAST_CABLING
Definition: ConstantsForRunType.h:84
SiStripDbParams::addPartition
void addPartition(const SiStripPartition &)
Definition: SiStripDbParams.cc:121
SiStripConfigDb::databaseCache
DbClient *const databaseCache(std::string method_name="") const
Definition: SiStripConfigDb.cc:208
recoMuon::in
Definition: RecoMuonEnumerators.h:6
sistrip::PEDESTALS
Definition: ConstantsForRunType.h:72
SiStripDbParams::outputFecXml
std::string outputFecXml() const
Definition: SiStripDbParams.h:189
SiStripConfigDb::checkFileExists
bool checkFileExists(const std::string &path)
Definition: SiStripConfigDb.cc:730
SiStripConfigDb::typedDevices_
DeviceDescriptionsV typedDevices_
Definition: SiStripConfigDb.h:399
SiStripConfigDb::usingDatabase
void usingDatabase()
Definition: SiStripConfigDb.cc:225
SiStripDbParams::outputDcuInfoXml
std::string outputDcuInfoXml() const
Definition: SiStripDbParams.h:188
sistrip::UNKNOWN_RUN_TYPE
Definition: ConstantsForRunType.h:94
SiStripDbParams::partitions
const_iterator_range partitions() const
Definition: SiStripDbParams.h:178
sistrip::FED_TIMING
Definition: ConstantsForRunType.h:80
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
sistrip::invalid_
static const uint16_t invalid_
Definition: Constants.h:16
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
SiStripDbParams::confdb
std::string confdb() const
Definition: SiStripDbParams.h:170
SiStripConfigDb::dbCache_
DbClient * dbCache_
Definition: SiStripConfigDb.h:358
SiStripConfigDb::clearLocalCache
void clearLocalCache()
Definition: SiStripConfigDb.cc:175
SiStripConfigDb::runs
void runs(Runs &) const
Definition: SiStripConfigDb.cc:742
SiStripConfigDb.h
EnviromentSettings.user
user
Definition: EnviromentSettings.py:30
sistrip::MULTI_MODE
Definition: ConstantsForRunType.h:79
alignCSCRings.r
r
Definition: alignCSCRings.py:93
SiStripConfigDb::DeviceAddress::reset
void reset()
Definition: SiStripConfigDb.cc:83
SiStripDbParams::outputFedXml
std::string outputFedXml() const
Definition: SiStripDbParams.h:190
sistrip::FINE_DELAY_PLL
Definition: ConstantsForRunType.h:77
sistrip::feChan_
static const char feChan_[]
Definition: ConstantsForGranularity.h:46
SiStripDbParams
Container class for database connection parameters.
Definition: SiStripDbParams.h:25
sistrip::CALIBRATION_SCAN_DECO
Definition: ConstantsForRunType.h:88
sistrip::PHYSICS
Definition: ConstantsForRunType.h:71
pickleFileParser.slash
slash
Definition: pickleFileParser.py:12
hgcalPerformanceValidation.df
df
Definition: hgcalPerformanceValidation.py:640
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
sistrip::APV_LATENCY
Definition: ConstantsForRunType.h:76
SiStripEnumsAndStrings.h
sistrip::UNDEFINED_RUN_TYPE
Definition: ConstantsForRunType.h:95
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
SiStripDbParams::usingDbCache
bool usingDbCache() const
Definition: SiStripDbParams.h:174
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
sistrip::fecRing_
static const char fecRing_[]
Definition: ConstantsForGranularity.h:54
cms::Exception
Definition: Exception.h:70
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
SiStripConfigDb::clearDeviceDescriptions
void clearDeviceDescriptions(std::string partition="")
Definition: DeviceDescriptions.cc:335
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
SiStripPartition::defaultPartitionName_
static const std::string defaultPartitionName_
Definition: SiStripPartition.h:40
SiStripDbParams::pset
void pset(const edm::ParameterSet &)
Definition: SiStripDbParams.cc:151
mps_splice.line
line
Definition: mps_splice.py:76
SiStripDbParams::reset
void reset()
Definition: SiStripDbParams.cc:102
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
cuy.ii
ii
Definition: cuy.py:590
SiStripDbParams::passwd
std::string passwd() const
Definition: SiStripDbParams.h:172
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
sistrip::feUnit_
static const char feUnit_[]
Definition: ConstantsForGranularity.h:45