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