CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FedDescriptions.cc
Go to the documentation of this file.
1 // Last commit: $Id: FedDescriptions.cc,v 1.31 2008/06/06 14:48:53 bainbrid Exp $
2 
7 
8 using namespace std;
9 using namespace sistrip;
10 
11 // -----------------------------------------------------------------------------
12 //
14 
15  // Check
16  if ( ( !dbParams_.usingDbCache() && !deviceFactory(__func__) ) ||
17  ( dbParams_.usingDbCache() && !databaseCache(__func__) ) ) {
18  return feds_.emptyRange();
19  }
20 
21  try {
22 
23  if ( !dbParams_.usingDbCache() ) {
24 
25  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
26  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
27  for ( ; iter != jter; ++iter ) {
28 
29  if ( partition == "" || partition == iter->second.partitionName() ) {
30 
31  if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
32 
33  FedDescriptionsRange range = feds_.find( iter->second.partitionName() );
34  if ( range == feds_.emptyRange() ) {
35 
36  // Extract versions
37  deviceFactory(__func__)->setUsingStrips( usingStrips_ );
38  int16_t major = iter->second.fedVersion().first;
39  int16_t minor = iter->second.fedVersion().second;
40  if ( iter->second.fedVersion().first == 0 &&
41  iter->second.fedVersion().second == 0 ) {
42  major = -1; //@@ "current state" for fed factory!
43  minor = -1; //@@ "current state" for fed factory!
44  }
45 
46  // Retrive FED descriptions
47  FedDescriptionsV tmp1;
48  tmp1 = *( deviceFactory(__func__)->getFed9UDescriptions( iter->second.partitionName(),
49  major,
50  minor ) );
51 
52  // Make local copy
53  FedDescriptionsV tmp2;
54  Fed9U::Fed9UDeviceFactory::vectorCopy( tmp2, tmp1 );
55 
56  // Add to cache
57  feds_.loadNext( iter->second.partitionName(), tmp2 );
58 
59  // Some debug
60  FedDescriptionsRange feds = feds_.find( iter->second.partitionName() );
61  std::stringstream ss;
62  ss << "[SiStripConfigDb::" << __func__ << "]"
63  << " Downloaded " << feds.size()
64  << " FED descriptions to local cache for partition \""
65  << iter->second.partitionName() << "\"" << std::endl;
66  ss << "[SiStripConfigDb::" << __func__ << "]"
67  << " Cache holds FED descriptions for "
68  << feds_.size() << " partitions.";
69  LogTrace(mlConfigDb_) << ss.str();
70 
71  }
72 
73  }
74 
75  }
76 
77  } else { // Using database cache
78 
79  FedDescriptionsV* tmp1 = databaseCache(__func__)->getFed9UDescriptions();
80 
81  if ( tmp1 ) {
82 
83  // Make local copy
84  FedDescriptionsV tmp2;
85  Fed9U::Fed9UDeviceFactory::vectorCopy( tmp2, *tmp1 );
86 
87  // Add to cache
88  feds_.loadNext( SiStripPartition::defaultPartitionName_, tmp2 );
89 
90  } else {
92  << "[SiStripConfigDb::" << __func__ << "]"
93  << " NULL pointer to FED descriptions vector!";
94  }
95 
96  }
97 
98  } catch (... ) { handleException( __func__ ); }
99 
100  // Create range object
101  uint16_t np = 0;
102  uint16_t nc = 0;
104  if ( partition != "" ) {
105  feds = feds_.find( partition );
106  np = 1;
107  nc = feds.size();
108  } else {
109  if ( !feds_.empty() ) {
110  feds = FedDescriptionsRange( feds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
111  feds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
112  } else { feds = feds_.emptyRange(); }
113  np = feds_.size();
114  nc = feds.size();
115  }
116 
117  stringstream ss;
118  ss << "[SiStripConfigDb::" << __func__ << "]"
119  << " Found " << nc << " FED descriptions";
120  if ( !dbParams_.usingDb() ) { ss << " in " << dbParams_.inputFedXmlFiles().size() << " 'fed.xml' file(s)"; }
121  else { if ( !dbParams_.usingDbCache() ) { ss << " in " << np << " database partition(s)"; }
122  else { ss << " from shared memory name '" << dbParams_.sharedMemory() << "'"; } }
123  if ( feds_.empty() ) { edm::LogWarning(mlConfigDb_) << ss.str(); }
124  else { LogTrace(mlConfigDb_) << ss.str(); }
125 
126  return feds;
127 
128 }
129 
130 // -----------------------------------------------------------------------------
131 //
132 void SiStripConfigDb::addFedDescriptions( std::string partition, FedDescriptionsV& feds ) {
133 
134  if ( !deviceFactory(__func__) ) { return; }
135 
136  if ( partition.empty() ) {
137  stringstream ss;
138  ss << "[SiStripConfigDb::" << __func__ << "]"
139  << " Partition string is empty,"
140  << " therefore cannot add FED descriptions to local cache!";
141  edm::LogWarning(mlConfigDb_) << ss.str();
142  return;
143  }
144 
145  if ( feds.empty() ) {
146  stringstream ss;
147  ss << "[SiStripConfigDb::" << __func__ << "]"
148  << " Vector of FED descriptions is empty,"
149  << " therefore cannot add FED descriptions to local cache!";
150  edm::LogWarning(mlConfigDb_) << ss.str();
151  return;
152  }
153 
154  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
155  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
156  for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
157  if ( iter == dbParams_.partitions().end() ) {
158  stringstream ss;
159  ss << "[SiStripConfigDb::" << __func__ << "]"
160  << " Partition \"" << partition
161  << "\" not found in partition list, "
162  << " therefore cannot add FED descriptions!";
163  edm::LogWarning(mlConfigDb_) << ss.str();
164  return;
165  }
166 
167  FedDescriptionsRange range = feds_.find( partition );
168  if ( range == feds_.emptyRange() ) {
169 
170  // Make local copy
172  Fed9U::Fed9UDeviceFactory::vectorCopy( tmp, feds );
173 
174  // Add to local cache
175  feds_.loadNext( partition, tmp );
176 
177  // Some debug
178  std::stringstream ss;
179  ss << "[SiStripConfigDb::" << __func__ << "]"
180  << " Added " << feds.size()
181  << " FED descriptions to local cache for partition \""
182  << iter->second.partitionName() << "\"" << std::endl;
183  ss << "[SiStripConfigDb::" << __func__ << "]"
184  << " Cache holds FED descriptions for "
185  << feds_.size() << " partitions.";
186  LogTrace(mlConfigDb_) << ss.str();
187 
188  } else {
189  stringstream ss;
190  ss << "[SiStripConfigDb::" << __func__ << "]"
191  << " Partition \"" << partition
192  << "\" already found in local cache, "
193  << " therefore cannot add new FED descriptions!";
194  edm::LogWarning(mlConfigDb_) << ss.str();
195  return;
196  }
197 
198 }
199 
200 // -----------------------------------------------------------------------------
201 //
202 void SiStripConfigDb::uploadFedDescriptions( std::string partition ) {
203 
204  if ( dbParams_.usingDbCache() ) {
206  << "[SiStripConfigDb::" << __func__ << "]"
207  << " Using database cache! No uploads allowed!";
208  return;
209  }
210 
211  if ( !deviceFactory(__func__) ) { return; }
212 
213  if ( feds_.empty() ) {
214  stringstream ss;
215  ss << "[SiStripConfigDb::" << __func__ << "]"
216  << " Found no cached FED descriptions, therefore no upload!";
217  edm::LogWarning(mlConfigDb_) << ss.str();
218  return;
219  }
220 
221  try {
222 
223  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
224  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
225  for ( ; iter != jter; ++iter ) {
226 
227  if ( partition == "" || partition == iter->second.partitionName() ) {
228 
229  FedDescriptionsRange range = feds_.find( iter->second.partitionName() );
230  if ( range != feds_.emptyRange() ) {
231 
232  FedDescriptionsV feds( range.begin(), range.end() );
233 
234  deviceFactory(__func__)->setFed9UDescriptions( feds,
235  iter->second.partitionName(),
236  (uint16_t*)(&iter->second.fedVersion().first),
237  (uint16_t*)(&iter->second.fedVersion().second),
238  1 ); // new major version
239 
240  // Some debug
241  std::stringstream ss;
242  ss << "[SiStripConfigDb::" << __func__ << "]"
243  << " Uploaded " << feds.size()
244  << " FED descriptions to database for partition \""
245  << iter->second.partitionName() << "\"";
246  LogTrace(mlConfigDb_) << ss.str();
247 
248  } else {
249  stringstream ss;
250  ss << "[SiStripConfigDb::" << __func__ << "]"
251  << " Vector of FED descriptions is empty for partition \""
252  << iter->second.partitionName()
253  << "\", therefore aborting upload for this partition!";
254  edm::LogWarning(mlConfigDb_) << ss.str();
255  continue;
256  }
257 
258  } else {
259  // stringstream ss;
260  // ss << "[SiStripConfigDb::" << __func__ << "]"
261  // << " Cannot find partition \"" << partition
262  // << "\" in cached partitions list: \""
263  // << dbParams_.partitionNames( dbParams_.partitionNames() )
264  // << "\", therefore aborting upload for this partition!";
265  // edm::LogWarning(mlConfigDb_) << ss.str();
266  }
267 
268  }
269 
270  } catch (...) { handleException( __func__ ); }
271 
272  allowCalibUpload_ = true;
273 
274 }
275 
276 // -----------------------------------------------------------------------------
277 //
278 void SiStripConfigDb::clearFedDescriptions( std::string partition ) {
279  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
280 
281  if ( feds_.empty() ) {
282  stringstream ss;
283  ss << "[SiStripConfigDb::" << __func__ << "]"
284  << " Found no cached FED descriptions!";
285  //edm::LogWarning(mlConfigDb_) << ss.str();
286  return;
287  }
288 
289  // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
290  FedDescriptions temporary_cache;
291  if ( partition == "" ) { temporary_cache = FedDescriptions(); }
292  else {
293  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
294  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
295  for ( ; iter != jter; ++iter ) {
296  if ( partition != iter->second.partitionName() ) {
297  FedDescriptionsRange range = feds_.find( iter->second.partitionName() );
298  if ( range != feds_.emptyRange() ) {
299  temporary_cache.loadNext( partition, FedDescriptionsV( range.begin(), range.end() ) );
300  }
301  } else {
302  FedDescriptionsRange range = feds_.find( iter->second.partitionName() );
303  if ( range != feds_.emptyRange() ) {
305  << "[SiStripConfigDb::" << __func__ << "]"
306  << " Deleting FED descriptions for partition \""
307  << iter->second.partitionName()
308  << "\" from local cache...";
309  }
310  }
311  }
312  }
313 
314  // Delete objects in local cache for specified partition (or all if not specified)
316  if ( partition == "" ) {
317  if ( !feds_.empty() ) {
318  feds = FedDescriptionsRange( feds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
319  feds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
320  } else { feds = feds_.emptyRange(); }
321  } else {
322  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
323  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
324  for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
325  feds = feds_.find( iter->second.partitionName() );
326  }
327 
328  if ( feds != feds_.emptyRange() ) {
329  FedDescriptionsV::const_iterator ifed = feds.begin();
330  FedDescriptionsV::const_iterator jfed = feds.end();
331  for ( ; ifed != jfed; ++ifed ) { if ( *ifed ) { delete *ifed; } }
332  } else {
333  stringstream ss;
334  ss << "[SiStripConfigDb::" << __func__ << "]";
335  if ( partition == "" ) { ss << " Found no FED descriptions in local cache!"; }
336  else { ss << " Found no FED descriptions in local cache for partition \"" << partition << "\"!"; }
337  edm::LogWarning(mlConfigDb_) << ss.str();
338  }
339 
340  // Overwrite local cache with temporary cache
341  feds_ = temporary_cache;
342 
343 }
344 
345 // -----------------------------------------------------------------------------
346 //
347 void SiStripConfigDb::printFedDescriptions( std::string partition ) {
348 
349  std::stringstream ss;
350  ss << "[SiStripConfigDb::" << __func__ << "]"
351  << " Contents of FedDescriptions container:" << std::endl;
352  ss << " Number of partitions: " << feds_.size() << std::endl;
353 
354  // Loop through partitions
355  uint16_t cntr = 0;
356  FedDescriptions::const_iterator iconn = feds_.begin();
357  FedDescriptions::const_iterator jconn = feds_.end();
358  for ( ; iconn != jconn; ++iconn ) {
359 
360  cntr++;
361  if ( partition == "" || partition == iconn->first ) {
362 
363  ss << " Partition number : " << cntr << " (out of " << feds_.size() << ")" << std::endl;
364  ss << " Partition name : \"" << iconn->first << "\"" << std::endl;
365  ss << " Num of FED ids : " << iconn->second.size() << std::endl;
366 
367  // Extract FED crates and ids
368  std::map< uint16_t, vector<uint16_t> > feds;
369  FedDescriptionsV::const_iterator iter = iconn->second.begin();
370  FedDescriptionsV::const_iterator jter = iconn->second.end();
371  for ( ; iter != jter; ++iter ) {
372  if ( *iter ) {
373  uint16_t key = (*iter)->getCrateNumber();
374  uint16_t data = (*iter)->getFedId();
375  if ( find( feds[key].begin(), feds[key].end(), data ) == feds[key].end() ) {
376  feds[key].push_back( data );
377  }
378  }
379  }
380 
381  // Sort contents
382  std::map< uint16_t, std::vector<uint16_t> > tmp;
383  std::map< uint16_t, std::vector<uint16_t> >::const_iterator ii = feds.begin();
384  std::map< uint16_t, std::vector<uint16_t> >::const_iterator jj = feds.end();
385  for ( ; ii != jj; ++ii ) {
386  std::vector<uint16_t> temp = ii->second;
387  std::sort( temp.begin(), temp.end() );
388  std::vector<uint16_t>::const_iterator iii = temp.begin();
389  std::vector<uint16_t>::const_iterator jjj = temp.end();
390  for ( ; iii != jjj; ++iii ) { tmp[ii->first].push_back( *iii ); }
391  }
392  feds.clear();
393  feds = tmp;
394 
395  // Print FED crates and ids
396  std::map< uint16_t, std::vector<uint16_t> >::const_iterator ifed = feds.begin();
397  std::map< uint16_t, std::vector<uint16_t> >::const_iterator jfed = feds.end();
398  for ( ; ifed != jfed; ++ifed ) {
399  ss << " Found " << std::setw(2) << ifed->second.size()
400  << " FED ids for crate number " << std::setw(2) << ifed->first << " : ";
401  if ( !ifed->second.empty() ) {
402  uint16_t first = ifed->second.front();
403  uint16_t last = ifed->second.front();
404  std::vector<uint16_t>::const_iterator icrate = ifed->second.begin();
405  std::vector<uint16_t>::const_iterator jcrate = ifed->second.end();
406  for ( ; icrate != jcrate; ++icrate ) {
407  if ( icrate != ifed->second.begin() ) {
408  if ( *icrate != last+1 ) {
409  ss << std::setw(2) << first << "->" << std::setw(2) << last << ", ";
410  if ( icrate != ifed->second.end() ) { first = *(icrate+1); }
411  }
412  }
413  last = *icrate;
414  }
415  if ( first != last ) { ss << std::setw(2) << first << "->" << std::setw(2) << last; }
416  ss << std::endl;
417  }
418  }
419 
420  }
421 
422  }
423 
424  LogTrace(mlConfigDb_) << ss.str();
425 
426 }
427 
428 // -----------------------------------------------------------------------------
431 
432  fedIds_.clear();
433 
434  if ( ( !dbParams_.usingDbCache() && !deviceFactory(__func__) ) ||
435  ( dbParams_.usingDbCache() && !databaseCache(__func__) ) ) {
436  return FedIdsRange( fedIds_.end(), fedIds_.end() );
437  }
438 
439  try {
440 
441  // Inhibit download of strip info
442  bool using_strips = usingStrips_;
443  if ( factory_ ) { factory_->setUsingStrips( false ); }
444  FedDescriptionsRange feds = getFedDescriptions( partition );
445  if ( factory_ ) { factory_->setUsingStrips( using_strips ); }
446 
447  if ( !feds.empty() ) {
448  FedDescriptionsV::const_iterator ifed = feds.begin();
449  FedDescriptionsV::const_iterator jfed = feds.end();
450  for ( ; ifed != jfed; ++ifed ) {
451  if ( *ifed ) { fedIds_.push_back( (*ifed)->getFedId() ); }
452  else {
454  << "[SiStripConfigDb::" << __func__ << "]"
455  << " NULL pointer to FedDescription!";
456  continue;
457  }
458  }
459  }
460 
461  } catch (...) { handleException( __func__ ); }
462 
463  if ( fedIds_.empty() ) {
465  << "[SiStripConfigDb::" << __func__ << "]"
466  << " No FED ids found!";
467  }
468 
469  return FedIdsRange( fedIds_.begin(), fedIds_.end() );
470 
471 }
472 
static std::string defaultPartitionName_
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:97
FedDescriptionsRange getFedDescriptions(std::string partition="")
FedDescriptions::range FedDescriptionsRange
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void addFedDescriptions(std::string partition, FedDescriptionsV &)
static const char mlConfigDb_[]
static const char mlCabling_[]
FedIdsRange getFedIds(std::string partition="")
#define end
Definition: vmac.h:38
bool first
Definition: L1TdeRCT.cc:79
#define LogTrace(id)
void printFedDescriptions(std::string partition="")
void uploadFedDescriptions(std::string partition="")
boost::iterator_range< FedIds::const_iterator > FedIdsRange
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
#define begin
Definition: vmac.h:31
list key
Definition: combine.py:13
void clearFedDescriptions(std::string partition="")
std::vector< FedDescription * > FedDescriptionsV