ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/Alignment/CommonAlignmentAlgorithm/src/AlignmentParametersIORoot.cc
Revision: 1.10
Committed: Thu Jan 8 18:00:06 2009 UTC (16 years, 3 months ago) by ewidl
Content type: text/plain
Branch: MAIN
CVS Tags: V02-03-02
Changes since 1.9: +41 -41 lines
Log Message:
improved file IO

File Contents

# User Rev Content
1 flucke 1.2 // this class's header
2     #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParametersIORoot.h"
3    
4 flucke 1.6 #include "Alignment/CommonAlignment/interface/Alignable.h"
5 flucke 1.9 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
6     #include "Alignment/CommonAlignmentParametrization/interface/AlignmentParametersFactory.h"
7 flucke 1.2
8 ewidl 1.10 #include "FWCore/MessageLogger/interface/MessageLogger.h"
9    
10     #include "TTree.h"
11    
12    
13 fronga 1.1 // ----------------------------------------------------------------------------
14     // constructor
15     AlignmentParametersIORoot::AlignmentParametersIORoot()
16     {
17     treename = "AlignmentParameters";
18     treetxt = "Alignment Parameters";
19     }
20    
21 ewidl 1.10
22 fronga 1.1 // ----------------------------------------------------------------------------
23     void AlignmentParametersIORoot::createBranches(void)
24     {
25     tree->Branch("parSize", &theCovRang, "CovRang/I");
26 cklae 1.8 tree->Branch("Id", &theId, "Id/i");
27 flucke 1.9 tree->Branch("paramType", &theParamType, "paramType/I");
28 fronga 1.1 tree->Branch("Par", &thePar, "Par[CovRang]/D");
29     tree->Branch("covarSize", &theCovarRang, "CovarRang/I");
30     tree->Branch("Cov", &theCov, "Cov[CovarRang]/D");
31     tree->Branch("ObjId", &theObjId, "ObjId/I");
32 flucke 1.3 tree->Branch("HieraLevel",&theHieraLevel,"HieraLevel/I");
33 fronga 1.1 }
34    
35 ewidl 1.10
36 fronga 1.1 // ----------------------------------------------------------------------------
37     void AlignmentParametersIORoot::setBranchAddresses(void)
38     {
39     tree->SetBranchAddress("parSize", &theCovRang);
40     tree->SetBranchAddress("covarSize", &theCovarRang);
41     tree->SetBranchAddress("Id", &theId);
42     tree->SetBranchAddress("Par", &thePar);
43 flucke 1.9 tree->SetBranchAddress("paramType", &theParamType);
44 fronga 1.1 tree->SetBranchAddress("Cov", &theCov);
45     tree->SetBranchAddress("ObjId", &theObjId);
46 flucke 1.3 tree->SetBranchAddress("HieraLevel",&theHieraLevel);
47 ewidl 1.10
48     int nIndices = tree->BuildIndex( "Id", "ObjId" );
49     edm::LogInfo( "Alignment" ) << "@SUB=AlignmentParametersIORoot::setBranchAddresses"
50     << "number of indexed entries: " << nIndices;
51 fronga 1.1 }
52    
53    
54     // ----------------------------------------------------------------------------
55     int AlignmentParametersIORoot::writeOne(Alignable* ali)
56     {
57 flucke 1.3 const AlignmentParameters* ap =ali->alignmentParameters();
58     const AlgebraicVector& params = ap->parameters();
59     const AlgebraicSymMatrix& cov = ap->covariance();
60 fronga 1.1
61     theCovRang = params.num_row();
62     theCovarRang = theCovRang*(theCovRang+1)/2;
63     int count=0;
64     for(int row=0;row<theCovRang;row++){
65     thePar[row]=params[row];
66     for(int col=0;col<theCovRang;col++){
67     if(row-1<col) { theCov[count] = cov[row][col]; count++; }
68     }
69     }
70    
71 cklae 1.7 theId = ali->id();
72 flucke 1.9 theParamType = ap->type();
73 cklae 1.7 theObjId = ali->alignableObjectId();
74 flucke 1.3 theHieraLevel = ap->hierarchyLevel();
75 fronga 1.1
76     tree->Fill();
77     return 0;
78     }
79    
80 ewidl 1.10
81 fronga 1.1 // ----------------------------------------------------------------------------
82 flucke 1.2 AlignmentParameters* AlignmentParametersIORoot::readOne( Alignable* ali, int& ierr )
83 fronga 1.1 {
84    
85     AlgebraicVector par(nParMax,0);
86     AlgebraicSymMatrix cov(nParMax,0);
87    
88 ewidl 1.10 if( tree->GetEntryWithIndex( ali->id(), ali->alignableObjectId() ) > 0 )
89     {
90     int covsize = theCovRang;
91     int count=0;
92     for(int row=0;row<covsize;row++)
93     {
94     par[row]=thePar[row];
95     for(int col=0; col < covsize;col++) {
96     if(row-1<col) {cov[row][col]=theCov[count];count++;}
97     }
98     }
99    
100     using namespace AlignmentParametersFactory;
101     ParametersType parType = parametersType(theParamType);
102     AlignmentParameters* alipar1;
103     if ( ali->alignmentParameters() )
104     {
105     const std::vector<bool>& sel = ali->alignmentParameters()->selector();
106     alipar1 = createParameters(ali, parType, sel);
107     } else {
108     const std::vector<bool> sel( theCovRang, true );
109     alipar1 = createParameters(ali, parType, sel);
110     }
111     AlignmentParameters* alipar = alipar1->clone(par,cov);
112     alipar->setValid(true);
113     ierr=0;
114     delete alipar1;
115     return alipar;
116     }
117 fronga 1.1
118     ierr=-1;
119     return(0);
120     }