test
CMS 3D CMS Logo

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