CMS 3D CMS Logo

DeviceDescriptions.cc
Go to the documentation of this file.
1 
5 
6 using namespace std;
7 using namespace sistrip;
8 
9 // -----------------------------------------------------------------------------
10 //
12 
13  // Check
14  if ( ( !dbParams_.usingDbCache() && !deviceFactory(__func__) ) ||
15  ( dbParams_.usingDbCache() && !databaseCache(__func__) ) ) {
16  return devices_.emptyRange();
17  }
18 
19  try {
20 
21  if ( !dbParams_.usingDbCache() ) {
22 
23  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
24  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
25  for ( ; iter != jter; ++iter ) {
26 
27  if ( partition == "" || partition == iter->second.partitionName() ) {
28 
29  if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
30 
31  DeviceDescriptionsRange range = devices_.find( iter->second.partitionName() );
32  if ( range == devices_.emptyRange() ) {
33 
34  // Retrieve conections
36  deviceFactory(__func__)->getFecDeviceDescriptions( iter->second.partitionName(),
37  tmp1,
38  iter->second.fecVersion().first,
39  iter->second.fecVersion().second,
40  //#ifdef USING_DATABASE_MASKING
41  iter->second.maskVersion().first,
42  iter->second.maskVersion().second,
43  //#endif
44  false ); //@@ do not get DISABLED devices
45 
46  // Make local copy
48  FecFactory::vectorCopyI( tmp2, tmp1, true );
49 
50  // Add to cache
51  devices_.loadNext( iter->second.partitionName(), tmp2 );
52 
53  // Some debug
54  DeviceDescriptionsRange range = devices_.find( iter->second.partitionName() );
55  std::stringstream ss;
56  ss << "[SiStripConfigDb::" << __func__ << "]"
57  << " Downloaded " << range.size()
58  << " device descriptions to local cache for partition \""
59  << iter->second.partitionName() << "\"" << std::endl;
60  ss << "[SiStripConfigDb::" << __func__ << "]"
61  << " Cache holds device descriptions for "
62  << devices_.size() << " partitions.";
63  LogTrace(mlConfigDb_) << ss.str();
64 
65  }
66 
67  }
68 
69  }
70 
71  } else { // Using database cache
72 
73  DeviceDescriptionsV* tmp1 = databaseCache(__func__)->getDevices();
74 
75  if ( tmp1 ) {
76 
77  // Make local copy
79  FecFactory::vectorCopyI( tmp2, *tmp1, true );
80 
81  // Add to cache
82  devices_.loadNext( SiStripPartition::defaultPartitionName_, tmp2 );
83 
84  } else {
86  << "[SiStripConfigDb::" << __func__ << "]"
87  << " NULL pointer to DeviceDescriptions vector!";
88  }
89 
90  }
91 
92  } catch (...) { handleException( __func__ ); }
93 
94  // Create range object
95  uint16_t np = 0;
96  uint16_t nc = 0;
98  if ( partition != "" ) {
99  devs = devices_.find( partition );
100  np = 1;
101  nc = devs.size();
102  } else {
103  if ( !devices_.empty() ) {
104  devs = DeviceDescriptionsRange( devices_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
105  devices_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
106  } else { devs = devices_.emptyRange(); }
107  np = devices_.size();
108  nc = devs.size();
109  }
110 
111  stringstream ss;
112  ss << "[SiStripConfigDb::" << __func__ << "]"
113  << " Found " << nc << " device descriptions";
114  if ( !dbParams_.usingDb() ) { ss << " in " << dbParams_.inputFecXmlFiles().size() << " 'fec.xml' file(s)"; }
115  else { if ( !dbParams_.usingDbCache() ) { ss << " in " << np << " database partition(s)"; }
116  else { ss << " from shared memory name '" << dbParams_.sharedMemory() << "'"; } }
117  if ( devices_.empty() ) { edm::LogWarning(mlConfigDb_) << ss.str(); }
118  else { LogTrace(mlConfigDb_) << ss.str(); }
119 
120  return devs;
121 
122 }
123 
124 // -----------------------------------------------------------------------------
125 //
127  std::string partition ) {
128 
129  typedDevices_.clear();
130  apvDevices_.clear();
131  muxDevices_.clear();
132  dcuDevices_.clear();
133  lldDevices_.clear();
134  pllDevices_.clear();
135  dohDevices_.clear();
136 
137  DeviceDescriptionsRange tmp( typedDevices_.end(), typedDevices_.end() );
138 
139  if ( ( !dbParams_.usingDbCache() && !deviceFactory(__func__) ) ||
140  ( dbParams_.usingDbCache() && !databaseCache(__func__) ) ) {
141  return tmp;
142  }
143 
144  try {
146  if ( !devs.empty() ) {
147  DeviceDescriptionsV tmp( devs.begin(), devs.end() );
148  typedDevices_ = FecFactory::getDeviceFromDeviceVector( tmp, device_type );
149  }
150  } catch (...) { handleException( __func__ ); }
151 
152  if ( device_type == APV25 ) {
153  apvDevices_.swap( typedDevices_ );
154  tmp = DeviceDescriptionsRange( apvDevices_.begin(), apvDevices_.end() );
155  } else if ( device_type == APVMUX ) {
156  muxDevices_.swap( typedDevices_ );
157  tmp = DeviceDescriptionsRange( muxDevices_.begin(), muxDevices_.end() );
158  } else if ( device_type == DCU ) {
159  dcuDevices_.swap( typedDevices_ );
160  tmp = DeviceDescriptionsRange( dcuDevices_.begin(), dcuDevices_.end() );
161  } else if ( device_type == LASERDRIVER ) {
162  lldDevices_.swap( typedDevices_ );
163  tmp = DeviceDescriptionsRange( lldDevices_.begin(), lldDevices_.end() );
164  } else if ( device_type == PLL ) {
165  pllDevices_.swap( typedDevices_ );
166  tmp = DeviceDescriptionsRange( pllDevices_.begin(), pllDevices_.end() );
167  } else if ( device_type == DOH ) {
168  dohDevices_.swap( typedDevices_ );
169  tmp = DeviceDescriptionsRange( dohDevices_.begin(), dohDevices_.end() );
170  } else {
171  tmp = DeviceDescriptionsRange( typedDevices_.begin(), typedDevices_.end() );
172  }
173 
174 // stringstream sss;
175 // sss << " Number of devices:"
176 // << " TYP: " << typedDevices_.size()
177 // << " APV: " << apvDevices_.size()
178 // << " MUX: " << muxDevices_.size()
179 // << " DCU: " << dcuDevices_.size()
180 // << " LLD: " << lldDevices_.size()
181 // << " PLL: " << pllDevices_.size()
182 // << " DOH: " << dohDevices_.size()
183 // << " tmp: " << tmp.size();
184 // LogTrace(mlConfigDb_) << sss.str();
185 
186  stringstream ss;
187  ss << "[SiStripConfigDb::" << __func__ << "]"
188  << " Extracted " << tmp.size()
189  << " device descriptions (for devices of type "
190  << deviceType( device_type ) << ")";
191  LogTrace(mlConfigDb_) << ss.str();
192 
193  return tmp;
194 
195 }
196 
197 // -----------------------------------------------------------------------------
198 //
200 
201  if ( !deviceFactory(__func__) ) { return; }
202 
203  if ( partition.empty() ) {
204  stringstream ss;
205  ss << "[SiStripConfigDb::" << __func__ << "]"
206  << " Partition string is empty,"
207  << " therefore cannot add device descriptions to local cache!";
208  edm::LogWarning(mlConfigDb_) << ss.str();
209  return;
210  }
211 
212  if ( devs.empty() ) {
213  stringstream ss;
214  ss << "[SiStripConfigDb::" << __func__ << "]"
215  << " Vector of device descriptions is empty,"
216  << " therefore cannot add device descriptions to local cache!";
217  edm::LogWarning(mlConfigDb_) << ss.str();
218  return;
219  }
220 
221  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
222  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
223  for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
224  if ( iter == dbParams_.partitions().end() ) {
225  stringstream ss;
226  ss << "[SiStripConfigDb::" << __func__ << "]"
227  << " Partition \"" << partition
228  << "\" not found in partition list, "
229  << " therefore cannot add device descriptions!";
230  edm::LogWarning(mlConfigDb_) << ss.str();
231  return;
232  }
233 
234  DeviceDescriptionsRange range = devices_.find( partition );
235  if ( range == devices_.emptyRange() ) {
236 
237  // Make local copy
239  FecFactory::vectorCopyI( tmp, devs, true );
240 
241  // Add to local cache
242  devices_.loadNext( partition, tmp );
243 
244  // Some debug
245  std::stringstream ss;
246  ss << "[SiStripConfigDb::" << __func__ << "]"
247  << " Added " << devs.size()
248  << " device descriptions to local cache for partition \""
249  << partition << "\"."
250  << " (Cache holds device descriptions for "
251  << devices_.size() << " partitions.)";
252  LogTrace(mlConfigDb_) << ss.str();
253 
254  } else {
255  stringstream ss;
256  ss << "[SiStripConfigDb::" << __func__ << "]"
257  << " Partition \"" << partition
258  << "\" already found in local cache, "
259  << " therefore cannot add device descriptions!";
260  edm::LogWarning(mlConfigDb_) << ss.str();
261  return;
262  }
263 
264 }
265 
266 // -----------------------------------------------------------------------------
267 //
269 
270  if ( dbParams_.usingDbCache() ) {
272  << "[SiStripConfigDb::" << __func__ << "]"
273  << " Using database cache! No uploads allowed!";
274  return;
275  }
276 
277  if ( !deviceFactory(__func__) ) { return; }
278 
279  if ( devices_.empty() ) {
280  stringstream ss;
281  ss << "[SiStripConfigDb::" << __func__ << "]"
282  << " Found no cached device descriptions, therefore no upload!";
283  edm::LogWarning(mlConfigDb_) << ss.str();
284  return;
285  }
286 
287  try {
288 
289  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
290  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
291  for ( ; iter != jter; ++iter ) {
292 
293  if ( partition == "" || partition == iter->second.partitionName() ) {
294 
295  DeviceDescriptionsRange range = devices_.find( iter->second.partitionName() );
296  if ( range != devices_.emptyRange() ) {
297 
298  DeviceDescriptionsV devs( range.begin(), range.end() );
299 
300  SiStripPartition::Versions fecVersion = iter->second.fecVersion();
301  deviceFactory(__func__)->setFecDeviceDescriptions( devs,
302  iter->second.partitionName(),
303  &(fecVersion.first),
304  &(fecVersion.second),
305  true ); // new major version
306 
307  // Some debug
308  std::stringstream ss;
309  ss << "[SiStripConfigDb::" << __func__ << "]"
310  << " Uploaded " << devs.size()
311  << " device descriptions to database for partition \""
312  << iter->second.partitionName() << "\".";
313  LogTrace(mlConfigDb_) << ss.str();
314 
315  } else {
316  stringstream ss;
317  ss << "[SiStripConfigDb::" << __func__ << "]"
318  << " Vector of device descriptions is empty for partition \""
319  << iter->second.partitionName()
320  << "\", therefore aborting upload for this partition!";
321  edm::LogWarning(mlConfigDb_) << ss.str();
322  continue;
323  }
324 
325  } else {
326  // stringstream ss;
327  // ss << "[SiStripConfigDb::" << __func__ << "]"
328  // << " Cannot find partition \"" << partition
329  // << "\" in cached partitions list: \""
330  // << dbParams_.partitionNames( dbParams_.partitionNames() )
331  // << "\", therefore aborting upload for this partition!";
332  // edm::LogWarning(mlConfigDb_) << ss.str();
333  }
334 
335  }
336 
337  } catch (...) { handleException( __func__ ); }
338 
339  allowCalibUpload_ = true;
340 
341 }
342 
343 // -----------------------------------------------------------------------------
344 //
346  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
347 
348  if ( devices_.empty() ) {
349  stringstream ss;
350  ss << "[SiStripConfigDb::" << __func__ << "]"
351  << " Found no cached device descriptions!";
352  //edm::LogWarning(mlConfigDb_) << ss.str();
353  return;
354  }
355 
356  // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
357  DeviceDescriptions temporary_cache;
358  if ( partition == "" ) { temporary_cache = DeviceDescriptions(); }
359  else {
360  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
361  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
362  for ( ; iter != jter; ++iter ) {
363  if ( partition != iter->second.partitionName() ) {
364  DeviceDescriptionsRange range = devices_.find( iter->second.partitionName() );
365  if ( range != devices_.emptyRange() ) {
366  temporary_cache.loadNext( partition, DeviceDescriptionsV( range.begin(), range.end() ) );
367  } else {
368  // stringstream ss;
369  // ss << "[SiStripConfigDb::" << __func__ << "]"
370  // << " Cannot find partition \"" << iter->second.partitionName()
371  // << "\" in local cache!";
372  // edm::LogWarning(mlConfigDb_) << ss.str();
373  }
374  }
375  }
376  }
377 
378  // Delete objects in local cache for specified partition (or all if not specified)
380  if ( partition == "" ) {
381  if ( !devices_.empty() ) {
382  devs = DeviceDescriptionsRange( devices_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
383  devices_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
384  } else { devs = devices_.emptyRange(); }
385  } else {
386  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
387  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
388  for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
389  devs = devices_.find( iter->second.partitionName() );
390  }
391 
392  if ( devs != devices_.emptyRange() ) {
393  DeviceDescriptionsV::const_iterator ifed = devs.begin();
394  DeviceDescriptionsV::const_iterator jfed = devs.end();
395  for ( ; ifed != jfed; ++ifed ) { if ( *ifed ) { delete *ifed; } }
396  } else {
397  stringstream ss;
398  ss << "[SiStripConfigDb::" << __func__ << "]";
399  if ( partition == "" ) { ss << " Found no device descriptions in local cache!"; }
400  else { ss << " Found no device descriptions in local cache for partition \"" << partition << "\"!"; }
401  edm::LogWarning(mlConfigDb_) << ss.str();
402  }
403 
404  // Overwrite local cache with temporary cache
405  devices_ = temporary_cache;
406 
407 }
408 
409 // -----------------------------------------------------------------------------
410 //
412 
413  std::stringstream ss;
414  ss << "[SiStripConfigDb::" << __func__ << "]"
415  << " Contents of DeviceDescriptions container:" << std::endl;
416  ss << " Number of partitions: " << devices_.size() << std::endl;
417 
418  // Loop through partitions
419  uint16_t cntr = 0;
420  DeviceDescriptions::const_iterator idev = devices_.begin();
421  DeviceDescriptions::const_iterator jdev = devices_.end();
422  for ( ; idev != jdev; ++idev ) {
423 
424  cntr++;
425  if ( partition == "" || partition == idev->first ) {
426 
427  ss << " Partition number : " << cntr << " (out of " << devices_.size() << ")" << std::endl;
428  ss << " Partition name : \"" << idev->first << "\"" << std::endl;
429  ss << " Num of devices : " << idev->second.size() << std::endl;
430 
431  // Extract FEC crate, slot, etc
432  std::map< uint32_t, vector<std::string> > devices;
433  DeviceDescriptionsV::const_iterator iter = idev->second.begin();
434  DeviceDescriptionsV::const_iterator jter = idev->second.end();
435  for ( ; iter != jter; ++iter ) {
436  if ( *iter ) {
437  DeviceAddress addr = deviceAddress( **iter );
438  uint32_t key = SiStripFecKey( addr.fecCrate_,
439  addr.fecSlot_,
440  addr.fecRing_,
441  0,
442  0,
443  0,
444  0 ).key();
445  std::stringstream data;
446  data << (*iter)->getDeviceType()
447  << "_"
448  << SiStripFecKey( addr.fecCrate_,
449  addr.fecSlot_,
450  addr.fecRing_,
451  addr.ccuAddr_,
452  addr.ccuChan_,
453  addr.lldChan_,
454  addr.i2cAddr_ ).key();
455  if ( find( devices[key].begin(), devices[key].end(), data.str() ) == devices[key].end() ) {
456  devices[key].push_back( data.str() );
457  }
458  }
459  }
460 
461  // Sort contents
462  std::map< uint32_t, std::vector<std::string> > tmp;
463  std::map< uint32_t, std::vector<std::string> >::const_iterator ii = devices.begin();
464  std::map< uint32_t, std::vector<std::string> >::const_iterator jj = devices.end();
465  for ( ; ii != jj; ++ii ) {
466  std::vector<std::string> temp = ii->second;
467  std::sort( temp.begin(), temp.end() );
468  std::vector<std::string>::const_iterator iii = temp.begin();
469  std::vector<std::string>::const_iterator jjj = temp.end();
470  for ( ; iii != jjj; ++iii ) { tmp[ii->first].push_back( *iii ); }
471  }
472  devices.clear();
473  devices = tmp;
474 
475  // Print FEC crate, slot, etc...
476  std::map< uint32_t, std::vector<std::string> >::const_iterator idev = devices.begin();
477  std::map< uint32_t, std::vector<std::string> >::const_iterator jdev = devices.end();
478  for ( ; idev != jdev; ++idev ) {
479  SiStripFecKey key(idev->first);
480  ss << " Found " << std::setw(3) << idev->second.size()
481  << " devices for FEC crate/slot/ring "
482  << key.fecCrate() << "/"
483  << key.fecSlot() << "/"
484  << key.fecRing();
485  //<< " (ccu/module/lld/i2c): ";
486  // if ( !idev->second.empty() ) {
487  // uint16_t first = idev->second.front();
488  // uint16_t last = idev->second.front();
489  // std::vector<std::string>::const_iterator chan = idev->second.begin();
490  // for ( ; chan != idev->second.end(); chan++ ) {
491  // if ( chan != idev->second.begin() ) {
492  // if ( *chan != last+1 ) {
493  // ss << std::setw(2) << first << "->" << std::setw(2) << last << ", ";
494  // if ( chan != idev->second.end() ) { first = *(chan+1); }
495  // }
496  // }
497  // last = *chan;
498  // }
499  // if ( first != last ) { ss << std::setw(2) << first << "->" << std::setw(2) << last; }
500  ss << std::endl;
501  }
502 
503  }
504 
505  }
506 
507  LogTrace(mlConfigDb_) << ss.str();
508 
509 }
510 
511 // -----------------------------------------------------------------------------
512 //
514 
515  deviceDescription& desc = const_cast<deviceDescription&>(description);
516 
517  DeviceAddress addr;
518  try {
519  addr.fecCrate_ = static_cast<uint16_t>( desc.getCrateId() + sistrip::FEC_CRATE_OFFSET ); //@@ temporary offset?
520  addr.fecSlot_ = static_cast<uint16_t>( desc.getFecSlot() );
521  addr.fecRing_ = static_cast<uint16_t>( desc.getRingSlot() + sistrip::FEC_RING_OFFSET ); //@@ temporary offset?
522  addr.ccuAddr_ = static_cast<uint16_t>( desc.getCcuAddress() );
523  addr.ccuChan_ = static_cast<uint16_t>( desc.getChannel() );
524  addr.lldChan_ = static_cast<uint16_t>( SiStripFecKey::lldChan( desc.getAddress() ) );
525  addr.i2cAddr_ = static_cast<uint16_t>( desc.getAddress() );
526  } catch (...) { handleException( __func__ ); }
527 
528  return addr;
529 }
530 
531 // -----------------------------------------------------------------------------
532 //
533 string SiStripConfigDb::deviceType( const enumDeviceType& device_type ) const {
534  if ( device_type == PLL ) { return "PLL"; }
535  else if ( device_type == LASERDRIVER ) { return "LLD"; }
536  else if ( device_type == DOH ) { return "DOH"; }
537  else if ( device_type == APVMUX ) { return "MUX"; }
538  else if ( device_type == APV25 ) { return "APV"; }
539  else if ( device_type == DCU ) { return "DCU"; }
540  else if ( device_type == GOH ) { return "GOH"; }
541  else { return "UNKNOWN DEVICE!"; }
542 }
static const std::string defaultPartitionName_
const uint16_t & fecRing() const
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:99
void addDeviceDescriptions(std::string partition, DeviceDescriptionsV &)
static const uint16_t FEC_RING_OFFSET
const uint16_t & lldChan() const
const uint16_t & fecSlot() const
void clearDeviceDescriptions(std::string partition="")
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::pair< uint32_t, uint32_t > Versions
sistrip classes
const uint32_t & key() const
Definition: SiStripKey.h:125
static const char mlConfigDb_[]
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
int np
Definition: AMPTWrapper.h:33
enumDeviceType DeviceType
DeviceDescriptions::range DeviceDescriptionsRange
#define end
Definition: vmac.h:39
DeviceAddress deviceAddress(const deviceDescription &)
#define LogTrace(id)
ii
Definition: cuy.py:589
const uint16_t & fecCrate() const
std::string deviceType(const enumDeviceType &device_type) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
#define begin
Definition: vmac.h:32
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void printDeviceDescriptions(std::string partition="")
static const uint16_t FEC_CRATE_OFFSET
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
void uploadDeviceDescriptions(std::string partition="")
std::vector< DeviceDescription * > DeviceDescriptionsV