CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TkModuleGroupSelector Class Reference

#include <TkModuleGroupSelector.h>

Public Member Functions

edm::RunNumber_t firstRunOfIOV (unsigned int iovNum) const
 First run of iov (0 if iovNum not treated). More...
 
unsigned int getNumberOfParameters () const
 
int getParameterIndexFromDetId (unsigned int detId, edm::RunNumber_t run) const
 
unsigned int numIovs () const
 Total number of IOVs. More...
 
 TkModuleGroupSelector (AlignableTracker *aliTracker, const edm::ParameterSet &cfg, const std::vector< int > &sdets)
 Constructor. More...
 
virtual ~TkModuleGroupSelector ()
 Destructor. More...
 

Private Member Functions

bool createGroup (unsigned int &Id, const std::vector< edm::RunNumber_t > &range, const std::list< Alignable *> &selected_alis, const edm::RunNumber_t refrun)
 
void createModuleGroups (AlignableTracker *aliTracker, const edm::VParameterSet &granularityConfig, const std::vector< edm::RunNumber_t > &defaultRunRange, edm::RunNumber_t defaultReferenceRun)
 
void fillDetIdMap (const unsigned int detid, const unsigned int groupid)
 
const bool testSplitOption (const edm::ParameterSet &pset) const
 
void verifyParameterNames (const edm::ParameterSet &pset, unsigned int psetnr) const
 

Private Attributes

std::vector< unsigned int > firstId_
 
std::vector< edm::RunNumber_tglobalRunRange_
 
std::map< unsigned int, unsigned int > mapDetIdGroupId_
 
unsigned int nparameters_
 
std::vector< edm::RunNumber_treferenceRun_
 
std::vector< std::vector< edm::RunNumber_t > > runRange_
 
std::vector< int > subdetids_
 

Detailed Description

Definition at line 35 of file TkModuleGroupSelector.h.

Constructor & Destructor Documentation

◆ TkModuleGroupSelector()

TkModuleGroupSelector::TkModuleGroupSelector ( AlignableTracker aliTracker,
const edm::ParameterSet cfg,
const std::vector< int > &  sdets 
)
explicit

Constructor.

Definition at line 22 of file TkModuleGroupSelector.cc.

References looper::cfg, createModuleGroups(), Exception, Skims_PA_cff::name, and AlCaHLTBitMon_QueryRunRegistry::string.

25  : nparameters_(0), subdetids_(sdets) {
26  //verify that all provided options are known
27  std::vector<std::string> parameterNames = cfg.getParameterNames();
28  for (std::vector<std::string>::const_iterator iParam = parameterNames.begin(); iParam != parameterNames.end();
29  ++iParam) {
30  const std::string &name = (*iParam);
31  if (name != "RunRange" && name != "ReferenceRun" && name != "Granularity") {
32  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector::TkModuleGroupSelector:"
33  << " Unknown parameter name '" << name << "' in PSet. Maybe a typo?";
34  }
35  }
36 
37  //extract the reference run range if defined
38  const edm::RunNumber_t defaultReferenceRun =
39  (cfg.exists("ReferenceRun") ? cfg.getParameter<edm::RunNumber_t>("ReferenceRun") : 0);
40 
41  //extract run range to be used for all module groups (if not locally overwritten)
42  const std::vector<edm::RunNumber_t> defaultRunRange =
43  (cfg.exists("RunRange") ? cfg.getParameter<std::vector<edm::RunNumber_t> >("RunRange")
44  : std::vector<edm::RunNumber_t>());
45 
46  // finally create everything from configuration
47  this->createModuleGroups(
48  aliTracker, cfg.getParameter<edm::VParameterSet>("Granularity"), defaultRunRange, defaultReferenceRun);
49 }
std::vector< int > subdetids_
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
void createModuleGroups(AlignableTracker *aliTracker, const edm::VParameterSet &granularityConfig, const std::vector< edm::RunNumber_t > &defaultRunRange, edm::RunNumber_t defaultReferenceRun)
unsigned int RunNumber_t

◆ ~TkModuleGroupSelector()

virtual TkModuleGroupSelector::~TkModuleGroupSelector ( )
inlinevirtual

Destructor.

Definition at line 43 of file TkModuleGroupSelector.h.

43 {};

Member Function Documentation

◆ createGroup()

bool TkModuleGroupSelector::createGroup ( unsigned int &  Id,
const std::vector< edm::RunNumber_t > &  range,
const std::list< Alignable *> &  selected_alis,
const edm::RunNumber_t  refrun 
)
private

Definition at line 74 of file TkModuleGroupSelector.cc.

References Exception, fillDetIdMap(), firstId_, nparameters_, FastTimerService_cff::range, referenceRun_, and runRange_.

Referenced by createModuleGroups().

77  {
78  bool modules_selected = false;
79 
80  referenceRun_.push_back(refrun);
81  firstId_.push_back(Id);
82  runRange_.push_back(range);
83  for (std::list<Alignable *>::const_iterator it = selected_alis.begin(); it != selected_alis.end(); ++it) {
84  this->fillDetIdMap((*it)->id(), firstId_.size() - 1);
85  modules_selected = true;
86  }
87  if (refrun > 0 && !range.empty()) { //FIXME: last condition not really needed?
88  Id += range.size() - 1;
89  nparameters_ += range.size() - 1;
90  } else {
91  Id += range.size();
92  nparameters_ += range.size();
93  }
94 
95  if (refrun > 0 && range.front() > refrun) { //range.size() > 0 checked before
96  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector::createGroup:\n"
97  << "Invalid combination of reference run number and specified run dependence"
98  << "\n in module group " << firstId_.size() << "."
99  << "\n Reference run number (" << refrun << ") is smaller than starting run "
100  << "\n number (" << range.front() << ") of first IOV.";
101  }
102  return modules_selected;
103 }
std::vector< edm::RunNumber_t > referenceRun_
void fillDetIdMap(const unsigned int detid, const unsigned int groupid)
std::vector< std::vector< edm::RunNumber_t > > runRange_
std::vector< unsigned int > firstId_

◆ createModuleGroups()

void TkModuleGroupSelector::createModuleGroups ( AlignableTracker aliTracker,
const edm::VParameterSet granularityConfig,
const std::vector< edm::RunNumber_t > &  defaultRunRange,
edm::RunNumber_t  defaultReferenceRun 
)
private

Definition at line 120 of file TkModuleGroupSelector.cc.

References AlignmentParameterSelector::addSelections(), align::AlignableDet, align::AlignableDetUnit, AlignmentParameterSelector::clear(), createGroup(), Exception, firstId_, dataset::firstRun, globalRunRange_, nparameters_, muonDTDigis_cfi::pset, FastTimerService_cff::range, AlignmentParameterSelector::selectedAlignables(), submitPVValidationJobs::split(), testSplitOption(), and verifyParameterNames().

Referenced by TkModuleGroupSelector().

123  {
124  std::set<edm::RunNumber_t> localRunRange;
125  nparameters_ = 0;
126  unsigned int Id = 0;
127  unsigned int psetnr = 0;
128  //loop over all LA groups
129  for (edm::VParameterSet::const_iterator pset = granularityConfig.begin(); pset != granularityConfig.end(); ++pset) {
130  //test for unknown parameters
131  this->verifyParameterNames((*pset), psetnr);
132  psetnr++;
133 
134  bool modules_selected = false; //track whether at all a module has been selected in this group
135  const std::vector<edm::RunNumber_t> range =
136  ((*pset).exists("RunRange") ? pset->getParameter<std::vector<edm::RunNumber_t> >("RunRange") : defaultRunRange);
137  if (range.empty()) {
138  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector::createModuleGroups:\n"
139  << "Run range array empty!";
140  }
141  const bool split = this->testSplitOption((*pset));
142 
143  edm::RunNumber_t refrun = 0;
144  if ((*pset).exists("ReferenceRun")) {
145  refrun = (*pset).getParameter<edm::RunNumber_t>("ReferenceRun");
146  } else {
147  refrun = defaultReferenceRun;
148  }
149 
150  AlignmentParameterSelector selector(aliTracker);
151  selector.clear();
152  selector.addSelections((*pset).getParameter<edm::ParameterSet>("levels"));
153 
154  const auto &alis = selector.selectedAlignables();
155  std::list<Alignable *> selected_alis;
156  for (const auto &it : alis) {
157  const auto &aliDaughts = it->deepComponents();
158  for (const auto &iD : aliDaughts) {
159  if (iD->alignableObjectId() == align::AlignableDetUnit || iD->alignableObjectId() == align::AlignableDet) {
160  if (split) {
161  modules_selected = this->createGroup(Id, range, std::list<Alignable *>(1, iD), refrun);
162  } else {
163  selected_alis.push_back(iD);
164  }
165  }
166  }
167  }
168 
169  if (!split) {
170  modules_selected = this->createGroup(Id, range, selected_alis, refrun);
171  }
172 
174  for (std::vector<edm::RunNumber_t>::const_iterator iRun = range.begin(); iRun != range.end(); ++iRun) {
175  localRunRange.insert((*iRun));
176  if ((*iRun) > firstRun) {
177  firstRun = (*iRun);
178  } else {
179  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector::createModuleGroups:"
180  << " Run range not sorted.";
181  }
182  }
183 
184  if (!modules_selected) {
185  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector:createModuleGroups:"
186  << " No module was selected in the module group selector in group "
187  << (firstId_.size() - 1) << ".";
188  }
189  }
190 
191  //copy local set into the global vector of run boundaries
192  for (std::set<edm::RunNumber_t>::const_iterator itRun = localRunRange.begin(); itRun != localRunRange.end();
193  ++itRun) {
194  globalRunRange_.push_back((*itRun));
195  }
196 }
bool createGroup(unsigned int &Id, const std::vector< edm::RunNumber_t > &range, const std::list< Alignable *> &selected_alis, const edm::RunNumber_t refrun)
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
std::vector< edm::RunNumber_t > globalRunRange_
firstRun
Definition: dataset.py:940
unsigned int RunNumber_t
const bool testSplitOption(const edm::ParameterSet &pset) const
std::vector< unsigned int > firstId_

◆ fillDetIdMap()

void TkModuleGroupSelector::fillDetIdMap ( const unsigned int  detid,
const unsigned int  groupid 
)
private

Definition at line 52 of file TkModuleGroupSelector.cc.

References Exception, and mapDetIdGroupId_.

Referenced by createGroup().

52  {
53  //only add new entries
54  if (mapDetIdGroupId_.find(detid) == mapDetIdGroupId_.end()) {
55  mapDetIdGroupId_.insert(std::pair<unsigned int, unsigned int>(detid, groupid));
56  } else {
57  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector:fillDetIdMap:"
58  << " Module with det ID " << detid << " configured in group " << groupid
59  << " but it was already selected"
60  << " in group " << mapDetIdGroupId_[detid] << ".";
61  }
62 }
std::map< unsigned int, unsigned int > mapDetIdGroupId_

◆ firstRunOfIOV()

edm::RunNumber_t TkModuleGroupSelector::firstRunOfIOV ( unsigned int  iovNum) const

First run of iov (0 if iovNum not treated).

Definition at line 205 of file TkModuleGroupSelector.cc.

References globalRunRange_, and numIovs().

Referenced by SiStripBackplaneCalibration::endOfJob(), and SiStripBackplaneCalibration::writeTree().

205  {
206  return iovNum < this->numIovs() ? globalRunRange_.at(iovNum) : 0;
207 }
unsigned int numIovs() const
Total number of IOVs.
std::vector< edm::RunNumber_t > globalRunRange_

◆ getNumberOfParameters()

unsigned int TkModuleGroupSelector::getNumberOfParameters ( ) const

Definition at line 199 of file TkModuleGroupSelector.cc.

References nparameters_.

Referenced by SiStripBackplaneCalibration::beginOfJob().

199 { return nparameters_; }

◆ getParameterIndexFromDetId()

int TkModuleGroupSelector::getParameterIndexFromDetId ( unsigned int  detId,
edm::RunNumber_t  run 
) const

Index of parameter for given detId (detId not treated => < 0) and the given run.

Definition at line 210 of file TkModuleGroupSelector.cc.

References DetId::det(), hcalRecHitTable_cff::detId, Exception, firstId_, mapDetIdGroupId_, referenceRun_, writedatasetfile::run, runRange_, writedatasetfile::runs, EgammaValidation_Wenu_cff::sel, DetId::subdetId(), subdetids_, and DetId::Tracker.

Referenced by SiStripBackplaneCalibration::derivatives(), SiStripBackplaneCalibration::endOfJob(), SiStripBackplaneCalibration::getParameterForDetId(), and SiStripBackplaneCalibration::writeTree().

210  {
211  // Return the index of the parameter that is used for this DetId.
212  // If this DetId is not treated, return values < 0.
213 
214  const DetId temp_id(detId);
215 
216  int index = -1;
217 
218  bool sel = false;
219  for (std::vector<int>::const_iterator itSubDets = subdetids_.begin(); itSubDets != subdetids_.end(); ++itSubDets) {
220  if (temp_id.det() == DetId::Tracker && temp_id.subdetId() == (*itSubDets)) {
221  sel = true;
222  break;
223  }
224  }
225 
226  if (temp_id.det() != DetId::Tracker || !sel)
227  return -1;
228 
229  std::map<unsigned int, unsigned int>::const_iterator it = mapDetIdGroupId_.find(detId);
230  if (it != mapDetIdGroupId_.end()) {
231  const unsigned int iAlignableGroup = (*it).second;
232  const std::vector<edm::RunNumber_t> &runs = runRange_.at(iAlignableGroup);
233  const unsigned int id0 = firstId_.at(iAlignableGroup);
234  const edm::RunNumber_t refrun = referenceRun_.at(iAlignableGroup);
235 
236  unsigned int iovNum = 0;
237  for (; iovNum < runs.size(); ++iovNum) {
238  if (runs[iovNum] > run)
239  break;
240  }
241  if (iovNum == 0) {
242  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector::getParameterIndexFromDetId:\n"
243  << "Run " << run << " not foreseen for detid '" << detId << "'"
244  << " in module group " << iAlignableGroup << ".";
245  } else {
246  --iovNum;
247  }
248 
249  //test whether the iov contains the reference run
250  if (refrun > 0) { //if > 0 a reference run number has been provided
251  if (iovNum + 1 == runs.size()) {
252  if (refrun >= runs[iovNum])
253  return -1;
254  } else if ((iovNum + 1) < runs.size()) {
255  if (refrun >= runs[iovNum] && refrun < runs[iovNum + 1]) {
256  return -1;
257  }
258  }
259  if (run > refrun) {
260  //iovNum > 0 due to checks in createGroup(...) and createModuleGroups(...)
261  //remove IOV in which the reference run can be found
262  iovNum -= 1;
263  }
264  }
265 
266  index = id0 + iovNum;
267  }
268  return index;
269 }
std::vector< int > subdetids_
std::vector< edm::RunNumber_t > referenceRun_
std::map< unsigned int, unsigned int > mapDetIdGroupId_
std::vector< std::vector< edm::RunNumber_t > > runRange_
Definition: DetId.h:17
unsigned int RunNumber_t
std::vector< unsigned int > firstId_

◆ numIovs()

unsigned int TkModuleGroupSelector::numIovs ( ) const

Total number of IOVs.

Definition at line 202 of file TkModuleGroupSelector.cc.

References globalRunRange_.

Referenced by SiStripBackplaneCalibration::beginOfJob(), SiStripBackplaneCalibration::endOfJob(), and firstRunOfIOV().

202 { return globalRunRange_.size(); }
std::vector< edm::RunNumber_t > globalRunRange_

◆ testSplitOption()

const bool TkModuleGroupSelector::testSplitOption ( const edm::ParameterSet pset) const
private

Definition at line 65 of file TkModuleGroupSelector.cc.

References muonDTDigis_cfi::pset, and submitPVValidationJobs::split().

Referenced by createModuleGroups().

65  {
66  bool split = false;
67  if (pset.exists("split")) {
68  split = pset.getParameter<bool>("split");
69  }
70  return split;
71 }

◆ verifyParameterNames()

void TkModuleGroupSelector::verifyParameterNames ( const edm::ParameterSet pset,
unsigned int  psetnr 
) const
private

Definition at line 106 of file TkModuleGroupSelector.cc.

References Exception, Skims_PA_cff::name, muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by createModuleGroups().

106  {
107  std::vector<std::string> parameterNames = pset.getParameterNames();
108  for (std::vector<std::string>::const_iterator iParam = parameterNames.begin(); iParam != parameterNames.end();
109  ++iParam) {
110  const std::string &name = (*iParam);
111  if (name != "levels" && name != "RunRange" && name != "split" && name != "ReferenceRun") {
112  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector::verifyParameterNames:"
113  << " Unknown parameter name '" << name << "' in PSet number " << psetnr
114  << ". Maybe a typo?";
115  }
116  }
117 }

Member Data Documentation

◆ firstId_

std::vector<unsigned int> TkModuleGroupSelector::firstId_
private

◆ globalRunRange_

std::vector<edm::RunNumber_t> TkModuleGroupSelector::globalRunRange_
private

Definition at line 84 of file TkModuleGroupSelector.h.

Referenced by createModuleGroups(), firstRunOfIOV(), and numIovs().

◆ mapDetIdGroupId_

std::map<unsigned int, unsigned int> TkModuleGroupSelector::mapDetIdGroupId_
private

Definition at line 93 of file TkModuleGroupSelector.h.

Referenced by fillDetIdMap(), and getParameterIndexFromDetId().

◆ nparameters_

unsigned int TkModuleGroupSelector::nparameters_
private

Definition at line 96 of file TkModuleGroupSelector.h.

Referenced by createGroup(), createModuleGroups(), and getNumberOfParameters().

◆ referenceRun_

std::vector<edm::RunNumber_t> TkModuleGroupSelector::referenceRun_
private

Definition at line 102 of file TkModuleGroupSelector.h.

Referenced by createGroup(), and getParameterIndexFromDetId().

◆ runRange_

std::vector<std::vector<edm::RunNumber_t> > TkModuleGroupSelector::runRange_
private

Definition at line 90 of file TkModuleGroupSelector.h.

Referenced by createGroup(), and getParameterIndexFromDetId().

◆ subdetids_

std::vector<int> TkModuleGroupSelector::subdetids_
private

Definition at line 99 of file TkModuleGroupSelector.h.

Referenced by getParameterIndexFromDetId().