Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:09

0001 #include "Alignment/CommonAlignment/interface/Alignable.h"
0002 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "Geometry/CommonTopologies/interface/SurfaceDeformation.h"
0005 
0006 // this class's header
0007 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignableDataIO.h"
0008 
0009 // ----------------------------------------------------------------------------
0010 AlignableAbsData AlignableDataIO::readAbsPos(Alignable* ali, int& ierr) { return readAbsRaw(ali, ierr); }
0011 
0012 // ----------------------------------------------------------------------------
0013 AlignableAbsData AlignableDataIO::readOrgPos(Alignable* ali, int& ierr) { return readAbsRaw(ali, ierr); }
0014 
0015 // ----------------------------------------------------------------------------
0016 AlignableRelData AlignableDataIO::readRelPos(Alignable* ali, int& ierr) { return readRelRaw(ali, ierr); }
0017 
0018 // ----------------------------------------------------------------------------
0019 int AlignableDataIO::writeAbsPos(Alignable* ali, bool validCheck) {
0020   if (!(validCheck) || ali->alignmentParameters()->isValid()) {
0021     // position in global frame
0022     align::PositionType pos = ali->surface().position();
0023     // global rotation
0024     align::RotationType rot = ali->surface().rotation();
0025     // if a unit: store surface deformation (little kind of hack)...
0026     std::vector<double> pars;
0027     if (ali->alignableObjectId() == align::AlignableDetUnit) {  // only detunits have them
0028       std::vector<std::pair<int, SurfaceDeformation*> > result;
0029       if (1 == ali->surfaceDeformationIdPairs(result)) {  // might not have any...
0030         pars = result[0].second->parameters();
0031       }
0032     }
0033 
0034     // write
0035     return writeAbsRaw(AlignableAbsData(pos, rot, ali->id(), ali->alignableObjectId(), pars));
0036   }
0037 
0038   return 1;
0039 }
0040 
0041 // ----------------------------------------------------------------------------
0042 int AlignableDataIO::writeRelPos(Alignable* ali, bool validCheck) {
0043   if (!(validCheck) || ali->alignmentParameters()->isValid()) {
0044     // rel. shift in global frame
0045     const align::GlobalVector& pos = ali->displacement();
0046     // rel. rotation in global frame
0047     align::RotationType rot = ali->rotation();
0048     // FIXME: should add something to store changes of surface deformations...
0049     std::vector<double> pars;
0050     // write
0051     return writeRelRaw(AlignableRelData(pos, rot, ali->id(), ali->alignableObjectId(), pars));
0052   }
0053 
0054   return 1;
0055 }
0056 
0057 // ----------------------------------------------------------------------------
0058 int AlignableDataIO::writeOrgPos(Alignable* ali, bool validCheck) {
0059   if (!(validCheck) || ali->alignmentParameters()->isValid()) {
0060     // orig position
0061     align::PositionType pos = ali->globalPosition() - ali->displacement();
0062     // orig rotation
0063     align::RotationType rot = ali->globalRotation() * ali->rotation().transposed();
0064     // FIXME: should add something to store changes of surface deformations...
0065     std::vector<double> pars;
0066     // write
0067     return writeAbsRaw(AlignableAbsData(pos, rot, ali->id(), ali->alignableObjectId(), pars));
0068   }
0069 
0070   return 1;
0071 }
0072 
0073 // ----------------------------------------------------------------------------
0074 int AlignableDataIO::writeAbsPos(const align::Alignables& alivec, bool validCheck) {
0075   int icount = 0;
0076   for (align::Alignables::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
0077     int iret = writeAbsPos(*it, validCheck);
0078     if (iret == 0)
0079       icount++;
0080   }
0081   LogDebug("WriteAbsPos") << "all,written: " << alivec.size() << "," << icount;
0082 
0083   return 0;
0084 }
0085 
0086 // ----------------------------------------------------------------------------
0087 AlignablePositions AlignableDataIO::readAbsPos(const align::Alignables& alivec, int& ierr) {
0088   AlignablePositions retvec;
0089   int ierr2 = 0;
0090   ierr = 0;
0091   for (align::Alignables::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
0092     AlignableAbsData ad = readAbsPos(*it, ierr2);
0093     if (ierr2 == 0)
0094       retvec.push_back(ad);
0095   }
0096 
0097   LogDebug("ReadAbsPos") << "all,written: " << alivec.size() << "," << retvec.size();
0098 
0099   return retvec;
0100 }
0101 
0102 // ----------------------------------------------------------------------------
0103 int AlignableDataIO::writeOrgPos(const align::Alignables& alivec, bool validCheck) {
0104   int icount = 0;
0105   for (align::Alignables::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
0106     int iret = writeOrgPos(*it, validCheck);
0107     if (iret == 0)
0108       icount++;
0109   }
0110 
0111   LogDebug("WriteOrgPos") << "all,written: " << alivec.size() << "," << icount;
0112   return 0;
0113 }
0114 
0115 // ----------------------------------------------------------------------------
0116 AlignablePositions AlignableDataIO::readOrgPos(const align::Alignables& alivec, int& ierr) {
0117   AlignablePositions retvec;
0118   int ierr2 = 0;
0119   ierr = 0;
0120   for (align::Alignables::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
0121     AlignableAbsData ad = readOrgPos(*it, ierr2);
0122     if (ierr2 == 0)
0123       retvec.push_back(ad);
0124   }
0125 
0126   LogDebug("ReadOrgPos") << "all,read: " << alivec.size() << ", " << retvec.size();
0127 
0128   return retvec;
0129 }
0130 
0131 // ----------------------------------------------------------------------------
0132 int AlignableDataIO::writeRelPos(const align::Alignables& alivec, bool validCheck) {
0133   int icount = 0;
0134   for (align::Alignables::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
0135     int iret = writeRelPos(*it, validCheck);
0136     if (iret == 0)
0137       icount++;
0138   }
0139   LogDebug("WriteRelPos") << "all,written: " << alivec.size() << ", " << icount;
0140   return 0;
0141 }
0142 
0143 // ----------------------------------------------------------------------------
0144 AlignableShifts AlignableDataIO::readRelPos(const align::Alignables& alivec, int& ierr) {
0145   AlignableShifts retvec;
0146   int ierr2 = 0;
0147   ierr = 0;
0148   for (align::Alignables::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
0149     AlignableRelData ad = readRelPos(*it, ierr2);
0150     if (ierr2 == 0)
0151       retvec.push_back(ad);
0152   }
0153   LogDebug("ReadRelPos") << "all,read: " << alivec.size() << ", " << retvec.size();
0154 
0155   return retvec;
0156 }