CMS 3D CMS Logo

TkModuleGroupSelector.cc
Go to the documentation of this file.
1 
16 
17 #include <vector>
18 #include <map>
19 #include <set>
20 
21 //============================================================================
23  const edm::ParameterSet &cfg,
24  const std::vector<int> &sdets)
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 }
50 
51 //============================================================================
52 void TkModuleGroupSelector::fillDetIdMap(const unsigned int detid, const unsigned int groupid) {
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 }
63 
64 //============================================================================
66  bool split = false;
67  if (pset.exists("split")) {
68  split = pset.getParameter<bool>("split");
69  }
70  return split;
71 }
72 
73 //============================================================================
74 bool TkModuleGroupSelector::createGroup(unsigned int &Id,
75  const std::vector<edm::RunNumber_t> &range,
76  const std::list<Alignable *> &selected_alis,
77  const edm::RunNumber_t refrun) {
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 }
104 
105 //============================================================================
106 void TkModuleGroupSelector::verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const {
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 }
118 
119 //============================================================================
121  const edm::VParameterSet &granularityConfig,
122  const std::vector<edm::RunNumber_t> &defaultRunRange,
123  edm::RunNumber_t defaultReferenceRun) {
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 }
197 
198 //============================================================================
200 
201 //============================================================================
202 unsigned int TkModuleGroupSelector::numIovs() const { return globalRunRange_.size(); }
203 
204 //============================================================================
206  return iovNum < this->numIovs() ? globalRunRange_.at(iovNum) : 0;
207 }
208 
209 //======================================================================
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 }
TkModuleGroupSelector::globalRunRange_
std::vector< edm::RunNumber_t > globalRunRange_
Definition: TkModuleGroupSelector.h:84
dataset.firstRun
firstRun
Definition: dataset.py:940
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
MessageLogger.h
AlignmentParameterSelector.h
TkModuleGroupSelector::getParameterIndexFromDetId
int getParameterIndexFromDetId(unsigned int detId, edm::RunNumber_t run) const
Definition: TkModuleGroupSelector.cc:210
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
TkModuleGroupSelector::runRange_
std::vector< std::vector< edm::RunNumber_t > > runRange_
Definition: TkModuleGroupSelector.h:90
writedatasetfile.runs
runs
Definition: writedatasetfile.py:27
TkModuleGroupSelector::firstId_
std::vector< unsigned int > firstId_
Definition: TkModuleGroupSelector.h:87
edm::VParameterSet
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
TkModuleGroupSelector::firstRunOfIOV
edm::RunNumber_t firstRunOfIOV(unsigned int iovNum) const
First run of iov (0 if iovNum not treated).
Definition: TkModuleGroupSelector.cc:205
AlignmentParameterSelector::selectedAlignables
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
Definition: AlignmentParameterSelector.h:37
DetId
Definition: DetId.h:17
TkModuleGroupSelector::numIovs
unsigned int numIovs() const
Total number of IOVs.
Definition: TkModuleGroupSelector.cc:202
TkModuleGroupSelector::TkModuleGroupSelector
TkModuleGroupSelector(AlignableTracker *aliTracker, const edm::ParameterSet &cfg, const std::vector< int > &sdets)
Constructor.
Definition: TkModuleGroupSelector.cc:22
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
AlignableTracker
Definition: AlignableTracker.h:17
AlignmentParameterSelector::clear
void clear()
remove all selected Alignables and geometrical restrictions
Definition: AlignmentParameterSelector.cc:41
TkModuleGroupSelector::createGroup
bool createGroup(unsigned int &Id, const std::vector< edm::RunNumber_t > &range, const std::list< Alignable * > &selected_alis, const edm::RunNumber_t refrun)
Definition: TkModuleGroupSelector.cc:74
TkModuleGroupSelector::referenceRun_
std::vector< edm::RunNumber_t > referenceRun_
Definition: TkModuleGroupSelector.h:102
TkModuleGroupSelector::fillDetIdMap
void fillDetIdMap(const unsigned int detid, const unsigned int groupid)
Definition: TkModuleGroupSelector.cc:52
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TkModuleGroupSelector.h
align::AlignableDetUnit
Definition: StructureType.h:19
edm::ParameterSet
Definition: ParameterSet.h:47
DetId::Tracker
Definition: DetId.h:25
TkModuleGroupSelector::nparameters_
unsigned int nparameters_
Definition: TkModuleGroupSelector.h:96
TkModuleGroupSelector::mapDetIdGroupId_
std::map< unsigned int, unsigned int > mapDetIdGroupId_
Definition: TkModuleGroupSelector.h:93
looper.cfg
cfg
Definition: looper.py:297
TkModuleGroupSelector::createModuleGroups
void createModuleGroups(AlignableTracker *aliTracker, const edm::VParameterSet &granularityConfig, const std::vector< edm::RunNumber_t > &defaultRunRange, edm::RunNumber_t defaultReferenceRun)
Definition: TkModuleGroupSelector.cc:120
align::AlignableDet
Definition: StructureType.h:20
writedatasetfile.run
run
Definition: writedatasetfile.py:27
AlignmentParameterSelector::addSelections
unsigned int addSelections(const edm::ParameterSet &pSet)
Definition: AlignmentParameterSelector.cc:67
DetId.h
TkModuleGroupSelector::subdetids_
std::vector< int > subdetids_
Definition: TkModuleGroupSelector.h:99
Exception
Definition: hltDiff.cc:246
Alignable.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
AlignmentParameterSelector
Definition: AlignmentParameterSelector.h:26
TkModuleGroupSelector::getNumberOfParameters
unsigned int getNumberOfParameters() const
Definition: TkModuleGroupSelector.cc:199
TkModuleGroupSelector::verifyParameterNames
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
Definition: TkModuleGroupSelector.cc:106
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
TkModuleGroupSelector::testSplitOption
const bool testSplitOption(const edm::ParameterSet &pset) const
Definition: TkModuleGroupSelector.cc:65