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