Skip to content

Commit 1553d3d

Browse files
committed
attempt to make getSubDetFolderAndTag produce less memory allocations via string_view
1 parent e3be593 commit 1553d3d

File tree

9 files changed

+127
-132
lines changed

9 files changed

+127
-132
lines changed

DQM/SiStripCommon/interface/SiStripFolderOrganizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class SiStripFolderOrganizer {
8888
}
8989
// SubDetector Folder
9090
void getSubDetFolder(const uint32_t& detid, const TrackerTopology* tTopo, std::string& folder_name);
91-
std::pair<const std::string, const char*> getSubDetFolderAndTag(const uint32_t& detid, const TrackerTopology* tTopo);
91+
std::pair<std::string, std::string_view> getSubDetFolderAndTag(const uint32_t& detid, const TrackerTopology* tTopo);
9292

9393
SiStripFolderOrganizer(const SiStripFolderOrganizer&) = delete; // stop default
9494
const SiStripFolderOrganizer& operator=(const SiStripFolderOrganizer&) = delete; // stop default

DQM/SiStripCommon/src/SiStripFolderOrganizer.cc

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,26 @@
99
// Original Author: dkcira
1010
// Created: Thu Jan 26 23:52:43 CET 2006
1111

12-
//
13-
12+
// system includes
13+
#include <cstring> // For strlen
1414
#include <iostream>
1515
#include <sstream>
16+
#include <string>
17+
#include <string_view>
18+
#include <utility>
1619

17-
#include "FWCore/ServiceRegistry/interface/Service.h"
18-
20+
// user includes
21+
#include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
22+
#include "DQMServices/Core/interface/DQMStore.h"
1923
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
2024
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
21-
2225
#include "FWCore/MessageLogger/interface/MessageLogger.h"
26+
#include "FWCore/ServiceRegistry/interface/Service.h"
2327

24-
#include "DQMServices/Core/interface/DQMStore.h"
25-
26-
#include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
2728
#define CONTROL_FOLDER_NAME "ControlView"
2829
#define MECHANICAL_FOLDER_NAME "MechanicalView"
2930
#define SEP "/"
3031

31-
#include <cstring>
32-
3332
SiStripFolderOrganizer::SiStripFolderOrganizer() {
3433
TopFolderName = "SiStrip";
3534
// get a pointer to DQMStore
@@ -406,8 +405,8 @@ void SiStripFolderOrganizer::setLayerFolder(uint32_t rawdetid,
406405
void SiStripFolderOrganizer::getSubDetFolder(const uint32_t& detid,
407406
const TrackerTopology* tTopo,
408407
std::string& folder_name) {
409-
std::pair<std::string, std::string> subdet_and_tag = getSubDetFolderAndTag(detid, tTopo);
410-
folder_name = subdet_and_tag.first;
408+
auto subdet_and_tag = getSubDetFolderAndTag(detid, tTopo);
409+
folder_name = std::string(subdet_and_tag.first);
411410
}
412411
//
413412
// -- Get the name of Subdetector Layer folder
@@ -472,10 +471,11 @@ void SiStripFolderOrganizer::getLayerFolderName(std::stringstream& ss,
472471
//
473472
// -- Get Subdetector Folder name and the Tag
474473
//
475-
std::pair<const std::string, const char*> SiStripFolderOrganizer::getSubDetFolderAndTag(const uint32_t& detid,
476-
const TrackerTopology* tTopo) {
477-
const char* subdet_folder = "";
478-
const char* tag = "";
474+
std::pair<std::string, std::string_view> SiStripFolderOrganizer::getSubDetFolderAndTag(const uint32_t& detid,
475+
const TrackerTopology* tTopo) {
476+
std::string_view subdet_folder;
477+
std::string_view tag;
478+
479479
switch (StripSubdetector::SubDetector(StripSubdetector(detid).subdetId())) {
480480
case StripSubdetector::TIB:
481481
subdet_folder = "TIB";
@@ -503,15 +503,14 @@ std::pair<const std::string, const char*> SiStripFolderOrganizer::getSubDetFolde
503503
tag = "TEC__MINUS";
504504
}
505505
break;
506-
default: {
506+
default:
507507
edm::LogWarning("SiStripCommon") << "WARNING!!! this detid does not belong to tracker" << std::endl;
508508
subdet_folder = "";
509-
}
509+
tag = "";
510510
}
511511

512-
std::string folder;
513-
folder.reserve(TopFolderName.size() + strlen(SEP MECHANICAL_FOLDER_NAME SEP) + strlen(subdet_folder) + 1);
514-
folder = TopFolderName + SEP MECHANICAL_FOLDER_NAME SEP + subdet_folder;
512+
// Concatenate the folder path
513+
std::string folder = std::string(TopFolderName) + SEP + MECHANICAL_FOLDER_NAME + SEP + std::string(subdet_folder);
515514

516-
return std::pair<const std::string, const char*>(folder, tag);
515+
return {folder, tag};
517516
}

DQM/SiStripMonitorCluster/interface/SiStripMonitorCluster.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class SiStripMonitorCluster : public DQMEDAnalyzer {
132132
void createMEs(const edm::EventSetup& es, DQMStore::IBooker& ibooker);
133133
void createLayerMEs(std::string label, int ndets, DQMStore::IBooker& ibooker);
134134
void createModuleMEs(ModMEs& mod_single, uint32_t detid, DQMStore::IBooker& ibooker, const SiStripDetCabling&);
135-
void createSubDetMEs(std::string label, DQMStore::IBooker& ibooker);
135+
void createSubDetMEs(std::string_view label, DQMStore::IBooker& ibooker);
136136
int FindRegion(int nstrip, int npixel);
137137
void fillModuleMEs(ModMEs& mod_mes, ClusterProperties& cluster);
138138
void fillLayerMEs(LayerMEs&, ClusterProperties& cluster);
@@ -163,7 +163,7 @@ class SiStripMonitorCluster : public DQMEDAnalyzer {
163163
std::map<uint32_t, ModMEs> ModuleMEsMap;
164164
std::map<std::string, LayerMEs> LayerMEsMap;
165165
std::map<std::string, std::vector<uint32_t> > LayerDetMap;
166-
std::map<std::string, SubDetMEs> SubDetMEsMap;
166+
std::map<std::string_view, SubDetMEs> SubDetMEsMap;
167167
std::map<std::string, std::string> SubDetPhasePartMap;
168168

169169
// flags

DQM/SiStripMonitorCluster/src/SiStripMonitorCluster.cc

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void SiStripMonitorCluster::createMEs(const edm::EventSetup& es, DQMStore::IBook
334334
createLayerMEs(label, layerDetIds.size(), ibooker);
335335
}
336336
// book sub-detector plots
337-
auto sdet_pair = folder_organizer.getSubDetFolderAndTag(detid, tTopo);
337+
const auto& sdet_pair = folder_organizer.getSubDetFolderAndTag(detid, tTopo);
338338
if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()) {
339339
ibooker.setCurrentFolder(sdet_pair.first);
340340

@@ -708,9 +708,8 @@ void SiStripMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSe
708708
}
709709
}
710710
// initialise # of clusters to zero
711-
for (std::map<std::string, SubDetMEs>::iterator iSubdet = SubDetMEsMap.begin(); iSubdet != SubDetMEsMap.end();
712-
iSubdet++) {
713-
iSubdet->second.totNClusters = 0;
711+
for (auto& iSubdet : SubDetMEsMap) {
712+
iSubdet.second.totNClusters = 0;
714713
}
715714

716715
SiStripFolderOrganizer folder_organizer;
@@ -904,7 +903,7 @@ void SiStripMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSe
904903
}
905904

906905
if (subdetswitchcluschargeon || subdetswitchcluswidthon) {
907-
std::map<std::string, SubDetMEs>::iterator iSubdet = SubDetMEsMap.find(subdet_label);
906+
const auto& iSubdet = SubDetMEsMap.find(subdet_label);
908907
if (iSubdet != SubDetMEsMap.end()) {
909908
if (subdetswitchcluschargeon and passDCSFilter_)
910909
iSubdet->second.SubDetClusterChargeTH1->Fill(cluster_signal);
@@ -914,7 +913,7 @@ void SiStripMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSe
914913
}
915914

916915
if (subdet_clusterWidth_vs_amplitude_on and passDCSFilter_) {
917-
std::map<std::string, SubDetMEs>::iterator iSubdet = SubDetMEsMap.find(subdet_label);
916+
const auto& iSubdet = SubDetMEsMap.find(subdet_label);
918917
if (iSubdet != SubDetMEsMap.end())
919918
iSubdet->second.SubDetClusWidthVsAmpTH2->Fill(cluster_signal, cluster_width);
920919
}
@@ -932,7 +931,7 @@ void SiStripMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSe
932931
} // end loop over clusters
933932

934933
if (subdetswitchtotclusprofon) {
935-
std::map<std::string, SubDetMEs>::iterator iSubdet = SubDetMEsMap.find(subdet_label);
934+
const auto& iSubdet = SubDetMEsMap.find(subdet_label);
936935
std::pair<std::string, int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid, tTopo);
937936
iSubdet->second.SubDetNumberOfClusterPerLayerTrend->Fill(
938937
trendVar, std::abs(det_layer_pair.second), ncluster_layer);
@@ -966,7 +965,7 @@ void SiStripMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSe
966965
if (subdetswitchtotclusprofon)
967966
fillME(layer_single.LayerNumberOfClusterTrend, trendVar, ncluster_layer);
968967

969-
std::map<std::string, SubDetMEs>::iterator iSubdet = SubDetMEsMap.find(subdet_label);
968+
const auto& iSubdet = SubDetMEsMap.find(subdet_label);
970969
if (iSubdet != SubDetMEsMap.end())
971970
iSubdet->second.totNClusters += ncluster_layer;
972971
} /// end of layer loop
@@ -994,10 +993,10 @@ void SiStripMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSe
994993
}
995994
// plot n 2
996995

997-
for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
998-
std::string sdet = it->first;
996+
for (const auto& it : SubDetMEsMap) {
997+
std::string sdet = std::string(it.first);
999998
// std::string sdet = sdet_tag.substr(0,sdet_tag.find_first_of("_"));
1000-
SubDetMEs sdetmes = it->second;
999+
SubDetMEs sdetmes = it.second;
10011000

10021001
int the_phase = APVCyclePhaseCollection::invalid;
10031002
long long tbx_corr = tbx;
@@ -1358,7 +1357,7 @@ void SiStripMonitorCluster::createLayerMEs(std::string label, int ndets, DQMStor
13581357
//
13591358
// -- Create SubDetector MEs
13601359
//
1361-
void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker& ibooker) {
1360+
void SiStripMonitorCluster::createSubDetMEs(std::string_view label, DQMStore::IBooker& ibooker) {
13621361
SubDetMEs subdetMEs;
13631362
subdetMEs.totNClusters = 0;
13641363
subdetMEs.SubDetTotClusterTH1 = nullptr;
@@ -1373,23 +1372,24 @@ void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker
13731372
subdetMEs.SubDetNumberOfClusterPerLayerTrend = nullptr;
13741373

13751374
std::string HistoName;
1375+
auto slabel = std::string(label);
13761376
// cluster charge
13771377
if (subdetswitchcluschargeon) {
1378-
HistoName = "ClusterCharge__" + label;
1378+
HistoName = "ClusterCharge__" + slabel;
13791379
subdetMEs.SubDetClusterChargeTH1 = bookME1D("TH1ClusterCharge", HistoName.c_str(), ibooker);
13801380
subdetMEs.SubDetClusterChargeTH1->setAxisTitle("Cluster charge [ADC counts]");
13811381
subdetMEs.SubDetClusterChargeTH1->setStatOverflows(kTRUE); // over/underflows in Mean calculation
13821382
}
13831383
// cluster width
13841384
if (subdetswitchcluswidthon) {
1385-
HistoName = "ClusterWidth__" + label;
1385+
HistoName = "ClusterWidth__" + slabel;
13861386
subdetMEs.SubDetClusterWidthTH1 = bookME1D("TH1ClusterWidth", HistoName.c_str(), ibooker);
13871387
subdetMEs.SubDetClusterWidthTH1->setAxisTitle("Cluster width [strips]");
13881388
subdetMEs.SubDetClusterWidthTH1->setStatOverflows(kTRUE); // over/underflows in Mean calculation
13891389
}
13901390
// Total Number of Cluster - 1D
13911391
if (subdetswitchtotclusth1on) {
1392-
HistoName = "TotalNumberOfCluster__" + label;
1392+
HistoName = "TotalNumberOfCluster__" + slabel;
13931393
subdetMEs.SubDetTotClusterTH1 = bookME1D("TH1TotalNumberOfClusters", HistoName.c_str(), ibooker);
13941394
subdetMEs.SubDetTotClusterTH1->setAxisTitle("Total number of clusters in subdetector");
13951395
subdetMEs.SubDetTotClusterTH1->setStatOverflows(kTRUE); // over/underflows in Mean calculation
@@ -1398,7 +1398,7 @@ void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker
13981398
if (subdetswitchtotclusprofon) {
13991399
edm::ParameterSet Parameters = trendVs10Ls_ ? conf_.getParameter<edm::ParameterSet>("TrendingLS")
14001400
: conf_.getParameter<edm::ParameterSet>("Trending");
1401-
HistoName = "TotalNumberOfClusterProfile__" + label;
1401+
HistoName = "TotalNumberOfClusterProfile__" + slabel;
14021402
subdetMEs.SubDetTotClusterProf = ibooker.bookProfile(HistoName,
14031403
HistoName,
14041404
Parameters.getParameter<int32_t>("Nbins"),
@@ -1412,7 +1412,7 @@ void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker
14121412
subdetMEs.SubDetTotClusterProf->setCanExtend(TH1::kAllAxes);
14131413

14141414
Parameters = conf_.getParameter<edm::ParameterSet>("NumberOfClusterPerLayerTrendVar");
1415-
HistoName = "TotalNumberOfClusterPerLayer__" + label;
1415+
HistoName = "TotalNumberOfClusterPerLayer__" + slabel;
14161416
subdetMEs.SubDetNumberOfClusterPerLayerTrend = ibooker.bookProfile2D("NumberOfClusterPerLayerTrendVar",
14171417
HistoName.c_str(),
14181418
Parameters.getParameter<int32_t>("Nbinsx"),
@@ -1431,7 +1431,7 @@ void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker
14311431
// Total Number of Cluster vs APV cycle - Profile
14321432
if (subdetswitchapvcycleprofon) {
14331433
edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TProfClustersApvCycle");
1434-
HistoName = "Cluster_vs_ApvCycle__" + label;
1434+
HistoName = "Cluster_vs_ApvCycle__" + slabel;
14351435
subdetMEs.SubDetClusterApvProf = ibooker.bookProfile(HistoName,
14361436
HistoName,
14371437
Parameters.getParameter<int32_t>("Nbins"),
@@ -1447,17 +1447,17 @@ void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker
14471447
// Total Number of Clusters vs ApvCycle - 2D
14481448
if (subdetswitchapvcycleth2on) {
14491449
edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH2ClustersApvCycle");
1450-
HistoName = "Cluster_vs_ApvCycle_2D__" + label;
1450+
HistoName = "Cluster_vs_ApvCycle_2D__" + slabel;
14511451
// Adjusting the scale for 2D histogram
14521452
double h2ymax = 9999.0;
14531453
double yfact = Parameters.getParameter<double>("yfactor");
1454-
if (label.find("TIB") != std::string::npos)
1454+
if (slabel.find("TIB") != std::string::npos)
14551455
h2ymax = (6984. * 256.) * yfact;
1456-
else if (label.find("TID") != std::string::npos)
1456+
else if (slabel.find("TID") != std::string::npos)
14571457
h2ymax = (2208. * 256.) * yfact;
1458-
else if (label.find("TOB") != std::string::npos)
1458+
else if (slabel.find("TOB") != std::string::npos)
14591459
h2ymax = (12906. * 256.) * yfact;
1460-
else if (label.find("TEC") != std::string::npos)
1460+
else if (slabel.find("TEC") != std::string::npos)
14611461
h2ymax = (7552. * 2. * 256.) * yfact;
14621462

14631463
subdetMEs.SubDetClusterApvTH2 = ibooker.book2D(HistoName,
@@ -1475,7 +1475,7 @@ void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker
14751475
// Cluster widths vs amplitudes - 2D
14761476
if (subdet_clusterWidth_vs_amplitude_on) {
14771477
edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("ClusWidthVsAmpTH2");
1478-
HistoName = "ClusterWidths_vs_Amplitudes__" + label;
1478+
HistoName = "ClusterWidths_vs_Amplitudes__" + slabel;
14791479
subdetMEs.SubDetClusWidthVsAmpTH2 = ibooker.book2D(HistoName,
14801480
HistoName,
14811481
Parameters.getParameter<int32_t>("Nbinsx"),
@@ -1491,7 +1491,7 @@ void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker
14911491
// Total Number of Cluster vs DeltaBxCycle - Profile
14921492
if (subdetswitchdbxcycleprofon) {
14931493
edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TProfClustersVsDBxCycle");
1494-
HistoName = "Cluster_vs_DeltaBxCycle__" + label;
1494+
HistoName = "Cluster_vs_DeltaBxCycle__" + slabel;
14951495
subdetMEs.SubDetClusterDBxCycleProf = ibooker.bookProfile(HistoName,
14961496
HistoName,
14971497
Parameters.getParameter<int32_t>("Nbins"),
@@ -1506,7 +1506,7 @@ void SiStripMonitorCluster::createSubDetMEs(std::string label, DQMStore::IBooker
15061506
// DeltaBx vs ApvCycle - 2DProfile
15071507
if (subdetswitchapvcycledbxprof2on) {
15081508
edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TProf2ApvCycleVsDBx");
1509-
HistoName = "DeltaBx_vs_ApvCycle__" + label;
1509+
HistoName = "DeltaBx_vs_ApvCycle__" + slabel;
15101510
subdetMEs.SubDetApvDBxProf2 = ibooker.bookProfile2D(HistoName,
15111511
HistoName,
15121512
Parameters.getParameter<int32_t>("Nbinsx"),

DQM/SiStripMonitorDigi/interface/SiStripMonitorDigi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SiStripMonitorDigi : public DQMOneEDAnalyzer<edm::LuminosityBlockCache<boo
120120

121121
void createModuleMEs(DQMStore::IBooker& ibooker, ModMEs& mod_single, uint32_t detid);
122122
void createLayerMEs(DQMStore::IBooker& ibooker, std::string label, int ndet);
123-
void createSubDetMEs(DQMStore::IBooker& ibooker, std::string label);
123+
void createSubDetMEs(DQMStore::IBooker& ibooker, std::string_view label);
124124
void createSubDetTH2(DQMStore::IBooker& ibooker, std::string label);
125125
int getDigiSourceIndex(uint32_t id);
126126
void AddApvShotsToSubDet(const std::vector<APVShot>&, std::vector<APVShot>&);
@@ -137,7 +137,7 @@ class SiStripMonitorDigi : public DQMOneEDAnalyzer<edm::LuminosityBlockCache<boo
137137

138138
std::map<std::string, std::vector<uint32_t>> LayerDetMap;
139139
std::map<std::string, LayerMEs> LayerMEsMap;
140-
std::map<std::string, SubDetMEs> SubDetMEsMap;
140+
std::map<std::string_view, SubDetMEs> SubDetMEsMap;
141141
std::map<std::string, std::string> SubDetPhasePartMap;
142142
DigiFailureMEs digiFailureMEs;
143143

0 commit comments

Comments
 (0)