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