Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:10

0001 // -*- C++ -*-
0002 //
0003 // Package:     SiPixelCommon
0004 // Class  :     SiPixelHistogramId
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  chiochia
0010 //         Created:  Wed Feb 22 16:07:58 CET 2006
0011 //
0012 
0013 #include <iostream>
0014 #include <sstream>
0015 
0016 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 
0019 using namespace edm;
0020 
0021 /// Constructor
0022 SiPixelHistogramId::SiPixelHistogramId() : dataCollection_("defaultData"), separator_("_") {}
0023 /// Constructor with collection
0024 SiPixelHistogramId::SiPixelHistogramId(std::string dataCollection) : dataCollection_(dataCollection), separator_("_") {}
0025 
0026 /// Destructor
0027 SiPixelHistogramId::~SiPixelHistogramId() {}
0028 /// Create Histogram Id
0029 std::string SiPixelHistogramId::setHistoId(std::string variable, uint32_t &rawId) {
0030   std::string histoId;
0031   std::ostringstream rawIdString;
0032   rawIdString << rawId;
0033   histoId = variable + separator_ + dataCollection_ + separator_ + rawIdString.str();
0034 
0035   return histoId;
0036 }
0037 /// get Data Collection
0038 std::string SiPixelHistogramId::getDataCollection(std::string histoid) { return returnIdPart(histoid, 2); }
0039 /// get Raw Id
0040 uint32_t SiPixelHistogramId::getRawId(std::string histoid) {
0041   uint32_t local_component_id;
0042   std::istringstream input(returnIdPart(histoid, 3));
0043   input >> local_component_id;
0044   return local_component_id;
0045 }
0046 /// get Part
0047 std::string SiPixelHistogramId::returnIdPart(std::string histoid, uint32_t whichpart) {
0048   size_t length1 = histoid.find(separator_, 0);
0049   if (length1 == std::string::npos) {  // no separator1 found
0050     LogWarning("PixelDQM") << "SiPixelHistogramId::returnIdPart - no regular histoid. Returning 0";
0051     return "0";
0052   }
0053   std::string part1 = histoid.substr(0, length1);  // part of 'histoid' up to 'separator1'
0054   if (whichpart == 1)
0055     return part1;
0056   std::string remain1 =
0057       histoid.substr(length1 + separator_.size());  // rest of 'histoid' starting at end of 'separator1'
0058   size_t length2 = remain1.find(separator_, 0);
0059   if (length2 == std::string::npos) {  // no separator2 found
0060     LogWarning("PixelDQM") << "SiPixelHistogramId::returnIdPart - no regular histoid. Returning 0";
0061     return "0";
0062   }
0063   std::string part2 = remain1.substr(0, length2);  // part of 'remain1' up to 'separator2'
0064   if (whichpart == 2)
0065     return part2;
0066   std::string part3 = remain1.substr(length2 + separator_.size());  // rest of remain1 starting at end of 'separator2'
0067   if (whichpart == 3)
0068     return part3;
0069   LogWarning("PixelDQM") << "SiPixelHistogramId::returnIdPart - no such whichpart=" << whichpart << " returning 0";
0070   return "0";
0071 }