CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/DQM/SiStripCommon/src/SiStripHistoId.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     SiStripCommon
00004 // Class  :     SiStripHistoId
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  dkcira
00010 //         Created:  Wed Feb 22 16:07:58 CET 2006
00011 // $Id: SiStripHistoId.cc,v 1.16 2011/05/31 10:38:46 eulisse Exp $
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 ); // check if std::string 'description' contains by mistake the 'separator1'
00038   size_t pos2 = description.find("__", 0 ); // check if std::string 'description' contains by mistake the 'separator2'
00039   std::string local_histo_id;
00040   std::ostringstream compid;
00041   compid<<component_id; // use std::ostringstream for casting integer to std::string
00042       
00043   if ( pos1 == std::string::npos && pos2 == std::string::npos ){ // ok, not found either separator
00044     if(id_type=="fed" || id_type=="det" || id_type=="fec"){ // ok! is one of the accepted id_type-s
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 ); // check if std::string 'description' contains by mistake the 'separator1'
00063   size_t pos2 = description.find( "__", 0 ); // check if std::string 'description' contains by mistake the 'separator2'
00064   std::string local_histo_id;
00065   if ( pos1 == std::string::npos && pos2 == std::string::npos ){ // ok, not found either separator
00066     if(id_type=="fed" || id_type=="det" || id_type=="fec"  || id_type=="layer"){ // ok! is one of the accepted id_type-s
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     // ---------------------------  TIB  --------------------------- //
00095     TIBDetId tib1 = TIBDetId(id);
00096     snprintf(temp_str, buf_len, "TIB__layer__%i", tib1.layer());
00097   }else if( subdet.subdetId() == StripSubdetector::TID){
00098     // ---------------------------  TID  --------------------------- //
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     // ---------------------------  TOB  --------------------------- //
00104     TOBDetId tob1 = TOBDetId(id);
00105     snprintf(temp_str, buf_len, "TOB__layer__%i",tob1.layer()); 
00106   }else if(subdet.subdetId() == StripSubdetector::TEC){
00107     // ---------------------------  TEC  --------------------------- //
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; // use std::istringstream for casting from std::string to uint32_t
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){ // no separator1 found
00135     edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
00136     return "0";
00137   }
00138   std::string part1 = histoid.substr(0,length1); // part of 'histoid' up to 'separator1'
00139   if(whichpart==1) return part1;
00140   std::string remain1 = histoid.substr(length1+2); // rest of 'histoid' starting at end of 'separator1'
00141   size_t length2=remain1.find("__",0);
00142   if(length2==std::string::npos){ // no separator2 found
00143     edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
00144     return "0";
00145   }
00146   std::string part2 = remain1.substr(0,length2); // part of 'remain1' up to 'separator2'
00147   if(whichpart==2) return part2;
00148   std::string part3 = remain1.substr(length2+2); // rest of remain1 starting at end of 'separator2'
00149   if(whichpart==3) return part3;
00150   edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no such whichpart="<<whichpart<<" returning 0";
00151   return "0";
00152 }
00153