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;
51  DOFs::dof mapOntoEnum(std::string coord);
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
void setAlignPCLThreshold(const std::string &AlignableId, const AlignPCLThreshold &Threshold)
double size() const
const std::vector< edm::ParameterSet > m_parameters
DOFs::dof mapOntoEnum(std::string coord)
AlignPCLThresholdsWriter(const edm::ParameterSet &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob()
Definition: Breakpoints.cc:14
void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned long long Time_t
Definition: Time.h:14
void addDefault(ParameterSetDescription const &psetDescription)
bool isAvailable() const
Definition: Service.h:40
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void setNRecords(const int &Nrecords)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
double a
Definition: hdecay.h:119
void setThresholds(float theCut, float theSigCut, float theErrorCut, float theMaxMoveCut, const std::string &theLabel)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)