File indexing completed on 2023-03-17 10:56:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <iostream>
0014 #include <sstream>
0015 #include <cstdio>
0016
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
0019 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0020 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0021
0022 SiStripHistoId::SiStripHistoId() {}
0023
0024 SiStripHistoId::~SiStripHistoId() {}
0025
0026 std::string SiStripHistoId::createHistoId(std::string description, std::string id_type, uint32_t component_id) {
0027 size_t pos1 = description.find("__", 0);
0028 size_t pos2 = description.find("__", 0);
0029 std::string local_histo_id;
0030 std::ostringstream compid;
0031 compid << component_id;
0032
0033 if (pos1 == std::string::npos && pos2 == std::string::npos) {
0034 if (id_type == "fed" || id_type == "det" || id_type == "fec") {
0035 local_histo_id = description + "__" + id_type + "__" + compid.str();
0036 } else {
0037 local_histo_id = description + "__dummy__" + compid.str();
0038 edm::LogError("SiStripHistoId") << " SiStripHistoId::WrongInput "
0039 << " no such type of component accepted: " << id_type
0040 << " id_type can be: fed, det, or fec.";
0041 }
0042 } else {
0043 local_histo_id = description + "_dummy___" + id_type + "__" + compid.str();
0044 edm::LogError("SiStripHistoId") << " SiStripHistoId::WrongInput "
0045 << " histogram description cannot contain: __ or: __"
0046 << " histogram description = " << description;
0047 }
0048 return local_histo_id;
0049 }
0050
0051 std::string SiStripHistoId::createHistoLayer(std::string description,
0052 std::string id_type,
0053 std::string path,
0054 std::string flag) {
0055 size_t pos1 = description.find("__", 0);
0056 size_t pos2 = description.find("__", 0);
0057 std::string local_histo_id;
0058 if (pos1 == std::string::npos && pos2 == std::string::npos) {
0059 if (id_type == "fed" || id_type == "det" || id_type == "fec" || id_type == "layer" ||
0060 id_type == "ring") {
0061 if (!flag.empty())
0062 local_histo_id = description + "__" + flag + "__" + path;
0063 else
0064 local_histo_id = description + "__" + path;
0065 LogTrace("SiStripHistoId") << "Local_histo_ID " << local_histo_id << std::endl;
0066 } else {
0067 local_histo_id = description + "___dummy___" + path;
0068 edm::LogError("SiStripHistoId") << " SiStripHistoId::WrongInput "
0069 << " no such type of component accepted: " << id_type
0070 << " id_type can be: fed, det, fec or layer ";
0071 }
0072 } else {
0073 local_histo_id = description + "_dummy___" + path;
0074 edm::LogWarning("SiStripHistoId") << " SiStripHistoId::WrongInput "
0075 << " histogram description cannot contain: __ or: __"
0076 << " histogram description = " << description;
0077 }
0078 return local_histo_id;
0079 }
0080
0081
0082 std::string SiStripHistoId::getSubdetid(uint32_t id, const TrackerTopology *tTopo, bool flag_ring) {
0083 const int buf_len = 50;
0084 char temp_str[buf_len];
0085
0086 StripSubdetector subdet(id);
0087 if (subdet.subdetId() == StripSubdetector::TIB) {
0088
0089
0090 snprintf(temp_str, buf_len, "TIB__layer__%i", tTopo->tibLayer(id));
0091 } else if (subdet.subdetId() == StripSubdetector::TID) {
0092
0093
0094 const char *side = "";
0095 if (tTopo->tidSide(id) == 1)
0096 side = "MINUS";
0097 else if (tTopo->tidSide(id) == 2)
0098 side = "PLUS";
0099
0100 if (flag_ring)
0101 snprintf(temp_str, buf_len, "TID__%s__ring__%i", side, tTopo->tidRing(id));
0102 else
0103 snprintf(temp_str, buf_len, "TID__%s__wheel__%i", side, tTopo->tidWheel(id));
0104
0105 } else if (subdet.subdetId() == StripSubdetector::TOB) {
0106
0107
0108 snprintf(temp_str, buf_len, "TOB__layer__%i", tTopo->tobLayer(id));
0109 } else if (subdet.subdetId() == StripSubdetector::TEC) {
0110
0111
0112 const char *side = "";
0113 if (tTopo->tecSide(id) == 1)
0114 side = "MINUS";
0115 else if (tTopo->tecSide(id) == 2)
0116 side = "PLUS";
0117
0118 if (flag_ring)
0119 snprintf(temp_str, buf_len, "TEC__%s__ring__%i", side, tTopo->tecRing(id));
0120 else {
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 snprintf(temp_str, buf_len, "TEC__%s__wheel__%i", side, tTopo->tecWheel(id));
0132 }
0133 } else {
0134
0135 edm::LogError("SiStripTkDQM|WrongInput")
0136 << "no such subdetector type :" << subdet.subdetId() << " no folder set!" << std::endl;
0137 snprintf(temp_str, 0, "%s", "");
0138 }
0139
0140 return std::string(temp_str);
0141 }
0142
0143 uint32_t SiStripHistoId::getComponentId(std::string histoid) {
0144 uint32_t local_component_id;
0145 std::istringstream input(returnIdPart(histoid, 3));
0146 input >> local_component_id;
0147 return local_component_id;
0148 }
0149
0150 std::string SiStripHistoId::getComponentType(std::string histoid) { return returnIdPart(histoid, 2); }
0151
0152 std::string SiStripHistoId::returnIdPart(std::string histoid, uint32_t whichpart) {
0153 size_t length1 = histoid.find("__", 0);
0154 if (length1 == std::string::npos) {
0155 edm::LogWarning("SiStripTkDQM|UnregularInput") << "no regular histoid. Returning 0";
0156 return "0";
0157 }
0158 std::string part1 = histoid.substr(0, length1);
0159 if (whichpart == 1)
0160 return part1;
0161 std::string remain1 = histoid.substr(length1 + 2);
0162 size_t length2 = remain1.find("__", 0);
0163 if (length2 == std::string::npos) {
0164 edm::LogWarning("SiStripTkDQM|UnregularInput") << "no regular histoid. Returning 0";
0165 return "0";
0166 }
0167 std::string part2 = remain1.substr(0, length2);
0168 if (whichpart == 2)
0169 return part2;
0170 std::string part3 = remain1.substr(length2 + 2);
0171 if (whichpart == 3)
0172 return part3;
0173 edm::LogWarning("SiStripTkDQM|UnregularInput") << "no such whichpart=" << whichpart << " returning 0";
0174 return "0";
0175 }