ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/Alignment/CommonAlignmentAlgorithm/src/AlignableDataIORoot.cc
Revision: 1.5
Committed: Mon Oct 8 14:38:16 2007 UTC (17 years, 6 months ago) by cklae
Content type: text/plain
Branch: MAIN
CVS Tags: CMSSW_1_8_0_pre2, CMSSW_1_8_0_pre1, V02-00-00
Branch point for: NewHierarchy165
Changes since 1.4: +25 -26 lines
Log Message:
Changes wrt CommmonAlignment and TrackerAlignment (use align::ID and StructureType). Clean up header files.

File Contents

# User Rev Content
1 cklae 1.5 #include "TTree.h"
2    
3     #include "Alignment/CommonAlignment/interface/Alignable.h"
4 fronga 1.1 #include "FWCore/MessageLogger/interface/MessageLogger.h"
5    
6     #include "Alignment/CommonAlignmentAlgorithm/interface/AlignableDataIORoot.h"
7    
8     // ----------------------------------------------------------------------------
9     // constructor
10     AlignableDataIORoot::AlignableDataIORoot(PosType p) :
11     AlignableDataIO(p)
12     {
13     if (thePosType == Abs) {
14     treename = "AlignablesAbsPos";
15     treetxt = "Alignables abs.Pos";
16     }
17     else if (thePosType == Org) {
18     treename = "AlignablesOrgPos";
19     treetxt = "Alignables org.Pos";
20     }
21     else if (thePosType == Rel) {
22     treename = "AlignablesRelPos";
23     treetxt = "Alignables rel.Pos";
24     }
25     }
26    
27     // ----------------------------------------------------------------------------
28     // create root tree branches (for writing)
29    
30     void AlignableDataIORoot::createBranches(void)
31     {
32     tree->Branch("Id", &Id, "Id/I");
33     tree->Branch("ObjId", &ObjId, "ObjId/I");
34     tree->Branch("Pos", &Pos, "Pos[3]/D");
35     tree->Branch("Rot", &Rot, "Rot[9]/D");
36     }
37    
38     // ----------------------------------------------------------------------------
39     // set root tree branch addresses (for reading)
40    
41     void AlignableDataIORoot::setBranchAddresses(void)
42     {
43     tree->SetBranchAddress("Id", &Id);
44     tree->SetBranchAddress("ObjId", &ObjId);
45     tree->SetBranchAddress("Pos", &Pos);
46     tree->SetBranchAddress("Rot", &Rot);
47     }
48    
49     // ----------------------------------------------------------------------------
50     // find root tree entry based on IDs
51    
52 cklae 1.5 int AlignableDataIORoot::findEntry(align::ID id, align::StructureType comp)
53 fronga 1.1 {
54     if (newopen) { // we're here first time
55 flucke 1.2 edm::LogInfo("Alignment") << "@SUB=AlignableDataIORoot::findEntry"
56     << "Filling map ...";
57 fronga 1.1 treemap.erase(treemap.begin(),treemap.end());
58     for (int ev = 0;ev<tree->GetEntries();ev++) {
59     tree->GetEntry(ev);
60     treemap[ std::make_pair(Id,ObjId) ] = ev;
61     }
62     newopen=false;
63     }
64    
65     // now we have filled the map
66 cklae 1.5 treemaptype::iterator imap = treemap.find( std::make_pair(id,comp) );
67 fronga 1.1 int result=-1;
68     if (imap != treemap.end()) result=(*imap).second;
69     return result;
70    
71     }
72    
73     // ----------------------------------------------------------------------------
74 flucke 1.3 int AlignableDataIORoot::writeAbsRaw(const AlignableAbsData &ad)
75 fronga 1.1 {
76 cklae 1.5 align::GlobalPoint pos = ad.pos();
77     align::RotationType rot = ad.rot();
78 fronga 1.1 Id = ad.id();
79     ObjId = ad.objId();
80     Pos[0]=pos.x(); Pos[1]=pos.y(); Pos[2]=pos.z();
81     Rot[0]=rot.xx(); Rot[1]=rot.xy(); Rot[2]=rot.xz();
82     Rot[3]=rot.yx(); Rot[4]=rot.yy(); Rot[5]=rot.yz();
83     Rot[6]=rot.zx(); Rot[7]=rot.zy(); Rot[8]=rot.zz();
84     tree->Fill();
85     return 0;
86     }
87    
88     // ----------------------------------------------------------------------------
89 flucke 1.3 int AlignableDataIORoot::writeRelRaw(const AlignableRelData &ad)
90 fronga 1.1 {
91 cklae 1.5 align::GlobalVector pos = ad.pos();
92     align::RotationType rot = ad.rot();
93 fronga 1.1 Id = ad.id();
94     ObjId = ad.objId();
95     Pos[0]=pos.x(); Pos[1]=pos.y(); Pos[2]=pos.z();
96     Rot[0]=rot.xx(); Rot[1]=rot.xy(); Rot[2]=rot.xz();
97     Rot[3]=rot.yx(); Rot[4]=rot.yy(); Rot[5]=rot.yz();
98     Rot[6]=rot.zx(); Rot[7]=rot.zy(); Rot[8]=rot.zz();
99     tree->Fill();
100     return 0;
101     }
102    
103     // ----------------------------------------------------------------------------
104     AlignableAbsData AlignableDataIORoot::readAbsRaw(Alignable* ali,int& ierr)
105     {
106 cklae 1.5 align::GlobalPoint pos;
107     align::RotationType rot;
108 fronga 1.1
109 cklae 1.5 align::StructureType typeId = ali->alignableObjectId();
110     align::ID id = ali->id();
111 fronga 1.1 int entry = findEntry(id,typeId);
112     if(entry!=-1) {
113     tree->GetEntry(entry);
114 cklae 1.5 align::GlobalPoint pos2(Pos[0],Pos[1],Pos[2]);
115     align::RotationType rot2(Rot[0],Rot[1],Rot[2],
116     Rot[3],Rot[4],Rot[5],
117     Rot[6],Rot[7],Rot[8]);
118 fronga 1.1 pos=pos2;
119     rot=rot2;
120     ierr=0;
121     }
122     else ierr=-1;
123    
124     return AlignableAbsData(pos,rot,id,typeId);
125     }
126    
127     // ----------------------------------------------------------------------------
128    
129     AlignableRelData AlignableDataIORoot::readRelRaw(Alignable* ali,int& ierr)
130     {
131 cklae 1.5 align::GlobalVector pos;
132     align::RotationType rot;
133 fronga 1.1
134 cklae 1.5 align::StructureType typeId = ali->alignableObjectId();
135     align::ID id = ali->id();
136 fronga 1.1 int entry = findEntry(id,typeId);
137     if(entry!=-1) {
138     tree->GetEntry(entry);
139 cklae 1.5 align::GlobalVector pos2(Pos[0],Pos[1],Pos[2]);
140     align::RotationType rot2(Rot[0],Rot[1],Rot[2],
141     Rot[3],Rot[4],Rot[5],
142     Rot[6],Rot[7],Rot[8]);
143 fronga 1.1 pos=pos2;
144     rot=rot2;
145     ierr=0;
146     }
147     else ierr=-1;
148    
149     return AlignableRelData(pos,rot,id,typeId);
150     }