00001
00002
00003 #include "OnlineDB/SiStripConfigDb/interface/SiStripDbParams.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include <iostream>
00007
00008 using namespace sistrip;
00009
00010
00011
00012 SiStripDbParams::SiStripDbParams() :
00013 usingDb_(false),
00014 confdb_(null_),
00015 user_(null_),
00016 passwd_(null_),
00017 path_(null_),
00018 usingDbCache_(false),
00019 sharedMemory_(""),
00020 tnsAdmin_(""),
00021 partitions_(),
00022 outputModuleXml_("/tmp/module.xml"),
00023 outputDcuInfoXml_("/tmp/dcuinfo.xml"),
00024 outputFecXml_("/tmp/fec.xml"),
00025 outputFedXml_("/tmp/fed.xml")
00026 {;}
00027
00028
00029
00030 SiStripDbParams::SiStripDbParams( const SiStripDbParams& input ) :
00031 usingDb_( input.usingDb() ),
00032 confdb_( input.confdb() ),
00033 user_( input.user() ),
00034 passwd_( input.passwd() ),
00035 path_( input.path() ),
00036 usingDbCache_( input.usingDbCache() ),
00037 sharedMemory_( input.sharedMemory() ),
00038 tnsAdmin_( input.tnsAdmin() ),
00039 partitions_( input.partitions().begin(), input.partitions().end() ),
00040 outputModuleXml_( input.outputModuleXml() ),
00041 outputDcuInfoXml_( input.outputDcuInfoXml() ),
00042 outputFecXml_( input.outputFecXml() ),
00043 outputFedXml_( input.outputFedXml() )
00044 {;}
00045
00046
00047
00048 SiStripDbParams& SiStripDbParams::operator= ( const SiStripDbParams& input ) {
00049 usingDb_ = input.usingDb();
00050 confdb_ = input.confdb();
00051 user_ = input.user();
00052 passwd_ = input.passwd();
00053 path_ = input.path();
00054 confdb( confdb_ );
00055 usingDbCache_ = input.usingDbCache();
00056 sharedMemory_ = input.sharedMemory();
00057 tnsAdmin_ = input.tnsAdmin();
00058 partitions_.clear();
00059 partitions_ = SiStripPartitions( input.partitions().begin(), input.partitions().end() );
00060 outputModuleXml_ = input.outputModuleXml();
00061 outputDcuInfoXml_ = input.outputDcuInfoXml();
00062 outputFecXml_ = input.outputFecXml();
00063 outputFedXml_ = input.outputFedXml();
00064 return *this;
00065 }
00066
00067
00068
00069 bool SiStripDbParams::operator== ( const SiStripDbParams& input ) const {
00070 if ( !( usingDb_ == input.usingDb() &&
00071 confdb_ == input.confdb() &&
00072 user_ == input.user() &&
00073 passwd_ == input.passwd() &&
00074 path_ == input.path() &&
00075 usingDbCache_ == input.usingDbCache() &&
00076 sharedMemory_ == input.sharedMemory() &&
00077 tnsAdmin_ == input.tnsAdmin() &&
00078 outputModuleXml_ == input.outputModuleXml() &&
00079 outputDcuInfoXml_ == input.outputDcuInfoXml() &&
00080 outputFecXml_ == input.outputFecXml() &&
00081 outputFedXml_ == input.outputFedXml() ) ) { return false; }
00082 if ( partitions_.size() != input.partitions().size() ) { return false; }
00083 SiStripPartitions::const_iterator ii = input.partitions().begin();
00084 SiStripPartitions::const_iterator jj = input.partitions().end();
00085 SiStripPartitions::const_iterator iter = partitions_.begin();
00086 for ( ; ii != jj; ++ii ) {
00087 if ( ii->first != iter->first || ii->second != iter->second ) { return false; }
00088 iter++;
00089 }
00090 return true;
00091 }
00092
00093
00094
00095 bool SiStripDbParams::operator!= ( const SiStripDbParams& input ) const {
00096 return !( *this == input );
00097 }
00098
00099
00100
00101 SiStripDbParams::~SiStripDbParams() {
00102 reset();
00103 }
00104
00105
00106
00107 void SiStripDbParams::reset() {
00108 usingDb_ = false;
00109 confdb_ = null_;
00110 user_ = null_;
00111 passwd_ = null_;
00112 path_ = null_;
00113 usingDbCache_ = false;
00114 sharedMemory_ = "";
00115 tnsAdmin_ = "";
00116 partitions_.clear();
00117 confdb( confdb_ );
00118 outputModuleXml_ = "/tmp/module.xml";
00119 outputDcuInfoXml_ = "/tmp/dcuinfo.xml";
00120 outputFecXml_ = "/tmp/fec.xml";
00121 outputFedXml_ = "/tmp/fed.xml";
00122 }
00123
00124
00125
00126 void SiStripDbParams::addPartition( const SiStripPartition& in ) {
00127
00128 if ( in.partitionName() == "" ) {
00129 std::stringstream ss;
00130 ss << "[SiStripDbParams::" << __func__ << "]"
00131 << " Attempting to add partition with null name!";
00132
00133 }
00134
00135 SiStripPartitions::const_iterator iter = partitions_.find( in.partitionName() );
00136 if ( iter == partitions_.end() ) {
00137 partitions_[in.partitionName()] = in;
00138 if ( in.partitionName() != SiStripPartition::defaultPartitionName_ ) {
00139 std::stringstream ss;
00140 ss << "[SiStripDbParams::" << __func__ << "]"
00141 << " Added new partition with name \""
00142 << in.partitionName() << "\"";
00143
00144 ss << " (Currently have "
00145 << partitions_.size()
00146 << " partitions in cache...)";
00147 LogTrace(mlConfigDb_) << ss.str();
00148 }
00149 } else {
00150 std::stringstream ss;
00151 ss << "[SiStripDbParams::" << __func__ << "]"
00152 << " Partition with name \""
00153 << in.partitionName()
00154 << "\" already found!"
00155 << " Not adding to cache...";
00156 edm::LogWarning(mlConfigDb_) << ss.str();
00157 }
00158
00159 }
00160
00161
00162
00163 void SiStripDbParams::pset( const edm::ParameterSet& cfg ) {
00164
00165
00166 usingDb_ = cfg.getUntrackedParameter<bool>( "UsingDb", false );
00167 usingDbCache_ = cfg.getUntrackedParameter<bool>( "UsingDbCache", false );
00168 sharedMemory_ = cfg.getUntrackedParameter<std::string>( "SharedMemory", "" );
00169 tnsAdmin_ = cfg.getUntrackedParameter<std::string>( "TNS_ADMIN", "" );
00170 confdb( cfg.getUntrackedParameter<std::string>( "ConfDb", "") );
00171
00172
00173 std::string partitions = "Partitions";
00174 std::vector<std::string> str = cfg.getParameterNamesForType<edm::ParameterSet>(false);
00175 std::vector<std::string>::const_iterator istr = std::find( str.begin(), str.end(), partitions );
00176 if ( istr != str.end() ) {
00177
00178
00179 edm::ParameterSet psets = cfg.getUntrackedParameter<edm::ParameterSet>( partitions );
00180
00181
00182 std::vector<std::string> names = psets.getParameterNamesForType<edm::ParameterSet>(false);
00183
00184
00185 std::vector<std::string>::iterator iname = names.begin();
00186 std::vector<std::string>::iterator jname = names.end();
00187 for ( ; iname != jname; ++iname ) {
00188 edm::ParameterSet pset = psets.getUntrackedParameter<edm::ParameterSet>( *iname );
00189 SiStripPartition tmp;
00190 tmp.pset( pset );
00191 addPartition( tmp );
00192 }
00193
00194 }
00195
00196
00197 if ( partitions_.empty() ) { addPartition( SiStripPartition() ); }
00198
00199
00200 outputModuleXml_ = cfg.getUntrackedParameter<std::string>( "OutputModuleXml", "/tmp/module.xml" );
00201 outputDcuInfoXml_ = cfg.getUntrackedParameter<std::string>( "OutputDcuInfoXml", "/tmp/dcuinfo.xml" );
00202 outputFecXml_ = cfg.getUntrackedParameter<std::string>( "OutputFecXml", "/tmp/fec.xml" );
00203 outputFedXml_ = cfg.getUntrackedParameter<std::string>( "OutputFedXml", "/tmp/fed.xml" );
00204
00205 }
00206
00207
00208
00209 void SiStripDbParams::confdb( const std::string& confdb ) {
00210 confdb_ = confdb;
00211 uint32_t ipass = confdb.find("/");
00212 uint32_t ipath = confdb.find("@");
00213 if ( ipass != std::string::npos &&
00214 ipath != std::string::npos ) {
00215 user_ = confdb.substr(0,ipass);
00216 passwd_ = confdb.substr(ipass+1,ipath-ipass-1);
00217 path_ = confdb.substr(ipath+1,confdb.size());
00218 } else {
00219 user_ = null_;
00220 passwd_ = null_;
00221 path_ = null_;
00222 }
00223 }
00224
00225
00226
00227 void SiStripDbParams::confdb( const std::string& user,
00228 const std::string& passwd,
00229 const std::string& path ) {
00230 if ( user != "" && passwd != "" && path != "" &&
00231 user != null_ && passwd != null_ && path != null_ ) {
00232 user_ = user;
00233 passwd_ = passwd;
00234 path_ = path;
00235 } else {
00236 user_ = null_;
00237 passwd_ = null_;
00238 path_ = null_;
00239 }
00240 confdb_ = user_ + "/" + passwd_ + "@" + path_;
00241 }
00242
00243
00244
00245 SiStripDbParams::SiStripPartitions::const_iterator SiStripDbParams::partition( std::string partition_name ) const {
00246 SiStripDbParams::SiStripPartitions::const_iterator ii = partitions().begin();
00247 SiStripDbParams::SiStripPartitions::const_iterator jj = partitions().end();
00248 for ( ; ii != jj; ++ii ) { if ( partition_name == ii->second.partitionName() ) { return ii; } }
00249 return partitions().end();
00250 }
00251
00252
00253
00254 SiStripDbParams::SiStripPartitions::iterator SiStripDbParams::partition( std::string partition_name ) {
00255 SiStripDbParams::SiStripPartitions::iterator ii = partitions().begin();
00256 SiStripDbParams::SiStripPartitions::iterator jj = partitions().end();
00257 for ( ; ii != jj; ++ii ) { if ( partition_name == ii->second.partitionName() ) { return ii; } }
00258 return partitions().end();
00259 }
00260
00261
00262
00263 std::vector<std::string> SiStripDbParams::partitionNames() const {
00264 std::vector<std::string> partitions;
00265 SiStripPartitions::const_iterator ii = partitions_.begin();
00266 SiStripPartitions::const_iterator jj = partitions_.end();
00267 for ( ; ii != jj; ++ii ) {
00268 if ( std::find( partitions.begin(),
00269 partitions.end(),
00270 ii->second.partitionName() ) == partitions.end() ) {
00271 if ( !ii->second.partitionName().empty() ) { partitions.push_back( ii->second.partitionName() ); }
00272 } else {
00273 edm::LogWarning(mlConfigDb_)
00274 << "[SiStripConfigDb::" << __func__ << "]"
00275 << " Partition " << ii->second.partitionName()
00276 << " already found! Not adding to vector...";
00277 }
00278 }
00279 return partitions;
00280 }
00281
00282
00283
00284 std::vector<std::string> SiStripDbParams::partitionNames( std::string input ) const {
00285 std::istringstream ss(input);
00286 std::vector<std::string> partitions;
00287 std::string delimiter = ":";
00288 std::string token;
00289 while ( getline( ss, token, ':' ) ) { if ( !token.empty() ) { partitions.push_back(token); } }
00290 return partitions;
00291 }
00292
00293
00294
00295 std::string SiStripDbParams::partitionNames( const std::vector<std::string>& partitions ) const {
00296 std::stringstream ss;
00297 std::vector<std::string>::const_iterator ii = partitions.begin();
00298 std::vector<std::string>::const_iterator jj = partitions.end();
00299 bool first = true;
00300 for ( ; ii != jj; ++ii ) {
00301 if ( !ii->empty() ) {
00302 first ? ss << *ii : ss << ":" << *ii;
00303 first = false;
00304 }
00305 }
00306 return ss.str();
00307 }
00308
00309
00310
00311 void SiStripDbParams::print( std::stringstream& ss ) const {
00312
00313 ss << " Using database account : " << std::boolalpha << usingDb_ << std::noboolalpha << std::endl;
00314 ss << " Using XML files : " << std::boolalpha << !usingDb_ << std::noboolalpha << std::endl;
00315 ss << " Using database cache : " << std::boolalpha << usingDbCache_ << std::noboolalpha << std::endl;
00316 if ( usingDbCache_ ) {
00317 ss << " Shared memory name : " << std::boolalpha << sharedMemory_ << std::noboolalpha << std::endl;
00318 }
00319
00320 if ( !usingDbCache_ ) {
00321
00322 if ( usingDb_ ) {
00323 ss << " Database account (ConfDb) : " << confdb_ << std::endl;
00324 }
00325
00326 ss << " Number of partitions : " << partitions_.size();
00327 if ( partitions_.empty() ) {
00328 if ( !usingDbCache_ ) { ss << " (Empty!)"; }
00329 else { ss << " (Using database cache!)"; }
00330 }
00331 ss << std::endl;
00332
00333 uint16_t cntr = 0;
00334 SiStripPartitions::const_iterator ii = partitions_.begin();
00335 SiStripPartitions::const_iterator jj = partitions_.end();
00336 for ( ; ii != jj; ++ii ) {
00337 cntr++;
00338 ss << " Partition #" << cntr << " (out of " << partitions_.size() << "):" << std::endl;
00339 ii->second.print( ss, usingDb_ );
00340 }
00341
00342 if ( !usingDb_ ) {
00343 ss << " Output \"module.xml\" file : " << outputModuleXml_ << std::endl
00344 << " Output \"dcuinfo.xml\" file : " << outputDcuInfoXml_ << std::endl
00345 << " Output \"fec.xml\" file(s) : " << outputFecXml_ << std::endl
00346 << " Output \"fed.xml\" file(s) : " << outputFedXml_ << std::endl;
00347 }
00348
00349 }
00350
00351 }
00352
00353
00354
00355 std::ostream& operator<< ( std::ostream& os, const SiStripDbParams& params ) {
00356 std::stringstream ss;
00357 params.print(ss);
00358 os << ss.str();
00359 return os;
00360 }
00361
00362
00363
00364 std::vector<std::string> SiStripDbParams::inputModuleXmlFiles() const {
00365 std::vector<std::string> files;
00366 SiStripPartitions::const_iterator ii = partitions_.begin();
00367 SiStripPartitions::const_iterator jj = partitions_.end();
00368 for ( ; ii != jj; ++ii ) { files.insert( files.end(), ii->second.inputModuleXml() ); }
00369 return files;
00370 }
00371
00372
00373
00374 std::vector<std::string> SiStripDbParams::inputDcuInfoXmlFiles() const {
00375 std::vector<std::string> files;
00376 SiStripPartitions::const_iterator ii = partitions_.begin();
00377 SiStripPartitions::const_iterator jj = partitions_.end();
00378 for ( ; ii != jj; ++ii ) { files.insert( files.end(), ii->second.inputDcuInfoXml() ); }
00379 return files;
00380 }
00381
00382
00383
00384 std::vector<std::string> SiStripDbParams::inputFecXmlFiles() const {
00385 std::vector<std::string> files;
00386 SiStripPartitions::const_iterator ii = partitions_.begin();
00387 SiStripPartitions::const_iterator jj = partitions_.end();
00388 for ( ; ii != jj; ++ii ) { files.insert( files.end(), ii->second.inputFecXml().begin(), ii->second.inputFecXml().end() ); }
00389 return files;
00390 }
00391
00392
00393
00394 std::vector<std::string> SiStripDbParams::inputFedXmlFiles() const {
00395 std::vector<std::string> files;
00396 SiStripPartitions::const_iterator ii = partitions_.begin();
00397 SiStripPartitions::const_iterator jj = partitions_.end();
00398 for ( ; ii != jj; ++ii ) { files.insert( files.end(), ii->second.inputFedXml().begin(), ii->second.inputFedXml().end() ); }
00399 return files;
00400 }