CMS 3D CMS Logo

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