Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:39

0001 // -*- C++ -*-
0002 //
0003 // Package:     SiStripCommon
0004 // Class  :     SiStripHistoId
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  dkcira
0010 //         Created:  Wed Feb 22 16:07:58 CET 2006
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);  // check if std::string 'description' contains by mistake the 'separator1'
0028   size_t pos2 = description.find("__", 0);  // check if std::string 'description' contains by mistake the 'separator2'
0029   std::string local_histo_id;
0030   std::ostringstream compid;
0031   compid << component_id;  // use std::ostringstream for casting integer to std::string
0032 
0033   if (pos1 == std::string::npos && pos2 == std::string::npos) {      // ok, not found either separator
0034     if (id_type == "fed" || id_type == "det" || id_type == "fec") {  // ok! is one of the accepted id_type-s
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);  // check if std::string 'description' contains by mistake the 'separator1'
0056   size_t pos2 = description.find("__", 0);  // check if std::string 'description' contains by mistake the 'separator2'
0057   std::string local_histo_id;
0058   if (pos1 == std::string::npos && pos2 == std::string::npos) {  // ok, not found either separator
0059     if (id_type == "fed" || id_type == "det" || id_type == "fec" || id_type == "layer" ||
0060         id_type == "ring") {  // ok! is one of the accepted id_type-s
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 //std::string SiStripHistoId::getSubdetid(uint32_t id, const TrackerTopology* tTopo, bool flag_ring, bool flag_thickness){
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     // ---------------------------  TIB  --------------------------- //
0089 
0090     snprintf(temp_str, buf_len, "TIB__layer__%i", tTopo->tibLayer(id));
0091   } else if (subdet.subdetId() == StripSubdetector::TID) {
0092     // ---------------------------  TID  --------------------------- //
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     // ---------------------------  TOB  --------------------------- //
0107 
0108     snprintf(temp_str, buf_len, "TOB__layer__%i", tTopo->tobLayer(id));
0109   } else if (subdet.subdetId() == StripSubdetector::TEC) {
0110     // ---------------------------  TEC  --------------------------- //
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       if (flag_thickness) {
0123     uint32_t ring = tTopo->tecRing(id);
0124     if ( ring >= 1 && ring <= 4 )
0125       snprintf(temp_str, buf_len, "TEC__%s__wheel__%i__THIN", side.c_str(), tTopo->tecWheel(id));       
0126     else 
0127       snprintf(temp_str, buf_len, "TEC__%s__wheel__%i__THICK", side.c_str(), tTopo->tecWheel(id));       
0128       }
0129       else
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;  // use std::istringstream for casting from std::string to uint32_t
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) {  // no separator1 found
0155     edm::LogWarning("SiStripTkDQM|UnregularInput") << "no regular histoid. Returning 0";
0156     return "0";
0157   }
0158   std::string part1 = histoid.substr(0, length1);  // part of 'histoid' up to 'separator1'
0159   if (whichpart == 1)
0160     return part1;
0161   std::string remain1 = histoid.substr(length1 + 2);  // rest of 'histoid' starting at end of 'separator1'
0162   size_t length2 = remain1.find("__", 0);
0163   if (length2 == std::string::npos) {  // no separator2 found
0164     edm::LogWarning("SiStripTkDQM|UnregularInput") << "no regular histoid. Returning 0";
0165     return "0";
0166   }
0167   std::string part2 = remain1.substr(0, length2);  // part of 'remain1' up to 'separator2'
0168   if (whichpart == 2)
0169     return part2;
0170   std::string part3 = remain1.substr(length2 + 2);  // rest of remain1 starting at end of 'separator2'
0171   if (whichpart == 3)
0172     return part3;
0173   edm::LogWarning("SiStripTkDQM|UnregularInput") << "no such whichpart=" << whichpart << " returning 0";
0174   return "0";
0175 }