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 
6 
7 using namespace std;
8 using namespace sistrip;
9 
10 // -----------------------------------------------------------------------------
11 //
13 
14  // Check
15  if ( ( !dbParams_.usingDbCache() && !deviceFactory(__func__) ) ||
16  ( dbParams_.usingDbCache() && !databaseCache(__func__) ) ) {
17  return feds_.emptyRange();
18  }
19 
20  try {
21 
22  if ( !dbParams_.usingDbCache() ) {
23 
24  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
25  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
26  for ( ; iter != jter; ++iter ) {
27 
28  if ( partition == "" || partition == iter->second.partitionName() ) {
29 
30  if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
31 
32  FedDescriptionsRange range = feds_.find( iter->second.partitionName() );
33  if ( range == feds_.emptyRange() ) {
34 
35  // Extract versions
36  deviceFactory(__func__)->setUsingStrips( usingStrips_ );
37  int16_t major = iter->second.fedVersion().first;
38  int16_t minor = iter->second.fedVersion().second;
39  if ( iter->second.fedVersion().first == 0 &&
40  iter->second.fedVersion().second == 0 ) {
41  major = -1; //@@ "current state" for fed factory!
42  minor = -1; //@@ "current state" for fed factory!
43  }
44 
45  // Retrive FED descriptions
46  FedDescriptionsV tmp1;
47  tmp1 = *( deviceFactory(__func__)->getFed9UDescriptions( iter->second.partitionName(),
48  major,
49  minor ) );
50 
51  // Make local copy
52  FedDescriptionsV tmp2;
53  Fed9U::Fed9UDeviceFactory::vectorCopy( tmp2, tmp1 );
54 
55  // Add to cache
56  feds_.loadNext( iter->second.partitionName(), tmp2 );
57 
58  // Some debug
59  FedDescriptionsRange feds = feds_.find( iter->second.partitionName() );
60  std::stringstream ss;
61  ss << "[SiStripConfigDb::" << __func__ << "]"
62  << " Downloaded " << feds.size()
63  << " FED descriptions to local cache for partition \""
64  << iter->second.partitionName() << "\"" << std::endl;
65  ss << "[SiStripConfigDb::" << __func__ << "]"
66  << " Cache holds FED descriptions for "
67  << feds_.size() << " partitions.";
68  LogTrace(mlConfigDb_) << ss.str();
69 
70  }
71 
72  }
73 
74  }
75 
76  } else { // Using database cache
77 
78  FedDescriptionsV* tmp1 = databaseCache(__func__)->getFed9UDescriptions();
79 
80  if ( tmp1 ) {
81 
82  // Make local copy
83  FedDescriptionsV tmp2;
84  Fed9U::Fed9UDeviceFactory::vectorCopy( tmp2, *tmp1 );
85 
86  // Add to cache
87  feds_.loadNext( SiStripPartition::defaultPartitionName_, tmp2 );
88 
89  } else {
91  << "[SiStripConfigDb::" << __func__ << "]"
92  << " NULL pointer to FED descriptions vector!";
93  }
94 
95  }
96 
97  } catch (... ) { handleException( __func__ ); }
98 
99  // Create range object
100  uint16_t np = 0;
101  uint16_t nc = 0;
103  if ( partition != "" ) {
104  feds = feds_.find( partition );
105  np = 1;
106  nc = feds.size();
107  } else {
108  if ( !feds_.empty() ) {
109  feds = FedDescriptionsRange( feds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
110  feds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
111  } else { feds = feds_.emptyRange(); }
112  np = feds_.size();
113  nc = feds.size();
114  }
115 
116  stringstream ss;
117  ss << "[SiStripConfigDb::" << __func__ << "]"
118  << " Found " << nc << " FED descriptions";
119  if ( !dbParams_.usingDb() ) { ss << " in " << dbParams_.inputFedXmlFiles().size() << " 'fed.xml' file(s)"; }
120  else { if ( !dbParams_.usingDbCache() ) { ss << " in " << np << " database partition(s)"; }
121  else { ss << " from shared memory name '" << dbParams_.sharedMemory() << "'"; } }
122  if ( feds_.empty() ) { edm::LogWarning(mlConfigDb_) << ss.str(); }
123  else { LogTrace(mlConfigDb_) << ss.str(); }
124 
125  return feds;
126 
127 }
128 
129 // -----------------------------------------------------------------------------
130 //
132 
133  if ( !deviceFactory(__func__) ) { return; }
134 
135  if ( partition.empty() ) {
136  stringstream ss;
137  ss << "[SiStripConfigDb::" << __func__ << "]"
138  << " Partition string is empty,"
139  << " therefore cannot add FED descriptions to local cache!";
140  edm::LogWarning(mlConfigDb_) << ss.str();
141  return;
142  }
143 
144  if ( feds.empty() ) {
145  stringstream ss;
146  ss << "[SiStripConfigDb::" << __func__ << "]"
147  << " Vector of FED descriptions is empty,"
148  << " therefore cannot add FED descriptions to local cache!";
149  edm::LogWarning(mlConfigDb_) << ss.str();
150  return;
151  }
152 
153  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
154  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
155  for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
156  if ( iter == dbParams_.partitions().end() ) {
157  stringstream ss;
158  ss << "[SiStripConfigDb::" << __func__ << "]"
159  << " Partition \"" << partition
160  << "\" not found in partition list, "
161  << " therefore cannot add FED descriptions!";
162  edm::LogWarning(mlConfigDb_) << ss.str();
163  return;
164  }
165 
166  FedDescriptionsRange range = feds_.find( partition );
167  if ( range == feds_.emptyRange() ) {
168 
169  // Make local copy
171  Fed9U::Fed9UDeviceFactory::vectorCopy( tmp, feds );
172 
173  // Add to local cache
174  feds_.loadNext( partition, tmp );
175 
176  // Some debug
177  std::stringstream ss;
178  ss << "[SiStripConfigDb::" << __func__ << "]"
179  << " Added " << feds.size()
180  << " FED descriptions to local cache for partition \""
181  << iter->second.partitionName() << "\"" << std::endl;
182  ss << "[SiStripConfigDb::" << __func__ << "]"
183  << " Cache holds FED descriptions for "
184  << feds_.size() << " partitions.";
185  LogTrace(mlConfigDb_) << ss.str();
186 
187  } else {
188  stringstream ss;
189  ss << "[SiStripConfigDb::" << __func__ << "]"
190  << " Partition \"" << partition
191  << "\" already found in local cache, "
192  << " therefore cannot add new FED descriptions!";
193  edm::LogWarning(mlConfigDb_) << ss.str();
194  return;
195  }
196 
197 }
198 
199 // -----------------------------------------------------------------------------
200 //
202 
203  if ( dbParams_.usingDbCache() ) {
205  << "[SiStripConfigDb::" << __func__ << "]"
206  << " Using database cache! No uploads allowed!";
207  return;
208  }
209 
210  if ( !deviceFactory(__func__) ) { return; }
211 
212  if ( feds_.empty() ) {
213  stringstream ss;
214  ss << "[SiStripConfigDb::" << __func__ << "]"
215  << " Found no cached FED descriptions, therefore no upload!";
216  edm::LogWarning(mlConfigDb_) << ss.str();
217  return;
218  }
219 
220  try {
221 
222  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
223  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
224  for ( ; iter != jter; ++iter ) {
225 
226  if ( partition == "" || partition == iter->second.partitionName() ) {
227 
228  FedDescriptionsRange range = feds_.find( iter->second.partitionName() );
229  if ( range != feds_.emptyRange() ) {
230 
231  FedDescriptionsV feds( range.begin(), range.end() );
232 
233  SiStripPartition::Versions fedVersion = iter->second.fedVersion();
234  deviceFactory(__func__)->setFed9UDescriptions( feds,
235  iter->second.partitionName(),
236  (uint16_t*)(&(fedVersion.first)),
237  (uint16_t*)(&(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 //
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 //
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 const std::string defaultPartitionName_
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:99
FedDescriptionsRange getFedDescriptions(std::string partition="")
FedDescriptions::range FedDescriptionsRange
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
std::pair< uint32_t, uint32_t > Versions
void addFedDescriptions(std::string partition, FedDescriptionsV &)
static const char mlConfigDb_[]
static const char mlCabling_[]
int np
Definition: AMPTWrapper.h:33
FedIdsRange getFedIds(std::string partition="")
#define end
Definition: vmac.h:37
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
#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:30
void clearFedDescriptions(std::string partition="")
std::vector< FedDescription * > FedDescriptionsV