CMS 3D CMS Logo

SiStripHistoId.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripCommon
4 // Class : SiStripHistoId
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: dkcira
10 // Created: Wed Feb 22 16:07:58 CET 2006
11 //
12 
13 #include<iostream>
14 #include<sstream>
15 #include<cstdio>
16 
21 
23 {
24 }
25 
26 
28 {
29 }
30 
31 
33  size_t pos1 = description.find("__", 0 ); // check if std::string 'description' contains by mistake the 'separator1'
34  size_t pos2 = description.find("__", 0 ); // check if std::string 'description' contains by mistake the 'separator2'
35  std::string local_histo_id;
36  std::ostringstream compid;
37  compid<<component_id; // use std::ostringstream for casting integer to std::string
38 
39  if ( pos1 == std::string::npos && pos2 == std::string::npos ){ // ok, not found either separator
40  if(id_type=="fed" || id_type=="det" || id_type=="fec"){ // ok! is one of the accepted id_type-s
41  local_histo_id = description + "__" + id_type + "__" + compid.str();
42  }else{
43  local_histo_id = description + "__dummy__" + compid.str();
44  edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
45  <<" no such type of component accepted: "<<id_type
46  <<" id_type can be: fed, det, or fec.";
47  }
48  }else{
49  local_histo_id = description + "_dummy___" + id_type + "__" + compid.str();
50  edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
51  <<" histogram description cannot contain: __ or: __"
52  <<" histogram description = "<<description;
53  }
54  return local_histo_id;
55 }
56 
58  size_t pos1 = description.find( "__", 0 ); // check if std::string 'description' contains by mistake the 'separator1'
59  size_t pos2 = description.find( "__", 0 ); // check if std::string 'description' contains by mistake the 'separator2'
60  std::string local_histo_id;
61  if ( pos1 == std::string::npos && pos2 == std::string::npos ){ // ok, not found either separator
62  if(id_type=="fed" || id_type=="det" || id_type=="fec" || id_type=="layer" || id_type=="ring"){ // ok! is one of the accepted id_type-s
63  if(!flag.empty())
64  local_histo_id = description + "__" + flag + "__" + path;
65  else
66  local_histo_id = description + "__" + path;
67  LogTrace("SiStripHistoId") << "Local_histo_ID " << local_histo_id << std::endl;
68  }else{
69  local_histo_id = description + "___dummy___" + path;
70  edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
71  <<" no such type of component accepted: "<<id_type
72  <<" id_type can be: fed, det, fec or layer ";
73  }
74  }else{
75  local_histo_id = description + "_dummy___" + path;
76  edm::LogWarning("SiStripHistoId") <<" SiStripHistoId::WrongInput "
77  <<" histogram description cannot contain: __ or: __"
78  <<" histogram description = "<<description;
79  }
80  return local_histo_id;
81 }
82 
83 //std::string SiStripHistoId::getSubdetid(uint32_t id, const TrackerTopology* tTopo, bool flag_ring, bool flag_thickness){
84 std::string SiStripHistoId::getSubdetid(uint32_t id, const TrackerTopology* tTopo, bool flag_ring){
85  const int buf_len = 50;
86  char temp_str[buf_len];
87 
88  StripSubdetector subdet(id);
89  if( subdet.subdetId() == StripSubdetector::TIB){
90  // --------------------------- TIB --------------------------- //
91 
92  snprintf(temp_str, buf_len, "TIB__layer__%i", tTopo->tibLayer(id));
93  }else if( subdet.subdetId() == StripSubdetector::TID){
94  // --------------------------- TID --------------------------- //
95 
96  const char *side = "";
97  if (tTopo->tidSide(id) == 1)
98  side = "MINUS";
99  else if (tTopo->tidSide(id) == 2)
100  side = "PLUS";
101 
102  if (flag_ring)
103  snprintf(temp_str, buf_len, "TID__%s__ring__%i", side, tTopo->tidRing(id) );
104  else
105  snprintf(temp_str, buf_len, "TID__%s__wheel__%i", side, tTopo->tidWheel(id));
106 
107  }else if(subdet.subdetId() == StripSubdetector::TOB){
108  // --------------------------- TOB --------------------------- //
109 
110  snprintf(temp_str, buf_len, "TOB__layer__%i",tTopo->tobLayer(id));
111  }else if(subdet.subdetId() == StripSubdetector::TEC){
112  // --------------------------- TEC --------------------------- //
113 
114  const char *side = "";
115  if (tTopo->tecSide(id) == 1)
116  side = "MINUS";
117  else if (tTopo->tecSide(id) == 2)
118  side = "PLUS";
119 
120  if (flag_ring)
121  snprintf(temp_str, buf_len, "TEC__%s__ring__%i", side, tTopo->tecRing(id) );
122  else {
123  /*
124  if (flag_thickness) {
125  uint32_t ring = tTopo->tecRing(id);
126  if ( ring >= 1 && ring <= 4 )
127  snprintf(temp_str, buf_len, "TEC__%s__wheel__%i__THIN", side.c_str(), tTopo->tecWheel(id));
128  else
129  snprintf(temp_str, buf_len, "TEC__%s__wheel__%i__THICK", side.c_str(), tTopo->tecWheel(id));
130  }
131  else
132 */
133  snprintf(temp_str, buf_len, "TEC__%s__wheel__%i", side, tTopo->tecWheel(id));
134  }
135  }else{
136  // --------------------------- ??? --------------------------- //
137  edm::LogError("SiStripTkDQM|WrongInput")<<"no such subdetector type :"<<subdet.subdetId()<<" no folder set!"<<std::endl;
138  snprintf(temp_str,0,"%s","");
139  }
140 
141  return std::string(temp_str);
142 }
143 
145  uint32_t local_component_id;
146  std::istringstream input(returnIdPart(histoid,3)); input >> local_component_id; // use std::istringstream for casting from std::string to uint32_t
147  return local_component_id;
148 }
149 
150 
152  return returnIdPart(histoid,2);
153 }
154 
155 
157  size_t length1=histoid.find("__",0);
158  if(length1==std::string::npos){ // no separator1 found
159  edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
160  return "0";
161  }
162  std::string part1 = histoid.substr(0,length1); // part of 'histoid' up to 'separator1'
163  if(whichpart==1) return part1;
164  std::string remain1 = histoid.substr(length1+2); // rest of 'histoid' starting at end of 'separator1'
165  size_t length2=remain1.find("__",0);
166  if(length2==std::string::npos){ // no separator2 found
167  edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
168  return "0";
169  }
170  std::string part2 = remain1.substr(0,length2); // part of 'remain1' up to 'separator2'
171  if(whichpart==2) return part2;
172  std::string part3 = remain1.substr(length2+2); // rest of remain1 starting at end of 'separator2'
173  if(whichpart==3) return part3;
174  edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no such whichpart="<<whichpart<<" returning 0";
175  return "0";
176 }
177 
std::string getComponentType(std::string histoid)
unsigned int tibLayer(const DetId &id) const
unsigned int tidRing(const DetId &id) const
unsigned int tecRing(const DetId &id) const
ring id
std::string returnIdPart(std::string histoid, uint32_t whichpart)
unsigned int tidWheel(const DetId &id) const
static std::string const input
Definition: EdmProvDump.cc:44
uint32_t getComponentId(std::string histoid)
unsigned int tidSide(const DetId &id) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
std::string getSubdetid(uint32_t id, const TrackerTopology *tTopo, bool flag_ring)
#define LogTrace(id)
std::string createHistoId(std::string description, std::string id_type, uint32_t component_id)
std::string createHistoLayer(std::string description, std::string id_type, std::string path, std::string flag)
unsigned int tecWheel(const DetId &id) const
virtual ~SiStripHistoId()
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const