CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Alignment/CommonAlignmentAlgorithm/src/AlignableDataIORoot.cc

Go to the documentation of this file.
00001 #include "TTree.h"
00002 
00003 #include "Alignment/CommonAlignment/interface/Alignable.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignableDataIORoot.h"
00007 
00008 // ----------------------------------------------------------------------------
00009 // constructor
00010 AlignableDataIORoot::AlignableDataIORoot(PosType p) : 
00011   AlignableDataIO(p)
00012 {
00013   if (thePosType == Abs) {
00014     treename = "AlignablesAbsPos";
00015     treetxt = "Alignables abs.Pos";
00016   }
00017   else if (thePosType == Org) {
00018     treename = "AlignablesOrgPos";
00019     treetxt = "Alignables org.Pos";
00020   }
00021   else if (thePosType == Rel) {
00022     treename = "AlignablesRelPos";
00023     treetxt = "Alignables rel.Pos";
00024   }
00025 }
00026 
00027 // ----------------------------------------------------------------------------
00028 // create root tree branches (for writing)
00029 
00030 void AlignableDataIORoot::createBranches(void) 
00031 {
00032   tree->Branch("Id",    &Id,    "Id/i");
00033   tree->Branch("ObjId", &ObjId, "ObjId/I");
00034   tree->Branch("Pos",   &Pos,   "Pos[3]/D");
00035   tree->Branch("Rot",   &Rot,   "Rot[9]/D");
00036 }
00037 
00038 // ----------------------------------------------------------------------------
00039 // set root tree branch addresses (for reading)
00040 
00041 void AlignableDataIORoot::setBranchAddresses(void) 
00042 {
00043   tree->SetBranchAddress("Id",    &Id);
00044   tree->SetBranchAddress("ObjId", &ObjId);
00045   tree->SetBranchAddress("Pos",   &Pos);
00046   tree->SetBranchAddress("Rot",   &Rot);
00047 }
00048 
00049 // ----------------------------------------------------------------------------
00050 // find root tree entry based on IDs
00051 
00052 int AlignableDataIORoot::findEntry(align::ID id, align::StructureType comp)
00053 {
00054   if (newopen) { // we're here first time
00055     edm::LogInfo("Alignment") << "@SUB=AlignableDataIORoot::findEntry"
00056                               << "Filling map ...";
00057     treemap.erase(treemap.begin(),treemap.end());
00058     for (int ev = 0;ev<tree->GetEntries();ev++) {
00059       tree->GetEntry(ev); 
00060       treemap[ std::make_pair(Id,ObjId) ] = ev;
00061     }
00062     newopen=false;
00063   }
00064   
00065   // now we have filled the map
00066   treemaptype::iterator imap = treemap.find( std::make_pair(id,comp) );
00067   int result=-1;
00068   if (imap != treemap.end()) result=(*imap).second;
00069   return result;
00070 
00071 }
00072 
00073 // ----------------------------------------------------------------------------
00074 int AlignableDataIORoot::writeAbsRaw(const AlignableAbsData &ad)
00075 {
00076   align::GlobalPoint pos = ad.pos();
00077   align::RotationType rot = ad.rot();
00078   Id = ad.id();
00079   ObjId = ad.objId();
00080   Pos[0]=pos.x(); Pos[1]=pos.y(); Pos[2]=pos.z();
00081   Rot[0]=rot.xx(); Rot[1]=rot.xy(); Rot[2]=rot.xz();
00082   Rot[3]=rot.yx(); Rot[4]=rot.yy(); Rot[5]=rot.yz();
00083   Rot[6]=rot.zx(); Rot[7]=rot.zy(); Rot[8]=rot.zz();
00084   tree->Fill();
00085   return 0;
00086 }
00087 
00088 // ----------------------------------------------------------------------------
00089 int AlignableDataIORoot::writeRelRaw(const AlignableRelData &ad)
00090 {
00091   align::GlobalVector pos = ad.pos();
00092   align::RotationType rot = ad.rot();
00093   Id = ad.id();
00094   ObjId = ad.objId();
00095   Pos[0]=pos.x(); Pos[1]=pos.y(); Pos[2]=pos.z();
00096   Rot[0]=rot.xx(); Rot[1]=rot.xy(); Rot[2]=rot.xz();
00097   Rot[3]=rot.yx(); Rot[4]=rot.yy(); Rot[5]=rot.yz();
00098   Rot[6]=rot.zx(); Rot[7]=rot.zy(); Rot[8]=rot.zz();
00099   tree->Fill();
00100   return 0;
00101 }
00102 
00103 // ----------------------------------------------------------------------------
00104 AlignableAbsData AlignableDataIORoot::readAbsRaw(Alignable* ali,int& ierr)
00105 {
00106   align::GlobalPoint pos;
00107   align::RotationType rot;
00108 
00109   align::StructureType typeId = ali->alignableObjectId();
00110   align::ID id = ali->id();
00111   int entry = findEntry(id,typeId);
00112   if(entry!=-1) {
00113     tree->GetEntry(entry);
00114     align::GlobalPoint pos2(Pos[0],Pos[1],Pos[2]);
00115     align::RotationType rot2(Rot[0],Rot[1],Rot[2],
00116                              Rot[3],Rot[4],Rot[5],
00117                              Rot[6],Rot[7],Rot[8]);
00118     pos=pos2;
00119     rot=rot2;
00120     ierr=0;
00121   }
00122   else ierr=-1;
00123 
00124   return AlignableAbsData(pos,rot,id,typeId);
00125 }
00126 
00127 // ----------------------------------------------------------------------------
00128 
00129 AlignableRelData AlignableDataIORoot::readRelRaw(Alignable* ali,int& ierr)
00130 {
00131   align::GlobalVector pos;
00132   align::RotationType rot;
00133 
00134   align::StructureType typeId = ali->alignableObjectId();
00135   align::ID id = ali->id();
00136   int entry = findEntry(id,typeId);
00137   if(entry!=-1) {
00138     tree->GetEntry(entry);
00139     align::GlobalVector pos2(Pos[0],Pos[1],Pos[2]);
00140     align::RotationType rot2(Rot[0],Rot[1],Rot[2],
00141                              Rot[3],Rot[4],Rot[5],
00142                              Rot[6],Rot[7],Rot[8]);
00143     pos=pos2;
00144     rot=rot2;
00145     ierr=0;
00146   }
00147   else ierr=-1;
00148 
00149   return AlignableRelData(pos,rot,id,typeId);
00150 }