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 std::vector<Alignable*> &alis = selector.selectedAlignables();
180  std::list<Alignable*> selected_alis;
181  for(std::vector<Alignable*>::const_iterator it = alis.begin(); it != alis.end(); ++it) {
182  const std::vector<Alignable*> &aliDaughts = (*it)->deepComponents();
183  for (std::vector<Alignable*>::const_iterator iD = aliDaughts.begin();
184  iD != aliDaughts.end(); ++iD) {
185  if((*iD)->alignableObjectId() == align::AlignableDetUnit || (*iD)->alignableObjectId() == align::AlignableDet) {
186  if(split) {
187  modules_selected = this->createGroup(Id, range, std::list<Alignable*>(1,(*iD)), refrun);
188  } else {
189  selected_alis.push_back((*iD));
190  }
191  }
192  }
193  }
194 
195  if(!split) {
196  modules_selected = this->createGroup(Id, range, selected_alis, refrun);
197  }
198 
200  for(std::vector<edm::RunNumber_t>::const_iterator iRun = range.begin();
201  iRun != range.end(); ++iRun) {
202  localRunRange.insert((*iRun));
203  if((*iRun) > firstRun) {
204  firstRun = (*iRun);
205  } else {
206  throw cms::Exception("BadConfig")
207  << "@SUB=TkModuleGroupSelector::createModuleGroups:"
208  << " Run range not sorted.";
209  }
210  }
211 
212  if(!modules_selected) {
213  throw cms::Exception("BadConfig")
214  << "@SUB=TkModuleGroupSelector:createModuleGroups:"
215  << " No module was selected in the module group selector in group " << (firstId_.size()-1)<< ".";
216  }
217  }
218 
219  //copy local set into the global vector of run boundaries
220  for(std::set<edm::RunNumber_t>::const_iterator itRun = localRunRange.begin();
221  itRun != localRunRange.end(); ++itRun) {
222  globalRunRange_.push_back((*itRun));
223  }
224 }
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 239 of file TkModuleGroupSelector.cc.

References globalRunRange_, and numIovs().

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

240 {
241  return iovNum < this->numIovs() ? globalRunRange_.at(iovNum) : 0;
242 }
std::vector< edm::RunNumber_t > globalRunRange_
unsigned int numIovs() const
Total number of IOVs.
unsigned int TkModuleGroupSelector::getNumberOfParameters ( ) const
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 245 of file TkModuleGroupSelector.cc.

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

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

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