CMS 3D CMS Logo

DcuDetIds.cc
Go to the documentation of this file.
1 
4 
5 using namespace std;
6 using namespace sistrip;
7 
8 // -----------------------------------------------------------------------------
9 //
11  // Check
12  if ((!dbParams_.usingDbCache() && !deviceFactory(__func__)) ||
13  (dbParams_.usingDbCache() && !databaseCache(__func__))) {
14  return dcuDetIds_.emptyRange();
15  }
16 
17  try {
18  if (!dbParams_.usingDbCache()) {
19  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
20  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
21  for (; iter != jter; ++iter) {
22  if (partition.empty() || partition == iter->second.partitionName()) {
23  if (iter->second.partitionName() == SiStripPartition::defaultPartitionName_) {
24  continue;
25  }
26 
27  DcuDetIdsRange range = dcuDetIds_.find(iter->second.partitionName());
28  if (range == dcuDetIds_.emptyRange()) {
29  deviceFactory(__func__)->addDetIdPartition(
30  iter->second.partitionName(), iter->second.dcuVersion().first, iter->second.dcuVersion().second);
31 
32  // Retrieve DCU-DetId map
33  DcuDetIdMap src = deviceFactory(__func__)->getInfos();
34 
35  // Make local copy
37  clone(src, dst);
38 
39  // Add to cache
40  dcuDetIds_.loadNext(iter->second.partitionName(), dst);
41  }
42  }
43  }
44 
45  } else { // Using database cache
46 
47  // Retrieve DCU-DetId map
48  DcuDetIdMap* src = databaseCache(__func__)->getInfos();
49 
50  if (src) {
51  // Make local copy
53  clone(*src, dst);
54 
55  // Add to cache
56  dcuDetIds_.loadNext(SiStripPartition::defaultPartitionName_, dst);
57 
58  } else {
59  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
60  << " NULL pointer to Dcu-DetId map!";
61  }
62  }
63 
64  } catch (...) {
65  handleException(__func__);
66  }
67 
68  // Create range object
69  uint16_t np = 0;
70  uint16_t nc = 0;
72  if (!partition.empty()) {
73  range = dcuDetIds_.find(partition);
74  np = 1;
75  nc = range.size();
76  } else {
77  if (!dcuDetIds_.empty()) {
78  range = DcuDetIdsRange(dcuDetIds_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
79  dcuDetIds_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
80  } else {
81  range = dcuDetIds_.emptyRange();
82  }
83  np = dcuDetIds_.size();
84  nc = range.size();
85  }
86 
87  stringstream ss;
88  ss << "[SiStripConfigDb::" << __func__ << "]"
89  << " Found " << nc << " entries in DCU-DetId map";
90  if (!dbParams_.usingDb()) {
91  ss << " in " << dbParams_.inputDcuInfoXmlFiles().size() << " 'module.xml' file(s)";
92  } else {
93  if (!dbParams_.usingDbCache()) {
94  ss << " in " << np << " database partition(s)";
95  } else {
96  ss << " from shared memory name '" << dbParams_.sharedMemory() << "'";
97  }
98  }
99  if (dcuDetIds_.empty()) {
100  edm::LogWarning(mlConfigDb_) << ss.str();
101  } else {
102  LogTrace(mlConfigDb_) << ss.str();
103  }
104 
105  return range;
106 }
107 
108 // -----------------------------------------------------------------------------
109 //
111  stringstream ss;
112  ss << "[SiStripConfigDb::" << __func__ << "]"
113  << " Cannot add to local cache! This functionality not allowed!";
114  edm::LogWarning(mlConfigDb_) << ss.str();
115 
116  // if ( !deviceFactory(__func__) ) { return; }
117 
118  // if ( partition.empty() ) {
119  // stringstream ss;
120  // ss << "[SiStripConfigDb::" << __func__ << "]"
121  // << " Partition string is empty,"
122  // << " therefore cannot add DCU-DetId map to local cache!";
123  // edm::LogWarning(mlConfigDb_) << ss.str();
124  // return;
125  // }
126 
127  // if ( dcus.empty() ) {
128  // stringstream ss;
129  // ss << "[SiStripConfigDb::" << __func__ << "]"
130  // << " Vector of DCU-DetId map is empty,"
131  // << " therefore cannot add DCU-DetId map to local cache!";
132  // edm::LogWarning(mlConfigDb_) << ss.str();
133  // return;
134  // }
135 
136  // SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
137  // SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
138  // for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
139  // if ( iter == dbParams_.partitions().end() ) {
140  // stringstream ss;
141  // ss << "[SiStripConfigDb::" << __func__ << "]"
142  // << " Partition \"" << partition
143  // << "\" not found in partition list, "
144  // << " therefore cannot add DCU-DetId map!";
145  // edm::LogWarning(mlConfigDb_) << ss.str();
146  // return;
147  // }
148 
149  // DcuDetIdsRange range = dcuDetIds_.find( partition );
150  // if ( range == dcuDetIds_.emptyRange() ) {
151 
152  // // Make local copy
153  // DcuDetIdsV dst;
154  // clone( dcus, dst );
155 
156  // // Add to local cache
157  // dcuDetIds_.loadNext( partition, dst );
158 
159  // // Some debug
160  // std::stringstream ss;
161  // ss << "[SiStripConfigDb::" << __func__ << "]"
162  // << " Added " << dst.size()
163  // << " DCU-DetId map to local cache for partition \""
164  // << partition << "\"" << std::endl;
165  // ss << "[SiStripConfigDb::" << __func__ << "]"
166  // << " Cache holds DCU-DetId map for "
167  // << dcuDetIds_.size() << " partitions.";
168  // LogTrace(mlConfigDb_) << ss.str();
169 
170  // } else {
171  // stringstream ss;
172  // ss << "[SiStripConfigDb::" << __func__ << "]"
173  // << " Partition \"" << partition
174  // << "\" already found in local cache, "
175  // << " therefore cannot add new DCU-DetId map!";
176  // edm::LogWarning(mlConfigDb_) << ss.str();
177  // return;
178  // }
179 }
180 
181 // -----------------------------------------------------------------------------
182 //
184  stringstream ss;
185  ss << "[SiStripConfigDb::" << __func__ << "]"
186  << " Cannot upload to database! This functionality not allowed!";
187  edm::LogWarning(mlConfigDb_) << ss.str();
188 
189  /*
190  addAllDetId => all detids
191  addAllDetId => to download (up to you)
192  change in the detids
193  setTkDcuInfo
194  getCurrentStates
195  setCurrentState
196  addDetIpartiton
197  AddAllDetId
198  */
199 
200  // if ( dbParams_.usingDbCache() ) {
201  // edm::LogWarning(mlConfigDb_)
202  // << "[SiStripConfigDb::" << __func__ << "]"
203  // << " Using database cache! No uploads allowed!";
204  // return;
205  // }
206 
207  // if ( !deviceFactory(__func__) ) { return; }
208 
209  // if ( dcuDetIds_.empty() ) {
210  // stringstream ss;
211  // ss << "[SiStripConfigDb::" << __func__ << "]"
212  // << " Found no cached DCU-DetId map, therefore no upload!";
213  // edm::LogWarning(mlConfigDb_) << ss.str();
214  // return;
215  // }
216 
217  // try {
218 
219  // SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
220  // SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
221  // for ( ; iter != jter; ++iter ) {
222 
223  // if ( partition == "" || partition == iter->second.partitionName() ) {
224 
225  // DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
226  // if ( range != dcuDetIds_.emptyRange() ) {
227 
228  // // Extract
229  // DcuDetIdMap dst;
230  // clone( DcuDetIdsV( range.begin(), range.end() ), dst );
231  // deviceFactory(__func__)->setTkDcuInfo( dst );
232  // getcurrentstate
233  // deviceFactory(__func__)->addAllDetId();
234 
235  // // Some debug
236  // std::stringstream ss;
237  // ss << "[SiStripConfigDb::" << __func__ << "]"
238  // << " Uploaded " << dst.size()
239  // << " DCU-DetId map to DB/xml for partition \""
240  // << iter->second.partitionName() << "\".";
241  // LogTrace(mlConfigDb_) << ss.str();
242 
243  // } else {
244  // stringstream ss;
245  // ss << "[SiStripConfigDb::" << __func__ << "]"
246  // << " Vector of DCU-DetId map is empty for partition \""
247  // << iter->second.partitionName()
248  // << "\", therefore aborting upload for this partition!";
249  // edm::LogWarning(mlConfigDb_) << ss.str();
250  // continue;
251  // }
252 
253  // } else {
254  // // stringstream ss;
255  // // ss << "[SiStripConfigDb::" << __func__ << "]"
256  // // << " Cannot find partition \"" << partition
257  // // << "\" in cached partitions list: \""
258  // // << dbParams_.partitionNames( dbParams_.partitionNames() )
259  // // << "\", therefore aborting upload for this partition!";
260  // // edm::LogWarning(mlConfigDb_) << ss.str();
261  // }
262 
263  // }
264 
265  // } catch (... ) { handleException( __func__, "Problems updating objects in TkDcuInfoFactory!" ); }
266 }
267 
268 // -----------------------------------------------------------------------------
269 //
271  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
272 
273  if (dcuDetIds_.empty()) {
274  stringstream ss;
275  ss << "[SiStripConfigDb::" << __func__ << "]"
276  << " Found no cached DCU-DetId map!";
277  //edm::LogWarning(mlConfigDb_) << ss.str();
278  return;
279  }
280 
281  // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
282  DcuDetIds temporary_cache;
283  if (partition.empty()) {
284  temporary_cache = DcuDetIds();
285  } else {
286  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
287  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
288  for (; iter != jter; ++iter) {
289  if (partition != iter->second.partitionName()) {
290  DcuDetIdsRange range = dcuDetIds_.find(iter->second.partitionName());
291  if (range != dcuDetIds_.emptyRange()) {
292  temporary_cache.loadNext(partition, DcuDetIdsV(range.begin(), range.end()));
293  } else {
294  // stringstream ss;
295  // ss << "[SiStripConfigDb::" << __func__ << "]"
296  // << " Cannot find partition \"" << iter->second.partitionName()
297  // << "\" in local cache!";
298  // edm::LogWarning(mlConfigDb_) << ss.str();
299  }
300  }
301  }
302  }
303 
304  // Delete objects in local cache for specified partition (or all if not specified)
305  DcuDetIdsRange dcus;
306  if (partition.empty()) {
307  if (!dcuDetIds_.empty()) {
308  dcus = DcuDetIdsRange(dcuDetIds_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
309  dcuDetIds_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
310  } else {
311  dcus = dcuDetIds_.emptyRange();
312  }
313  } else {
314  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
315  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
316  for (; iter != jter; ++iter) {
317  if (partition == iter->second.partitionName()) {
318  break;
319  }
320  }
321  dcus = dcuDetIds_.find(iter->second.partitionName());
322  }
323 
324  if (dcus != dcuDetIds_.emptyRange()) {
325  DcuDetIdsV::const_iterator ifed = dcus.begin();
326  DcuDetIdsV::const_iterator jfed = dcus.end();
327  for (; ifed != jfed; ++ifed) {
328  if (ifed->second) {
329  delete ifed->second;
330  }
331  }
332  } else {
333  stringstream ss;
334  ss << "[SiStripConfigDb::" << __func__ << "]";
335  if (partition.empty()) {
336  ss << " Found no DCU-DetId map in local cache!";
337  } else {
338  ss << " Found no DCU-DetId map in local cache for partition \"" << partition << "\"!";
339  }
340  edm::LogWarning(mlConfigDb_) << ss.str();
341  }
342 
343  // Overwrite local cache with temporary cache
344  dcuDetIds_ = temporary_cache;
345 }
346 
347 // -----------------------------------------------------------------------------
348 //
350  std::stringstream ss;
351  ss << "[SiStripConfigDb::" << __func__ << "]"
352  << " Contents of DcuDetIds container:" << std::endl;
353  ss << " Number of partitions: " << dcuDetIds_.size() << std::endl;
354 
355  // Loop through partitions
356  uint16_t cntr = 0;
357  DcuDetIds::const_iterator idcu = dcuDetIds_.begin();
358  DcuDetIds::const_iterator jdcu = dcuDetIds_.end();
359  for (; idcu != jdcu; ++idcu) {
360  cntr++;
361  if (partition.empty() || partition == idcu->first) {
362  ss << " Partition number : " << cntr << " (out of " << dcuDetIds_.size() << ")" << std::endl;
363  ss << " Partition name : \"" << idcu->first << "\"" << std::endl;
364  ss << " Size of DCU-DetId map : " << idcu->second.size() << std::endl;
365  }
366  }
367 
368  LogTrace(mlConfigDb_) << ss.str();
369 }
370 
371 // -----------------------------------------------------------------------------
372 //
374  output.clear();
375  DcuDetIdMap::const_iterator ii = input.begin();
376  DcuDetIdMap::const_iterator jj = input.end();
377  for (; ii != jj; ++ii) {
378  if (ii->second) {
379  output.push_back(std::make_pair(ii->first, new TkDcuInfo(*(ii->second))));
380  }
381  }
382 }
383 
384 // -----------------------------------------------------------------------------
385 //
387  output.clear();
388  DcuDetIdsV::const_iterator ii = input.begin();
389  DcuDetIdsV::const_iterator jj = input.end();
390  for (; ii != jj; ++ii) {
391  if (ii->second) {
392  output[ii->first] = new TkDcuInfo(*(ii->second));
393  }
394  }
395 }
396 
397 // -----------------------------------------------------------------------------
398 //
400  output.clear();
401  DcuDetIdsV::const_iterator ii = input.begin();
402  DcuDetIdsV::const_iterator jj = input.end();
403  for (; ii != jj; ++ii) {
404  if (ii->second) {
405  output.push_back(std::make_pair(ii->first, new TkDcuInfo(*(ii->second))));
406  }
407  }
408 }
409 
410 // -----------------------------------------------------------------------------
411 //
412 SiStripConfigDb::DcuDetIdsV::const_iterator SiStripConfigDb::findDcuDetId(DcuDetIdsV::const_iterator begin,
413  DcuDetIdsV::const_iterator end,
414  uint32_t dcu_id) {
415  DcuDetIdsV::const_iterator iter = begin;
416  DcuDetIdsV::const_iterator jter = end;
417  for (; iter != jter; ++iter) {
418  if (iter->second && iter->second->getDcuHardId() == dcu_id) {
419  return iter;
420  }
421  }
422  return end;
423 }
424 
425 // -----------------------------------------------------------------------------
426 //
427 SiStripConfigDb::DcuDetIdsV::iterator SiStripConfigDb::findDcuDetId(DcuDetIdsV::iterator begin,
428  DcuDetIdsV::iterator end,
429  uint32_t dcu_id) {
430  DcuDetIdsV::iterator iter = begin;
431  DcuDetIdsV::iterator jter = end;
432  for (; iter != jter; ++iter) {
433  if (iter->second && iter->second->getDcuHardId() == dcu_id) {
434  return iter;
435  }
436  }
437  return end;
438 }
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
SiStripConfigDb::addDcuDetIds
void addDcuDetIds(std::string partition, DcuDetIdsV &)
Definition: DcuDetIds.cc:110
SiStripConfigDb::DcuDetIdsRange
DcuDetIds::range DcuDetIdsRange
Definition: SiStripConfigDb.h:127
SiStripConfigDb::DcuDetIdsV
std::vector< DcuDetId > DcuDetIdsV
Definition: SiStripConfigDb.h:128
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
SiStripConfigDb::printDcuDetIds
void printDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:349
np
int np
Definition: AMPTWrapper.h:43
SiStripConfigDb::DcuDetIdMap
Sgi::hash_map< unsigned long, TkDcuInfo * > DcuDetIdMap
Definition: SiStripConfigDb.h:124
SiStripConfigDb::clearDcuDetIds
void clearDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:270
SiStripConfigDb::findDcuDetId
static DcuDetIdsV::const_iterator findDcuDetId(DcuDetIdsV::const_iterator begin, DcuDetIdsV::const_iterator end, uint32_t dcu_id)
Definition: DcuDetIds.cc:412
end
#define end
Definition: vmac.h:39
sistrip::mlConfigDb_
static const char mlConfigDb_[]
Definition: ConstantsForLogger.h:16
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::MapOfVectors::loadNext
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:87
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
SiStripConfigDb.h
std
Definition: JetResolutionObject.h:76
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
SiStripConfigDb::clone
void clone(const DcuDetIdMap &in, DcuDetIdsV &out) const
Definition: DcuDetIds.cc:373
edm::MapOfVectors< std::string, DcuDetId >
math::cholesky::dst
M2 & dst
Definition: choleskyInversion.h:158
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
SiStripPartition::defaultPartitionName_
static const std::string defaultPartitionName_
Definition: SiStripPartition.h:40
SiStripConfigDb::uploadDcuDetIds
void uploadDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:183
SiStripConfigDb::getDcuDetIds
DcuDetIdsRange getDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:10
cuy.ii
ii
Definition: cuy.py:590
begin
#define begin
Definition: vmac.h:32
edm::MapOfVectors< std::string, DcuDetId >::const_iterator
Iter const_iterator
Definition: MapOfVectors.h:69