00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include<iostream>
00015 #include<sstream>
00016 #include<cstdio>
00017
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00020 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00021 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00022 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00023 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00024 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00025
00026 SiStripHistoId::SiStripHistoId()
00027 {
00028 separator1="__";
00029 separator2="__";
00030 }
00031
00032
00033 SiStripHistoId::~SiStripHistoId()
00034 {
00035 }
00036
00037
00038 std::string SiStripHistoId::createHistoId(std::string description, std::string id_type,uint32_t component_id){
00039 size_t pos1 = description.find( separator1, 0 );
00040 size_t pos2 = description.find( separator2, 0 );
00041 std::string local_histo_id;
00042 std::ostringstream compid;
00043 compid<<component_id;
00044
00045 if ( pos1 == std::string::npos && pos2 == std::string::npos ){
00046 if(id_type=="fed" || id_type=="det" || id_type=="fec"){
00047 local_histo_id = description + separator1 + id_type + separator2 + compid.str();
00048 }else{
00049 local_histo_id = description + separator1 + "dummy" + separator2 + compid.str();
00050 edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
00051 <<" no such type of component accepted: "<<id_type
00052 <<" id_type can be: fed, det, or fec.";
00053 }
00054 }else{
00055 local_histo_id = description + "_dummy_" + separator1 + id_type + separator2 + compid.str();
00056 edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
00057 <<" histogram description cannot contain: "<<separator1<<" or: "<<separator2
00058 <<" histogram description = "<<description;
00059 }
00060 return local_histo_id;
00061 }
00062
00063 std::string SiStripHistoId::createHistoLayer(std::string description, std::string id_type,std::string path,std::string flag){
00064 size_t pos1 = description.find( separator1, 0 );
00065 size_t pos2 = description.find( separator2, 0 );
00066 std::string local_histo_id;
00067 if ( pos1 == std::string::npos && pos2 == std::string::npos ){
00068 if(id_type=="fed" || id_type=="det" || id_type=="fec" || id_type=="layer"){
00069 if(flag.size() > 0)
00070 local_histo_id = description + separator1 + flag + separator2 + path;
00071 else
00072 local_histo_id = description + separator2 + path;
00073 LogTrace("SiStripHistoId") << "Local_histo_ID " << local_histo_id << std::endl;
00074 }else{
00075 local_histo_id = description + separator2 + "_dummy_" + path;
00076 edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput "
00077 <<" no such type of component accepted: "<<id_type
00078 <<" id_type can be: fed, det, fec or layer ";
00079 }
00080 }else{
00081 local_histo_id = description + "_dummy_" + separator2 + path;
00082 edm::LogWarning("SiStripHistoId") <<" SiStripHistoId::WrongInput "
00083 <<" histogram description cannot contain: "<<separator1<<" or: "<<separator2
00084 <<" histogram description = "<<description;
00085 }
00086 return local_histo_id;
00087 }
00088
00089 std::string SiStripHistoId::getSubdetid(uint32_t id,bool flag_ring){ std::string rest1;
00090
00091 const int buf_len = 50;
00092 char temp_str[buf_len];
00093
00094 StripSubdetector subdet(id);
00095 if( subdet.subdetId() == StripSubdetector::TIB){
00096
00097 TIBDetId tib1 = TIBDetId(id);
00098 snprintf(temp_str, buf_len, "TIB__layer__%i", tib1.layer());
00099 }else if( subdet.subdetId() == StripSubdetector::TID){
00100
00101 TIDDetId tid1 = TIDDetId(id);
00102 if (flag_ring) snprintf(temp_str, buf_len, "TID__side__%i__ring__%i", tid1.side(), tid1.ring());
00103 else snprintf(temp_str, buf_len, "TID__side__%i__wheel__%i", tid1.side(), tid1.wheel());
00104 }else if(subdet.subdetId() == StripSubdetector::TOB){
00105
00106 TOBDetId tob1 = TOBDetId(id);
00107 snprintf(temp_str, buf_len, "TOB__layer__%i",tob1.layer());
00108 }else if(subdet.subdetId() == StripSubdetector::TEC){
00109
00110 TECDetId tec1 = TECDetId(id);
00111 if (flag_ring) snprintf(temp_str, buf_len, "TEC__side__%i__ring__%i", tec1.side(), tec1.ring());
00112 else snprintf(temp_str, buf_len, "TEC__side__%i__wheel__%i", tec1.side(), tec1.wheel());
00113 }else{
00114
00115 edm::LogError("SiStripTkDQM|WrongInput")<<"no such subdetector type :"<<subdet.subdetId()<<" no folder set!"<<std::endl;
00116 snprintf(temp_str,0,"%s","");
00117 }
00118
00119 return std::string(temp_str);
00120 }
00121
00122 uint32_t SiStripHistoId::getComponentId(std::string histoid){
00123 uint32_t local_component_id;
00124 std::istringstream input(returnIdPart(histoid,3)); input >> local_component_id;
00125 return local_component_id;
00126 }
00127
00128
00129 std::string SiStripHistoId::getComponentType(std::string histoid){
00130 return returnIdPart(histoid,2);
00131 }
00132
00133
00134 std::string SiStripHistoId::returnIdPart(std::string histoid, uint32_t whichpart){
00135 size_t length1=histoid.find(separator1,0);
00136 if(length1==std::string::npos){
00137 edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
00138 return "0";
00139 }
00140 std::string part1 = histoid.substr(0,length1);
00141 if(whichpart==1) return part1;
00142 std::string remain1 = histoid.substr(length1+separator1.size());
00143 size_t length2=remain1.find(separator2,0);
00144 if(length2==std::string::npos){
00145 edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
00146 return "0";
00147 }
00148 std::string part2 = remain1.substr(0,length2);
00149 if(whichpart==2) return part2;
00150 std::string part3 = remain1.substr(length2+separator2.size());
00151 if(whichpart==3) return part3;
00152 edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no such whichpart="<<whichpart<<" returning 0";
00153 return "0";
00154 }
00155