CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripPsuDetIdMap.cc
Go to the documentation of this file.
7 
11 #include <cstdlib>
12 #include <iostream>
13 #include <iomanip>
14 #include <sstream>
15 #include <string>
16 
17 using namespace sistrip;
18 
19 // only one constructor
20 SiStripPsuDetIdMap::SiStripPsuDetIdMap() { LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] Constructing ..."; }
21 // destructor
22 SiStripPsuDetIdMap::~SiStripPsuDetIdMap() {LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] Destructing ..."; }
23 
24 // Build PSU-DETID map
25 void SiStripPsuDetIdMap::BuildMap( const std::string & mapFile, const bool debug )
26 {
27  BuildMap(mapFile, debug, LVMap, HVMap, HVUnmapped_Map, HVCrosstalking_Map);
28 }
29 
30 void SiStripPsuDetIdMap::BuildMap( const std::string & mapFile, std::vector<std::pair<uint32_t,std::string> > & rawmap) {
31  //This method is a remnant of the old method, that provided a vector type of map, based on the
32  //raw reading of a file, with no processing.
33  //FIXME:
34  //This is not currently used, but I think we could slim this down to just a vector with
35  //the detIDs since the PSUChannel part of the excludedlist (if it ever is in a file) is never used!
36  edm::FileInPath file(mapFile.c_str());
37  std::ifstream ifs( file.fullPath().c_str() );
38  string line;
39  while( getline( ifs, line ) ) {
40  if( line != "" ) {
41  // split the line and insert in the map
42  stringstream ss(line);
43  string PSUChannel;
44  uint32_t detId;
45  ss >> detId;
46  ss >> PSUChannel;
47  rawmap.push_back(std::make_pair(detId, PSUChannel) );
48  }
49  }
50 }
51 
52 //The following is the currently used method (called from SiStripDetVOffBuilder::buildPSUdetIdMap)
53 void SiStripPsuDetIdMap::BuildMap( const std::string & mapFile, const bool debug, PsuDetIdMap & LVmap, PsuDetIdMap & HVmap,PsuDetIdMap & HVUnmappedmap,PsuDetIdMap & HVCrosstalkingmap ) //Maybe it would be nicer to return the map instead of using a reference...
54 {
55  //This method reads the map from the mapfile indicated in the cfg
56  //It populates the 4 maps (private data members of the SiStripPSUDetIdMap in question) (all maps are std::map<std::string,uint32_t > ):
57  //LVMap
58  //HVMap
59  //HVUnmapped_Map
60  //HVCrosstalking_Map
61  //These maps are accessed, based on the LV/HV case, to extract the detIDs connected to a given PSUChannel...
62  //see the getDetIDs method...
63  edm::FileInPath file(mapFile.c_str());
64  std::ifstream ifs( file.fullPath().c_str() );
65  string line;
66  while( getline( ifs, line ) ) {
67  if( line != "" ) {
68  // split the line and insert in the map
69  stringstream ss(line);
70  string PSUChannel;
71  uint32_t detId;
72  ss >> detId;
73  ss >> PSUChannel;
74  //Old "vector of pairs" map!
75  //map.push_back( std::make_pair(detId, dpName) );//This "map" is normally the pgMap of the map of which we are executing BuildMap()...
76  //Using a map to make the look-up easy and avoid lots of lookup loops.
77  std::string PSU=PSUChannel.substr(0,PSUChannel.size()-10);
78  std::string Channel=PSUChannel.substr(PSUChannel.size()-10);
79  LVmap[PSU].push_back(detId); // LVmap uses simply the PSU since there is no channel distinction necessary
80  if (Channel=="channel000") {
81  HVUnmappedmap[PSU].push_back(detId); //Populate HV Unmapped map, by PSU listing all detids unmapped in that PSU (not necessarily all will be unmapped)
82  }
83  else if (Channel=="channel999") {
84  HVCrosstalkingmap[PSU].push_back(detId); //Populate HV Crosstalking map, by PSU listing all detids crosstalking in that PSU (usually all will be unmapped)
85  }
86  else {
87  HVmap[PSUChannel].push_back(detId); //HV map for HV mapped channels, populated by PSU channel!
88  }
89  }
90  }
91 
92  //Remove duplicates for all 4 maps
93  for (PsuDetIdMap::iterator psu = LVMap.begin(); psu != LVMap.end(); psu++) {
94  RemoveDuplicateDetIDs(psu->second);
95  }
96  for (PsuDetIdMap::iterator psuchan = HVMap.begin(); psuchan != HVMap.end(); psuchan++) {
97  RemoveDuplicateDetIDs(psuchan->second);
98  }
99  for (PsuDetIdMap::iterator psu = HVUnmapped_Map.begin(); psu != HVUnmapped_Map.end(); psu++) {
100  RemoveDuplicateDetIDs(psu->second);
101  }
102  for (PsuDetIdMap::iterator psu = HVCrosstalking_Map.begin(); psu != HVCrosstalking_Map.end(); psu++) {
103  RemoveDuplicateDetIDs(psu->second);
104  }
105  if (debug) {
106  //Print out all the 4 maps:
107  std::cout<<"Dumping the LV map"<<std::endl;
108  std::cout<<"PSU->detids"<<std::endl;
109  for (PsuDetIdMap::iterator psu = LVMap.begin(); psu != LVMap.end(); psu++) {
110  std::cout<<psu->first<<" corresponds to following detids"<<endl;
111  for (unsigned int i=0; i<psu->second.size(); i++) {
112  std::cout<<"\t\t"<<psu->second[i]<<std::endl;
113  }
114  }
115  std::cout<<"Dumping the HV map for HV mapped channels"<<std::endl;
116  std::cout<<"PSUChannel->detids"<<std::endl;
117  for (PsuDetIdMap::iterator psuchan = HVMap.begin(); psuchan != HVMap.end(); psuchan++) {
118  std::cout<<psuchan->first<<" corresponds to following detids"<<endl;
119  for (unsigned int i=0; i<psuchan->second.size(); i++) {
120  std::cout<<"\t\t"<<psuchan->second[i]<<std::endl;
121  }
122  }
123  std::cout<<"Dumping the HV map for HV UNmapped channels"<<std::endl;
124  std::cout<<"PSU->detids"<<std::endl;
125  for (PsuDetIdMap::iterator psu = HVUnmapped_Map.begin(); psu != HVUnmapped_Map.end(); psu++) {
126  std::cout<<psu->first<<" corresponds to following detids"<<endl;
127  for (unsigned int i=0; i<psu->second.size(); i++) {
128  std::cout<<"\t\t"<<psu->second[i]<<std::endl;
129  }
130  }
131  std::cout<<"Dumping the HV map for HV Crosstalking channels"<<std::endl;
132  std::cout<<"PSU->detids"<<std::endl;
133  for (PsuDetIdMap::iterator psu = HVCrosstalking_Map.begin(); psu != HVCrosstalking_Map.end(); psu++) {
134  std::cout<<psu->first<<" corresponds to following detids"<<endl;
135  for (unsigned int i=0; i<psu->second.size(); i++) {
136  std::cout<<"\t\t"<<psu->second[i]<<std::endl;
137  }
138  }
139  //Could add here consistency checks against the list of detIDs for Strip or Pixels
140  //Number of total detIDs LVMapped, HV Mapped, HVunmapped, HV crosstalking...
141  }
142 }
143 
144 void SiStripPsuDetIdMap::RemoveDuplicateDetIDs(std::vector<uint32_t> & detids) {
145  //Function to remove duplicates from a vector of detids
146  if (!detids.empty()) { //Leave empty vector alone ;)
147  std::sort(detids.begin(),detids.end());
148  std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
149  detids.resize( it - detids.begin() );
150  }
151 }
152 
153 std::vector<uint32_t> SiStripPsuDetIdMap::getLvDetID(std::string PSU) {
154  //Function that returns a vector with all detids associated with a PSU
155  //(no channel information is saved in the map since it is not relevant for LV!)
156  if (LVMap.find(PSU)!=LVMap.end()) {
157  return LVMap[PSU];
158  }
159  else {
160  std::vector<uint32_t> detids;
161  return detids;
162  }
163 }
164 
165 void SiStripPsuDetIdMap::getHvDetID(std::string PSUChannel, std::vector<uint32_t> & ids, std::vector<uint32_t> & unmapped_ids, std::vector<uint32_t> & crosstalking_ids ) {
166  //Function that (via reference parameters) populates ids, unmapped_ids, crosstalking_ids vectors of detids associated with a given PSU *HV* channel.
167  if (HVMap.find(PSUChannel)!=HVMap.end()) {
168  ids=HVMap[PSUChannel];
169  }
170  //Extract the PSU to check the unmapped and crosstalking maps too corresponding to this channel
171  std::string PSU = PSUChannel.substr(0,PSUChannel.size()-10);
172  if (HVUnmapped_Map.find(PSU)!=HVUnmapped_Map.end()) {
173  unmapped_ids=HVUnmapped_Map[PSU];
174  }
175  if (HVCrosstalking_Map.find(PSU)!=HVCrosstalking_Map.end()) {
176  crosstalking_ids=HVCrosstalking_Map[PSU];
177  }
178 }
179 
180 // This method needs to be updated once HV channel mapping is known
181 // Currently, channel number is ignored for mapping purposes
182 // check both PG and CG as the channels should be unique
183 
184 void SiStripPsuDetIdMap::getDetID(std::string PSUChannel,const bool debug,std::vector<uint32_t> & detids,std::vector<uint32_t> & unmapped_detids,std::vector<uint32_t> & crosstalking_detids ) {
185  //This function takes as argument the PSUChannel (i.e. the dpname as it comes from the PVSS query, e.g. cms_trk_dcs_02:CAEN/CMS_TRACKER_SY1527_2/branchController05/easyCrate0/easyBoard12/channel001)
186  //And it returns 3 vectors:
187  //1-detids->all the detids positively matching the PSUChannel in question
188  //2-unmapped_detids->the detids that are matching the PSU in question but that are not HV mapped
189  //3-crosstalking_detids->the detids that are matching the PSU in question but exhibit the HV channel cross-talking behavior (they are ON as long as ANY of the 2 HV channels of the supply is ON, so they only go OFF when both channels are OFF)
190  //The second and third vectors are only relevant for the HV case, when unmapped and cross-talking channels need further processing before being turned ON and OFF.
191 
192  std::string PSUChannelFromQuery = PSUChannel;
193 
194  //Get the channel to see if it is LV or HV, they will be treated differently
195  std::string ChannelFromQuery=PSUChannelFromQuery.substr(PSUChannelFromQuery.size()-10);
196  //Get the PSU from Query, to be used for LVMap and for the HVUnmapped and HVCrosstalking maps:
197  std::string PSUFromQuery=PSUChannelFromQuery.substr(0,PSUChannelFromQuery.size()-10);
198  if (debug) {
199  //FIXME:
200  //Should handle all the couts with MessageLogger!
201  std::cout << "DPNAME from QUERY: "<<PSUChannelFromQuery<<", Channel: "<<ChannelFromQuery<<"PSU: "<<PSUFromQuery<<std::endl;
202  }
203 
204  //First prepare the strings needed to do the matching of the PSUChannel from the query to the ones in the map
205 
206  //Handle the LV case first:
207  if (ChannelFromQuery=="channel000" or ChannelFromQuery=="channel001") {
208  //For LV channels we need to look for any detID that is reported either as channel000 (not HV mapped)
209  //but also as channel002 and channel003 (if they are HV mapped), or as channel999 (if they are in a crosstalking PSU)
210  //Get the PSU to do a PSU-only matching to get all detIDs connected to the LV channel:
211  //Now loop over the map!
212  //for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
213  // std::string PSUFromMap = iter->second.substr(0,iter->second.size()-10);
214  // //Careful if you uncomment this cout: it prints 15148 lines when checking for 1 psu name match! (meant for debugging of course)
215  // //std::cout<<"Truncated DPNAME from MAP: "<<PSUFromMap<<std::endl;
216  // if (PSUFromQuery == PSUFromMap) {
217  // detids.push_back(iter->first); //And fill the detids vector with the all detids matching the PSU from the query!
218  // }
219  //}
220  //No need to loop over if we use an actual map!
221 
222  if (LVMap.find(PSUFromQuery)!=LVMap.end()) {
223  detids=LVMap[PSUFromQuery];
224  }
225  }
226  //Handle the HV case too:
227  else if (ChannelFromQuery=="channel002" or ChannelFromQuery=="channel003") {
228  //For the HV channel we need to look at the actual positive matching detIDs,
229  //but also to the unmapped one (channel000) and the crosstalking ones (channel999).
230  //Assemble the corresponding channel000 (unmapped channels) replacing the last character in PSUChannelFromQuery:
231  // std::string ZeroedPSUChannelFromQuery= PSUChannelFromQuery;
232  // ZeroedPSUChannelFromQuery.replace(ZeroedPSUChannelFromQuery.size()-1,1,"0");
233  // //Same for channel999 for the crosstalking channels:
234  // //std::string NineNineNine='999';
235  // std::string NinedPSUChannelFromQuery= PSUChannelFromQuery;
236  // NinedPSUChannelFromQuery.replace(NinedPSUChannelFromQuery.size()-3,3,"999");
237  // //std::string NinedPSUChannelFromQuery= PSUChannelFromQuery.substr(0,PSUChannelFromQuery.size()-3);// + '999';
238  // //Now loop over the map!
239  // for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
240  // std::string PSUChannelFromMap = iter->second;
241  // //Careful if you uncomment this cout: it prints 15148 lines when checking for 1 psu name match! (meant for debugging of course)
242  // //std::cout<<"Truncated DPNAME from MAP: "<<PSUFromMap<<std::endl;
243  // if (PSUChannelFromMap==PSUChannelFromQuery) {
244  // detids.push_back(iter->first); //Fill the detids vector with the all detids matching the PSUChannel from the query!
245  // }
246  // if (PSUChannelFromMap==ZeroedPSUChannelFromQuery) {
247  // unmapped_detids.push_back(iter->first); //Fill the unmapped_detids vector with the all detids matching the channel000 for the PSU from the query!
248  // if (debug) { //BEWARE: this debug printouts can become very heavy! 1 print out per detID matched!
249  // std::cout<<"Matched one of the HV-UNMAPPED channels: "<<ZeroedPSUChannelFromQuery<<std::endl;
250  // std::cout<<"Corresponding to detID: "<<iter->first<<std::endl;
251  // //for (unsigned int i_nohvmap_detid=0;i_nohvmap_detid < iter->first.size();i_nohvmap_detid++) {
252  // // cout<< iter->first[i_nohvmap_detid] << std::endl;
253  // }
254  // }
255  // if (PSUChannelFromMap==NinedPSUChannelFromQuery) {
256  // crosstalking_detids.push_back(iter->first); //Fill the crosstalking_detids vector with the all detids matching the channel999 for the PSU from the query!
257  // }
258  // }
259  if (HVMap.find(PSUChannelFromQuery)!=HVMap.end()) {
260  detids=HVMap[PSUChannelFromQuery];
261  }
262  else if (HVUnmapped_Map.find(PSUFromQuery)!=HVUnmapped_Map.end()) {
263  unmapped_detids=HVUnmapped_Map[PSUFromQuery];
264  }
265  else if (HVCrosstalking_Map.find(PSUFromQuery)!=HVCrosstalking_Map.end()) {
266  crosstalking_detids=HVCrosstalking_Map[PSUFromQuery];
267  }
268  }
269  //
270  //
271  // //With the new code above that makes use of the channel00X information in the map
272  // //we should no more need to remove duplicates by construction.
273  // //The following code was used when there was no channel information in the map,
274  // //to elegantly eliminate duplicates.
275  // //We can now use it as a cross-check (still removing duplicates in case they happen, but writing a message out)
276  //
277  // // remove duplicates
278  //
279  // //First sort detIDs vector, so that duplicates will be consecutive
280  // if (!detids.empty()) {
281  // std::sort(detids.begin(),detids.end());
282  // //Then use the forward iterator unique from STD that basically removes all consecutive duplicates from the vector
283  // //and reports a forward iterator pointing to the new end of the sequence
284  // std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
285  // if (it!=detids.end()) {
286  // std::cout<<"ARGH! It seems we found duplicate detIDs in the map corresponding to this PSUChannel: "<<PSUChannelFromQuery<<std::endl;
287  // detids.resize( it - detids.begin() );
288  // }
289  // if (debug) {
290  // std::cout<<"Matched the following detIDs to PSU channel from query "<<PSUChannelFromQuery <<":"<<std::endl;
291  // for (std::vector<uint32_t>::iterator i_detid=detids.begin();i_detid!=detids.end(); i_detid++) {
292  // std::cout<<*i_detid<<std::endl;;
293  // }
294  // }
295  // }
296  // //Same for unmapped detIDs:
297  // if (!unmapped_detids.empty()) {
298  // std::sort(unmapped_detids.begin(),unmapped_detids.end());
299  // //Then use the forward iterator unique from STD that basically removes all consecutive duplicates from the vector
300  // //and reports a forward iterator pointing to the new end of the sequence
301  // std::vector<uint32_t>::iterator it = std::unique(unmapped_detids.begin(),unmapped_detids.end());
302  // if (it!=unmapped_detids.end()) {
303  // std::cout<<"ARGH! It seems we found duplicate unmapped_detids in the map corresponding to this PSUChannel: "<<PSUChannelFromQuery<<std::endl;
304  // unmapped_detids.resize( it - unmapped_detids.begin() );
305  // }
306  // if (debug) {
307  // std::cout<<"Matched the following unmapped_detids to PSU channel from query "<<PSUChannelFromQuery <<":"<<std::endl;
308  // for (std::vector<uint32_t>::iterator i_detid=unmapped_detids.begin();i_detid!=unmapped_detids.end(); i_detid++) {
309  // std::cout<<*i_detid<<std::endl;;
310  // }
311  // }
312  // }
313  // //Finally, same for crosstalking detIDs:
314  // if (!crosstalking_detids.empty()) {
315  // std::sort(crosstalking_detids.begin(),crosstalking_detids.end());
316  // //Then use the forward iterator unique from STD that basically removes all consecutive duplicates from the vector
317  // //and reports a forward iterator pointing to the new end of the sequence
318  // std::vector<uint32_t>::iterator it = std::unique(crosstalking_detids.begin(),crosstalking_detids.end());
319  // if (it!=crosstalking_detids.end()) {
320  // std::cout<<"ARGH! It seems we found duplicate crosstalking_detids in the map corresponding to this PSUChannel: "<<PSUChannelFromQuery<<std::endl;
321  // crosstalking_detids.resize( it - crosstalking_detids.begin() );
322  // }
323  // if (debug) {
324  // std::cout<<"Matched the following crosstalking_detids to PSU channel from query "<<PSUChannelFromQuery <<":"<<std::endl;
325  // for (std::vector<uint32_t>::iterator i_detid=crosstalking_detids.begin();i_detid!=crosstalking_detids.end(); i_detid++) {
326  // std::cout<<*i_detid<<std::endl;;
327  // }
328  // }
329  // }
330  //
331  // //Using reference parameters since we are returning multiple objects.
332  // //return detids;
333 
334 }
335 
336 // returns PSU channel name for a given DETID
338  std::vector< std::pair<uint32_t, std::string> >::iterator iter;
339  for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
340  if (iter->first && iter->first == detid) {return iter->second;}
341  }
342  // if we reach here, then we didn't find the detid in the map
343  return "UNKNOWN";
344 }
345 
347  std::vector< std::pair<uint32_t, std::string> >::iterator iter;
348  if (group == "PG") {
349  for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
350  if (iter->first && iter->first == detid) {return iter->second;}
351  }
352  }
353  if (group == "CG") {
354  for (iter = cgMap.begin(); iter != cgMap.end(); iter++) {
355  if (iter->first && iter->first == detid) {return iter->second;}
356  }
357  }
358  // if we reach here, then we didn't find the detid in the map
359  return "UNKNOWN";
360 }
361 
362 // returns the PVSS name for a given DETID
364  for (unsigned int i = 0; i < pgMap.size(); i++) {
365  if (pgMap[i].first == detid) {return detectorLocations[i];}
366  }
367  return "UNKNOWN";
368 }
369 
370 // returns the PVSS name for a given DETID, depending on specified map
372  if (group == "PG") {
373  for (unsigned int i = 0; i < pgMap.size(); i++) {
374  if (pgMap[i].first == detid) {return detectorLocations[i];}
375  }
376  }
377  if (group == "CG") {
378  for (unsigned int i = 0; i < cgMap.size(); i++) {
379  if (cgMap[i].first == detid) {return controlLocations[i];}
380  }
381  }
382  return "UNKNOWN";
383 }
384 
385 // returns the PVSS name for a given PSU channel
387  for (unsigned int i = 0; i < pgMap.size(); i++) {
388  if (pgMap[i].second == PSUChannel) {return detectorLocations[i];}
389  }
390  for (unsigned int i = 0; i < cgMap.size(); i++) {
391  if (cgMap[i].second == PSUChannel) {return controlLocations[i];}
392  }
393  return "UNKNOWN";
394 }
395 
396 // returns the DCU ID for a given PSU channel
398  for (unsigned int i = 0; i < pgMap.size(); i++) {
399  if (pgMap[i].second == PSUChannel) {return dcuIds[i];}
400  }
401  for (unsigned int i = 0; i < cgMap.size(); i++) {
402  if (cgMap[i].second == PSUChannel) {return cgDcuIds[i];}
403  }
404  return 0;
405 }
406 
408  for (unsigned int i = 0; i < pgMap.size(); i++) {
409  if (pgMap[i].first == detid) {return dcuIds[i];}
410  }
411  return 0;
412 }
413 
414 // determine if a given PSU channel is HV or not
416  // isHV = 0 means LV, = 1 means HV, = -1 means error
417  int isHV = 0;
418  std::string::size_type loc = PSUChannel.find( "channel", 0 );
419  if (loc != std::string::npos) {
420  std::string chNumber = PSUChannel.substr(loc+7,3);
421  if (chNumber == "002" || chNumber == "003") {
422  isHV = 1;
423  } else if (chNumber == "000" || chNumber == "001") {
424  isHV = 0;
425  } else {
426  edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] channel number of unexpected format, setting error flag!";
427  isHV = -1;
428  }
429  } else {
430  edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] channel number not located in PSU channel name, setting error flag!";
431  isHV = -1;
432  }
433  return isHV;
434 }
435 
437  output.clear();
438  for (unsigned int i = 0; i < input.size(); i++) {
439  output.push_back(new TkDcuPsuMap(*(input[i])));
440  }
441 }
442 
444  stringstream pg;
445  pg << "Map of power supplies to DET IDs: " << std::endl
446  << "-- PSU name -- -- Det Id --" << std::endl;
447  for (unsigned int p = 0; p < pgMap.size(); p++) {
448  pg << pgMap[p].first << " " << pgMap[p].second << std::endl;
449  }
450  edm::LogInfo("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << pg.str();
451 }
452 
454  stringstream cg;
455  cg << "Map of control power supplies to DET IDs: " << std::endl
456  << "-- PSU name -- -- Det Id --" << std::endl;
457  for (unsigned int p = 0; p < cgMap.size(); p++) {
458  cg << cgMap[p].first << " " << cgMap[p].second << std::endl;
459  }
460  edm::LogInfo("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << cg.str();
461 }
462 
463 std::vector< std::pair<uint32_t, std::string> > SiStripPsuDetIdMap::getDcuPsuMap() {
464  if (pgMap.size() != 0) { return pgMap; }
465  std::vector< std::pair<uint32_t, std::string> > emptyVec;
466  return emptyVec;
467 }
468 
470  std::cout << "Number of entries in DCU-PSU map: " << dcuPsus_.size() << std::endl;
471  std::cout << "Number of entries in DCU-DETID map: " << dcuDetIds_.size() << std::endl;
472  std::cout << std::endl;
473 
474  std::vector<bool> ddUsed(dcuDetIds_.size(),false);
475  std::vector<bool> dpUsed(dcuPsus_.size(),false);
476 
477  for (unsigned int dp = 0; dp < dcuPsus_.size(); dp++) {
478  for (unsigned int dd = 0; dd < dcuDetIds_.size(); dd++) {
479  if (dcuPsus_[dp]->getDcuHardId() == dcuDetIds_[dd].second->getDcuHardId()) {
480  dpUsed[dp] = true;
481  ddUsed[dd] = true;
482  }
483  }
484  }
485  unsigned int numDpUsed = 0, numDpNotUsed = 0;
486  for (unsigned int dp = 0; dp < dpUsed.size(); dp++) {
487  if (dpUsed[dp]) { numDpUsed++; }
488  else { numDpNotUsed++; }
489  }
490 
491  std::cout << "Number of used DCU-PSU entries: " << numDpUsed << std::endl;
492  std::cout << "Number of unused DCU-PSU entries: " << numDpNotUsed << std::endl;
493 
494  unsigned int numDdUsed = 0, numDdNotUsed = 0;
495  for (unsigned int dd = 0; dd < ddUsed.size(); dd++) {
496  if (ddUsed[dd]) { numDdUsed++; }
497  else { numDdNotUsed++; }
498  }
499 
500  std::cout << "Number of used DCU-DETID entries: " << numDdUsed << std::endl;
501  std::cout << "Number of unused DCU-DETID entries: " << numDdNotUsed << std::endl;
502  std::cout << std::endl;
503  std::cout << "Size of PSU-DETID map: " << pgMap.size() << std::endl;
504  std::cout << "Size of detectorLocations: " << detectorLocations.size() << std::endl;
505 }
506 
507 //std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > SiStripPsuDetIdMap::retrieveDcuDeviceAddresses(std::string partition) {
508 std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > SiStripPsuDetIdMap::retrieveDcuDeviceAddresses(std::string partition) {
509  // get the DB parameters
510  SiStripDbParams dbParams_ = db_->dbParams();
511  SiStripDbParams::SiStripPartitions::const_iterator iter;
512 
513  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > resultVec;
514 
516  SiStripConfigDb::DeviceType device_ = DCU;
517 
518  for (iter = dbParams_.partitions().begin(); iter != dbParams_.partitions().end(); ++iter) {
519  if ( partition == "" || partition == iter->second.partitionName() ) {
520  if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
521  if (iter->second.dcuVersion().first > 0 && iter->second.fecVersion().first > 0) {
522  SiStripConfigDb::DeviceDescriptionsRange range = db_->getDeviceDescriptions(device_,iter->second.partitionName());
523  if (!range.empty()) {
524  SiStripConfigDb::DeviceDescriptionsV nextVec( range.begin(), range.end() );
525  for (unsigned int i = 0; i < nextVec.size(); i++) {
526  dcuDescription * desc = dynamic_cast<dcuDescription *>(nextVec[i]);
527  resultVec.push_back( std::make_pair( desc->getDcuHardId(), db_->deviceAddress(*(nextVec[i])) ) );
528  }
529  }
530  }
531  }
532  }
533 
534  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > testVec;
535  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >::iterator reorg_iter = resultVec.begin();
536 
537  for ( ; reorg_iter != resultVec.end(); reorg_iter++) {
538  std::vector<uint16_t> fecInfo(4,0);
539  fecInfo[0] = reorg_iter->second.fecCrate_;
540  fecInfo[1] = reorg_iter->second.fecSlot_;
541  fecInfo[2] = reorg_iter->second.fecRing_;
542  fecInfo[3] = reorg_iter->second.ccuAddr_;
543  std::vector<uint32_t> dcuids;
544  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >::iterator jter = reorg_iter;
545  for ( ; jter != resultVec.end(); jter++) {
546  if (reorg_iter->second.fecCrate_ == jter->second.fecCrate_ &&
547  reorg_iter->second.fecSlot_ == jter->second.fecSlot_ &&
548  reorg_iter->second.fecRing_ == jter->second.fecRing_ &&
549  reorg_iter->second.ccuAddr_ == jter->second.ccuAddr_) {
550  dcuids.push_back(jter->first);
551  }
552  }
553  // handle duplicates
554  bool isDup = false;
555  for (unsigned int i = 0; i < testVec.size(); i++) {
556  if (fecInfo == testVec[i].first) {
557  isDup = true;
558  dcuids.insert(dcuids.end(), (testVec[i].second).begin(), (testVec[i].second).end() );
559  std::sort(dcuids.begin(),dcuids.end());
560  std::vector<uint32_t>::iterator it = std::unique(dcuids.begin(),dcuids.end());
561  dcuids.resize( it - dcuids.begin() );
562  testVec[i].second = dcuids;
563  }
564  }
565  if (!isDup) {
566  std::sort(dcuids.begin(),dcuids.end());
567  std::vector<uint32_t>::iterator it = std::unique(dcuids.begin(),dcuids.end());
568  dcuids.resize( it - dcuids.begin() );
569  testVec.push_back(std::make_pair(fecInfo,dcuids));
570  }
571  }
572  // return resultVec;
573  return testVec;
574 }
575 
576 std::vector<uint32_t> SiStripPsuDetIdMap::findDcuIdFromDeviceAddress(uint32_t dcuid_) {
577  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > >::iterator iter = dcu_device_addr_vector.begin();
578  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > >::iterator res_iter = dcu_device_addr_vector.end();
579  std::vector<uint32_t> pgDcu;
580 
581  for ( ; iter != dcu_device_addr_vector.end(); iter++) {
582  std::vector<uint32_t> dcuids = iter->second;
583  std::vector<uint32_t>::iterator dcu_iter = std::find(dcuids.begin(),dcuids.end(),dcuid_);
584  bool alreadyFound = false;
585  if (res_iter != dcu_device_addr_vector.end()) {alreadyFound = true;}
586  if (dcu_iter != dcuids.end()) {
587  res_iter = iter;
588  if (!alreadyFound) {
589  for (unsigned int i = 0; i < dcuids.size(); i++) {
590  if (dcuids[i] != dcuid_) {pgDcu.push_back(dcuids[i]);}
591  }
592  } else {
593  std::cout << "Oh oh ... we have a duplicate :-(" << std::endl;
594  }
595  }
596  }
597  return pgDcu;
598 }
599 
600 
static std::string defaultPartitionName_
void clone(DcuPsuVector &input, DcuPsuVector &output)
int i
Definition: DBlmapReader.cc:9
std::string getPSUName(uint32_t detid)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void getDetID(std::string pvss, bool, std::vector< uint32_t > &detids, std::vector< uint32_t > &unmapped_detids, std::vector< uint32_t > &crosstalking_detids)
std::vector< std::pair< std::vector< uint16_t >, std::vector< uint32_t > > > retrieveDcuDeviceAddresses(std::string partition)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
uint16_t size_type
static std::string const input
Definition: EdmProvDump.cc:44
U second(std::pair< T, U > const &p)
const_iterator_range partitions() const
enumDeviceType DeviceType
int IsHVChannel(std::string pvss)
DeviceDescriptions::range DeviceDescriptionsRange
std::vector< uint32_t > getLvDetID(std::string psu)
#define end
Definition: vmac.h:37
std::vector< std::pair< uint32_t, std::string > > getDcuPsuMap()
bool first
Definition: L1TdeRCT.cc:75
void getHvDetID(std::string psuchannel, std::vector< uint32_t > &ids, std::vector< uint32_t > &unmapped_ids, std::vector< uint32_t > &crosstalking_ids)
void RemoveDuplicateDetIDs(std::vector< uint32_t > &detids)
#define LogTrace(id)
std::vector< uint32_t > findDcuIdFromDeviceAddress(uint32_t dcuid_)
tuple group
Definition: watchdog.py:82
#define debug
Definition: HDRShower.cc:19
std::vector< DcuDetId > DcuDetIdsV
Container class for database connection parameters.
auto dp
Definition: deltaR.h:24
void BuildMap(const std::string &mapFile, const bool debug)
#define begin
Definition: vmac.h:30
uint32_t getDcuId(std::string pvss)
std::vector< TkDcuPsuMap * > DcuPsuVector
tuple cout
Definition: gather_cfg.py:121
DQMChannel Channel
std::string getDetectorLocation(uint32_t detid)
std::vector< DeviceDescription * > DeviceDescriptionsV
void checkMapInputValues(const SiStripConfigDb::DcuDetIdsV &dcuDetIds_, const DcuPsuVector &dcuPsus_)