CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DcuDetIds.cc
Go to the documentation of this file.
1 // Last commit: $Id: DcuDetIds.cc,v 1.7 2009/04/06 16:57:28 lowette Exp $
2 
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 dcuDetIds_.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  DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
32  if ( range == dcuDetIds_.emptyRange() ) {
33 
34  deviceFactory(__func__)->addDetIdPartition( iter->second.partitionName(),
35  iter->second.dcuVersion().first,
36  iter->second.dcuVersion().second );
37 
38  // Retrieve DCU-DetId map
39  DcuDetIdMap src = deviceFactory(__func__)->getInfos();
40 
41  // Make local copy
42  DcuDetIdsV dst;
43  clone( src, dst );
44 
45  // Add to cache
46  dcuDetIds_.loadNext( iter->second.partitionName(), dst );
47 
48  }
49 
50  }
51 
52  }
53 
54  } else { // Using database cache
55 
56  // Retrieve DCU-DetId map
57  DcuDetIdMap* src = databaseCache(__func__)->getInfos();
58 
59  if ( src ) {
60 
61  // Make local copy
62  DcuDetIdsV dst;
63  clone( *src, dst );
64 
65  // Add to cache
66  dcuDetIds_.loadNext( SiStripPartition::defaultPartitionName_, dst );
67 
68  } else {
70  << "[SiStripConfigDb::" << __func__ << "]"
71  << " NULL pointer to Dcu-DetId map!";
72  }
73 
74  }
75 
76  } catch (... ) { handleException( __func__ ); }
77 
78  // Create range object
79  uint16_t np = 0;
80  uint16_t nc = 0;
81  DcuDetIdsRange range;
82  if ( partition != "" ) {
83  range = dcuDetIds_.find( partition );
84  np = 1;
85  nc = range.size();
86  } else {
87  if ( !dcuDetIds_.empty() ) {
88  range = DcuDetIdsRange( dcuDetIds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
89  dcuDetIds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
90  } else { range = dcuDetIds_.emptyRange(); }
91  np = dcuDetIds_.size();
92  nc = range.size();
93  }
94 
95  stringstream ss;
96  ss << "[SiStripConfigDb::" << __func__ << "]"
97  << " Found " << nc << " entries in DCU-DetId map";
98  if ( !dbParams_.usingDb() ) { ss << " in " << dbParams_.inputDcuInfoXmlFiles().size() << " 'module.xml' file(s)"; }
99  else { if ( !dbParams_.usingDbCache() ) { ss << " in " << np << " database partition(s)"; }
100  else { ss << " from shared memory name '" << dbParams_.sharedMemory() << "'"; } }
101  if ( dcuDetIds_.empty() ) { edm::LogWarning(mlConfigDb_) << ss.str(); }
102  else { LogTrace(mlConfigDb_) << ss.str(); }
103 
104  return range;
105 }
106 
107 // -----------------------------------------------------------------------------
108 //
109 void SiStripConfigDb::addDcuDetIds( std::string partition, DcuDetIdsV& dcus ) {
110 
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 // -----------------------------------------------------------------------------
183 //
184 void SiStripConfigDb::uploadDcuDetIds( std::string partition ) {
185 
186  stringstream ss;
187  ss << "[SiStripConfigDb::" << __func__ << "]"
188  << " Cannot upload to database! This functionality not allowed!";
189  edm::LogWarning(mlConfigDb_) << ss.str();
190 
191  /*
192  addAllDetId => all detids
193  addAllDetId => to download (up to you)
194  change in the detids
195  setTkDcuInfo
196  getCurrentStates
197  setCurrentState
198  addDetIpartiton
199  AddAllDetId
200  */
201 
202  // if ( dbParams_.usingDbCache() ) {
203  // edm::LogWarning(mlConfigDb_)
204  // << "[SiStripConfigDb::" << __func__ << "]"
205  // << " Using database cache! No uploads allowed!";
206  // return;
207  // }
208 
209  // if ( !deviceFactory(__func__) ) { return; }
210 
211  // if ( dcuDetIds_.empty() ) {
212  // stringstream ss;
213  // ss << "[SiStripConfigDb::" << __func__ << "]"
214  // << " Found no cached DCU-DetId map, therefore no upload!";
215  // edm::LogWarning(mlConfigDb_) << ss.str();
216  // return;
217  // }
218 
219  // try {
220 
221  // SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
222  // SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
223  // for ( ; iter != jter; ++iter ) {
224 
225  // if ( partition == "" || partition == iter->second.partitionName() ) {
226 
227  // DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
228  // if ( range != dcuDetIds_.emptyRange() ) {
229 
230  // // Extract
231  // DcuDetIdMap dst;
232  // clone( DcuDetIdsV( range.begin(), range.end() ), dst );
233  // deviceFactory(__func__)->setTkDcuInfo( dst );
234  // getcurrentstate
235  // deviceFactory(__func__)->addAllDetId();
236 
237  // // Some debug
238  // std::stringstream ss;
239  // ss << "[SiStripConfigDb::" << __func__ << "]"
240  // << " Uploaded " << dst.size()
241  // << " DCU-DetId map to DB/xml for partition \""
242  // << iter->second.partitionName() << "\".";
243  // LogTrace(mlConfigDb_) << ss.str();
244 
245  // } else {
246  // stringstream ss;
247  // ss << "[SiStripConfigDb::" << __func__ << "]"
248  // << " Vector of DCU-DetId map is empty for partition \""
249  // << iter->second.partitionName()
250  // << "\", therefore aborting upload for this partition!";
251  // edm::LogWarning(mlConfigDb_) << ss.str();
252  // continue;
253  // }
254 
255  // } else {
256  // // stringstream ss;
257  // // ss << "[SiStripConfigDb::" << __func__ << "]"
258  // // << " Cannot find partition \"" << partition
259  // // << "\" in cached partitions list: \""
260  // // << dbParams_.partitionNames( dbParams_.partitionNames() )
261  // // << "\", therefore aborting upload for this partition!";
262  // // edm::LogWarning(mlConfigDb_) << ss.str();
263  // }
264 
265  // }
266 
267  // } catch (... ) { handleException( __func__, "Problems updating objects in TkDcuInfoFactory!" ); }
268 
269 }
270 
271 // -----------------------------------------------------------------------------
272 //
273 void SiStripConfigDb::clearDcuDetIds( std::string partition ) {
274  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
275 
276  if ( dcuDetIds_.empty() ) {
277  stringstream ss;
278  ss << "[SiStripConfigDb::" << __func__ << "]"
279  << " Found no cached DCU-DetId map!";
280  //edm::LogWarning(mlConfigDb_) << ss.str();
281  return;
282  }
283 
284  // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
285  DcuDetIds temporary_cache;
286  if ( partition == "" ) { temporary_cache = DcuDetIds(); }
287  else {
288  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
289  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
290  for ( ; iter != jter; ++iter ) {
291  if ( partition != iter->second.partitionName() ) {
292  DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
293  if ( range != dcuDetIds_.emptyRange() ) {
294  temporary_cache.loadNext( partition, DcuDetIdsV( range.begin(), range.end() ) );
295  } else {
296  // stringstream ss;
297  // ss << "[SiStripConfigDb::" << __func__ << "]"
298  // << " Cannot find partition \"" << iter->second.partitionName()
299  // << "\" in local cache!";
300  // edm::LogWarning(mlConfigDb_) << ss.str();
301  }
302  }
303  }
304  }
305 
306  // Delete objects in local cache for specified partition (or all if not specified)
307  DcuDetIdsRange dcus;
308  if ( partition == "" ) {
309  if ( !dcuDetIds_.empty() ) {
310  dcus = DcuDetIdsRange( dcuDetIds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
311  dcuDetIds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
312  } else { dcus = dcuDetIds_.emptyRange(); }
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 ) { if ( partition == iter->second.partitionName() ) { break; } }
317  dcus = dcuDetIds_.find( iter->second.partitionName() );
318  }
319 
320  if ( dcus != dcuDetIds_.emptyRange() ) {
321  DcuDetIdsV::const_iterator ifed = dcus.begin();
322  DcuDetIdsV::const_iterator jfed = dcus.end();
323  for ( ; ifed != jfed; ++ifed ) { if ( ifed->second ) { delete ifed->second; } }
324  } else {
325  stringstream ss;
326  ss << "[SiStripConfigDb::" << __func__ << "]";
327  if ( partition == "" ) { ss << " Found no DCU-DetId map in local cache!"; }
328  else { ss << " Found no DCU-DetId map in local cache for partition \"" << partition << "\"!"; }
329  edm::LogWarning(mlConfigDb_) << ss.str();
330  }
331 
332  // Overwrite local cache with temporary cache
333  dcuDetIds_ = temporary_cache;
334 
335 }
336 
337 // -----------------------------------------------------------------------------
338 //
339 void SiStripConfigDb::printDcuDetIds( std::string partition ) {
340 
341  std::stringstream ss;
342  ss << "[SiStripConfigDb::" << __func__ << "]"
343  << " Contents of DcuDetIds container:" << std::endl;
344  ss << " Number of partitions: " << dcuDetIds_.size() << std::endl;
345 
346  // Loop through partitions
347  uint16_t cntr = 0;
348  DcuDetIds::const_iterator idcu = dcuDetIds_.begin();
349  DcuDetIds::const_iterator jdcu = dcuDetIds_.end();
350  for ( ; idcu != jdcu; ++idcu ) {
351 
352  cntr++;
353  if ( partition == "" || partition == idcu->first ) {
354 
355  ss << " Partition number : " << cntr << " (out of " << dcuDetIds_.size() << ")" << std::endl;
356  ss << " Partition name : \"" << idcu->first << "\"" << std::endl;
357  ss << " Size of DCU-DetId map : " << idcu->second.size() << std::endl;
358 
359  }
360 
361  }
362 
363  LogTrace(mlConfigDb_) << ss.str();
364 
365 }
366 
367 // -----------------------------------------------------------------------------
368 //
370  output.clear();
371  DcuDetIdMap::const_iterator ii = input.begin();
372  DcuDetIdMap::const_iterator jj = input.end();
373  for ( ; ii != jj; ++ii ) { if ( ii->second ) { output.push_back( std::make_pair( ii->first, new TkDcuInfo( *(ii->second) ) ) ); } }
374 }
375 
376 // -----------------------------------------------------------------------------
377 //
379  output.clear();
380  DcuDetIdsV::const_iterator ii = input.begin();
381  DcuDetIdsV::const_iterator jj = input.end();
382  for ( ; ii != jj; ++ii ) { if ( ii->second ) { output[ii->first] = new TkDcuInfo( *(ii->second) ); } }
383 }
384 
385 // -----------------------------------------------------------------------------
386 //
388  output.clear();
389  DcuDetIdsV::const_iterator ii = input.begin();
390  DcuDetIdsV::const_iterator jj = input.end();
391  for ( ; ii != jj; ++ii ) { if ( ii->second ) { output.push_back( std::make_pair( ii->first, new TkDcuInfo( *(ii->second) ) ) ); } }
392 }
393 
394 // -----------------------------------------------------------------------------
395 //
396 SiStripConfigDb::DcuDetIdsV::const_iterator SiStripConfigDb::findDcuDetId( DcuDetIdsV::const_iterator begin,
397  DcuDetIdsV::const_iterator end,
398  uint32_t dcu_id ) {
399  DcuDetIdsV::const_iterator iter = begin;
400  DcuDetIdsV::const_iterator jter = end;
401  for ( ; iter != jter; ++iter ) {
402  if ( iter->second && iter->second->getDcuHardId() == dcu_id ) { return iter; }
403  }
404  return end;
405 }
406 
407 // -----------------------------------------------------------------------------
408 //
409 SiStripConfigDb::DcuDetIdsV::iterator SiStripConfigDb::findDcuDetId( DcuDetIdsV::iterator begin,
410  DcuDetIdsV::iterator end,
411  uint32_t dcu_id ) {
412  DcuDetIdsV::iterator iter = begin;
413  DcuDetIdsV::iterator jter = end;
414  for ( ; iter != jter; ++iter ) {
415  if ( iter->second && iter->second->getDcuHardId() == dcu_id ) { return iter; }
416  }
417  return end;
418 }
void clone(const DcuDetIdMap &in, DcuDetIdsV &out) const
Definition: DcuDetIds.cc:369
static std::string defaultPartitionName_
DcuDetIds::range DcuDetIdsRange
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:97
void uploadDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:184
static const char mlConfigDb_[]
static DcuDetIdsV::const_iterator findDcuDetId(DcuDetIdsV::const_iterator begin, DcuDetIdsV::const_iterator end, uint32_t dcu_id)
Definition: DcuDetIds.cc:396
int np
Definition: AMPTWrapper.h:33
void printDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:339
#define end
Definition: vmac.h:38
#define LogTrace(id)
std::vector< DcuDetId > DcuDetIdsV
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
Sgi::hash_map< unsigned long, TkDcuInfo * > DcuDetIdMap
void addDcuDetIds(std::string partition, DcuDetIdsV &)
Definition: DcuDetIds.cc:109
#define begin
Definition: vmac.h:31
void clearDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:273
DcuDetIdsRange getDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:11