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
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
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 tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
00038 tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
00039 }
00040
00041
00042
00043
00044 void AlignableDataIORoot::setBranchAddresses(void)
00045 {
00046 tree->SetBranchAddress("Id", &Id);
00047 tree->SetBranchAddress("ObjId", &ObjId);
00048 tree->SetBranchAddress("Pos", &Pos);
00049 tree->SetBranchAddress("Rot", &Rot);
00050
00051 tree->SetBranchAddress("NumDeform", &numDeformationValues_);
00052 tree->SetBranchAddress("DeformValues", deformationValues_);
00053 }
00054
00055
00056
00057
00058 int AlignableDataIORoot::findEntry(align::ID id, align::StructureType comp)
00059 {
00060 if (newopen) {
00061 edm::LogInfo("Alignment") << "@SUB=AlignableDataIORoot::findEntry"
00062 << "Filling map ...";
00063 treemap.erase(treemap.begin(),treemap.end());
00064 for (int ev = 0;ev<tree->GetEntries();ev++) {
00065 tree->GetEntry(ev);
00066 treemap[ std::make_pair(Id,ObjId) ] = ev;
00067 }
00068 newopen=false;
00069 }
00070
00071
00072 treemaptype::iterator imap = treemap.find( std::make_pair(id,comp) );
00073 int result=-1;
00074 if (imap != treemap.end()) result=(*imap).second;
00075 return result;
00076
00077 }
00078
00079
00080 int AlignableDataIORoot::writeAbsRaw(const AlignableAbsData &ad)
00081 {
00082 align::GlobalPoint pos = ad.pos();
00083 align::RotationType rot = ad.rot();
00084 Id = ad.id();
00085 ObjId = ad.objId();
00086 Pos[0]=pos.x(); Pos[1]=pos.y(); Pos[2]=pos.z();
00087 Rot[0]=rot.xx(); Rot[1]=rot.xy(); Rot[2]=rot.xz();
00088 Rot[3]=rot.yx(); Rot[4]=rot.yy(); Rot[5]=rot.yz();
00089 Rot[6]=rot.zx(); Rot[7]=rot.zy(); Rot[8]=rot.zz();
00090
00091 const std::vector<double> &deformPars = ad.deformationParameters();
00092 numDeformationValues_ = (deformPars.size() > kMaxNumPar ? kMaxNumPar : deformPars.size());
00093 for (unsigned int i = 0; i < numDeformationValues_; ++i) {
00094 deformationValues_[i] = deformPars[i];
00095 }
00096
00097 tree->Fill();
00098 return 0;
00099 }
00100
00101
00102 int AlignableDataIORoot::writeRelRaw(const AlignableRelData &ad)
00103 {
00104 align::GlobalVector pos = ad.pos();
00105 align::RotationType rot = ad.rot();
00106 Id = ad.id();
00107 ObjId = ad.objId();
00108 Pos[0]=pos.x(); Pos[1]=pos.y(); Pos[2]=pos.z();
00109 Rot[0]=rot.xx(); Rot[1]=rot.xy(); Rot[2]=rot.xz();
00110 Rot[3]=rot.yx(); Rot[4]=rot.yy(); Rot[5]=rot.yz();
00111 Rot[6]=rot.zx(); Rot[7]=rot.zy(); Rot[8]=rot.zz();
00112
00113 const std::vector<double> &deformPars = ad.deformationParameters();
00114 numDeformationValues_ = (deformPars.size() > kMaxNumPar ? kMaxNumPar : deformPars.size());
00115 for (unsigned int i = 0; i < numDeformationValues_; ++i) {
00116 deformationValues_[i] = deformPars[i];
00117 }
00118
00119 tree->Fill();
00120 return 0;
00121 }
00122
00123
00124 AlignableAbsData AlignableDataIORoot::readAbsRaw(Alignable* ali,int& ierr)
00125 {
00126 align::GlobalPoint pos;
00127 align::RotationType rot;
00128
00129 align::StructureType typeId = ali->alignableObjectId();
00130 align::ID id = ali->id();
00131 int entry = findEntry(id,typeId);
00132 if(entry!=-1) {
00133 tree->GetEntry(entry);
00134 align::GlobalPoint pos2(Pos[0],Pos[1],Pos[2]);
00135 align::RotationType rot2(Rot[0],Rot[1],Rot[2],
00136 Rot[3],Rot[4],Rot[5],
00137 Rot[6],Rot[7],Rot[8]);
00138 pos=pos2;
00139 rot=rot2;
00140
00141
00142
00143 ierr=0;
00144 }
00145 else ierr=-1;
00146
00147 return AlignableAbsData(pos,rot,id,typeId);
00148 }
00149
00150
00151
00152 AlignableRelData AlignableDataIORoot::readRelRaw(Alignable* ali,int& ierr)
00153 {
00154 align::GlobalVector pos;
00155 align::RotationType rot;
00156
00157 align::StructureType typeId = ali->alignableObjectId();
00158 align::ID id = ali->id();
00159 int entry = findEntry(id,typeId);
00160 if(entry!=-1) {
00161 tree->GetEntry(entry);
00162 align::GlobalVector pos2(Pos[0],Pos[1],Pos[2]);
00163 align::RotationType rot2(Rot[0],Rot[1],Rot[2],
00164 Rot[3],Rot[4],Rot[5],
00165 Rot[6],Rot[7],Rot[8]);
00166 pos=pos2;
00167 rot=rot2;
00168
00169
00170
00171 ierr=0;
00172 }
00173 else ierr=-1;
00174
00175 return AlignableRelData(pos,rot,id,typeId);
00176 }