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 pToPrint = "******";
230  std::string path = "";
231  DbAccess::getDbConfiguration(user, passwd, path);
232  if (!user.empty() && !passwd.empty() && !path.empty()) {
233  std::stringstream ss;
234  ss << "[SiStripConfigDb::" << __func__ << "]"
235  << " Setting \"user/passwd@path\" to \"" << user << "/" << pToPrint << "@" << path
236  << "\" using 'CONFDB' environmental variable";
237  if (dbParams_.user() != null_ || dbParams_.passwd() != null_ || dbParams_.path() != null_) {
238  ss << " (Overwriting existing value of \"" << dbParams_.user() << "/" << pToPrint << "@" << dbParams_.path()
239  << "\" read from .cfg file)";
240  }
241  edm::LogVerbatim(mlConfigDb_) << ss.str() << std::endl;
242  dbParams_.confdb(user, passwd, path);
243 
244  } else if (dbParams_.user() != null_ && dbParams_.passwd() != null_ && dbParams_.path() != null_) {
245  std::stringstream ss;
246  ss << "[SiStripConfigDb::" << __func__ << "]"
247  << " Setting \"user/passwd@path\" to \"" << dbParams_.user() << "/" << pToPrint << "@" << dbParams_.path()
248  << "\" using 'ConfDb' configurable read from .cfg file";
249  edm::LogVerbatim(mlConfigDb_) << ss.str();
250 
251  } else {
252  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
253  << " Unable to retrieve 'user/passwd@path' parameters"
254  << " from 'CONFDB' environmental variable or .cfg file"
255  << " (present value is \"" << user << "/" << pToPrint << "@" << path
256  << "\"). Aborting connection to database...";
257  return;
258  }
259 
260  // Check TNS_ADMIN environmental variable
261  std::string pattern = "TNS_ADMIN";
262  std::string tns_admin = "/afs/cern.ch/project/oracle/admin";
263  if (std::getenv(pattern.c_str()) != nullptr) {
264  tns_admin = std::getenv(pattern.c_str());
265  edm::LogVerbatim(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
266  << " TNS_ADMIN is set to: \"" << tns_admin << "\"";
267  } else {
268  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
269  << " TNS_ADMIN is not set!"
270  << " Trying to use /afs and setting to: \"" << tns_admin << "\"";
271  }
272 
273  // Retrieve TNS_ADMIN from .cfg file and override
274  if (!dbParams_.tnsAdmin().empty()) {
275  std::stringstream ss;
276  ss << "[SiStripConfigDb::" << __func__ << "]"
277  << " Overriding TNS_ADMIN value using cfg file!" << std::endl
278  << " Original value : \"" << tns_admin << "\"!" << std::endl
279  << " New value : \"" << dbParams_.tnsAdmin() << "\"!";
280  tns_admin = dbParams_.tnsAdmin();
281  edm::LogVerbatim(mlConfigDb_) << ss.str();
282  }
283 
284  // Remove trailing slash and set TNS_ADMIN
285  if (tns_admin.empty()) {
286  tns_admin = ".";
287  }
288  std::string slash = tns_admin.substr(tns_admin.size() - 1, 1);
289  if (slash == sistrip::dir_) {
290  tns_admin = tns_admin.substr(0, tns_admin.size() - 1);
291  }
292  setenv(pattern.c_str(), tns_admin.c_str(), 1);
293 
294  // Check if database is found in tnsnames.ora file
295  std::string filename(tns_admin + "/tnsnames.ora");
296  std::ifstream tnsnames_ora(filename.c_str());
297  bool ok = false;
298  if (tnsnames_ora.is_open()) {
300  while (!tnsnames_ora.eof()) {
301  getline(tnsnames_ora, line);
302  if (!dbParams_.path().empty() && line.find(dbParams_.path()) != std::string::npos) {
303  ok = true;
304  }
305  }
306  } else {
307  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
308  << " Cannot open file \"" << filename << "\"";
309  }
310 
311  if (ok) {
312  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
313  << " Found database account \"" << dbParams_.path() << "\" in file \"" << filename << "\"!";
314  } else {
315  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
316  << " Cannot find database account \"" << dbParams_.path() << "\" in file \""
317  << filename << "\""
318  << " Aborting connection to database...";
319  return;
320  }
321 
322  // Create device factory object
323  try {
324  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
325  << " Creating DeviceFactory object...";
326  factory_ = new DeviceFactory(dbParams_.user(), dbParams_.passwd(), dbParams_.path());
327  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
328  << " Created DeviceFactory object!";
329  } catch (...) {
330  std::stringstream ss;
331  ss << "Failed to connect to database using parameters '" << dbParams_.user() << "/" << pToPrint << "@"
332  << dbParams_.path() << "' and partitions '" << dbParams_.partitionNames(dbParams_.partitionNames()) << "'";
333  handleException(__func__, ss.str());
334  return;
335  }
336 
337  // Check for valid pointer to DeviceFactory
338  if (deviceFactory(__func__)) {
339  std::stringstream ss;
340  ss << "[SiStripConfigDb::" << __func__ << "]"
341  << " DeviceFactory created at address 0x" << std::hex << std::setw(8) << std::setfill('0') << factory_
342  << std::dec << ", using database account with parameters '" << dbParams_.user() << "/" << pToPrint << "@"
343  << dbParams_.path();
344  LogTrace(mlConfigDb_) << ss.str();
345  } else {
346  edm::LogError(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
347  << " NULL pointer to DeviceFactory!"
348  << " Unable to connect to database using connection parameters '" << dbParams_.user()
349  << "/" << pToPrint << "@" << dbParams_.path() << "' and partitions '"
351  return;
352  }
353 
354  try {
355  deviceFactory(__func__)->setUsingDb(dbParams_.usingDb());
356  } catch (...) {
357  handleException(__func__, "Attempted to 'setUsingDb'");
358  }
359 
360  // Retrieve partition name from ENV_CMS_TK_PARTITION env. var. and override .cfg value
361  std::string partition = "ENV_CMS_TK_PARTITION";
362  if (std::getenv(partition.c_str()) != nullptr) {
363  std::stringstream ss;
364  ss << "[SiStripConfigDb::" << __func__ << "]"
365  << " Setting \"partitions\" to \"" << std::getenv(partition.c_str())
366  << "\" using 'ENV_CMS_TK_PARTITION' environmental variable";
367  if (!dbParams_.partitionNames().empty()) {
368  ss << " (Overwriting existing value of \"" << dbParams_.partitionNames(dbParams_.partitionNames())
369  << "\" read from .cfg file)";
370  }
371  edm::LogVerbatim(mlConfigDb_) << ss.str() << std::endl;
372 
373  // Build partitions from env. var.
374  std::vector<std::string> partitions = dbParams_.partitionNames(std::getenv(partition.c_str()));
375  if (!partitions.empty()) {
377  std::vector<std::string>::iterator ii = partitions.begin();
378  std::vector<std::string>::iterator jj = partitions.end();
379  for (; ii != jj; ++ii) {
380  SiStripPartition partition(*ii);
381  dbParams_.addPartition(partition);
382  }
383  }
384 
385  } else if (!dbParams_.partitionNames().empty()) {
386  std::stringstream ss;
387  ss << "[SiStripConfigDb::" << __func__ << "]"
388  << " Setting \"partitions\" to \"" << dbParams_.partitionNames(dbParams_.partitionNames())
389  << "\" using 'PartitionName' configurables read from .cfg file";
390  edm::LogVerbatim(mlConfigDb_) << ss.str();
391  } else {
392  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
393  << " Unable to retrieve 'partition' parameter"
394  << " from 'CONFDB' environmental variable or .cfg file!"
395  << " Aborting connection to database...";
396  return;
397  }
398 
399  // Check if should use current state, run number or versions
400  SiStripDbParams::SiStripPartitions::iterator ip = dbParams_.partitions().begin();
401  SiStripDbParams::SiStripPartitions::iterator jp = dbParams_.partitions().end();
402  for (; ip != jp; ++ip) {
403  ip->second.update(this);
404  }
405 }
406 
407 // -----------------------------------------------------------------------------
408 //
410  // Reset all DbParams except for those concerning database cache
412  temp = dbParams_;
413  dbParams_.reset();
414  dbParams_.usingDb(temp.usingDb());
415  dbParams_.usingDbCache(temp.usingDbCache());
416  dbParams_.sharedMemory(temp.sharedMemory());
417 
418  // Add default partition
420 
421  // Check shared memory name from .cfg file
422  if (dbParams_.sharedMemory().empty()) {
423  std::stringstream ss;
424  ss << "[SiStripConfigDb::" << __func__ << "]"
425  << " Empty string for shared memory name!"
426  << " Cannot accept shared memory!";
427  edm::LogError(mlConfigDb_) << ss.str();
428  return;
429  }
430 
431  // Create database cache object
432  try {
433  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
434  << " Creating DbClient object...";
435  dbCache_ = new DbClient(dbParams_.sharedMemory());
436  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
437  << " Created DbClient object...";
438  } catch (...) {
439  std::stringstream ss;
440  ss << "Failed to connect to database cache using shared memory name: '" << dbParams_.sharedMemory() << "'!";
441  handleException(__func__, ss.str());
442  return;
443  }
444 
445  // Check for valid pointer to DbClient object
446  if (databaseCache(__func__)) {
447  std::stringstream ss;
448  ss << "[SiStripConfigDb::" << __func__ << "]"
449  << " DbClient object created at address 0x" << std::hex << std::setw(8) << std::setfill('0') << dbCache_
450  << std::dec << " using shared memory name '" << dbParams_.sharedMemory() << "'";
451  LogTrace(mlConfigDb_) << ss.str();
452  } else {
453  edm::LogError(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
454  << " NULL pointer to DbClient object!"
455  << " Unable to connect to database cache using shared memory name '"
456  << dbParams_.sharedMemory() << "'";
457  return;
458  }
459 
460  // Try retrieve descriptions from Database Client
461  try {
462  databaseCache(__func__)->parse();
463  } catch (...) {
464  handleException(__func__, "Attempted to called DbClient::parse() method");
465  }
466 }
467 
468 // -----------------------------------------------------------------------------
469 //
471  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
472  << " Using XML description files...";
473 
474  // Create device factory object
475  try {
476  factory_ = new DeviceFactory();
477  } catch (...) {
478  handleException(__func__, "Attempting to create DeviceFactory for use with xml files");
479  }
480 
481  // Check for valid pointer to DeviceFactory
482  if (deviceFactory(__func__)) {
483  std::stringstream ss;
484  ss << "[SiStripConfigDb::" << __func__ << "]"
485  << " DeviceFactory created at address 0x" << std::hex << std::setw(8) << std::setfill('0') << factory_
486  << std::dec << ", using XML description files";
487  LogTrace(mlConfigDb_) << ss.str();
488  } else {
489  edm::LogError(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
490  << " NULL pointer to DeviceFactory!"
491  << " Unable to connect to database!";
492  return;
493  }
494 
495  try {
496  deviceFactory(__func__)->setUsingDb(dbParams_.usingDb());
497  } catch (...) {
498  handleException(__func__, "Attempted to 'setUsingDb'");
499  }
500 
501  // Iterate through partitions
502  SiStripDbParams::SiStripPartitions::const_iterator ip = dbParams_.partitions().begin();
503  SiStripDbParams::SiStripPartitions::const_iterator jp = dbParams_.partitions().end();
504  for (; ip != jp; ++ip) {
505  // Input module.xml file
506  if (ip->second.inputModuleXml().empty()) {
507  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
508  << " NULL path to input 'module.xml' file!";
509  } else {
510  if (checkFileExists(ip->second.inputModuleXml())) {
511  try {
512  deviceFactory(__func__)->addConnectionFileName(ip->second.inputModuleXml());
513  } catch (...) {
514  handleException(__func__);
515  }
516  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
517  << " Added input 'module.xml' file: " << ip->second.inputModuleXml();
518  } else {
519  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
520  << " No 'module.xml' file found at " << ip->second.inputModuleXml();
521  ip->second.inputModuleXml() = "";
522  }
523  }
524 
525  // Input dcuinfo.xml file
526  if (ip->second.inputDcuInfoXml().empty()) {
527  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
528  << " NULL path to input 'dcuinfo.xml' file!";
529  } else {
530  if (checkFileExists(ip->second.inputDcuInfoXml())) {
531  try {
532  deviceFactory(__func__)->addTkDcuInfoFileName(ip->second.inputDcuInfoXml());
533  } catch (...) {
534  handleException(__func__);
535  }
536  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
537  << " Added 'dcuinfo.xml' file: " << ip->second.inputDcuInfoXml();
538  } else {
539  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
540  << " No 'dcuinfo.xml' file found at " << ip->second.inputDcuInfoXml();
541  ip->second.inputDcuInfoXml() = "";
542  }
543  }
544 
545  // Input FEC xml files
546  if (ip->second.inputFecXml().empty()) {
547  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
548  << " NULL paths to input 'fec.xml' files!";
549  } else {
550  for (const auto& iter : ip->second.inputFecXml()) {
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  }
567  }
568  }
569  }
570 
571  // Input FED xml files
572  if (ip->second.inputFedXml().empty()) {
573  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
574  << " NULL paths to input 'fed.xml' files!";
575  } else {
576  for (const auto& iter : ip->second.inputFedXml()) {
577  if (iter.empty()) {
578  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
579  << " NULL path to input 'fed.xml' file!";
580  } else {
581  if (checkFileExists(iter)) {
582  try {
583  deviceFactory(__func__)->addFedFileName(iter);
584  } catch (...) {
585  handleException(__func__);
586  }
587  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
588  << " Added 'fed.xml' file: " << iter;
589  } else {
590  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
591  << " No 'fed.xml' file found at " << iter;
592  }
593  }
594  }
595  }
596  }
597 
598  // Output module.xml file
599  if (dbParams_.outputModuleXml().empty()) {
600  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
601  << " NULL path to output 'module.xml' file!"
602  << " Setting to '/tmp/module.xml'...";
603  dbParams_.outputModuleXml() = "/tmp/module.xml";
604  } else {
605  try {
606  ConnectionFactory* factory = deviceFactory(__func__);
607  factory->setOutputFileName(dbParams_.outputModuleXml());
608  } catch (...) {
609  handleException(__func__, "Problems setting output 'module.xml' file!");
610  }
611  }
612 
613  // Output dcuinfo.xml file
614  if (dbParams_.outputDcuInfoXml().empty()) {
615  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
616  << " NULL path to output 'dcuinfo.xml' file!"
617  << " Setting to '/tmp/dcuinfo.xml'...";
618  dbParams_.outputModuleXml() = "/tmp/dcuinfo.xml";
619  } else {
620  try {
621  TkDcuInfoFactory* factory = deviceFactory(__func__);
622  factory->setOutputFileName(dbParams_.outputDcuInfoXml());
623  } catch (...) {
624  handleException(__func__, "Problems setting output 'dcuinfo.xml' file!");
625  }
626  }
627 
628  // Output fec.xml file
629  if (dbParams_.outputFecXml().empty()) {
630  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
631  << " NULL path to output 'fec.xml' file!"
632  << " Setting to '/tmp/fec.xml'...";
633  dbParams_.outputFecXml() = "/tmp/fec.xml";
634  } else {
635  try {
636  FecDeviceFactory* factory = deviceFactory(__func__);
637  factory->setOutputFileName(dbParams_.outputFecXml());
638  } catch (...) {
639  handleException(__func__, "Problems setting output 'fec.xml' file!");
640  }
641  }
642 
643  // Output fed.xml file
644  if (dbParams_.outputFedXml().empty()) {
645  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
646  << " NULL path to output 'fed.xml' file!"
647  << " Setting to '/tmp/fed.xml'...";
648  dbParams_.outputFedXml() = "/tmp/fed.xml";
649  } else {
650  try {
651  Fed9U::Fed9UDeviceFactory* factory = deviceFactory(__func__);
652  factory->setOutputFileName(dbParams_.outputFedXml());
653  } catch (...) {
654  handleException(__func__, "Problems setting output 'fed.xml' file!");
655  }
656  }
657 }
658 
659 // -----------------------------------------------------------------------------
660 //
661 void SiStripConfigDb::handleException(const std::string& method_name, const std::string& extra_info) const {
662  std::stringstream ss;
663  try {
664  throw; // rethrow caught exception to be dealt with below
665  }
666 
667  catch (const cms::Exception& e) {
668  ss << " Caught cms::Exception in method " << method_name << " with message: " << std::endl << e.what();
669  if (!extra_info.empty()) {
670  ss << "Additional info: " << extra_info << std::endl;
671  }
672  //throw e; // rethrow cms::Exception
673  }
674 
675  catch (const oracle::occi::SQLException& e) {
676  ss << " Caught oracle::occi::SQLException in method " << method_name << " with message: " << std::endl
677  << e.getMessage();
678  if (!extra_info.empty()) {
679  ss << "Additional info: " << extra_info << std::endl;
680  }
681  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
682  }
683 
684  catch (const FecExceptionHandler& e) {
685  ss << " Caught FecExceptionHandler exception in method " << method_name << " with message: " << std::endl
686  << const_cast<FecExceptionHandler&>(e).what();
687  if (!extra_info.empty()) {
688  ss << "Additional info: " << extra_info << std::endl;
689  }
690  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
691  }
692 
693  // catch ( const Fed9UDeviceFactoryException& e ) {
694  // ss << " Caught Fed9UDeviceFactoryException exception in method "
695  // << method_name << " with message: " << std::endl
696  // << e.what();
697  // if ( extra_info != "" ) { ss << "Additional info: " << extra_info << std::endl; }
698  // //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
699  // }
700 
701  catch (const ICUtils::ICException& e) {
702  ss << " Caught ICUtils::ICException in method " << method_name << " with message: " << std::endl << e.what();
703  if (!extra_info.empty()) {
704  ss << "Additional info: " << extra_info << std::endl;
705  }
706  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
707  }
708 
709  catch (const exception& e) {
710  ss << " Caught std::exception in method " << method_name << " with message: " << std::endl << e.what();
711  if (!extra_info.empty()) {
712  ss << "Additional info: " << extra_info << std::endl;
713  }
714  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
715  }
716 
717  catch (...) {
718  ss << " Caught unknown exception in method " << method_name << " (No message) " << std::endl;
719  if (!extra_info.empty()) {
720  ss << "Additional info: " << extra_info << std::endl;
721  }
722  //throw cms::Exception(mlConfigDb_) << ss.str() << std::endl;
723  }
724 
725  // Message
726  edm::LogError(mlConfigDb_) << ss.str();
727 }
728 
729 // -----------------------------------------------------------------------------
730 //
732  fstream fs;
733  fs.open(path.c_str(), ios::in);
734  if (!fs.is_open()) {
735  return false;
736  }
737  fs.close();
738  return true;
739 }
740 
741 // -----------------------------------------------------------------------------
742 //
744  runs.clear();
745 
746  // Check DF pointer
747  DeviceFactory* const df = deviceFactory(__func__);
748  if (!df) {
749  edm::LogError(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
750  << " NULL pointer to DeviceFactory object!";
751  return;
752  }
753 
754  // Retrieve runs
755  tkRunVector all;
756  all = df->getAllRuns();
757 
758  // Iterate through tkRunVector
759  tkRunVector::const_iterator ii = all.begin();
760  tkRunVector::const_iterator jj = all.end();
761  for (; ii != jj; ++ii) {
762  // Check TkRun pointer
763  if (*ii) {
764  // Retrieve run type
765  uint16_t type = (*ii)->getModeId((*ii)->getMode());
767  if (type == 1) {
769  } else if (type == 2) {
771  } else if (type == 3) {
773  } else if (type == 33) {
775  } else if (type == 4) {
777  } else if (type == 5) {
779  } else if (type == 6) {
781  } else if (type == 7) {
783  } else if (type == 10) {
785  } else if (type == 8) {
787  } else if (type == 12) {
789  } else if (type == 13) {
791  } else if (type == 14) {
793  } else if (type == 15) {
795  } else if (type == 16) {
797  } else if (type == 17) {
799  } else if (type == 18) {
801  } else if (type == 19) {
803  } else if (type == 20) {
805  } else if (type == 21) {
807  } else if (type == 0) {
809  } else {
811  }
812 
813  // Store run details
814  Run r;
815  r.type_ = temp;
816  r.partition_ = (*ii)->getPartitionName();
817  r.number_ = (*ii)->getRunNumber();
818  runs.push_back(r);
819 
820  } else {
821  edm::LogWarning(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
822  << " NULL pointer to TkRun object!";
823  }
824  }
825 }
826 
827 // -----------------------------------------------------------------------------
828 //
831  std::string optional_partition) const {
832  out.clear();
833 
834  // Check partition name (if not empty string)
835  if (!optional_partition.empty()) {
836  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partition(optional_partition);
837  if (iter == dbParams_.partitions().end()) {
838  edm::LogWarning(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
839  << " Partition name not found!";
840  return;
841  }
842  }
843 
844  // Iterate through runs
845  Runs::const_iterator ii = in.begin();
846  Runs::const_iterator jj = in.end();
847  for (; ii != jj; ++ii) {
848  // Check partition name
849  if (ii->partition_ == optional_partition || optional_partition.empty()) {
850  // Check run type
851  if (ii->type_ != sistrip::UNKNOWN_RUN_TYPE && ii->type_ != sistrip::UNDEFINED_RUN_TYPE) {
852  // Check run number
853  if (ii->number_) {
854  bool found = false;
855  if (out.find(ii->type_) != out.end()) {
856  Runs::const_iterator irun = out[ii->type_].begin();
857  Runs::const_iterator jrun = out[ii->type_].end();
858  while (!found && irun != jrun) {
859  if (irun->number_ == ii->number_) {
860  found = true;
861  }
862  ++irun;
863  }
864  }
865  // Check if run number already found
866  if (!found) {
867  out[ii->type_].push_back(*ii);
868  } else {
869  // edm::LogWarning(mlConfigDb_)
870  // << "[SiStripPartition::" << __func__ << "]"
871  // << " Run number already found!";
872  }
873  } else {
874  // edm::LogWarning(mlConfigDb_)
875  // << "[SiStripPartition::" << __func__ << "]"
876  // << " NULL run number!";
877  }
878  } else {
879  // edm::LogWarning(mlConfigDb_)
880  // << "[SiStripPartition::" << __func__ << "]"
881  // << " Unexpected run type!";
882  }
883  } else {
884  // edm::LogWarning(mlConfigDb_)
885  // << "[SiStripPartition::" << __func__ << "]"
886  // << " Partition name does not match!";
887  }
888  }
889 }
890 
891 // -----------------------------------------------------------------------------
892 //
895  sistrip::RunType optional_type) const {
896  out.clear();
897 
898  // Iterate through runs
899  Runs::const_iterator ii = in.begin();
900  Runs::const_iterator jj = in.end();
901  for (; ii != jj; ++ii) {
902  // Check partition name
903  if (!ii->partition_.empty()) {
904  // Check run type
905  if (ii->type_ == optional_type || optional_type == sistrip::UNDEFINED_RUN_TYPE) {
906  // Check run number
907  if (ii->number_) {
908  bool found = false;
909  if (out.find(ii->partition_) != out.end()) {
910  Runs::const_iterator irun = out[ii->partition_].begin();
911  Runs::const_iterator jrun = out[ii->partition_].end();
912  while (!found && irun != jrun) {
913  if (irun->number_ == ii->number_) {
914  found = true;
915  }
916  ++irun;
917  }
918  }
919  // Check if run number already found
920  if (!found) {
921  out[ii->partition_].push_back(*ii);
922  } else {
923  // edm::LogWarning(mlConfigDb_)
924  // << "[SiStripPartition::" << __func__ << "]"
925  // << " Run number already found!";
926  }
927  } else {
928  // edm::LogWarning(mlConfigDb_)
929  // << "[SiStripPartition::" << __func__ << "]"
930  // << " NULL run number!";
931  }
932  } else {
933  // edm::LogWarning(mlConfigDb_)
934  // << "[SiStripPartition::" << __func__ << "]"
935  // << " Run type does not match!";
936  }
937  } else {
938  // edm::LogWarning(mlConfigDb_)
939  // << "[SiStripPartition::" << __func__ << "]"
940  // << " NULL value for partition!";
941  }
942  }
943 }
944 
945 // -----------------------------------------------------------------------------
946 //
947 void SiStripConfigDb::partitions(std::list<std::string>& partitions) const {
948  partitions.clear();
949 
950  // Check DF pointer
951  DeviceFactory* const df = deviceFactory(__func__);
952  if (!df) {
953  edm::LogError(mlConfigDb_) << "[SiStripPartition::" << __func__ << "]"
954  << " NULL pointer to DeviceFactory object!";
955  return;
956  }
957 
958  partitions = df->getAllPartitionNames();
959 }
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:661
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:25
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:947
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:134
SiStripConfigDb::usingXmlFiles
void usingXmlFiles()
Definition: SiStripConfigDb.cc:470
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:409
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
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:39
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:731
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
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripConfigDb::clearLocalCache
void clearLocalCache()
Definition: SiStripConfigDb.cc:175
SiStripConfigDb::runs
void runs(Runs &) const
Definition: SiStripConfigDb.cc:743
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:733
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:234
SiStripConfigDb::clearDeviceDescriptions
void clearDeviceDescriptions(std::string partition="")
Definition: DeviceDescriptions.cc:335
sistrip
sistrip classes
Definition: EnsembleCalibrationLA.cc:10
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:142
cuy.ii
ii
Definition: cuy.py:589
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