CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AnalysisDescriptions.cc
Go to the documentation of this file.
1 
5 
6 using namespace std;
7 using namespace sistrip;
8 
9 // -----------------------------------------------------------------------------
21  std::string partition ) {
22 
23  // Check
24  if ( ( !dbParams_.usingDbCache() && !deviceFactory(__func__) ) ||
25  ( dbParams_.usingDbCache() && !databaseCache(__func__) ) ) {
26  return analyses_.emptyRange();
27  }
28 
29  try {
30 
31  if ( !dbParams_.usingDbCache() ) {
32 
33  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
34  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
35  for ( ; iter != jter; ++iter ) {
36 
37  if ( partition == "" || partition == iter->second.partitionName() ) {
38 
39  if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
40 
41  AnalysisDescriptionsRange range = analyses_.find( iter->second.partitionName() );
42  if ( range == analyses_.emptyRange() ) {
43 
45  if ( analysis_type == AnalysisDescription::T_ANALYSIS_FASTFEDCABLING ) {
46  tmp1 = deviceFactory(__func__)->getAnalysisHistory( iter->second.partitionName(),
47  iter->second.fastCablingVersion().first,
48  iter->second.fastCablingVersion().second,
49  analysis_type );
50  } else if ( analysis_type == AnalysisDescription::T_ANALYSIS_TIMING ) {
51  tmp1 = deviceFactory(__func__)->getAnalysisHistory( iter->second.partitionName(),
52  iter->second.apvTimingVersion().first,
53  iter->second.apvTimingVersion().second,
54  analysis_type );
55  } else if ( analysis_type == AnalysisDescription::T_ANALYSIS_OPTOSCAN ) {
56  tmp1 = deviceFactory(__func__)->getAnalysisHistory( iter->second.partitionName(),
57  iter->second.optoScanVersion().first,
58  iter->second.optoScanVersion().second,
59  analysis_type );
60  } else if ( analysis_type == AnalysisDescription::T_ANALYSIS_VPSPSCAN ) {
61  tmp1 = deviceFactory(__func__)->getAnalysisHistory( iter->second.partitionName(),
62  iter->second.vpspScanVersion().first,
63  iter->second.vpspScanVersion().second,
64  analysis_type );
65  } else if ( analysis_type == AnalysisDescription::T_ANALYSIS_CALIBRATION ) {
66  tmp1 = deviceFactory(__func__)->getAnalysisHistory( iter->second.partitionName(),
67  iter->second.apvCalibVersion().first,
68  iter->second.apvCalibVersion().second,
69  analysis_type );
70  } else if ( analysis_type == AnalysisDescription::T_ANALYSIS_PEDESTALS ) {
71  tmp1 = deviceFactory(__func__)->getAnalysisHistory( iter->second.partitionName(),
72  iter->second.pedestalsVersion().first,
73  iter->second.pedestalsVersion().second,
74  analysis_type );
75  } else if ( analysis_type == AnalysisDescription::T_ANALYSIS_APVLATENCY ) {
76  tmp1 = deviceFactory(__func__)->getAnalysisHistory( iter->second.partitionName(),
77  iter->second.apvLatencyVersion().first,
78  iter->second.apvLatencyVersion().second,
79  analysis_type );
80  } else if ( analysis_type == AnalysisDescription::T_ANALYSIS_FINEDELAY ) {
81  tmp1 = deviceFactory(__func__)->getAnalysisHistory( iter->second.partitionName(),
82  iter->second.fineDelayVersion().first,
83  iter->second.fineDelayVersion().second,
84  analysis_type );
85  } else {
86  std::stringstream ss;
87  ss << "[SiStripConfigDb::" << __func__ << "]"
88  << " Unexpected analysis type \""
89  << analysisType( analysis_type )
90  << "\"! Aborting download...";
91  edm::LogWarning(mlConfigDb_) << ss.str();
92  return analyses_.emptyRange();
93  }
94 
95  // Make local copy
97  CommissioningAnalysisFactory::vectorCopy( tmp1, tmp2 );
98 
99  // Add to cache
100  analyses_.loadNext( iter->second.partitionName(), tmp2 );
101 
102  // Some debug
103  AnalysisDescriptionsRange anals = analyses_.find( iter->second.partitionName() );
104  std::stringstream ss;
105  ss << "[SiStripConfigDb::" << __func__ << "]"
106  << " Downloaded " << anals.size()
107  << " analysis descriptions of type \""
108  << analysisType( analysis_type )
109  << "\" to local cache for partition \""
110  << iter->second.partitionName() << "\"" << std::endl;
111  ss << "[SiStripConfigDb::" << __func__ << "]"
112  << " Cache holds analysis descriptions for "
113  << analyses_.size() << " partitions.";
114  LogTrace(mlConfigDb_) << ss.str();
115 
116  }
117  }
118  }
119 
120  } else { // Use database cache
121  std::stringstream ss;
122  ss << "[SiStripConfigDb::" << __func__ << "]"
123  << " No database cache for analysis objects!";
124  edm::LogWarning(mlConfigDb_) << ss.str();
125  }
126 
127  } catch (...) { handleException( __func__ ); }
128 
129  // Create range object
130  uint16_t np = 0;
131  uint16_t nc = 0;
132  AnalysisDescriptionsRange anals = analyses_.emptyRange();
133  if ( partition != "" ) {
134  anals = analyses_.find( partition );
135  np = 1;
136  nc = anals.size();
137  } else {
138  if ( !analyses_.empty() ) {
139  anals = AnalysisDescriptionsRange( analyses_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
140  analyses_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
141  } else { anals = analyses_.emptyRange(); }
142  np = analyses_.size();
143  nc = anals.size();
144  }
145 
146  stringstream ss;
147  ss << "[SiStripConfigDb::" << __func__ << "]"
148  << " Found " << nc << " analysis descriptions";
149  if ( !dbParams_.usingDbCache() ) { ss << " in " << np << " database partition(s)"; }
150  else { ss << " from shared memory name '" << dbParams_.sharedMemory() << "'"; }
151  if ( analyses_.empty() ) { edm::LogWarning(mlConfigDb_) << ss.str(); }
152  else { LogTrace(mlConfigDb_) << ss.str(); }
153 
154  return anals;
155 
156 }
157 
158 // -----------------------------------------------------------------------------
159 //
161 
162  if ( !deviceFactory(__func__) ) { return; }
163 
164  if ( partition.empty() ) {
165  stringstream ss;
166  ss << "[SiStripConfigDb::" << __func__ << "]"
167  << " Partition string is empty,"
168  << " therefore cannot add analysis descriptions to local cache!";
169  edm::LogWarning(mlConfigDb_) << ss.str();
170  return;
171  }
172 
173  if ( anals.empty() ) {
174  stringstream ss;
175  ss << "[SiStripConfigDb::" << __func__ << "]"
176  << " Vector of analysis descriptions is empty,"
177  << " therefore cannot add analysis descriptions to local cache!";
178  edm::LogWarning(mlConfigDb_) << ss.str();
179  return;
180  }
181 
182  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
183  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
184  for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
185  if ( iter == dbParams_.partitions().end() ) {
186  stringstream ss;
187  ss << "[SiStripConfigDb::" << __func__ << "]"
188  << " Partition \"" << partition
189  << "\" not found in partition list, "
190  << " therefore cannot add analysis descriptions!";
191  edm::LogWarning(mlConfigDb_) << ss.str();
192  return;
193  }
194 
195  AnalysisDescriptionsRange range = analyses_.find( partition );
196  if ( range == analyses_.emptyRange() ) {
197 
198  // Make local copy
200  CommissioningAnalysisFactory::vectorCopy( anals, tmp );
201 
202  // Add to local cache
203  analyses_.loadNext( partition, tmp );
204 
205  // Some debug
206  std::stringstream ss;
207  ss << "[SiStripConfigDb::" << __func__ << "]"
208  << " Added " << anals.size()
209  << " analysis descriptions to local cache for partition \""
210  << partition << "\"."
211  << " (Cache holds analysis descriptions for "
212  << analyses_.size() << " partitions.)";
213  LogTrace(mlConfigDb_) << ss.str();
214 
215  } else {
216  stringstream ss;
217  ss << "[SiStripConfigDb::" << __func__ << "]"
218  << " Partition \"" << partition
219  << "\" already found in local cache, "
220  << " therefore cannot add analysis descriptions!";
221  edm::LogWarning(mlConfigDb_) << ss.str();
222  return;
223  }
224 
225 }
226 
227 // -----------------------------------------------------------------------------
228 //
229 void SiStripConfigDb::uploadAnalysisDescriptions( bool calibration_for_physics,
230  std::string partition ) {
231 
232  if ( dbParams_.usingDbCache() ) {
234  << "[SiStripConfigDb::" << __func__ << "]"
235  << " Using database cache! No uploads allowed!";
236  return;
237  }
238 
239  if ( !deviceFactory(__func__) ) { return; }
240 
241  if ( analyses_.empty() ) {
243  << "[SiStripConfigDb::" << __func__ << "]"
244  << " Found no cached analysis descriptions, therefore no upload!";
245  return;
246  }
247 
248  if ( calibration_for_physics && !allowCalibUpload_ ) {
250  << "[SiStripConfigDb::" << __func__ << "]"
251  << " Attempting to upload calibration constants"
252  << " without uploading any hardware descriptions!"
253  << " Aborting upload...";
254  return;
255  } else { allowCalibUpload_ = false; }
256 
257  try {
258 
259  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
260  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
261  for ( ; iter != jter; ++iter ) {
262 
263  if ( partition == "" || partition == iter->second.partitionName() ) {
264 
265  AnalysisDescriptionsRange range = analyses_.find( iter->second.partitionName() );
266  if ( range != analyses_.emptyRange() ) {
267 
268  AnalysisDescriptionsV anals( range.begin(), range.end() );
269 
270  AnalysisType analysis_type = AnalysisDescription::T_UNKNOWN;
271  if ( anals.front() ) { analysis_type = anals.front()->getType(); }
272  if ( analysis_type == AnalysisDescription::T_UNKNOWN ) {
274  << "[SiStripConfigDb::" << __func__ << "]"
275  << " Analysis type is UNKNOWN. Aborting upload!";
276  return;
277  }
278 
279  uint32_t version = deviceFactory(__func__)->uploadAnalysis( iter->second.runNumber(),
280  iter->second.partitionName(),
281  analysis_type,
282  anals,
283  calibration_for_physics );
284 
285  // Update current state with analysis descriptions
286  if ( calibration_for_physics ) { deviceFactory(__func__)->uploadAnalysisState( version ); }
287 
288  // Some debug
289  std::stringstream ss;
290  ss << "[SiStripConfigDb::" << __func__ << "]"
291  << " Uploaded " << anals.size()
292  << " device descriptions to database for partition \""
293  << iter->second.partitionName() << "\".";
294  LogTrace(mlConfigDb_) << ss.str();
295 
296  } else {
297  stringstream ss;
298  ss << "[SiStripConfigDb::" << __func__ << "]"
299  << " Vector of device descriptions is empty for partition \""
300  << iter->second.partitionName()
301  << "\", therefore aborting upload for this partition!";
302  edm::LogWarning(mlConfigDb_) << ss.str();
303  continue;
304  }
305 
306  } else {
307  // stringstream ss;
308  // ss << "[SiStripConfigDb::" << __func__ << "]"
309  // << " Cannot find partition \"" << partition
310  // << "\" in cached partitions list: \""
311  // << dbParams_.partitionNames( dbParams_.partitionNames() )
312  // << "\", therefore aborting upload for this partition!";
313  // edm::LogWarning(mlConfigDb_) << ss.str();
314  }
315 
316  }
317 
318  } catch (...) { handleException( __func__ ); }
319 
320  allowCalibUpload_ = true;
321 
322 }
323 
324 // -----------------------------------------------------------------------------
325 //
327  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
328 
329  if ( analyses_.empty() ) {
330  stringstream ss;
331  ss << "[SiStripConfigDb::" << __func__ << "]"
332  << " Found no cached analysis descriptions!";
333  //edm::LogWarning(mlConfigDb_) << ss.str();
334  return;
335  }
336 
337  // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
338  AnalysisDescriptions temporary_cache;
339  if ( partition == "" ) { temporary_cache = AnalysisDescriptions(); }
340  else {
341  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
342  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
343  for ( ; iter != jter; ++iter ) {
344  if ( partition != iter->second.partitionName() ) {
345  AnalysisDescriptionsRange range = analyses_.find( iter->second.partitionName() );
346  if ( range != analyses_.emptyRange() ) {
347  temporary_cache.loadNext( partition, AnalysisDescriptionsV( range.begin(), range.end() ) );
348  } else {
349  // stringstream ss;
350  // ss << "[SiStripConfigDb::" << __func__ << "]"
351  // << " Cannot find partition \"" << iter->second.partitionName()
352  // << "\" in local cache!";
353  // edm::LogWarning(mlConfigDb_) << ss.str();
354  }
355  }
356  }
357  }
358 
359  // Delete objects in local cache for specified partition (or all if not specified)
360  AnalysisDescriptionsRange anals = analyses_.emptyRange();
361  if ( partition == "" ) {
362  if ( !analyses_.empty() ) {
363  anals = AnalysisDescriptionsRange( analyses_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
364  analyses_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
365  } else { anals = analyses_.emptyRange(); }
366  } else {
367  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
368  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
369  for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
370  anals = analyses_.find( iter->second.partitionName() );
371  }
372 
373  if ( anals != analyses_.emptyRange() ) {
374  AnalysisDescriptionsV::const_iterator ianal = anals.begin();
375  AnalysisDescriptionsV::const_iterator janal = anals.end();
376  for ( ; ianal != janal; ++ianal ) { if ( *ianal ) { delete *ianal; } }
377  } else {
378  stringstream ss;
379  ss << "[SiStripConfigDb::" << __func__ << "]";
380  if ( partition == "" ) { ss << " Found no analysis descriptions in local cache!"; }
381  else { ss << " Found no analysis descriptions in local cache for partition \"" << partition << "\"!"; }
382  edm::LogWarning(mlConfigDb_) << ss.str();
383  }
384 
385  // Overwrite local cache with temporary cache
386  analyses_ = temporary_cache;
387 
388 }
389 
390 // -----------------------------------------------------------------------------
391 //
393 
394  std::stringstream ss;
395  ss << "[SiStripConfigDb::" << __func__ << "]"
396  << " Contents of AnalysisDescriptions container:" << std::endl;
397  ss << " Number of partitions: " << analyses_.size() << std::endl;
398 
399  // Loop through partitions
400  uint16_t cntr = 0;
401  AnalysisDescriptions::const_iterator ianal = analyses_.begin();
402  AnalysisDescriptions::const_iterator janal = analyses_.end();
403  for ( ; ianal != janal; ++ianal ) {
404 
405  cntr++;
406  if ( partition == "" || partition == ianal->first ) {
407 
408  ss << " Partition number : " << cntr << " (out of " << analyses_.size() << ")" << std::endl;
409  ss << " Partition name : \"" << ianal->first << "\"" << std::endl;
410  ss << " Num of analyses : " << ianal->second.size() << std::endl;
411 
412  // Extract FEC crate, slot, etc
413  std::map< uint32_t, vector<uint32_t> > analyses;
414  AnalysisDescriptionsV::const_iterator iter = ianal->second.begin();
415  AnalysisDescriptionsV::const_iterator jter = ianal->second.end();
416  for ( ; iter != jter; ++iter ) {
417  if ( *iter ) {
418  DeviceAddress addr = deviceAddress( **iter );
419  uint32_t key = SiStripFecKey( addr.fecCrate_,
420  addr.fecSlot_,
421  addr.fecRing_,
422  0,
423  0,
424  0,
425  0 ).key();
426  uint32_t data = SiStripFecKey( addr.fecCrate_,
427  addr.fecSlot_,
428  addr.fecRing_,
429  addr.ccuAddr_,
430  addr.ccuChan_,
431  addr.lldChan_,
432  addr.i2cAddr_ ).key();
433  if ( find( analyses[key].begin(), analyses[key].end(), data ) == analyses[key].end() ) {
434  analyses[key].push_back( data );
435  }
436  }
437  }
438 
439  // Sort contents
440  std::map< uint32_t, std::vector<uint32_t> > tmp;
441  std::map< uint32_t, std::vector<uint32_t> >::const_iterator ii = analyses.begin();
442  std::map< uint32_t, std::vector<uint32_t> >::const_iterator jj = analyses.end();
443  for ( ; ii != jj; ++ii ) {
444  std::vector<uint32_t> temp = ii->second;
445  std::sort( temp.begin(), temp.end() );
446  std::vector<uint32_t>::const_iterator iii = temp.begin();
447  std::vector<uint32_t>::const_iterator jjj = temp.end();
448  for ( ; iii != jjj; ++iii ) { tmp[ii->first].push_back( *iii ); }
449  }
450  analyses.clear();
451  analyses = tmp;
452 
453  // Print FEC crate, slot, etc...
454  std::map< uint32_t, std::vector<uint32_t> >::const_iterator ianal = analyses.begin();
455  std::map< uint32_t, std::vector<uint32_t> >::const_iterator janal = analyses.end();
456  for ( ; ianal != janal; ++ianal ) {
457  SiStripFecKey key(ianal->first);
458  ss << " Found " << std::setw(3) << ianal->second.size()
459  << " analyses for FEC crate/slot/ring "
460  << key.fecCrate() << "/"
461  << key.fecSlot() << "/"
462  << key.fecRing();
463  //<< " (ccu/module/lld/i2c): ";
464  // if ( !ianal->second.empty() ) {
465  // uint16_t first = ianal->second.front();
466  // uint16_t last = ianal->second.front();
467  // std::vector<uint32_t>::const_iterator chan = ianal->second.begin();
468  // for ( ; chan != ianal->second.end(); chan++ ) {
469  // if ( chan != ianal->second.begin() ) {
470  // if ( *chan != last+1 ) {
471  // ss << std::setw(2) << first << "->" << std::setw(2) << last << ", ";
472  // if ( chan != ianal->second.end() ) { first = *(chan+1); }
473  // }
474  // }
475  // last = *chan;
476  // }
477  // if ( first != last ) { ss << std::setw(2) << first << "->" << std::setw(2) << last; }
478  ss << std::endl;
479  }
480 
481  }
482 
483  }
484 
485  LogTrace(mlConfigDb_) << ss.str();
486 
487 }
488 
489 // -----------------------------------------------------------------------------
490 //
492 
493  DeviceAddress addr;
494  try {
495  addr.fecCrate_ = static_cast<uint16_t>( desc.getCrate() + sistrip::FEC_CRATE_OFFSET );
496  addr.fecSlot_ = static_cast<uint16_t>( desc.getSlot() );
497  addr.fecRing_ = static_cast<uint16_t>( desc.getRing() + sistrip::FEC_RING_OFFSET );
498  addr.ccuAddr_ = static_cast<uint16_t>( desc.getCcuAdr() );
499  addr.ccuChan_ = static_cast<uint16_t>( desc.getCcuChan() );
500  addr.lldChan_ = static_cast<uint16_t>( SiStripFecKey::lldChan( desc.getI2cAddr() ) );
501  addr.i2cAddr_ = static_cast<uint16_t>( desc.getI2cAddr() );
502  addr.fedId_ = static_cast<uint16_t>( desc.getFedId() ); //@@ offset required? crate/slot needed?
503  addr.feUnit_ = static_cast<uint16_t>( desc.getFeUnit() );
504  addr.feChan_ = static_cast<uint16_t>( desc.getFeChan() );
505  } catch (...) { handleException( __func__ ); }
506 
507  return addr;
508 }
509 
510 // -----------------------------------------------------------------------------
511 //
513  if ( analysis_type == AnalysisDescription::T_ANALYSIS_FASTFEDCABLING ) { return "FAST_CABLING"; }
514  else if ( analysis_type == AnalysisDescription::T_ANALYSIS_TIMING ) { return "APV_TIMING"; }
515  else if ( analysis_type == AnalysisDescription::T_ANALYSIS_OPTOSCAN ) { return "OPTO_SCAN"; }
516  else if ( analysis_type == AnalysisDescription::T_ANALYSIS_PEDESTALS ) { return "PEDESTALS"; }
517  else if ( analysis_type == AnalysisDescription::T_ANALYSIS_APVLATENCY ) { return "APV_LATENCY"; }
518  else if ( analysis_type == AnalysisDescription::T_ANALYSIS_FINEDELAY ) { return "FINE_DELAY"; }
519  else if ( analysis_type == AnalysisDescription::T_ANALYSIS_CALIBRATION ) { return "CALIBRATION"; }
520  else if ( analysis_type == AnalysisDescription::T_UNKNOWN ) { return "UNKNOWN ANALYSIS TYPE"; }
521  else { return "UNDEFINED ANALYSIS TYPE"; }
522 }
static std::string defaultPartitionName_
const uint16_t & fecRing() const
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:97
void uploadAnalysisDescriptions(bool calibration_for_physics=false, std::string partition="")
void addAnalysisDescriptions(std::string partition, AnalysisDescriptionsV &)
static const uint16_t FEC_RING_OFFSET
const uint16_t & lldChan() const
const uint16_t & fecSlot() 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
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
CommissioningAnalysisDescription AnalysisDescription
void clearAnalysisDescriptions(std::string partition="")
#define end
Definition: vmac.h:37
DeviceAddress deviceAddress(const deviceDescription &)
AnalysisDescriptionsRange getAnalysisDescriptions(AnalysisType, std::string partition="")
#define LogTrace(id)
const uint16_t & fecCrate() const
AnalysisDescriptions::range AnalysisDescriptionsRange
CommissioningAnalysisDescription::commissioningType AnalysisType
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
#define begin
Definition: vmac.h:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
list key
Definition: combine.py:13
std::string analysisType(AnalysisType) const
std::vector< AnalysisDescription * > AnalysisDescriptionsV
static const uint16_t FEC_CRATE_OFFSET
void printAnalysisDescriptions(std::string partition="")