CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: SiStripHistoId.cc,v 1.15 2010/03/27 11:03:34 dutta Exp $
12 //
13 
14 #include<iostream>
15 #include<sstream>
16 #include<cstdio>
17 
25 
27 {
28 }
29 
30 
32 {
33 }
34 
35 
36 std::string SiStripHistoId::createHistoId(std::string description, std::string id_type,uint32_t component_id){
37  size_t pos1 = description.find("__", 0 ); // check if std::string 'description' contains by mistake the 'separator1'
38  size_t pos2 = description.find("__", 0 ); // check if std::string 'description' contains by mistake the 'separator2'
39  std::string local_histo_id;
40  std::ostringstream compid;
41  compid<<component_id; // use std::ostringstream for casting integer to std::string
42 
43  if ( pos1 == std::string::npos && pos2 == std::string::npos ){ // ok, not found either separator
44  if(id_type=="fed" || id_type=="det" || id_type=="fec"){ // ok! is one of the accepted id_type-s
45  local_histo_id = description + "__" + id_type + "__" + compid.str();
46  }else{
47  local_histo_id = description + "__dummy__" + compid.str();
48  edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
49  <<" no such type of component accepted: "<<id_type
50  <<" id_type can be: fed, det, or fec.";
51  }
52  }else{
53  local_histo_id = description + "_dummy___" + id_type + "__" + compid.str();
54  edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
55  <<" histogram description cannot contain: __ or: __"
56  <<" histogram description = "<<description;
57  }
58  return local_histo_id;
59 }
60 
61 std::string SiStripHistoId::createHistoLayer(std::string description, std::string id_type,std::string path,std::string flag){
62  size_t pos1 = description.find( "__", 0 ); // check if std::string 'description' contains by mistake the 'separator1'
63  size_t pos2 = description.find( "__", 0 ); // check if std::string 'description' contains by mistake the 'separator2'
64  std::string local_histo_id;
65  if ( pos1 == std::string::npos && pos2 == std::string::npos ){ // ok, not found either separator
66  if(id_type=="fed" || id_type=="det" || id_type=="fec" || id_type=="layer"){ // ok! is one of the accepted id_type-s
67  if(flag.size() > 0)
68  local_histo_id = description + "__" + flag + "__" + path;
69  else
70  local_histo_id = description + "__" + path;
71  LogTrace("SiStripHistoId") << "Local_histo_ID " << local_histo_id << std::endl;
72  }else{
73  local_histo_id = description + "___dummy___" + path;
74  edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
75  <<" no such type of component accepted: "<<id_type
76  <<" id_type can be: fed, det, fec or layer ";
77  }
78  }else{
79  local_histo_id = description + "_dummy___" + path;
80  edm::LogWarning("SiStripHistoId") <<" SiStripHistoId::WrongInput "
81  <<" histogram description cannot contain: __ or: __"
82  <<" histogram description = "<<description;
83  }
84  return local_histo_id;
85 }
86 
87 std::string SiStripHistoId::getSubdetid(uint32_t id,bool flag_ring){ std::string rest1;
88 
89  const int buf_len = 50;
90  char temp_str[buf_len];
91 
92  StripSubdetector subdet(id);
93  if( subdet.subdetId() == StripSubdetector::TIB){
94  // --------------------------- TIB --------------------------- //
95  TIBDetId tib1 = TIBDetId(id);
96  snprintf(temp_str, buf_len, "TIB__layer__%i", tib1.layer());
97  }else if( subdet.subdetId() == StripSubdetector::TID){
98  // --------------------------- TID --------------------------- //
99  TIDDetId tid1 = TIDDetId(id);
100  if (flag_ring) snprintf(temp_str, buf_len, "TID__side__%i__ring__%i", tid1.side(), tid1.ring());
101  else snprintf(temp_str, buf_len, "TID__side__%i__wheel__%i", tid1.side(), tid1.wheel());
102  }else if(subdet.subdetId() == StripSubdetector::TOB){
103  // --------------------------- TOB --------------------------- //
104  TOBDetId tob1 = TOBDetId(id);
105  snprintf(temp_str, buf_len, "TOB__layer__%i",tob1.layer());
106  }else if(subdet.subdetId() == StripSubdetector::TEC){
107  // --------------------------- TEC --------------------------- //
108  TECDetId tec1 = TECDetId(id);
109  if (flag_ring) snprintf(temp_str, buf_len, "TEC__side__%i__ring__%i", tec1.side(), tec1.ring());
110  else snprintf(temp_str, buf_len, "TEC__side__%i__wheel__%i", tec1.side(), tec1.wheel());
111  }else{
112  // --------------------------- ??? --------------------------- //
113  edm::LogError("SiStripTkDQM|WrongInput")<<"no such subdetector type :"<<subdet.subdetId()<<" no folder set!"<<std::endl;
114  snprintf(temp_str,0,"%s","");
115  }
116 
117  return std::string(temp_str);
118 }
119 
120 uint32_t SiStripHistoId::getComponentId(std::string histoid){
121  uint32_t local_component_id;
122  std::istringstream input(returnIdPart(histoid,3)); input >> local_component_id; // use std::istringstream for casting from std::string to uint32_t
123  return local_component_id;
124 }
125 
126 
127 std::string SiStripHistoId::getComponentType(std::string histoid){
128  return returnIdPart(histoid,2);
129 }
130 
131 
132 std::string SiStripHistoId::returnIdPart(std::string histoid, uint32_t whichpart){
133  size_t length1=histoid.find("__",0);
134  if(length1==std::string::npos){ // no separator1 found
135  edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
136  return "0";
137  }
138  std::string part1 = histoid.substr(0,length1); // part of 'histoid' up to 'separator1'
139  if(whichpart==1) return part1;
140  std::string remain1 = histoid.substr(length1+2); // rest of 'histoid' starting at end of 'separator1'
141  size_t length2=remain1.find("__",0);
142  if(length2==std::string::npos){ // no separator2 found
143  edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
144  return "0";
145  }
146  std::string part2 = remain1.substr(0,length2); // part of 'remain1' up to 'separator2'
147  if(whichpart==2) return part2;
148  std::string part3 = remain1.substr(length2+2); // rest of remain1 starting at end of 'separator2'
149  if(whichpart==3) return part3;
150  edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no such whichpart="<<whichpart<<" returning 0";
151  return "0";
152 }
153 
std::string getComponentType(std::string histoid)
long int flag
Definition: mlp_lapack.h:47
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
std::string returnIdPart(std::string histoid, uint32_t whichpart)
unsigned int side() const
positive or negative id
Definition: TECDetId.h:47
uint32_t getComponentId(std::string histoid)
int path() const
Definition: HLTadd.h:3
std::string getSubdetid(uint32_t id, bool flag_ring)
unsigned int ring() const
ring id
Definition: TIDDetId.h:55
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
#define LogTrace(id)
tuple input
Definition: collect_tpl.py:10
tuple description
Definition: idDealer.py:66
std::string createHistoId(std::string description, std::string id_type, uint32_t component_id)
unsigned int side() const
positive or negative id
Definition: TIDDetId.h:45
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
unsigned int ring() const
ring id
Definition: TECDetId.h:71
std::string createHistoLayer(std::string description, std::string id_type, std::string path, std::string flag)
virtual ~SiStripHistoId()
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50