CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripDbParams.cc
Go to the documentation of this file.
1 // Last commit: $Id: SiStripDbParams.cc,v 1.14 2010/11/29 20:42:01 wmtan Exp $
2 
6 #include <iostream>
7 
8 using namespace sistrip;
9 
10 // -----------------------------------------------------------------------------
11 //
13  usingDb_(false),
14  confdb_(null_),
15  user_(null_),
16  passwd_(null_),
17  path_(null_),
18  usingDbCache_(false),
19  sharedMemory_(""),
20  tnsAdmin_(""),
21  partitions_(),
22  outputModuleXml_("/tmp/module.xml"),
23  outputDcuInfoXml_("/tmp/dcuinfo.xml"),
24  outputFecXml_("/tmp/fec.xml"),
25  outputFedXml_("/tmp/fed.xml")
26 {;}
27 
28 // -----------------------------------------------------------------------------
29 //
31  usingDb_( input.usingDb() ),
32  confdb_( input.confdb() ),
33  user_( input.user() ),
34  passwd_( input.passwd() ),
35  path_( input.path() ),
36  usingDbCache_( input.usingDbCache() ),
37  sharedMemory_( input.sharedMemory() ),
38  tnsAdmin_( input.tnsAdmin() ),
39  partitions_( input.partitions().begin(), input.partitions().end() ),
40  outputModuleXml_( input.outputModuleXml() ),
41  outputDcuInfoXml_( input.outputDcuInfoXml() ),
42  outputFecXml_( input.outputFecXml() ),
43  outputFedXml_( input.outputFedXml() )
44 {;}
45 
46 // -----------------------------------------------------------------------------
47 //
49  usingDb_ = input.usingDb();
50  confdb_ = input.confdb();
51  user_ = input.user();
52  passwd_ = input.passwd();
53  path_ = input.path();
54  confdb( confdb_ );
55  usingDbCache_ = input.usingDbCache();
56  sharedMemory_ = input.sharedMemory();
57  tnsAdmin_ = input.tnsAdmin();
58  partitions_.clear();
59  partitions_ = SiStripPartitions( input.partitions().begin(), input.partitions().end() );
62  outputFecXml_ = input.outputFecXml();
63  outputFedXml_ = input.outputFedXml();
64  return *this;
65 }
66 
67 // -----------------------------------------------------------------------------
68 //
70  if ( !( usingDb_ == input.usingDb() &&
71  confdb_ == input.confdb() &&
72  user_ == input.user() &&
73  passwd_ == input.passwd() &&
74  path_ == input.path() &&
75  usingDbCache_ == input.usingDbCache() &&
76  sharedMemory_ == input.sharedMemory() &&
77  tnsAdmin_ == input.tnsAdmin() &&
78  outputModuleXml_ == input.outputModuleXml() &&
80  outputFecXml_ == input.outputFecXml() &&
81  outputFedXml_ == input.outputFedXml() ) ) { return false; }
82  if ( partitionsSize() != input.partitionsSize() ) { return false; }
83 // SiStripPartitions::const_iterator ii = input.partitions().begin();
84 // SiStripPartitions::const_iterator jj = input.partitions().end();
85 // SiStripPartitions::const_iterator iter = partitions_.begin();
86 // for ( ; ii != jj; ++ii ) {
87 // if ( ii->first != iter->first || ii->second != iter->second ) { return false; }
88 // iter++;
89 // }
90 // return true;
91  return partitions_ == input.partitions_;
92 }
93 
94 // -----------------------------------------------------------------------------
95 //
97  return !( *this == input );
98 }
99 
100 // -----------------------------------------------------------------------------
101 //
103  reset();
104 }
105 
106 // -----------------------------------------------------------------------------
107 //
109  usingDb_ = false;
110  confdb_ = null_;
111  user_ = null_;
112  passwd_ = null_;
113  path_ = null_;
114  usingDbCache_ = false;
115  sharedMemory_ = "";
116  tnsAdmin_ = "";
117  partitions_.clear();
118  confdb( confdb_ );
119  outputModuleXml_ = "/tmp/module.xml";
120  outputDcuInfoXml_ = "/tmp/dcuinfo.xml";
121  outputFecXml_ = "/tmp/fec.xml";
122  outputFedXml_ = "/tmp/fed.xml";
123 }
124 
125 // -----------------------------------------------------------------------------
126 //
128 
129  if ( in.partitionName() == "" ) {
130  std::stringstream ss;
131  ss << "[SiStripDbParams::" << __func__ << "]"
132  << " Attempting to add partition with null name!";
133  //edm::LogWarning(mlConfigDb_) << ss.str();
134  }
135 
136  SiStripPartitions::const_iterator iter = partitions_.find( in.partitionName() );
137  if ( iter == partitions_.end() ) {
138  partitions_[in.partitionName()] = in;
140  std::stringstream ss;
141  ss << "[SiStripDbParams::" << __func__ << "]"
142  << " Added new partition with name \""
143  << in.partitionName() << "\"";
144  //ss << std::endl << partitions_[in.partitionName()];
145  ss << " (Currently have "
146  << partitions_.size()
147  << " partitions in cache...)";
148  LogTrace(mlConfigDb_) << ss.str();
149  }
150  } else {
151  std::stringstream ss;
152  ss << "[SiStripDbParams::" << __func__ << "]"
153  << " Partition with name \""
154  << in.partitionName()
155  << "\" already found!"
156  << " Not adding to cache...";
157  edm::LogWarning(mlConfigDb_) << ss.str();
158  }
159 
160 }
161 
162 // -----------------------------------------------------------------------------
163 //
165 
166  // "Common" configurables
167  usingDb_ = cfg.getUntrackedParameter<bool>( "UsingDb", false );
168  usingDbCache_ = cfg.getUntrackedParameter<bool>( "UsingDbCache", false );
169  sharedMemory_ = cfg.getUntrackedParameter<std::string>( "SharedMemory", "" );
170  tnsAdmin_ = cfg.getUntrackedParameter<std::string>( "TNS_ADMIN", "" );
171  confdb( cfg.getUntrackedParameter<std::string>( "ConfDb", "") );
172 
173  // Check if top-level PSet (containing partition-level Psets) exists
174  std::string partitions = "Partitions";
175  std::vector<std::string> str = cfg.getParameterNamesForType<edm::ParameterSet>(false);
176  std::vector<std::string>::const_iterator istr = std::find( str.begin(), str.end(), partitions );
177  if ( istr != str.end() ) {
178 
179  // Retrieve top-level PSet containing partition-level Psets
181 
182  // Extract names of partition-level PSets
183  std::vector<std::string> names = psets.getParameterNamesForType<edm::ParameterSet>(false);
184 
185  // Iterator through PSets names, retrieve PSet for each partition and extract info
186  std::vector<std::string>::iterator iname = names.begin();
187  std::vector<std::string>::iterator jname = names.end();
188  for ( ; iname != jname; ++iname ) {
191  tmp.pset( pset );
192  addPartition( tmp );
193  }
194 
195  }
196 
197  // Ensure at least one "default" partition
198  if ( partitions_.empty() ) { addPartition( SiStripPartition() ); }
199 
200  // Set output XML files
201  outputModuleXml_ = cfg.getUntrackedParameter<std::string>( "OutputModuleXml", "/tmp/module.xml" );
202  outputDcuInfoXml_ = cfg.getUntrackedParameter<std::string>( "OutputDcuInfoXml", "/tmp/dcuinfo.xml" );
203  outputFecXml_ = cfg.getUntrackedParameter<std::string>( "OutputFecXml", "/tmp/fec.xml" );
204  outputFedXml_ = cfg.getUntrackedParameter<std::string>( "OutputFedXml", "/tmp/fed.xml" );
205 
206 }
207 
208 // -----------------------------------------------------------------------------
209 //
210 void SiStripDbParams::confdb( const std::string& confdb ) {
211  confdb_ = confdb;
212  size_t ipass = confdb.find("/");
213  size_t ipath = confdb.find("@");
214  if ( ipass != std::string::npos &&
215  ipath != std::string::npos ) {
216  user_ = confdb.substr(0,ipass);
217  passwd_ = confdb.substr(ipass+1,ipath-ipass-1);
218  path_ = confdb.substr(ipath+1,confdb.size());
219  } else {
220  user_ = null_;
221  passwd_ = null_;
222  path_ = null_;
223  }
224 }
225 
226 // -----------------------------------------------------------------------------
227 //
228 void SiStripDbParams::confdb( const std::string& user,
229  const std::string& passwd,
230  const std::string& path ) {
231  if ( user != "" && passwd != "" && path != "" &&
232  user != null_ && passwd != null_ && path != null_ ) {
233  user_ = user;
234  passwd_ = passwd;
235  path_ = path;
236  } else {
237  user_ = null_;
238  passwd_ = null_;
239  path_ = null_;
240  }
241  confdb_ = user_ + "/" + passwd_ + "@" + path_;
242 }
243 
244 // -----------------------------------------------------------------------------
245 //
246 SiStripDbParams::SiStripPartitions::const_iterator SiStripDbParams::partition( std::string partition_name ) const {
247  SiStripDbParams::SiStripPartitions::const_iterator ii = partitions().begin();
248  SiStripDbParams::SiStripPartitions::const_iterator jj = partitions().end();
249  for ( ; ii != jj; ++ii ) { if ( partition_name == ii->second.partitionName() ) { return ii; } }
250  return partitions().end();
251 }
252 
253 // -----------------------------------------------------------------------------
254 //
255 SiStripDbParams::SiStripPartitions::iterator SiStripDbParams::partition( std::string partition_name ) {
256  SiStripDbParams::SiStripPartitions::iterator ii = partitions().begin();
257  SiStripDbParams::SiStripPartitions::iterator jj = partitions().end();
258  for ( ; ii != jj; ++ii ) { if ( partition_name == ii->second.partitionName() ) { return ii; } }
259  return partitions().end();
260 }
261 
262 // -----------------------------------------------------------------------------
263 //
264 std::vector<std::string> SiStripDbParams::partitionNames() const {
265  std::vector<std::string> partitions;
266  SiStripPartitions::const_iterator ii = partitions_.begin();
267  SiStripPartitions::const_iterator jj = partitions_.end();
268  for ( ; ii != jj; ++ii ) {
269  if ( std::find( partitions.begin(),
270  partitions.end(),
271  ii->second.partitionName() ) == partitions.end() ) {
272  if ( !ii->second.partitionName().empty() ) { partitions.push_back( ii->second.partitionName() ); }
273  } else {
275  << "[SiStripConfigDb::" << __func__ << "]"
276  << " Partition " << ii->second.partitionName()
277  << " already found! Not adding to vector...";
278  }
279  }
280  return partitions;
281 }
282 
283 // -----------------------------------------------------------------------------
284 //
285 std::vector<std::string> SiStripDbParams::partitionNames( std::string input ) const {
286  std::istringstream ss(input);
287  std::vector<std::string> partitions;
288  std::string delimiter = ":";
289  std::string token;
290  while ( getline( ss, token, ':' ) ) { if ( !token.empty() ) { partitions.push_back(token); } }
291  return partitions;
292 }
293 
294 // -----------------------------------------------------------------------------
295 //
296 std::string SiStripDbParams::partitionNames( const std::vector<std::string>& partitions ) const {
297  std::stringstream ss;
298  std::vector<std::string>::const_iterator ii = partitions.begin();
299  std::vector<std::string>::const_iterator jj = partitions.end();
300  bool first = true;
301  for ( ; ii != jj; ++ii ) {
302  if ( !ii->empty() ) {
303  first ? ss << *ii : ss << ":" << *ii;
304  first = false;
305  }
306  }
307  return ss.str();
308 }
309 
310 // -----------------------------------------------------------------------------
311 //
312 void SiStripDbParams::print( std::stringstream& ss ) const {
313 
314  ss << " Using database account : " << std::boolalpha << usingDb_ << std::noboolalpha << std::endl;
315  ss << " Using XML files : " << std::boolalpha << !usingDb_ << std::noboolalpha << std::endl;
316  ss << " Using database cache : " << std::boolalpha << usingDbCache_ << std::noboolalpha << std::endl;
317  if ( usingDbCache_ ) {
318  ss << " Shared memory name : " << std::boolalpha << sharedMemory_ << std::noboolalpha << std::endl;
319  }
320 
321  if ( !usingDbCache_ ) {
322 
323  if ( usingDb_ ) {
324  ss << " Database account (ConfDb) : " << confdb_ << std::endl;
325  }
326 
327  ss << " Number of partitions : " << partitions_.size();
328  if ( partitions_.empty() ) {
329  if ( !usingDbCache_ ) { ss << " (Empty!)"; }
330  else { ss << " (Using database cache!)"; }
331  }
332  ss << std::endl;
333 
334  uint16_t cntr = 0;
335  SiStripPartitions::const_iterator ii = partitions_.begin();
336  SiStripPartitions::const_iterator jj = partitions_.end();
337  for ( ; ii != jj; ++ii ) {
338  cntr++;
339  ss << " Partition #" << cntr << " (out of " << partitions_.size() << "):" << std::endl;
340  ii->second.print( ss, usingDb_ );
341  }
342 
343  if ( !usingDb_ ) {
344  ss << " Output \"module.xml\" file : " << outputModuleXml_ << std::endl
345  << " Output \"dcuinfo.xml\" file : " << outputDcuInfoXml_ << std::endl
346  << " Output \"fec.xml\" file(s) : " << outputFecXml_ << std::endl
347  << " Output \"fed.xml\" file(s) : " << outputFedXml_ << std::endl;
348  }
349 
350  }
351 
352 }
353 
354 // -----------------------------------------------------------------------------
355 //
356 std::ostream& operator<< ( std::ostream& os, const SiStripDbParams& params ) {
357  std::stringstream ss;
358  params.print(ss);
359  os << ss.str();
360  return os;
361 }
362 
363 // -----------------------------------------------------------------------------
364 //
365 std::vector<std::string> SiStripDbParams::inputModuleXmlFiles() const {
366  std::vector<std::string> files;
367  SiStripPartitions::const_iterator ii = partitions_.begin();
368  SiStripPartitions::const_iterator jj = partitions_.end();
369  for ( ; ii != jj; ++ii ) { files.insert( files.end(), ii->second.inputModuleXml() ); }
370  return files;
371 }
372 
373 // -----------------------------------------------------------------------------
374 //
375 std::vector<std::string> SiStripDbParams::inputDcuInfoXmlFiles() const {
376  std::vector<std::string> files;
377  SiStripPartitions::const_iterator ii = partitions_.begin();
378  SiStripPartitions::const_iterator jj = partitions_.end();
379  for ( ; ii != jj; ++ii ) { files.insert( files.end(), ii->second.inputDcuInfoXml() ); }
380  return files;
381 }
382 
383 // -----------------------------------------------------------------------------
384 //
385 std::vector<std::string> SiStripDbParams::inputFecXmlFiles() const {
386  std::vector<std::string> files;
387  SiStripPartitions::const_iterator ii = partitions_.begin();
388  SiStripPartitions::const_iterator jj = partitions_.end();
389  for ( ; ii != jj; ++ii ) { files.insert( files.end(), ii->second.inputFecXml().begin(), ii->second.inputFecXml().end() ); }
390  return files;
391 }
392 
393 // -----------------------------------------------------------------------------
394 //
395 std::vector<std::string> SiStripDbParams::inputFedXmlFiles() const {
396  std::vector<std::string> files;
397  SiStripPartitions::const_iterator ii = partitions_.begin();
398  SiStripPartitions::const_iterator jj = partitions_.end();
399  for ( ; ii != jj; ++ii ) { files.insert( files.end(), ii->second.inputFedXml().begin(), ii->second.inputFedXml().end() ); }
400  return files;
401 }
static std::string defaultPartitionName_
bool operator==(const SiStripDbParams &) const
void print(std::stringstream &) const
T getUntrackedParameter(std::string const &, T const &) const
std::string passwd() const
std::vector< std::string > inputFedXmlFiles() const
std::string tnsAdmin_
static const HistoName names[]
std::string partitionName() const
std::vector< std::string > inputDcuInfoXmlFiles() const
bool operator!=(const SiStripDbParams &) const
std::map< std::string, SiStripPartition > SiStripPartitions
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
bool usingDb() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
SiStripDbParams & operator=(const SiStripDbParams &)
std::string outputDcuInfoXml_
static const char mlConfigDb_[]
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:195
const_iterator_range partitions() const
std::vector< std::string > partitionNames() const
list path
Definition: scaleCards.py:51
std::string outputModuleXml() const
std::string outputFecXml_
size_type partitionsSize() const
void pset(const edm::ParameterSet &)
std::string outputModuleXml_
std::string user_
std::string tnsAdmin() const
std::string sharedMemory() const
std::string outputFedXml_
std::string passwd_
Container class for database partition parameters.
#define end
Definition: vmac.h:38
std::string sharedMemory_
std::vector< std::string > inputModuleXmlFiles() const
std::string user() const
bool first
Definition: L1TdeRCT.cc:94
std::string path_
#define LogTrace(id)
std::string confdb() const
Container class for database connection parameters.
std::string & path_
std::string outputFedXml() const
SiStripPartitions::const_iterator partition(std::string partition_name) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::string path() const
std::vector< std::string > inputFecXmlFiles() const
void pset(const edm::ParameterSet &)
std::string confdb_
#define begin
Definition: vmac.h:31
bool usingDbCache() const
void addPartition(const SiStripPartition &)
std::string outputFecXml() const
SiStripPartitions partitions_
std::string outputDcuInfoXml() const
static const char null_[]
Definition: Constants.h:23