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();
49  dbParams_.pset(pset);
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 //
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());
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  std::vector<std::string>::iterator iter = ip->second.inputFecXml().begin();
550  for (; iter != ip->second.inputFecXml().end(); iter++) {
551  if ((*iter).empty()) {
552  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
553  << " NULL path to input 'fec.xml' file!";
554  } else {
555  if (checkFileExists(*iter)) {
556  try {
557  deviceFactory(__func__)->addFecFileName(*iter);
558  } catch (...) {
559  handleException(__func__);
560  }
561  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
562  << " Added 'fec.xml' file: " << *iter;
563  } else {
564  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
565  << " No 'fec.xml' file found at " << *iter;
566  *iter = "";
567  }
568  }
569  }
570  }
571 
572  // Input FED xml files
573  if (ip->second.inputFedXml().empty()) {
574  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
575  << " NULL paths to input 'fed.xml' files!";
576  } else {
577  std::vector<std::string>::iterator iter = ip->second.inputFedXml().begin();
578  for (; iter != ip->second.inputFedXml().end(); iter++) {
579  if ((*iter).empty()) {
580  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
581  << " NULL path to input 'fed.xml' file!";
582  } else {
583  if (checkFileExists(*iter)) {
584  try {
585  deviceFactory(__func__)->addFedFileName(*iter);
586  } catch (...) {
587  handleException(__func__);
588  }
589  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
590  << " Added 'fed.xml' file: " << *iter;
591  } else {
592  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
593  << " No 'fed.xml' file found at " << *iter;
594  *iter = "";
595  }
596  }
597  }
598  }
599  }
600 
601  // Output module.xml file
602  if (dbParams_.outputModuleXml().empty()) {
603  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
604  << " NULL path to output 'module.xml' file!"
605  << " Setting to '/tmp/module.xml'...";
606  dbParams_.outputModuleXml() = "/tmp/module.xml";
607  } else {
608  try {
609  ConnectionFactory* factory = deviceFactory(__func__);
610  factory->setOutputFileName(dbParams_.outputModuleXml());
611  } catch (...) {
612  handleException(__func__, "Problems setting output 'module.xml' file!");
613  }
614  }
615 
616  // Output dcuinfo.xml file
617  if (dbParams_.outputDcuInfoXml().empty()) {
618  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
619  << " NULL path to output 'dcuinfo.xml' file!"
620  << " Setting to '/tmp/dcuinfo.xml'...";
621  dbParams_.outputModuleXml() = "/tmp/dcuinfo.xml";
622  } else {
623  try {
624  TkDcuInfoFactory* factory = deviceFactory(__func__);
625  factory->setOutputFileName(dbParams_.outputDcuInfoXml());
626  } catch (...) {
627  handleException(__func__, "Problems setting output 'dcuinfo.xml' file!");
628  }
629  }
630 
631  // Output fec.xml file
632  if (dbParams_.outputFecXml().empty()) {
633  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
634  << " NULL path to output 'fec.xml' file!"
635  << " Setting to '/tmp/fec.xml'...";
636  dbParams_.outputFecXml() = "/tmp/fec.xml";
637  } else {
638  try {
639  FecDeviceFactory* factory = deviceFactory(__func__);
640  factory->setOutputFileName(dbParams_.outputFecXml());
641  } catch (...) {
642  handleException(__func__, "Problems setting output 'fec.xml' file!");
643  }
644  }
645 
646  // Output fed.xml file
647  if (dbParams_.outputFedXml().empty()) {
648  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
649  << " NULL path to output 'fed.xml' file!"
650  << " Setting to '/tmp/fed.xml'...";
651  dbParams_.outputFedXml() = "/tmp/fed.xml";
652  } else {
653  try {
654  Fed9U::Fed9UDeviceFactory* factory = deviceFactory(__func__);
655  factory->setOutputFileName(dbParams_.outputFedXml());
656  } catch (...) {
657  handleException(__func__, "Problems setting output 'fed.xml' file!");
658  }
659  }
660 }
661 
662 // -----------------------------------------------------------------------------
663 //
664 void SiStripConfigDb::handleException(const std::string& method_name, const std::string& extra_info) const {
665  std::stringstream ss;
666  try {
667  throw; // rethrow caught exception to be dealt with below
668  }
669 
670  catch (const cms::Exception& e) {
671  ss << " Caught cms::Exception in method " << method_name << " with message: " << std::endl << e.what();
672  if (!extra_info.empty()) {
673  ss << "Additional info: " << extra_info << std::endl;
674  }
675  //throw e; // rethrow cms::Exception
676  }
677 
678  catch (const oracle::occi::SQLException& e) {
679  ss << " Caught oracle::occi::SQLException in method " << method_name << " with message: " << std::endl
680  << e.getMessage();
681  if (!extra_info.empty()) {
682  ss << "Additional info: " << extra_info << std::endl;
683  }
684  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
685  }
686 
687  catch (const FecExceptionHandler& e) {
688  ss << " Caught FecExceptionHandler exception in method " << method_name << " with message: " << std::endl
689  << const_cast<FecExceptionHandler&>(e).what();
690  if (!extra_info.empty()) {
691  ss << "Additional info: " << extra_info << std::endl;
692  }
693  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
694  }
695 
696  // catch ( const Fed9UDeviceFactoryException& e ) {
697  // ss << " Caught Fed9UDeviceFactoryException exception in method "
698  // << method_name << " with message: " << std::endl
699  // << e.what();
700  // if ( extra_info != "" ) { ss << "Additional info: " << extra_info << std::endl; }
701  // //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
702  // }
703 
704  catch (const ICUtils::ICException& e) {
705  ss << " Caught ICUtils::ICException in method " << method_name << " with message: " << std::endl << e.what();
706  if (!extra_info.empty()) {
707  ss << "Additional info: " << extra_info << std::endl;
708  }
709  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
710  }
711 
712  catch (const exception& e) {
713  ss << " Caught std::exception in method " << method_name << " with message: " << std::endl << e.what();
714  if (!extra_info.empty()) {
715  ss << "Additional info: " << extra_info << std::endl;
716  }
717  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
718  }
719 
720  catch (...) {
721  ss << " Caught unknown exception in method " << method_name << " (No message) " << std::endl;
722  if (!extra_info.empty()) {
723  ss << "Additional info: " << extra_info << std::endl;
724  }
725  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
726  }
727 
728  // Message
729  edm::LogError(mlConfigDb_) << ss.str();
730 }
731 
732 // -----------------------------------------------------------------------------
733 //
735  fstream fs;
736  fs.open(path.c_str(), ios::in);
737  if (!fs.is_open()) {
738  return false;
739  }
740  fs.close();
741  return true;
742 }
743 
744 // -----------------------------------------------------------------------------
745 //
747  runs.clear();
748 
749  // Check DF pointer
750  DeviceFactory* const df = deviceFactory(__func__);
751  if (!df) {
752  edm::LogError(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
753  << " NULL pointer to DeviceFactory object!";
754  return;
755  }
756 
757  // Retrieve runs
758  tkRunVector all;
759  all = df->getAllRuns();
760 
761  // Iterate through tkRunVector
762  tkRunVector::const_iterator ii = all.begin();
763  tkRunVector::const_iterator jj = all.end();
764  for (; ii != jj; ++ii) {
765  // Check TkRun pointer
766  if (*ii) {
767  // Retrieve run type
768  uint16_t type = (*ii)->getModeId((*ii)->getMode());
770  if (type == 1) {
771  temp = sistrip::PHYSICS;
772  } else if (type == 2) {
773  temp = sistrip::PEDESTALS;
774  } else if (type == 3) {
775  temp = sistrip::CALIBRATION;
776  } else if (type == 33) {
778  } else if (type == 4) {
779  temp = sistrip::OPTO_SCAN;
780  } else if (type == 5) {
781  temp = sistrip::APV_TIMING;
782  } else if (type == 6) {
783  temp = sistrip::APV_LATENCY;
784  } else if (type == 7) {
786  } else if (type == 10) {
787  temp = sistrip::MULTI_MODE;
788  } else if (type == 8) {
790  } else if (type == 12) {
791  temp = sistrip::FED_TIMING;
792  } else if (type == 13) {
793  temp = sistrip::FED_CABLING;
794  } else if (type == 14) {
795  temp = sistrip::VPSP_SCAN;
796  } else if (type == 15) {
798  } else if (type == 16) {
800  } else if (type == 17) {
801  temp = sistrip::FINE_DELAY;
802  } else if (type == 18) {
803  temp = sistrip::PHYSICS_ZS;
804  } else if (type == 19) {
806  } else if (type == 20) {
808  } else if (type == 21) {
809  temp = sistrip::FAST_CABLING;
810  } else if (type == 0) {
812  } else {
814  }
815 
816  // Store run details
817  Run r;
818  r.type_ = temp;
819  r.partition_ = (*ii)->getPartitionName();
820  r.number_ = (*ii)->getRunNumber();
821  runs.push_back(r);
822 
823  } else {
824  edm::LogWarning(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
825  << " NULL pointer to TkRun object!";
826  }
827  }
828 }
829 
830 // -----------------------------------------------------------------------------
831 //
834  std::string optional_partition) const {
835  out.clear();
836 
837  // Check partition name (if not empty string)
838  if (!optional_partition.empty()) {
839  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partition(optional_partition);
840  if (iter == dbParams_.partitions().end()) {
841  edm::LogWarning(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
842  << " Partition name not found!";
843  return;
844  }
845  }
846 
847  // Iterate through runs
848  Runs::const_iterator ii = in.begin();
849  Runs::const_iterator jj = in.end();
850  for (; ii != jj; ++ii) {
851  // Check partition name
852  if (ii->partition_ == optional_partition || optional_partition.empty()) {
853  // Check run type
854  if (ii->type_ != sistrip::UNKNOWN_RUN_TYPE && ii->type_ != sistrip::UNDEFINED_RUN_TYPE) {
855  // Check run number
856  if (ii->number_) {
857  bool found = false;
858  if (out.find(ii->type_) != out.end()) {
859  Runs::const_iterator irun = out[ii->type_].begin();
860  Runs::const_iterator jrun = out[ii->type_].end();
861  while (!found && irun != jrun) {
862  if (irun->number_ == ii->number_) {
863  found = true;
864  }
865  ++irun;
866  }
867  }
868  // Check if run number already found
869  if (!found) {
870  out[ii->type_].push_back(*ii);
871  } else {
872  // edm::LogWarning(mlConfigDb_)
873  // << "[SiStripPartition::" << __func__ << "]"
874  // << " Run number already found!";
875  }
876  } else {
877  // edm::LogWarning(mlConfigDb_)
878  // << "[SiStripPartition::" << __func__ << "]"
879  // << " NULL run number!";
880  }
881  } else {
882  // edm::LogWarning(mlConfigDb_)
883  // << "[SiStripPartition::" << __func__ << "]"
884  // << " Unexpected run type!";
885  }
886  } else {
887  // edm::LogWarning(mlConfigDb_)
888  // << "[SiStripPartition::" << __func__ << "]"
889  // << " Partition name does not match!";
890  }
891  }
892 }
893 
894 // -----------------------------------------------------------------------------
895 //
898  sistrip::RunType optional_type) const {
899  out.clear();
900 
901  // Iterate through runs
902  Runs::const_iterator ii = in.begin();
903  Runs::const_iterator jj = in.end();
904  for (; ii != jj; ++ii) {
905  // Check partition name
906  if (!ii->partition_.empty()) {
907  // Check run type
908  if (ii->type_ == optional_type || optional_type == sistrip::UNDEFINED_RUN_TYPE) {
909  // Check run number
910  if (ii->number_) {
911  bool found = false;
912  if (out.find(ii->partition_) != out.end()) {
913  Runs::const_iterator irun = out[ii->partition_].begin();
914  Runs::const_iterator jrun = out[ii->partition_].end();
915  while (!found && irun != jrun) {
916  if (irun->number_ == ii->number_) {
917  found = true;
918  }
919  ++irun;
920  }
921  }
922  // Check if run number already found
923  if (!found) {
924  out[ii->partition_].push_back(*ii);
925  } else {
926  // edm::LogWarning(mlConfigDb_)
927  // << "[SiStripPartition::" << __func__ << "]"
928  // << " Run number already found!";
929  }
930  } else {
931  // edm::LogWarning(mlConfigDb_)
932  // << "[SiStripPartition::" << __func__ << "]"
933  // << " NULL run number!";
934  }
935  } else {
936  // edm::LogWarning(mlConfigDb_)
937  // << "[SiStripPartition::" << __func__ << "]"
938  // << " Run type does not match!";
939  }
940  } else {
941  // edm::LogWarning(mlConfigDb_)
942  // << "[SiStripPartition::" << __func__ << "]"
943  // << " NULL value for partition!";
944  }
945  }
946 }
947 
948 // -----------------------------------------------------------------------------
949 //
950 void SiStripConfigDb::partitions(std::list<std::string>& partitions) const {
951  partitions.clear();
952 
953  // Check DF pointer
954  DeviceFactory* const df = deviceFactory(__func__);
955  if (!df) {
956  edm::LogError(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
957  << " NULL pointer to DeviceFactory object!";
958  return;
959  }
960 
961  partitions = df->getAllPartitionNames();
962 }
type
Definition: HCALResponse.h:21
DeviceDescriptionsV typedDevices_
std::string passwd() const
static const std::string defaultPartitionName_
DeviceFactory * factory_
void partitions(std::list< std::string > &) const
static const char dir_[]
DeviceFactory *const deviceFactory(std::string method_name="") const
void handleException(const std::string &method_name, const std::string &extra_info="") const
SiStripConfigDb(const edm::ParameterSet &, const edm::ActivityRegistry &)
#define nullptr
char const * what() const override
Definition: Exception.cc:103
void runs(Runs &) const
std::map< std::string, Runs > RunsByPartition
void clearDeviceDescriptions(std::string partition="")
bool checkFileExists(const std::string &path)
bool usingDb() const
sistrip classes
static const char fecSlot_[]
static const char mlConfigDb_[]
static const char ccuChan_[]
static const char ccuAddr_[]
const_iterator_range partitions() const
static const char lldChan_[]
std::vector< std::string > partitionNames() const
std::string outputModuleXml() const
std::string tnsAdmin() const
void clearAnalysisDescriptions(std::string partition="")
static std::atomic< uint32_t > cntr_
static const char fecCrate_[]
std::string sharedMemory() const
Container class for database partition parameters.
std::string user() const
std::map< sistrip::RunType, Runs > RunsByType
#define LogTrace(id)
void clearFedConnections(std::string partition="")
ii
Definition: cuy.py:590
std::vector< Run > Runs
DbClient *const databaseCache(std::string method_name="") const
std::string confdb() const
sistrip::RunType type_
static const char feChan_[]
Container class for database connection parameters.
static const char fecRing_[]
static const uint16_t invalid_
Definition: Constants.h:16
std::string outputFedXml() const
SiStripPartitions::const_iterator partition(std::string partition_name) const
std::string path() const
void pset(const edm::ParameterSet &)
SiStripDbParams dbParams_
bool usingDbCache() const
static std::atomic< bool > allowCalibUpload_
static const char feUnit_[]
DbClient * dbCache_
friend class SiStripPartition
void clearDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:270
void clearFedDescriptions(std::string partition="")
void addPartition(const SiStripPartition &)
std::string outputFecXml() const
std::string outputDcuInfoXml() const
static const char null_[]
Definition: Constants.h:22