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 33 of file TkModuleGroupSelector.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 22 of file TkModuleGroupSelector.cc.

References createModuleGroups(), Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Destructor.

Definition at line 42 of file TkModuleGroupSelector.h.

References muonDTDigis_cfi::pset, and findQualityFiles::run.

42 {};

Member Function Documentation

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 83 of file TkModuleGroupSelector.cc.

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

Referenced by createModuleGroups().

89 {
90  bool modules_selected = false;
91 
92  referenceRun_.push_back(refrun);
93  firstId_.push_back(Id);
94  runRange_.push_back(range);
95  for(std::list<Alignable*>::const_iterator it = selected_alis.begin();
96  it != selected_alis.end(); ++it) {
97  this->fillDetIdMap((*it)->id(), firstId_.size()-1);
98  modules_selected = true;
99  }
100  if(refrun > 0 && !range.empty()) { //FIXME: last condition not really needed?
101  Id += range.size() - 1;
102  nparameters_ += range.size() - 1;
103  } else {
104  Id += range.size();
105  nparameters_ += range.size();
106  }
107 
108  if(refrun > 0 && range.front() > refrun) { //range.size() > 0 checked before
109  throw cms::Exception("BadConfig")
110  << "@SUB=TkModuleGroupSelector::createGroup:\n"
111  << "Invalid combination of reference run number and specified run dependence"
112  << "\n in module group " << firstId_.size() << "."
113  << "\n Reference run number (" << refrun << ") is smaller than starting run "
114  << "\n number (" << range.front() << ") of first IOV.";
115  }
116  return modules_selected;
117 }
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_
void TkModuleGroupSelector::createModuleGroups ( AlignableTracker aliTracker,
const edm::VParameterSet granularityConfig,
const std::vector< edm::RunNumber_t > &  defaultRunRange,
edm::RunNumber_t  defaultReferenceRun 
)
private

Definition at line 139 of file TkModuleGroupSelector.cc.

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

Referenced by TkModuleGroupSelector().

143 {
144  std::set<edm::RunNumber_t> localRunRange;
145  nparameters_ = 0;
146  unsigned int Id = 0;
147  unsigned int psetnr = 0;
148  //loop over all LA groups
149  for(edm::VParameterSet::const_iterator pset = granularityConfig.begin();
150  pset != granularityConfig.end();
151  ++pset) {
152 
153  //test for unknown parameters
154  this->verifyParameterNames((*pset),psetnr);
155  psetnr++;
156 
157  bool modules_selected = false; //track whether at all a module has been selected in this group
158  const std::vector<edm::RunNumber_t> range =
159  ((*pset).exists("RunRange") ? pset->getParameter<std::vector<edm::RunNumber_t> >("RunRange")
160  : defaultRunRange);
161  if(range.empty()) {
162  throw cms::Exception("BadConfig")
163  << "@SUB=TkModuleGroupSelector::createModuleGroups:\n"
164  << "Run range array empty!";
165  }
166  const bool split = this->testSplitOption((*pset));
167 
168  edm::RunNumber_t refrun = 0;
169  if((*pset).exists("ReferenceRun")) {
170  refrun = (*pset).getParameter<edm::RunNumber_t>("ReferenceRun");
171  } else {
172  refrun = defaultReferenceRun;
173  }
174 
175  AlignmentParameterSelector selector(aliTracker);
176  selector.clear();
177  selector.addSelections((*pset).getParameter<edm::ParameterSet> ("levels"));
178 
179  const auto& alis = selector.selectedAlignables();
180  std::list<Alignable*> selected_alis;
181  for(const auto& it: alis) {
182  const auto& aliDaughts = it->deepComponents();
183  for (const auto& iD: aliDaughts) {
184  if(iD->alignableObjectId() == align::AlignableDetUnit || iD->alignableObjectId() == align::AlignableDet) {
185  if(split) {
186  modules_selected = this->createGroup(Id, range, std::list<Alignable*>(1,iD), refrun);
187  } else {
188  selected_alis.push_back(iD);
189  }
190  }
191  }
192  }
193 
194  if(!split) {
195  modules_selected = this->createGroup(Id, range, selected_alis, refrun);
196  }
197 
199  for(std::vector<edm::RunNumber_t>::const_iterator iRun = range.begin();
200  iRun != range.end(); ++iRun) {
201  localRunRange.insert((*iRun));
202  if((*iRun) > firstRun) {
203  firstRun = (*iRun);
204  } else {
205  throw cms::Exception("BadConfig")
206  << "@SUB=TkModuleGroupSelector::createModuleGroups:"
207  << " Run range not sorted.";
208  }
209  }
210 
211  if(!modules_selected) {
212  throw cms::Exception("BadConfig")
213  << "@SUB=TkModuleGroupSelector:createModuleGroups:"
214  << " No module was selected in the module group selector in group " << (firstId_.size()-1)<< ".";
215  }
216  }
217 
218  //copy local set into the global vector of run boundaries
219  for(std::set<edm::RunNumber_t>::const_iterator itRun = localRunRange.begin();
220  itRun != localRunRange.end(); ++itRun) {
221  globalRunRange_.push_back((*itRun));
222  }
223 }
std::vector< edm::RunNumber_t > globalRunRange_
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
const bool testSplitOption(const edm::ParameterSet &pset) const
bool createGroup(unsigned int &Id, const std::vector< edm::RunNumber_t > &range, const std::list< Alignable * > &selected_alis, const edm::RunNumber_t refrun)
firstRun
Definition: dataset.py:933
unsigned int RunNumber_t
std::vector< unsigned int > firstId_
double split
Definition: MVATrainer.cc:139
void TkModuleGroupSelector::fillDetIdMap ( const unsigned int  detid,
const unsigned int  groupid 
)
private

Definition at line 58 of file TkModuleGroupSelector.cc.

References Exception, and mapDetIdGroupId_.

Referenced by createGroup().

59 {
60  //only add new entries
61  if(mapDetIdGroupId_.find(detid) == mapDetIdGroupId_.end()) {
62  mapDetIdGroupId_.insert(std::pair<unsigned int, unsigned int>(detid, groupid));
63  } else {
64  throw cms::Exception("BadConfig")
65  << "@SUB=TkModuleGroupSelector:fillDetIdMap:"
66  << " Module with det ID " << detid << " configured in group " << groupid
67  << " but it was already selected"
68  << " in group " << mapDetIdGroupId_[detid] << ".";
69  }
70 }
std::map< unsigned int, unsigned int > mapDetIdGroupId_
edm::RunNumber_t TkModuleGroupSelector::firstRunOfIOV ( unsigned int  iovNum) const

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

Definition at line 238 of file TkModuleGroupSelector.cc.

References globalRunRange_, and numIovs().

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

239 {
240  return iovNum < this->numIovs() ? globalRunRange_.at(iovNum) : 0;
241 }
std::vector< edm::RunNumber_t > globalRunRange_
unsigned int numIovs() const
Total number of IOVs.
unsigned int TkModuleGroupSelector::getNumberOfParameters ( ) const

Definition at line 226 of file TkModuleGroupSelector.cc.

References nparameters_.

Referenced by SiStripBackplaneCalibration::beginOfJob().

227 {
228  return nparameters_;
229 }
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 244 of file TkModuleGroupSelector.cc.

References DetId::det(), Exception, firstId_, mapDetIdGroupId_, referenceRun_, runRange_, gather_cfg::runs, triggerObjects_cff::sel, DetId::subdetId(), subdetids_, and DetId::Tracker.

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

246 {
247  // Return the index of the parameter that is used for this DetId.
248  // If this DetId is not treated, return values < 0.
249 
250  const DetId temp_id(detId);
251 
252  int index = -1;
253 
254  bool sel = false;
255  for(std::vector<int>::const_iterator itSubDets = subdetids_.begin();
256  itSubDets != subdetids_.end();
257  ++itSubDets) {
258  if (temp_id.det() == DetId::Tracker && temp_id.subdetId() == (*itSubDets)) {
259  sel = true;
260  break;
261  }
262  }
263 
264  if (temp_id.det() != DetId::Tracker || !sel) return -1;
265 
266  std::map<unsigned int, unsigned int>::const_iterator it = mapDetIdGroupId_.find(detId);
267  if(it != mapDetIdGroupId_.end()) {
268  const unsigned int iAlignableGroup = (*it).second;
269  const std::vector<edm::RunNumber_t> &runs = runRange_.at(iAlignableGroup);
270  const unsigned int id0 = firstId_.at(iAlignableGroup);
271  const edm::RunNumber_t refrun = referenceRun_.at(iAlignableGroup);
272 
273 
274  unsigned int iovNum = 0;
275  for ( ; iovNum < runs.size(); ++iovNum) {
276  if (runs[iovNum] > run) break;
277  }
278  if (iovNum == 0) {
279  throw cms::Exception("BadConfig") << "@SUB=TkModuleGroupSelector::getParameterIndexFromDetId:\n"
280  << "Run " << run << " not foreseen for detid '"<< detId <<"'"
281  << " in module group " << iAlignableGroup << ".";
282  } else {
283  --iovNum;
284  }
285 
286  //test whether the iov contains the reference run
287  if(refrun > 0) { //if > 0 a reference run number has been provided
288  if(iovNum+1 == runs.size()) {
289  if(refrun >= runs[iovNum])
290  return -1;
291  } else if( (iovNum+1) < runs.size()) {
292  if(refrun >= runs[iovNum] && refrun < runs[iovNum+1]) {
293  return -1;
294  }
295  }
296  if(run > refrun) {
297  //iovNum > 0 due to checks in createGroup(...) and createModuleGroups(...)
298  //remove IOV in which the reference run can be found
299  iovNum -= 1;
300  }
301  }
302 
303  index = id0 + iovNum;
304  }
305  return index;
306 }
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:18
unsigned int RunNumber_t
std::vector< unsigned int > firstId_
unsigned int TkModuleGroupSelector::numIovs ( ) const

Total number of IOVs.

Definition at line 232 of file TkModuleGroupSelector.cc.

References globalRunRange_.

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

233 {
234  return globalRunRange_.size();
235 }
std::vector< edm::RunNumber_t > globalRunRange_
const bool TkModuleGroupSelector::testSplitOption ( const edm::ParameterSet pset) const
private

Definition at line 73 of file TkModuleGroupSelector.cc.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), and split.

Referenced by createModuleGroups().

74 {
75  bool split = false;
76  if(pset.exists("split")) {
77  split = pset.getParameter<bool>("split");
78  }
79  return split;
80 }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
double split
Definition: MVATrainer.cc:139
void TkModuleGroupSelector::verifyParameterNames ( const edm::ParameterSet pset,
unsigned int  psetnr 
) const
private

Definition at line 120 of file TkModuleGroupSelector.cc.

References Exception, edm::ParameterSet::getParameterNames(), dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by createModuleGroups().

121 {
122  std::vector<std::string> parameterNames = pset.getParameterNames();
123  for ( std::vector<std::string>::const_iterator iParam = parameterNames.begin();
124  iParam != parameterNames.end(); ++iParam) {
125  const std::string name = (*iParam);
126  if(
127  name != "levels" && name != "RunRange"
128  && name != "split" && name != "ReferenceRun"
129  ) {
130  throw cms::Exception("BadConfig")
131  << "@SUB=TkModuleGroupSelector::verifyParameterNames:"
132  << " Unknown parameter name '" << name << "' in PSet number " << psetnr << ". Maybe a typo?";
133  }
134  }
135 }
std::vector< std::string > getParameterNames() const

Member Data Documentation

std::vector<unsigned int> TkModuleGroupSelector::firstId_
private
std::vector<edm::RunNumber_t> TkModuleGroupSelector::globalRunRange_
private

Definition at line 84 of file TkModuleGroupSelector.h.

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

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

Definition at line 93 of file TkModuleGroupSelector.h.

Referenced by fillDetIdMap(), and getParameterIndexFromDetId().

unsigned int TkModuleGroupSelector::nparameters_
private

Definition at line 96 of file TkModuleGroupSelector.h.

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

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

Definition at line 102 of file TkModuleGroupSelector.h.

Referenced by createGroup(), and getParameterIndexFromDetId().

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

Definition at line 90 of file TkModuleGroupSelector.h.

Referenced by createGroup(), and getParameterIndexFromDetId().

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

Definition at line 99 of file TkModuleGroupSelector.h.

Referenced by getParameterIndexFromDetId().