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