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{
38  X,
39  Y,
40  Z,
45  };
46 }
47 
49  public:
51  ~AlignPCLThresholdsWriter() override;
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55 
56  private:
57  void beginJob() override;
58  void analyze(const edm::Event&, const edm::EventSetup&) override;
59  void endJob() override;
60  DOFs::dof mapOntoEnum(std::string coord);
61 
62  // ----------member data ---------------------------
64  const unsigned int m_minNrecords;
65  const std::vector<edm::ParameterSet> m_parameters;
67 
68 };
69 
70 //
71 // constructors and destructor
72 //
74  m_record(iConfig.getParameter<std::string>("record")),
75  m_minNrecords(iConfig.getParameter<unsigned int>("minNRecords")),
76  m_parameters(iConfig.getParameter<std::vector<edm::ParameterSet> >("thresholds"))
77 {
78  //now do what ever initialization is needed
80 }
81 
82 
84 {
85  delete myThresholds;
86 }
87 
88 //
89 // member functions
90 //
91 
92 // ------------ method called for each event ------------
93 void
95 {
96  using namespace edm;
97 
98  edm::LogInfo("AlignPCLThresholdsWriter")<<"Size of AlignPCLThresholds object "<< myThresholds->size() <<std::endl<<std::endl;
99 
100  // loop on the PSet and insert the conditions
101 
102  std::array<std::string,6> mandatories = {{"X","Y","Z","thetaX","thetaY","thetaZ"}};
103  std::vector<std::string> alignables;
104 
105  // fill the list of alignables
106  for(auto& thePSet : m_parameters){
107  const std::string alignableId(thePSet.getParameter<std::string>("alignableId"));
108  // only if it is not yet in the list
109  if(std::find(alignables.begin(), alignables.end(), alignableId) == alignables.end()) {
110  alignables.push_back(alignableId);
111  }
112  }
113 
114  for (auto& alignable : alignables){
115 
122 
123  std::vector<std::string> presentDOF;
124 
125  // extra degrees of freedom
126  std::vector< AlignPCLThreshold::coordThresholds > extraDOFs = std::vector< AlignPCLThreshold::coordThresholds >();
127 
128  for(auto& thePSet : m_parameters){
129 
130  const std::string alignableId(thePSet.getParameter<std::string>("alignableId"));
131  const std::string DOF(thePSet.getParameter<std::string>("DOF"));
132 
133  const double cutoff(thePSet.getParameter<double>("cut"));
134  const double sigCut(thePSet.getParameter<double>("sigCut"));
135  const double maxMoveCut(thePSet.getParameter<double>("maxMoveCut"));
136  const double maxErrorCut(thePSet.getParameter<double>("maxErrorCut"));
137 
138  if (alignableId == alignable){
139  presentDOF.push_back(DOF);
140  // create the objects
141 
142  switch( mapOntoEnum(DOF) )
143  {
144  case DOFs::X:
145  my_X.setThresholds(cutoff,sigCut,maxErrorCut,maxMoveCut,DOF);
146  break;
147  case DOFs::Y:
148  my_Y.setThresholds(cutoff,sigCut,maxErrorCut,maxMoveCut,DOF);
149  break;
150  case DOFs::Z:
151  my_Z.setThresholds(cutoff,sigCut,maxErrorCut,maxMoveCut,DOF);
152  break;
153  case DOFs::thetaX:
154  my_tX.setThresholds(cutoff,sigCut,maxErrorCut,maxMoveCut,DOF);
155  break;
156  case DOFs::thetaY:
157  my_tY.setThresholds(cutoff,sigCut,maxErrorCut,maxMoveCut,DOF);
158  break;
159  case DOFs::thetaZ:
160  my_tZ.setThresholds(cutoff,sigCut,maxErrorCut,maxMoveCut,DOF);
161  break;
162  default:
163  edm::LogInfo("AlignPCLThresholdsWriter")<<"Appending Extra degree of freeedom: "<< DOF <<" " << mapOntoEnum(DOF) << std::endl;
165  ExtraDOF.setThresholds(cutoff,sigCut,maxErrorCut,maxMoveCut,DOF);
166  extraDOFs.push_back(ExtraDOF);
167  }
168 
169  AlignPCLThreshold a(my_X,my_tX,my_Y,my_tY,my_Z,my_tZ,extraDOFs);
170  myThresholds->setAlignPCLThreshold(alignableId,a);
171 
172  } // if alignable is found in the PSet
173  } // loop on the PSets
174 
175  // checks if all mandatories are present
176  edm::LogInfo("AlignPCLThresholdsWriter")<<"Size of AlignPCLThresholds object "<<myThresholds->size() <<std::endl;
177  for(auto& mandatory : mandatories){
178  if(std::find(presentDOF.begin(), presentDOF.end(), mandatory) == presentDOF.end()) {
179  edm::LogWarning("AlignPCLThresholdsWriter")<<"Configuration for DOF: "<<mandatory<<" for alignable "<< alignable <<"is not present \n"
180  <<"Will build object with defaults!" <<std::endl;
181  }
182  }
183 
184  } // ends loop on the alignable units
185 
186  // set the minimum number of records to be used in pede
188  edm::LogInfo("AlignPCLThresholdsWriter")<<"Content of AlignPCLThresholds "<<std::endl;
189 
190  // use buil-in method in the CondFormat
192 
193  // Form the data here
195  if( poolDbService.isAvailable() ){
196  cond::Time_t valid_time = poolDbService->currentTime();
197  // this writes the payload to begin in current run defined in cfg
198  poolDbService->writeOne(myThresholds,valid_time, m_record);
199  }
200 }
201 
202 // ------------ method called once each job just before starting event loop ------------
203 void
205 {
206 }
207 
208 // ------------ method called once each job just after ending the event loop ------------
209 void
211 {
212 }
213 
215  if( coord=="X" ){
216  return DOFs::X;
217  }
218  else if ( coord=="Y" ){
219  return DOFs::Y;
220  }
221  else if ( coord=="Z" ){
222  return DOFs::Z;
223  }
224  else if ( coord=="thetaX" ){
225  return DOFs::thetaX;
226  }
227  else if ( coord=="thetaY" ){
228  return DOFs::thetaY;
229  }
230  else if ( coord=="thetaZ" ){
231  return DOFs::thetaZ;
232  }
233  else {
234  return DOFs::extraDOF;
235  }
236 
237 }
238 
239 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
240 void
243  desc.setUnknown();
244  descriptions.addDefault(desc);
245 }
246 
247 //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
def analyze(function, filename, filter=None)
Definition: Profiling.py:11
DOFs::dof mapOntoEnum(std::string coord)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
AlignPCLThresholdsWriter(const edm::ParameterSet &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void beginJob()
Definition: Breakpoints.cc:15
void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
unsigned long long Time_t
Definition: Time.h:16
void addDefault(ParameterSetDescription const &psetDescription)
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void setNRecords(const int &Nrecords)
HLT enums.
double a
Definition: hdecay.h:121
void setThresholds(float theCut, float theSigCut, float theErrorCut, float theMaxMoveCut, const std::string &theLabel)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)