CMS 3D CMS Logo

CocoaDBMgr.cc
Go to the documentation of this file.
10 
18 
27 
31 
33 
35 
36 //----------------------------------------------------------------------
38  if (!instance) {
39  instance = new CocoaDBMgr;
40  }
41  return instance;
42 }
43 
44 //----------------------------------------------------------------------
46 
47 //-----------------------------------------------------------------------
50 
52  int nrcd;
53 
54  cond::Time_t appendTime = Fit::nEvent + 1;
55  if (gomgr->GlobalOptions()["writeDBOptAlign"] > 0) {
56  //----- Build OpticalAlignments
58 
59  //--- Dump OpticalAlignments
60  nrcd = optalign->opticalAlignments_.size();
61  if (!myDbService.isAvailable()) {
62  throw cms::Exception("CocoaDBMgr::DumpCocoaResults DB not available");
63  }
64  // try{
65  if (myDbService->isNewTagRequest("OpticalAlignmentsRcd")) {
66  std::cout << " new OA to DB "
67  << "begin " << myDbService->beginOfTime() << " current " << myDbService->currentTime() << " end "
68  << myDbService->endOfTime() << std::endl;
69  myDbService->createNewIOV<OpticalAlignments>(
70  optalign,
71  myDbService->beginOfTime(),
72  myDbService->endOfTime(),
73  // myDbService->endOfTime(),
74  "OpticalAlignmentsRcd");
75  } else {
76  std::cout << " old OA to DB "
77  << " current " << myDbService->currentTime() << " end " << myDbService->endOfTime() << std::endl;
78  myDbService->appendSinceTime<OpticalAlignments>(
79  optalign,
80  // myDbService->endOfTime(),
81  appendTime,
82  // myDbService->currentTime(),
83  "OpticalAlignmentsRcd");
84  }
85 
86  /* }catch(const cond::Exception& er) {
87  std::cout<<er.what()<<std::endl;
88  }catch(const std::exception& er){
89  std::cout<<"caught std::exception "<<er.what()<<std::endl;
90  }catch(...){
91  std::cout<<"Funny error"<<std::endl;
92  } */
93 
94  if (ALIUtils::debug >= 2)
95  std::cout << "OpticalAlignmentsRcd WRITTEN TO DB : " << nrcd << std::endl;
96  }
97 
98  if (gomgr->GlobalOptions()["writeDBAlign"] > 0) {
99  // Build DT alignments and errors
100  std::pair<Alignments*, AlignmentErrorsExtended*> dtali = BuildAlignments(true);
101  Alignments* dt_Alignments = dtali.first;
102  AlignmentErrorsExtended* dt_AlignmentErrors = dtali.second;
103 
104  // Dump DT alignments and errors
105  nrcd = dt_Alignments->m_align.size();
106  if (myDbService->isNewTagRequest("DTAlignmentRcd")) {
107  myDbService->createNewIOV<Alignments>(
108  &(*dt_Alignments), myDbService->beginOfTime(), myDbService->endOfTime(), "DTAlignmentRcd");
109  } else {
110  myDbService->appendSinceTime<Alignments>(&(*dt_Alignments),
111  appendTime,
112  // myDbService->currentTime(),
113  "DTAlignmentRcd");
114  }
115  if (ALIUtils::debug >= 2)
116  std::cout << "DTAlignmentRcd WRITTEN TO DB : " << nrcd << std::endl;
117 
118  nrcd = dt_AlignmentErrors->m_alignError.size();
119  if (myDbService->isNewTagRequest("DTAlignmentErrorExtendedRcd")) {
121  &(*dt_AlignmentErrors), myDbService->beginOfTime(), myDbService->endOfTime(), "DTAlignmentErrorExtendedRcd");
122  } else {
124  &(*dt_AlignmentErrors), appendTime, "DTAlignmentErrorExtendedRcd");
125  }
126  if (ALIUtils::debug >= 2)
127  std::cout << "DTAlignmentErrorExtendedRcd WRITTEN TO DB : " << nrcd << std::endl;
128 
129  // Build CSC alignments and errors
130  std::pair<Alignments*, AlignmentErrorsExtended*> cscali = BuildAlignments(false);
131  Alignments* csc_Alignments = cscali.first;
132  AlignmentErrorsExtended* csc_AlignmentErrors = cscali.second;
133 
134  // Dump CSC alignments and errors
135  nrcd = csc_Alignments->m_align.size();
136  if (myDbService->isNewTagRequest("CSCAlignmentRcd")) {
137  myDbService->createNewIOV<Alignments>(
138  &(*csc_Alignments), myDbService->beginOfTime(), myDbService->endOfTime(), "CSCAlignmentRcd");
139  } else {
140  myDbService->appendSinceTime<Alignments>(&(*csc_Alignments), appendTime, "CSCAlignmentRcd");
141  }
142  if (ALIUtils::debug >= 2)
143  std::cout << "CSCAlignmentRcd WRITTEN TO DB : " << nrcd << std::endl;
144 
145  nrcd = csc_AlignmentErrors->m_alignError.size();
146  if (myDbService->isNewTagRequest("CSCAlignmentErrorExtendedRcd")) {
147  myDbService->createNewIOV<AlignmentErrorsExtended>(&(*csc_AlignmentErrors),
148  myDbService->beginOfTime(),
149  myDbService->endOfTime(),
150  "CSCAlignmentErrorExtendedRcd");
151  } else {
153  &(*csc_AlignmentErrors), appendTime, "CSCAlignmentErrorExtendedRcd");
154  }
155  if (ALIUtils::debug >= 2)
156  std::cout << "CSCAlignmentErrorExtendedRcd WRITTEN TO DB : " << nrcd << std::endl;
157 
158  //? gives unreadable error??? std::cout << "@@@@ OPTICALALIGNMENTS WRITTEN TO DB " << *optalign << std::endl;
159 
160  return TRUE;
161  }
162 
163  return TRUE;
164 }
165 
166 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
168  std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO " << opto->name() << std::endl;
170  data.ID_ = opto->getCmsswID();
171  data.type_ = opto->type();
172  data.name_ = opto->name();
173 
174  //----- Centre in local coordinates
175  CLHEP::Hep3Vector centreLocal = opto->centreGlob() - opto->parent()->centreGlob();
176  CLHEP::HepRotation parentRmGlobInv = inverseOf(opto->parent()->rmGlob());
177  centreLocal = parentRmGlobInv * centreLocal;
178 
179  const std::vector<Entry*>& theCoordinateEntryVector = opto->CoordinateEntryList();
180  std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO starting coord " << std::endl;
181 
182  data.x_.value_ = centreLocal.x() / 100.; // in cm
183  std::cout << " matrix " << Fit::GetAtWAMatrix() << std::endl;
184  std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[0]->fitPos() << std::endl;
185  data.x_.error_ = GetEntryError(theCoordinateEntryVector[0]) / 100.; // in cm
186 
187  data.y_.value_ = centreLocal.y() / 100.; // in cm
188  std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[1]->fitPos() << std::endl;
189  data.y_.error_ = GetEntryError(theCoordinateEntryVector[1]) / 100.; // in cm
190 
191  data.z_.value_ = centreLocal.z() / 100.; // in cm
192  std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[2]->fitPos() << std::endl;
193  data.z_.error_ = GetEntryError(theCoordinateEntryVector[2]) / 100.; // in cm
194 
195  //----- angles in local coordinates
196  std::vector<double> anglocal = opto->getLocalRotationAngles(theCoordinateEntryVector);
197 
198  data.angx_.value_ = anglocal[0] * 180. / M_PI; // in deg
199  std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[3]->fitPos() << std::endl;
200  data.angx_.error_ = GetEntryError(theCoordinateEntryVector[3]) * 180. / M_PI; // in deg;
201 
202  data.angy_.value_ = anglocal[1] * 180. / M_PI; // in deg
203  std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[4]->fitPos() << std::endl;
204  data.angy_.error_ = GetEntryError(theCoordinateEntryVector[4]) * 180. / M_PI; // in deg;;
205 
206  data.angz_.value_ = anglocal[2] * 180. / M_PI; // in deg
207  std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[5]->fitPos() << std::endl;
208  data.angz_.error_ = GetEntryError(theCoordinateEntryVector[5]) * 180. / M_PI; // in deg;
209 
210  const std::vector<Entry*>& theExtraEntryVector = opto->ExtraEntryList();
211  std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO starting entry " << std::endl;
212 
213  std::vector<Entry*>::const_iterator ite;
214  for (ite = theExtraEntryVector.begin(); ite != theExtraEntryVector.end(); ++ite) {
215  OpticalAlignParam extraEntry;
216  extraEntry.name_ = (*ite)->name();
217  extraEntry.dim_type_ = (*ite)->type();
218  extraEntry.value_ = (*ite)->value();
219  extraEntry.error_ = (*ite)->sigma();
220  extraEntry.quality_ = (*ite)->quality();
221  data.extraEntries_.push_back(extraEntry);
222  std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO done extra entry " << extraEntry.name_ << std::endl;
223  }
224 
225  return data;
226 }
227 
228 //-----------------------------------------------------------------------
230  if (entry->quality() > 0) {
231  return sqrt(Fit::GetAtWAMatrix()->Mat()->me[entry->fitPos()][entry->fitPos()]);
232  } else { //entry not fitted, return original error
233  return entry->sigma();
234  }
235 }
236 
237 //-----------------------------------------------------------------------
238 double CocoaDBMgr::GetEntryError(const Entry* entry1, const Entry* entry2) {
239  if (entry1 == entry2)
240  return GetEntryError(entry1);
241 
242  if (entry1->quality() > 0 && entry2->quality() > 0) {
243  return sqrt(Fit::GetAtWAMatrix()->Mat()->me[entry1->fitPos()][entry2->fitPos()]);
244  } else { //entries not fitted, correlation is 0
245  return 0.;
246  }
247 }
248 
249 //-----------------------------------------------------------------------
251  OpticalAlignments* optalign = new OpticalAlignments;
252 
253  static std::vector<OpticalObject*> optolist = Model::OptOList();
254  static std::vector<OpticalObject*>::const_iterator ite;
255  for (ite = optolist.begin(); ite != optolist.end(); ++ite) {
256  if ((*ite)->type() == "system")
257  continue;
259  optalign->opticalAlignments_.push_back(data);
260  if (ALIUtils::debug >= 5) {
261  std::cout << "@@@@ OPTALIGNINFO TO BE WRITTEN TO DB " << data << std::endl;
262  }
263  }
264  return optalign;
265 }
266 
267 //-----------------------------------------------------------------------
268 std::pair<Alignments*, AlignmentErrorsExtended*> CocoaDBMgr::BuildAlignments(bool bDT) {
269  Alignments* alignments = new Alignments;
270  AlignmentErrorsExtended* alignmentErrors = new AlignmentErrorsExtended;
271 
272  //read
273  static std::vector<OpticalObject*> optolist = Model::OptOList();
274  static std::vector<OpticalObject*>::const_iterator ite;
275  for (ite = optolist.begin(); ite != optolist.end(); ++ite) {
276  if ((*ite)->type() == "system")
277  continue;
278  std::cout << "CocoaDBMgr::BuildAlignments getCmsswID " << (*ite) << std::endl;
279  std::cout << "CocoaDBMgr::BuildAlignments getCmsswID " << (*ite)->getCmsswID() << std::endl;
280  //check CMSSW ID
281  if ((*ite)->getCmsswID() > 0) { //put the numbers of DT or CSC objects
282  std::cout << " cal fill alignments " << std::endl;
283  alignments->m_align.push_back(*(GetAlignInfoFromOptO(*ite)));
284  std::cout << " fill alignments " << std::endl;
285  // AlignTransformErrorExtended* err =
286  //GetAlignInfoErrorFromOptO( *ite );
287  alignmentErrors->m_alignError.push_back(*(GetAlignInfoErrorFromOptO(*ite)));
288  std::cout << "CocoaDBMgr::BuildAlignments add alignmentError " << alignmentErrors->m_alignError.size()
289  << std::endl;
290  }
291  }
292 
293  if (ALIUtils::debug >= 4)
294  std::cout << "CocoaDBMgr::BuildAlignments end with n alignment " << alignments->m_align.size()
295  << " n alignmentError " << alignmentErrors->m_alignError.size() << std::endl;
296  return std::pair<Alignments*, AlignmentErrorsExtended*>(alignments, alignmentErrors);
297 }
298 
299 //-----------------------------------------------------------------------
301  if (ALIUtils::debug >= 3)
302  std::cout << "@@@ CocoaDBMgr::GetAlignInfoFromOptO " << opto->name() << std::endl;
303 
304  const AlignTransform::Translation& trans = opto->centreGlob();
305  const AlignTransform::Rotation& rot = opto->rmGlob();
306  align::ID cmsswID = opto->getCmsswID();
307 
308  std::cout << "@@@ CocoaDBMgr::GetAlignInfoFromOptO buildalign" << opto->name() << std::endl;
309  AlignTransform* align = new AlignTransform(trans, rot, cmsswID);
310 
311  std::cout << "@@@ CocoaDBMgr::GetAlignInfoFromOptO alig built " << opto->name() << std::endl;
312 
313  return align;
314  // return dd;
315 }
316 
317 //-----------------------------------------------------------------------
319  if (ALIUtils::debug >= 3)
320  std::cout << "@@@ CocoaDBMgr::GetAlignInfoErrorFromOptO " << opto->name() << std::endl;
321 
322  align::ID cmsswID = opto->getCmsswID();
323 
324  GlobalError gerr(1., 0., 1., 0., 0., 1.);
325  //double(dx*dx), 0., double(dy*dy), 0., 0., double(dz*dz) ) ;
326  CLHEP::HepSymMatrix errms = asHepMatrix(gerr.matrix());
327  AlignTransformErrorExtended* alignError = new AlignTransformErrorExtended(errms, cmsswID);
328  return alignError;
329 
330  CLHEP::HepMatrix errm(3, 3);
331  const std::vector<Entry*>& theCoordinateEntryVector = opto->CoordinateEntryList();
332  std::cout << "@@@ CocoaDBMgr::GetAlignInfoFromOptOfill errm " << opto->name() << std::endl;
333  errm(0, 0) = GetEntryError(theCoordinateEntryVector[0]) / 100.; // in cm
334  errm(1, 1) = GetEntryError(theCoordinateEntryVector[1]) / 100.; // in cm
335  errm(2, 2) = GetEntryError(theCoordinateEntryVector[2]) / 100.; // in cm
336  errm(0, 1) = GetEntryError(theCoordinateEntryVector[0], theCoordinateEntryVector[1]) / 100.; // in cm
337  errm(0, 2) = GetEntryError(theCoordinateEntryVector[0], theCoordinateEntryVector[2]) / 100.; // in cm
338  errm(1, 2) = GetEntryError(theCoordinateEntryVector[1], theCoordinateEntryVector[2]) / 100.; // in cm
339  // errm(1,0) = errm(0,1);
340  // errm(2,0) = errm(0,2);
341  // errm(2,1) = errm(1,2);
342 
343  std::cout << "@@@ CocoaDBMgr::GetAlignInfoFromOptO errm filled" << opto->name() << std::endl;
344  // CLHEP::HepSymMatrix errms(3);
345  // errms.assign(errm);
346 
347  std::cout << "@@@ CocoaDBMgr::GetAlignInfoFromOptO errms filled " << opto->name() << std::endl;
348  // AlignTransformErrorExtended* alignError = new AlignTransformErrorExtended( errms, cmsswID );
349  // AlignTransformErrorExtended* alignError = 0;
350 
351  std::cout << alignError << "@@@ CocoaDBMgr::GetAlignInfoFromOptO error built " << opto->name() << std::endl;
352  //t return alignError;
353  return (AlignTransformErrorExtended*)nullptr;
354 }
const ALIuint getCmsswID() const
Definition: OpticalObject.h:97
CLHEP::HepMatrix asHepMatrix(const ROOT::Math::SMatrix< double, N1, N2, typename ROOT::Math::MatRepStd< double, N1, N2 > > &rm)
Definition: Migration.h:59
#define TRUE
Definition: scimark2.h:12
OpticalAlignParam x_
AlignTransformErrorExtended * GetAlignInfoErrorFromOptO(OpticalObject *opto)
Definition: CocoaDBMgr.cc:318
Definition: Entry.h:18
const AlgebraicSymMatrix33 matrix() const
static ALIMatrix * GetAtWAMatrix()
Definition: Fit.h:152
uint32_t ID
Definition: Definitions.h:24
static std::vector< OpticalObject * > & OptOList()
Definition: Model.h:84
bool DumpCocoaResults()
Definition: CocoaDBMgr.cc:48
CLHEP::Hep3Vector Translation
OpticalAlignments * BuildOpticalAlignments()
Definition: CocoaDBMgr.cc:250
static ALIint debug
Definition: ALIUtils.h:34
static GlobalOptionMgr * getInstance()
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:63
const CLHEP::HepRotation & rmGlob() const
Definition: OpticalObject.h:83
static CocoaDBMgr * instance
Definition: CocoaDBMgr.h:59
OpticalAlignParam angx_
std::vector< double > getLocalRotationAngles(const std::vector< Entry * > &entries) const
OpticalAlignParam y_
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
unsigned long long Time_t
Definition: Time.h:14
bool isNewTagRequest(const std::string &recordName)
std::vector< OpticalAlignInfo > opticalAlignments_
T sqrt(T t)
Definition: SSEVec.h:19
const OpticalObject * parent() const
Definition: OpticalObject.h:60
bool isAvailable() const
Definition: Service.h:40
const MAT * Mat() const
static ALIuint nEvent
Definition: Fit.h:208
AlignTransform * GetAlignInfoFromOptO(OpticalObject *opto)
Definition: CocoaDBMgr.cc:300
double GetEntryError(const Entry *entry)
Definition: CocoaDBMgr.cc:229
OpticalAlignInfo GetOptAlignInfoFromOptO(OpticalObject *opto)
Definition: CocoaDBMgr.cc:167
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
OpticalAlignParam angz_
ALIint fitPos() const
Definition: Entry.h:58
#define M_PI
OpticalAlignParam z_
std::vector< AlignTransformErrorExtended > m_alignError
static CocoaDBMgr * getInstance()
Definition: CocoaDBMgr.cc:37
std::vector< OpticalAlignParam > extraEntries_
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
const CLHEP::Hep3Vector & centreGlob() const
Definition: OpticalObject.h:75
OpticalAlignParam angy_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ALIint quality() const
Definition: Entry.h:57
const ALIstring & name() const
Definition: OpticalObject.h:58
std::pair< Alignments *, AlignmentErrorsExtended * > BuildAlignments(bool bDT)
Definition: CocoaDBMgr.cc:268
std::string dim_type_
const std::vector< Entry * > & ExtraEntryList() const
Definition: OpticalObject.h:65
unsigned int ID_
const ALIstring & type() const
Definition: OpticalObject.h:59
ALIdouble sigma() const
Definition: Entry.h:55
CLHEP::HepRotation Rotation