CMS 3D CMS Logo

AlignPCLThresholdsWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondFormats/PCLConfig
4 // Class: AlignPCLThresholdsWriter
5 //
11 //
12 // Original Author: Marco Musich
13 // Created: Wed, 22 Feb 2017 12:04:36 GMT
14 //
15 //
16 
17 // system include files
18 #include <memory>
19 
20 // user include files
23 
26 
31 
32 //
33 // class declaration
34 //
35 
36 namespace DOFs {
37  enum dof { X, Y, Z, thetaX, thetaY, thetaZ, extraDOF };
38 }
39 
41 public:
43  ~AlignPCLThresholdsWriter() override;
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47 private:
48  void beginJob() override;
49  void analyze(const edm::Event&, const edm::EventSetup&) override;
50  void endJob() override;
52 
53  // ----------member data ---------------------------
55  const unsigned int m_minNrecords;
56  const std::vector<edm::ParameterSet> m_parameters;
58 };
59 
60 //
61 // constructors and destructor
62 //
64  : m_record(iConfig.getParameter<std::string>("record")),
65  m_minNrecords(iConfig.getParameter<unsigned int>("minNRecords")),
66  m_parameters(iConfig.getParameter<std::vector<edm::ParameterSet> >("thresholds")) {
67  //now do what ever initialization is needed
69 }
70 
72 
73 //
74 // member functions
75 //
76 
77 // ------------ method called for each event ------------
79  using namespace edm;
80 
81  edm::LogInfo("AlignPCLThresholdsWriter") << "Size of AlignPCLThresholds object " << myThresholds->size() << std::endl
82  << std::endl;
83 
84  // loop on the PSet and insert the conditions
85 
86  std::array<std::string, 6> mandatories = {{"X", "Y", "Z", "thetaX", "thetaY", "thetaZ"}};
87  std::vector<std::string> alignables;
88 
89  // fill the list of alignables
90  for (auto& thePSet : m_parameters) {
91  const std::string alignableId(thePSet.getParameter<std::string>("alignableId"));
92  // only if it is not yet in the list
93  if (std::find(alignables.begin(), alignables.end(), alignableId) == alignables.end()) {
94  alignables.push_back(alignableId);
95  }
96  }
97 
98  for (auto& alignable : alignables) {
105 
106  std::vector<std::string> presentDOF;
107 
108  // extra degrees of freedom
109  std::vector<AlignPCLThreshold::coordThresholds> extraDOFs = std::vector<AlignPCLThreshold::coordThresholds>();
110 
111  for (auto& thePSet : m_parameters) {
112  const std::string alignableId(thePSet.getParameter<std::string>("alignableId"));
113  const std::string DOF(thePSet.getParameter<std::string>("DOF"));
114 
115  const double cutoff(thePSet.getParameter<double>("cut"));
116  const double sigCut(thePSet.getParameter<double>("sigCut"));
117  const double maxMoveCut(thePSet.getParameter<double>("maxMoveCut"));
118  const double maxErrorCut(thePSet.getParameter<double>("maxErrorCut"));
119 
120  if (alignableId == alignable) {
121  presentDOF.push_back(DOF);
122  // create the objects
123 
124  switch (mapOntoEnum(DOF)) {
125  case DOFs::X:
126  my_X.setThresholds(cutoff, sigCut, maxErrorCut, maxMoveCut, DOF);
127  break;
128  case DOFs::Y:
129  my_Y.setThresholds(cutoff, sigCut, maxErrorCut, maxMoveCut, DOF);
130  break;
131  case DOFs::Z:
132  my_Z.setThresholds(cutoff, sigCut, maxErrorCut, maxMoveCut, DOF);
133  break;
134  case DOFs::thetaX:
135  my_tX.setThresholds(cutoff, sigCut, maxErrorCut, maxMoveCut, DOF);
136  break;
137  case DOFs::thetaY:
138  my_tY.setThresholds(cutoff, sigCut, maxErrorCut, maxMoveCut, DOF);
139  break;
140  case DOFs::thetaZ:
141  my_tZ.setThresholds(cutoff, sigCut, maxErrorCut, maxMoveCut, DOF);
142  break;
143  default:
144  edm::LogInfo("AlignPCLThresholdsWriter")
145  << "Appending Extra degree of freeedom: " << DOF << " " << mapOntoEnum(DOF) << std::endl;
147  ExtraDOF.setThresholds(cutoff, sigCut, maxErrorCut, maxMoveCut, DOF);
148  extraDOFs.push_back(ExtraDOF);
149  }
150 
151  AlignPCLThreshold a(my_X, my_tX, my_Y, my_tY, my_Z, my_tZ, extraDOFs);
152  myThresholds->setAlignPCLThreshold(alignableId, a);
153 
154  } // if alignable is found in the PSet
155  } // loop on the PSets
156 
157  // checks if all mandatories are present
158  edm::LogInfo("AlignPCLThresholdsWriter")
159  << "Size of AlignPCLThresholds object " << myThresholds->size() << std::endl;
160  for (auto& mandatory : mandatories) {
161  if (std::find(presentDOF.begin(), presentDOF.end(), mandatory) == presentDOF.end()) {
162  edm::LogWarning("AlignPCLThresholdsWriter")
163  << "Configuration for DOF: " << mandatory << " for alignable " << alignable << "is not present \n"
164  << "Will build object with defaults!" << std::endl;
165  }
166  }
167 
168  } // ends loop on the alignable units
169 
170  // set the minimum number of records to be used in pede
172  edm::LogInfo("AlignPCLThresholdsWriter") << "Content of AlignPCLThresholds " << std::endl;
173 
174  // use buil-in method in the CondFormat
176 
177  // Form the data here
179  if (poolDbService.isAvailable()) {
180  cond::Time_t valid_time = poolDbService->currentTime();
181  // this writes the payload to begin in current run defined in cfg
182  poolDbService->writeOne(myThresholds, valid_time, m_record);
183  }
184 }
185 
186 // ------------ method called once each job just before starting event loop ------------
188 
189 // ------------ method called once each job just after ending the event loop ------------
191 
193  if (coord == "X") {
194  return DOFs::X;
195  } else if (coord == "Y") {
196  return DOFs::Y;
197  } else if (coord == "Z") {
198  return DOFs::Z;
199  } else if (coord == "thetaX") {
200  return DOFs::thetaX;
201  } else if (coord == "thetaY") {
202  return DOFs::thetaY;
203  } else if (coord == "thetaZ") {
204  return DOFs::thetaZ;
205  } else {
206  return DOFs::extraDOF;
207  }
208 }
209 
210 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
213  desc.setUnknown();
214  descriptions.addDefault(desc);
215 }
216 
217 //define this as a plug-in
AlignPCLThresholdsWriter::m_minNrecords
const unsigned int m_minNrecords
Definition: AlignPCLThresholdsWriter.cc:55
EDAnalyzer.h
DOFs::dof
dof
Definition: AlignPCLThresholdsWriter.cc:37
AlignPCLThresholds::printAll
void printAll() const
Definition: AlignPCLThresholds.cc:182
edm
HLT enums.
Definition: AlignableModifier.h:19
AlignPCLThreshold
Definition: AlignPCLThreshold.h:6
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
AlignPCLThresholds::setNRecords
void setNRecords(const int &Nrecords)
Definition: AlignPCLThresholds.cc:20
AlignPCLThresholds
Definition: AlignPCLThresholds.h:11
AlignPCLThresholdsWriter::myThresholds
AlignPCLThresholds * myThresholds
Definition: AlignPCLThresholdsWriter.cc:57
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
AlignPCLThresholdsWriter::m_record
const std::string m_record
Definition: AlignPCLThresholdsWriter.cc:54
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
AlignPCLThresholdsWriter::mapOntoEnum
DOFs::dof mapOntoEnum(std::string coord)
Definition: AlignPCLThresholdsWriter.cc:192
MakerMacros.h
PoolDBOutputService.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
DOFs::extraDOF
Definition: AlignPCLThresholdsWriter.cc:37
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlignPCLThresholdsWriter
Definition: AlignPCLThresholdsWriter.cc:40
AlignPCLThresholds::setAlignPCLThreshold
void setAlignPCLThreshold(const std::string &AlignableId, const AlignPCLThreshold &Threshold)
Definition: AlignPCLThresholds.cc:9
AlignPCLThresholdsWriter::beginJob
void beginJob() override
Definition: AlignPCLThresholdsWriter.cc:187
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
AlignPCLThresholds.h
AlignPCLThresholdsWriter::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: AlignPCLThresholdsWriter.cc:211
Event.h
ParameterSet
Definition: Functions.h:16
DOFs::X
Definition: AlignPCLThresholdsWriter.cc:37
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
edm::Service< cond::service::PoolDBOutputService >
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
HLT_FULL_cff.sigCut
sigCut
Definition: HLT_FULL_cff.py:51991
DOFs::Z
Definition: AlignPCLThresholdsWriter.cc:37
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
DOFs::thetaY
Definition: AlignPCLThresholdsWriter.cc:37
AlignPCLThresholds::size
double size() const
Definition: AlignPCLThresholds.h:43
edm::EventSetup
Definition: EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
AlignPCLThresholdsWriter::m_parameters
const std::vector< edm::ParameterSet > m_parameters
Definition: AlignPCLThresholdsWriter.cc:56
DOFs::thetaX
Definition: AlignPCLThresholdsWriter.cc:37
AlignPCLThreshold::coordThresholds
Definition: AlignPCLThreshold.h:8
DOFs
Definition: AlignPCLThresholdsWriter.cc:36
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
DOFs::Y
Definition: AlignPCLThresholdsWriter.cc:37
EcalSCDynamicDPhiParametersESProducer_cfi.cutoff
cutoff
Definition: EcalSCDynamicDPhiParametersESProducer_cfi.py:15
Frameworkfwd.h
DOFs::thetaZ
Definition: AlignPCLThresholdsWriter.cc:37
cond::service::PoolDBOutputService::writeOne
Hash writeOne(const T *payload, Time_t time, const std::string &recordName)
Definition: PoolDBOutputService.h:63
AlignPCLThresholdsWriter::AlignPCLThresholdsWriter
AlignPCLThresholdsWriter(const edm::ParameterSet &)
Definition: AlignPCLThresholdsWriter.cc:63
AlignPCLThreshold::coordThresholds::setThresholds
void setThresholds(float theCut, float theSigCut, float theErrorCut, float theMaxMoveCut, const std::string &theLabel)
Definition: AlignPCLThreshold.h:17
ParameterSet.h
AlignPCLThresholdsWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: AlignPCLThresholdsWriter.cc:78
edm::Event
Definition: Event.h:73
AlignPCLThresholdsWriter::~AlignPCLThresholdsWriter
~AlignPCLThresholdsWriter() override
Definition: AlignPCLThresholdsWriter.cc:71
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
AlignPCLThresholdsWriter::endJob
void endJob() override
Definition: AlignPCLThresholdsWriter.cc:190
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:217