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