CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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.18 2013/01/03 18:59:35 wmtan 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/TrackerCommon/interface/TrackerTopology.h"
00022 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00023 
00024 SiStripHistoId::SiStripHistoId()
00025 {
00026 }
00027 
00028 
00029 SiStripHistoId::~SiStripHistoId()
00030 {
00031 }
00032 
00033 
00034 std::string SiStripHistoId::createHistoId(std::string description, std::string id_type,uint32_t component_id){
00035   size_t pos1 = description.find("__", 0 ); // check if std::string 'description' contains by mistake the 'separator1'
00036   size_t pos2 = description.find("__", 0 ); // check if std::string 'description' contains by mistake the 'separator2'
00037   std::string local_histo_id;
00038   std::ostringstream compid;
00039   compid<<component_id; // use std::ostringstream for casting integer to std::string
00040       
00041   if ( pos1 == std::string::npos && pos2 == std::string::npos ){ // ok, not found either separator
00042     if(id_type=="fed" || id_type=="det" || id_type=="fec"){ // ok! is one of the accepted id_type-s
00043       local_histo_id = description + "__" + id_type + "__" + compid.str();
00044     }else{
00045       local_histo_id = description + "__dummy__" + compid.str();
00046       edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput " 
00047                                  <<" no such type of component accepted: "<<id_type
00048                                  <<" id_type can be: fed, det, or fec.";      
00049     }
00050   }else{
00051     local_histo_id = description + "_dummy___" + id_type + "__" + compid.str();
00052     edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput " 
00053                                <<" histogram description cannot contain: __ or: __" 
00054                                <<" histogram description = "<<description;
00055   }
00056   return local_histo_id;
00057 }
00058 
00059 std::string SiStripHistoId::createHistoLayer(std::string description, std::string id_type,std::string path,std::string flag){
00060   size_t pos1 = description.find( "__", 0 ); // check if std::string 'description' contains by mistake the 'separator1'
00061   size_t pos2 = description.find( "__", 0 ); // check if std::string 'description' contains by mistake the 'separator2'
00062   std::string local_histo_id;
00063   if ( pos1 == std::string::npos && pos2 == std::string::npos ){ // ok, not found either separator
00064     if(id_type=="fed" || id_type=="det" || id_type=="fec"  || id_type=="layer"){ // ok! is one of the accepted id_type-s
00065       if(flag.size() > 0)
00066         local_histo_id = description + "__" + flag + "__" + path;
00067       else 
00068         local_histo_id = description + "__" + path;
00069       LogTrace("SiStripHistoId") << "Local_histo_ID " << local_histo_id << std::endl;
00070     }else{
00071       local_histo_id = description + "___dummy___" + path;
00072       edm::LogError("SiStripHistoId") <<" SiStripHistoId::WrongInput " 
00073                                  <<" no such type of component accepted: "<<id_type
00074                                  <<" id_type can be: fed, det, fec or layer ";
00075     }
00076   }else{
00077     local_histo_id = description + "_dummy___" + path;
00078     edm::LogWarning("SiStripHistoId") <<" SiStripHistoId::WrongInput " 
00079                                  <<" histogram description cannot contain: __ or: __"
00080                                  <<" histogram description = "<<description;
00081   }
00082   return local_histo_id;
00083 }
00084 
00085 std::string SiStripHistoId::getSubdetid(uint32_t id, const TrackerTopology* tTopo, bool flag_ring){
00086   std::string rest1;
00087   
00088   const int buf_len = 50;
00089   char temp_str[buf_len];
00090 
00091   StripSubdetector subdet(id);
00092   if( subdet.subdetId() == StripSubdetector::TIB){
00093     // ---------------------------  TIB  --------------------------- //
00094     
00095     snprintf(temp_str, buf_len, "TIB__layer__%i", tTopo->tibLayer(id));
00096   }else if( subdet.subdetId() == StripSubdetector::TID){
00097     // ---------------------------  TID  --------------------------- //
00098     
00099     if (flag_ring) snprintf(temp_str, buf_len, "TID__side__%i__ring__%i", tTopo->tidSide(id), tTopo->tidRing(id));
00100     else snprintf(temp_str, buf_len, "TID__side__%i__wheel__%i", tTopo->tidSide(id), tTopo->tidWheel(id));
00101   }else if(subdet.subdetId() == StripSubdetector::TOB){ 
00102     // ---------------------------  TOB  --------------------------- //
00103     
00104     snprintf(temp_str, buf_len, "TOB__layer__%i",tTopo->tobLayer(id)); 
00105   }else if(subdet.subdetId() == StripSubdetector::TEC){
00106     // ---------------------------  TEC  --------------------------- //
00107     
00108     if (flag_ring) snprintf(temp_str, buf_len, "TEC__side__%i__ring__%i", tTopo->tecSide(id), tTopo->tecRing(id));
00109     else snprintf(temp_str, buf_len, "TEC__side__%i__wheel__%i", tTopo->tecSide(id), tTopo->tecWheel(id)); 
00110   }else{
00111     // ---------------------------  ???  --------------------------- //
00112     edm::LogError("SiStripTkDQM|WrongInput")<<"no such subdetector type :"<<subdet.subdetId()<<" no folder set!"<<std::endl;
00113     snprintf(temp_str,0,"%s","");  
00114   }
00115   
00116   return std::string(temp_str);
00117 }
00118 
00119 uint32_t SiStripHistoId::getComponentId(std::string histoid){
00120   uint32_t local_component_id;
00121   std::istringstream input(returnIdPart(histoid,3)); input >> local_component_id; // use std::istringstream for casting from std::string to uint32_t
00122   return local_component_id;
00123 }
00124 
00125 
00126 std::string SiStripHistoId::getComponentType(std::string histoid){
00127  return returnIdPart(histoid,2);
00128 }
00129 
00130 
00131 std::string SiStripHistoId::returnIdPart(std::string histoid, uint32_t whichpart){
00132   size_t length1=histoid.find("__",0);
00133   if(length1==std::string::npos){ // no separator1 found
00134     edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
00135     return "0";
00136   }
00137   std::string part1 = histoid.substr(0,length1); // part of 'histoid' up to 'separator1'
00138   if(whichpart==1) return part1;
00139   std::string remain1 = histoid.substr(length1+2); // rest of 'histoid' starting at end of 'separator1'
00140   size_t length2=remain1.find("__",0);
00141   if(length2==std::string::npos){ // no separator2 found
00142     edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no regular histoid. Returning 0";
00143     return "0";
00144   }
00145   std::string part2 = remain1.substr(0,length2); // part of 'remain1' up to 'separator2'
00146   if(whichpart==2) return part2;
00147   std::string part3 = remain1.substr(length2+2); // rest of remain1 starting at end of 'separator2'
00148   if(whichpart==3) return part3;
00149   edm::LogWarning("SiStripTkDQM|UnregularInput")<<"no such whichpart="<<whichpart<<" returning 0";
00150   return "0";
00151 }
00152