CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/Alignment/CommonAlignmentAlgorithm/src/AlignableDataIO.cc

Go to the documentation of this file.
00001 #include "Alignment/CommonAlignment/interface/Alignable.h"
00002 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "Geometry/CommonTopologies/interface/SurfaceDeformation.h"
00005 
00006 // this class's header
00007 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignableDataIO.h"
00008 
00009 // ----------------------------------------------------------------------------
00010 AlignableAbsData AlignableDataIO::readAbsPos(Alignable* ali, int& ierr)
00011 { 
00012   return readAbsRaw(ali,ierr);
00013 }
00014 
00015 
00016 // ----------------------------------------------------------------------------
00017 AlignableAbsData AlignableDataIO::readOrgPos(Alignable* ali, int& ierr)
00018 { 
00019   return readAbsRaw(ali,ierr);
00020 }
00021 
00022 
00023 // ----------------------------------------------------------------------------
00024 AlignableRelData AlignableDataIO::readRelPos(Alignable* ali, int& ierr)
00025 { 
00026   return readRelRaw(ali,ierr);
00027 }
00028 
00029 
00030 // ----------------------------------------------------------------------------
00031 int AlignableDataIO::writeAbsPos(Alignable* ali, bool validCheck)
00032 {
00033   
00034   if ( !(validCheck) || ali->alignmentParameters()->isValid() ) 
00035     {
00036       // position in global frame
00037       align::PositionType pos = ali->surface().position();
00038       // global rotation
00039       align::RotationType rot = ali->surface().rotation();
00040       // if a unit: store surface deformation (little kind of hack)...
00041       std::vector<double> pars;
00042       if (ali->alignableObjectId() == align::AlignableDetUnit) { // only detunits have them
00043         std::vector<std::pair<int,SurfaceDeformation*> > result;
00044         if (1 == ali->surfaceDeformationIdPairs(result)) { // might not have any...
00045           pars = result[0].second->parameters();
00046         }
00047       }
00048 
00049       // write
00050       return writeAbsRaw( 
00051                          AlignableAbsData( pos,rot,
00052                                            ali->id(),
00053                                            ali->alignableObjectId(),
00054                                            pars)
00055                          );
00056     }
00057 
00058   return 1;
00059 }
00060 
00061 
00062 // ----------------------------------------------------------------------------
00063 int AlignableDataIO::writeRelPos(Alignable* ali, bool validCheck)
00064 {
00065   if ( !(validCheck) || ali->alignmentParameters()->isValid() ) 
00066     {
00067       // rel. shift in global frame
00068       align::GlobalVector pos = ali->displacement();
00069       // rel. rotation in global frame
00070       align::RotationType rot = ali->rotation();
00071       // FIXME: should add something to store changes of surface deformations...
00072       std::vector<double> pars;
00073       // write
00074       return writeRelRaw(AlignableRelData(pos,rot,ali->id(),
00075                                           ali->alignableObjectId(), pars));
00076     }
00077 
00078   return 1;
00079 }
00080 
00081 
00082 // ----------------------------------------------------------------------------
00083 int AlignableDataIO::writeOrgPos(Alignable* ali, bool validCheck)
00084 {
00085   if ( !(validCheck) || ali->alignmentParameters()->isValid() ) 
00086     {
00087       // orig position
00088       align::PositionType pos = ali->globalPosition() - ali->displacement();
00089       // orig rotation
00090       align::RotationType rot = ali->globalRotation() * ali->rotation().transposed();
00091       // FIXME: should add something to store changes of surface deformations...
00092       std::vector<double> pars;
00093       // write
00094       return writeAbsRaw(AlignableAbsData(pos,rot,ali->id(),
00095                                           ali->alignableObjectId(), pars));
00096     }
00097 
00098   return 1;
00099 }
00100 
00101 
00102 // ----------------------------------------------------------------------------
00103 int AlignableDataIO::writeAbsPos(const align::Alignables& alivec, 
00104                                  bool validCheck)
00105 {
00106 
00107   int icount=0;
00108   for( align::Alignables::const_iterator it=alivec.begin();
00109        it!=alivec.end(); it++ ) 
00110     {
00111       int iret = writeAbsPos(*it,validCheck);
00112       if (iret==0) icount++;
00113     }
00114   LogDebug("WriteAbsPos") << "all,written: " << alivec.size() <<","<< icount;
00115 
00116   return 0;
00117 
00118 }
00119 
00120 
00121 // ----------------------------------------------------------------------------
00122 AlignablePositions 
00123 AlignableDataIO::readAbsPos(const align::Alignables& alivec, int& ierr) 
00124 {
00125  
00126   AlignablePositions retvec;
00127   int ierr2=0;
00128   ierr=0;
00129   for( align::Alignables::const_iterator it=alivec.begin();
00130        it!=alivec.end(); it++ ) 
00131     {
00132       AlignableAbsData ad=readAbsPos(*it, ierr2);
00133       if (ierr2==0) retvec.push_back(ad);
00134     }
00135   
00136   LogDebug("ReadAbsPos") << "all,written: " << alivec.size() <<"," << retvec.size();
00137 
00138   return retvec;
00139 
00140 }
00141 
00142 
00143 // ----------------------------------------------------------------------------
00144 int AlignableDataIO::writeOrgPos( const align::Alignables& alivec, 
00145                                   bool validCheck )
00146 {
00147 
00148   int icount=0;
00149   for( align::Alignables::const_iterator it=alivec.begin();
00150        it!=alivec.end(); it++ ) 
00151     {
00152       int iret=writeOrgPos(*it,validCheck);
00153       if (iret==0) icount++;
00154     }
00155   
00156   LogDebug("WriteOrgPos") << "all,written: " << alivec.size() <<"," << icount;
00157   return 0;
00158 
00159 }
00160 
00161 
00162 // ----------------------------------------------------------------------------
00163 AlignablePositions 
00164 AlignableDataIO::readOrgPos(const align::Alignables& alivec, int& ierr) 
00165 {
00166 
00167   AlignablePositions retvec;
00168   int ierr2=0;
00169   ierr=0;
00170   for( align::Alignables::const_iterator it=alivec.begin();
00171        it!=alivec.end(); it++ ) 
00172     {
00173       AlignableAbsData ad=readOrgPos(*it, ierr2);
00174       if (ierr2==0) retvec.push_back(ad);
00175     }
00176 
00177   LogDebug("ReadOrgPos") << "all,read: " << alivec.size() <<", "<< retvec.size();
00178 
00179   return retvec;
00180 
00181 }
00182 
00183 
00184 // ----------------------------------------------------------------------------
00185 int AlignableDataIO::writeRelPos(const align::Alignables& alivec, 
00186                                  bool validCheck )
00187 {
00188 
00189   int icount=0;
00190   for( align::Alignables::const_iterator it=alivec.begin();
00191        it!=alivec.end(); it++ ) {
00192     int iret=writeRelPos(*it,validCheck);
00193     if (iret==0) icount++;
00194   }
00195   LogDebug("WriteRelPos") << "all,written: " << alivec.size() <<", "<< icount;
00196   return 0;
00197 
00198 }
00199 
00200 
00201 // ----------------------------------------------------------------------------
00202 AlignableShifts 
00203 AlignableDataIO::readRelPos(const align::Alignables& alivec, int& ierr) 
00204 {
00205 
00206   AlignableShifts retvec;
00207   int ierr2=0;
00208   ierr=0;
00209   for( align::Alignables::const_iterator it=alivec.begin();
00210        it!=alivec.end(); it++ ) 
00211     {
00212       AlignableRelData ad=readRelPos(*it, ierr2);
00213       if (ierr2==0) retvec.push_back(ad);
00214     }
00215   LogDebug("ReadRelPos") << "all,read: " << alivec.size() <<", "<< retvec.size();
00216 
00217   return retvec;
00218 
00219 }