CMS 3D CMS Logo

FedConnections.cc
Go to the documentation of this file.
1 
4 #include <ostream>
5 
6 using namespace std;
7 using namespace sistrip;
8 
9 // -----------------------------------------------------------------------------
10 //
12  // Check
13  if ((!dbParams_.usingDbCache() && !deviceFactory(__func__)) ||
14  (dbParams_.usingDbCache() && !databaseCache(__func__))) {
15  return connections_.emptyRange();
16  }
17 
18  try {
19  if (!dbParams_.usingDbCache()) {
20  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
21  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
22  for (; iter != jter; ++iter) {
23  if (partition.empty() || partition == iter->second.partitionName()) {
24  if (iter->second.partitionName() == SiStripPartition::defaultPartitionName_) {
25  continue;
26  }
27 
28  FedConnectionsRange range = connections_.find(iter->second.partitionName());
29  if (range == connections_.emptyRange()) {
30  FedConnectionsV tmp2;
31 
32  // Retrieve connections
33  FedConnectionsV tmp1;
34  deviceFactory(__func__)->getConnectionDescriptions(iter->second.partitionName(),
35  tmp1,
36  iter->second.cabVersion().first,
37  iter->second.cabVersion().second,
38  //#ifdef USING_DATABASE_MASKING
39  iter->second.maskVersion().first,
40  iter->second.maskVersion().second,
41  //#endif
42  false); //@@ do not get DISABLED connections
43 
44  // Make local copy
45  ConnectionFactory::vectorCopyI(tmp2, tmp1, true);
46 
47  // Add to cache
48  connections_.loadNext(iter->second.partitionName(), tmp2);
49 
50  // Some debug
51  FedConnectionsRange conns = connections_.find(iter->second.partitionName());
52  std::stringstream ss;
53  ss << "[SiStripConfigDb::" << __func__ << "]"
54  << " Downloaded " << conns.size() << " FED connections to local cache for partition \""
55  << iter->second.partitionName() << "\"" << std::endl;
56  ss << "[SiStripConfigDb::" << __func__ << "]"
57  << " Cache holds FED connections for " << connections_.size() << " partitions.";
58  LogTrace(mlConfigDb_) << ss.str();
59  }
60  }
61  }
62 
63  } else { // Use database cache
64 
65  FedConnectionsV* tmp1 = databaseCache(__func__)->getConnections();
66 
67  if (tmp1) {
68  // Make local copy
69  FedConnectionsV tmp2;
70  ConnectionFactory::vectorCopyI(tmp2, *tmp1, true);
71 
72  // Add to cache
73  connections_.loadNext(SiStripPartition::defaultPartitionName_, tmp2);
74 
75  } else {
76  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
77  << " NULL pointer to FedConnections vector!";
78  }
79  }
80 
81  } catch (...) {
82  handleException(__func__);
83  }
84 
85  // Create range object
86  uint16_t np = 0;
87  uint16_t nc = 0;
88  FedConnectionsRange conns;
89  if (!partition.empty()) {
90  conns = connections_.find(partition);
91  np = 1;
92  nc = conns.size();
93  } else {
94  if (!connections_.empty()) {
95  conns = FedConnectionsRange(connections_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
96  connections_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
97  } else {
98  conns = connections_.emptyRange();
99  }
100  np = connections_.size();
101  nc = conns.size();
102  }
103 
104  stringstream ss;
105  ss << "[SiStripConfigDb::" << __func__ << "]"
106  << " Found " << nc << " FED connections";
107  if (!dbParams_.usingDb()) {
108  ss << " in " << dbParams_.inputModuleXmlFiles().size() << " 'module.xml' file(s)";
109  } else {
110  if (!dbParams_.usingDbCache()) {
111  ss << " in " << np << " database partition(s)";
112  } else {
113  ss << " from shared memory name '" << dbParams_.sharedMemory() << "'";
114  }
115  }
116  if (connections_.empty()) {
117  edm::LogWarning(mlConfigDb_) << ss.str();
118  } else {
119  LogTrace(mlConfigDb_) << ss.str();
120  }
121 
122  return conns;
123 }
124 
125 // -----------------------------------------------------------------------------
126 //
128  if (!deviceFactory(__func__)) {
129  return;
130  }
131 
132  if (partition.empty()) {
133  stringstream ss;
134  ss << "[SiStripConfigDb::" << __func__ << "]"
135  << " Partition string is empty,"
136  << " therefore cannot add FED connections to local cache!";
137  edm::LogWarning(mlConfigDb_) << ss.str();
138  return;
139  }
140 
141  if (conns.empty()) {
142  stringstream ss;
143  ss << "[SiStripConfigDb::" << __func__ << "]"
144  << " Vector of FED connections is empty,"
145  << " therefore cannot add FED connections to local cache!";
146  edm::LogWarning(mlConfigDb_) << ss.str();
147  return;
148  }
149 
150  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
151  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
152  for (; iter != jter; ++iter) {
153  if (partition == iter->second.partitionName()) {
154  break;
155  }
156  }
157  if (iter == dbParams_.partitions().end()) {
158  stringstream ss;
159  ss << "[SiStripConfigDb::" << __func__ << "]"
160  << " Partition \"" << partition << "\" not found in partition list, "
161  << " therefore cannot add FED connections!";
162  edm::LogWarning(mlConfigDb_) << ss.str();
163  return;
164  }
165 
166  FedConnectionsRange range = connections_.find(partition);
167  if (range == connections_.emptyRange()) {
168  // Make local copy
170  ConnectionFactory::vectorCopyI(tmp, conns, true);
171 
172  // Add to local cache
173  connections_.loadNext(partition, tmp);
174 
175  // Some debug
176  std::stringstream ss;
177  ss << "[SiStripConfigDb::" << __func__ << "]"
178  << " Added " << conns.size() << " FED connections to local cache for partition \"" << partition << "\""
179  << std::endl;
180  ss << "[SiStripConfigDb::" << __func__ << "]"
181  << " Cache holds FED connections for " << connections_.size() << " partitions.";
182  LogTrace(mlConfigDb_) << ss.str();
183 
184  } else {
185  stringstream ss;
186  ss << "[SiStripConfigDb::" << __func__ << "]"
187  << " Partition \"" << partition << "\" already found in local cache, "
188  << " therefore cannot add new FED connections!";
189  edm::LogWarning(mlConfigDb_) << ss.str();
190  return;
191  }
192 }
193 
194 // -----------------------------------------------------------------------------
195 //
197  if (dbParams_.usingDbCache()) {
198  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
199  << " Using database cache! No uploads allowed!";
200  return;
201  }
202 
203  if (!deviceFactory(__func__)) {
204  return;
205  }
206 
207  if (connections_.empty()) {
208  stringstream ss;
209  ss << "[SiStripConfigDb::" << __func__ << "]"
210  << " Found no cached FED connections, therefore no upload!";
211  edm::LogWarning(mlConfigDb_) << ss.str();
212  return;
213  }
214 
215  if (dbParams_.usingDb()) {
216  try {
217  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
218  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
219  for (; iter != jter; ++iter) {
220  if (partition.empty() || partition == iter->second.partitionName()) {
221  FedConnectionsRange range = connections_.find(iter->second.partitionName());
222  if (range != connections_.emptyRange()) {
223  FedConnectionsV conns(range.begin(), range.end());
224 
225  SiStripPartition::Versions cabVersion = iter->second.cabVersion();
226  deviceFactory(__func__)->setConnectionDescriptions(conns,
227  iter->second.partitionName(),
228  &(cabVersion.first),
229  &(cabVersion.second),
230  true); // new major version
231 
232  // Some debug
233  std::stringstream ss;
234  ss << "[SiStripConfigDb::" << __func__ << "]"
235  << " Uploaded " << conns.size() << " FED connections to database for partition \""
236  << iter->second.partitionName() << "\".";
237  LogTrace(mlConfigDb_) << ss.str();
238 
239  } else {
240  stringstream ss;
241  ss << "[SiStripConfigDb::" << __func__ << "]"
242  << " Vector of FED connections is empty for partition \"" << iter->second.partitionName()
243  << "\", therefore aborting upload for this partition!";
244  edm::LogWarning(mlConfigDb_) << ss.str();
245  continue;
246  }
247 
248  } else {
249  // stringstream ss;
250  // ss << "[SiStripConfigDb::" << __func__ << "]"
251  // << " Cannot find partition \"" << partition
252  // << "\" in cached partitions list: \""
253  // << dbParams_.partitionNames( dbParams_.partitionNames() )
254  // << "\", therefore aborting upload for this partition!";
255  // edm::LogWarning(mlConfigDb_) << ss.str();
256  }
257  }
258 
259  } catch (...) {
260  handleException(__func__);
261  }
262  }
263 
264  allowCalibUpload_ = true;
265 }
266 
267 // -----------------------------------------------------------------------------
268 //
270  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
271 
272  if (connections_.empty()) {
273  stringstream ss;
274  ss << "[SiStripConfigDb::" << __func__ << "]"
275  << " Found no cached FED connections!";
276  //edm::LogWarning(mlConfigDb_) << ss.str();
277  return;
278  }
279 
280  // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
281  FedConnections temporary_cache;
282  if (partition.empty()) {
283  temporary_cache = FedConnections();
284  } else {
285  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
286  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
287  for (; iter != jter; ++iter) {
288  if (partition != iter->second.partitionName()) {
289  FedConnectionsRange range = connections_.find(iter->second.partitionName());
290  if (range != connections_.emptyRange()) {
291  temporary_cache.loadNext(partition, FedConnectionsV(range.begin(), range.end()));
292  } else {
293  // stringstream ss;
294  // ss << "[SiStripConfigDb::" << __func__ << "]"
295  // << " Cannot find partition \"" << iter->second.partitionName()
296  // << "\" in local cache!";
297  // edm::LogWarning(mlConfigDb_) << ss.str();
298  }
299  }
300  }
301  }
302 
303  // Delete objects in local cache for specified partition (or all if not specified)
304  FedConnectionsRange conns;
305  if (partition.empty()) {
306  if (!connections_.empty()) {
307  conns = FedConnectionsRange(connections_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
308  connections_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
309  } else {
310  conns = connections_.emptyRange();
311  }
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) {
316  if (partition == iter->second.partitionName()) {
317  break;
318  }
319  }
320  conns = connections_.find(iter->second.partitionName());
321  }
322 
323  if (conns != connections_.emptyRange()) {
324  FedConnectionsV::const_iterator ifed = conns.begin();
325  FedConnectionsV::const_iterator jfed = conns.end();
326  for (; ifed != jfed; ++ifed) {
327  if (*ifed) {
328  delete *ifed;
329  }
330  }
331  } else {
332  stringstream ss;
333  ss << "[SiStripConfigDb::" << __func__ << "]";
334  if (partition.empty()) {
335  ss << " Found no FED connections in local cache!";
336  } else {
337  ss << " Found no FED connections in local cache for partition \"" << partition << "\"!";
338  }
339  edm::LogWarning(mlConfigDb_) << ss.str();
340  }
341 
342  // Overwrite local cache with temporary cache
343  connections_ = temporary_cache;
344 }
345 
346 // -----------------------------------------------------------------------------
347 //
349  std::stringstream ss;
350  ss << "[SiStripConfigDb::" << __func__ << "]"
351  << " Contents of FedConnections container:" << std::endl;
352  ss << " Number of partitions: " << connections_.size() << std::endl;
353 
354  // Loop through partitions
355  uint16_t cntr = 0;
356  FedConnections::const_iterator iconn = connections_.begin();
357  FedConnections::const_iterator jconn = connections_.end();
358  for (; iconn != jconn; ++iconn) {
359  cntr++;
360  if (partition.empty() || partition == iconn->first) {
361  ss << " Partition number : " << cntr << " (out of " << connections_.size() << ")" << std::endl;
362  ss << " Partition name : \"" << iconn->first << "\"" << std::endl;
363  ss << " Num of connections : " << iconn->second.size() << std::endl;
364 
365  // Extract FED ids and channels
366  std::map<uint16_t, vector<uint16_t> > feds;
367  FedConnectionsV::const_iterator iter = iconn->second.begin();
368  FedConnectionsV::const_iterator jter = iconn->second.end();
369  for (; iter != jter; ++iter) {
370  if (*iter) {
371  uint16_t fed_id = (*iter)->getFedId();
372  uint16_t fed_ch = (*iter)->getFedChannel();
373  if (find(feds[fed_id].begin(), feds[fed_id].end(), fed_ch) == feds[fed_id].end()) {
374  feds[fed_id].push_back(fed_ch);
375  }
376  }
377  }
378 
379  // Sort contents
380  std::map<uint16_t, std::vector<uint16_t> > tmp;
381  std::map<uint16_t, std::vector<uint16_t> >::const_iterator ii = feds.begin();
382  std::map<uint16_t, std::vector<uint16_t> >::const_iterator jj = feds.end();
383  for (; ii != jj; ++ii) {
384  std::vector<uint16_t> temp = ii->second;
385  std::sort(temp.begin(), temp.end());
386  std::vector<uint16_t>::const_iterator iii = temp.begin();
387  std::vector<uint16_t>::const_iterator jjj = temp.end();
388  for (; iii != jjj; ++iii) {
389  tmp[ii->first].push_back(*iii);
390  }
391  }
392  feds.clear();
393  feds = tmp;
394 
395  // Print FED ids and channels
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() << " channels for FED id " << std::setw(3)
400  << 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 ichan = ifed->second.begin();
405  std::vector<uint16_t>::const_iterator jchan = ifed->second.end();
406  for (; ichan != jchan; ++ichan) {
407  if (ichan != ifed->second.begin()) {
408  if (*ichan != last + 1) {
409  ss << std::setw(2) << first << "->" << std::setw(2) << last << ", ";
410  if (ichan != ifed->second.end()) {
411  first = *(ichan + 1);
412  }
413  }
414  }
415  last = *ichan;
416  }
417  if (first != last) {
418  ss << std::setw(2) << first << "->" << std::setw(2) << last;
419  }
420  ss << std::endl;
421  }
422  }
423  }
424  }
425 
426  LogTrace(mlConfigDb_) << ss.str();
427 }
static const std::string defaultPartitionName_
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:87
void uploadFedConnections(std::string partition="")
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
sistrip classes
#define LogTrace(id)
FedConnections::range FedConnectionsRange
static const char mlConfigDb_[]
int np
Definition: AMPTWrapper.h:43
FedConnectionsRange getFedConnections(std::string partition="")
void clearFedConnections(std::string partition="")
ii
Definition: cuy.py:589
std::pair< uint32_t, uint32_t > Versions
void printFedConnections(std::string partition="")
std::vector< FedConnection * > FedConnectionsV
void addFedConnections(std::string partition, FedConnectionsV &)
Log< level::Warning, false > LogWarning
tmp
align.sh
Definition: createJobs.py:716