CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Alignment/CommonAlignmentAlgorithm/src/AlignmentParametersIORoot.cc

Go to the documentation of this file.
00001 // this class's header
00002 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParametersIORoot.h"
00003 
00004 #include "Alignment/CommonAlignment/interface/Alignable.h" 
00005 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
00006 #include "Alignment/CommonAlignmentParametrization/interface/AlignmentParametersFactory.h"
00007 
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 
00010 #include "TTree.h"
00011 
00012 
00013 // ----------------------------------------------------------------------------
00014 // constructor
00015 AlignmentParametersIORoot::AlignmentParametersIORoot()
00016 {
00017   treename = "AlignmentParameters";
00018   treetxt = "Alignment Parameters";
00019 }
00020 
00021 
00022 // ----------------------------------------------------------------------------
00023 void AlignmentParametersIORoot::createBranches(void) 
00024 {
00025   tree->Branch("parSize",   &theCovRang,   "CovRang/I");
00026   tree->Branch("Id",        &theId,        "Id/i");
00027   tree->Branch("paramType", &theParamType, "paramType/I");
00028   tree->Branch("Par",       &thePar,       "Par[CovRang]/D");
00029   tree->Branch("covarSize", &theCovarRang, "CovarRang/I");
00030   tree->Branch("Cov",       &theCov,       "Cov[CovarRang]/D");
00031   tree->Branch("ObjId",     &theObjId,     "ObjId/I");
00032   tree->Branch("HieraLevel",&theHieraLevel,"HieraLevel/I");
00033 }
00034 
00035 
00036 // ----------------------------------------------------------------------------
00037 void AlignmentParametersIORoot::setBranchAddresses(void) 
00038 {
00039   tree->SetBranchAddress("parSize",   &theCovRang);
00040   tree->SetBranchAddress("covarSize", &theCovarRang);
00041   tree->SetBranchAddress("Id",        &theId);
00042   tree->SetBranchAddress("Par",       &thePar);
00043   tree->SetBranchAddress("paramType", &theParamType);
00044   tree->SetBranchAddress("Cov",       &theCov);
00045   tree->SetBranchAddress("ObjId",     &theObjId);
00046   tree->SetBranchAddress("HieraLevel",&theHieraLevel);
00047 }
00048 
00049 
00050 // ----------------------------------------------------------------------------
00051 int AlignmentParametersIORoot::writeOne(Alignable* ali)
00052 {
00053   const AlignmentParameters* ap =ali->alignmentParameters();
00054   const AlgebraicVector& params = ap->parameters();
00055   const AlgebraicSymMatrix& cov = ap->covariance();
00056 
00057   theCovRang   = params.num_row();
00058   theCovarRang = theCovRang*(theCovRang+1)/2;
00059   int count=0;
00060   for(int row=0;row<theCovRang;row++){
00061     thePar[row]=params[row];
00062     for(int col=0;col<theCovRang;col++){
00063       if(row-1<col) { theCov[count] = cov[row][col]; count++; }
00064     }
00065   }
00066 
00067   theId = ali->id();
00068   theParamType = ap->type();
00069   theObjId = ali->alignableObjectId();
00070   theHieraLevel = ap->hierarchyLevel();
00071 
00072   tree->Fill();
00073   return 0;
00074 }
00075 
00076 
00077 // ----------------------------------------------------------------------------
00078 AlignmentParameters* AlignmentParametersIORoot::readOne( Alignable* ali, int& ierr )
00079 {
00080   
00081   if( tree->GetEntryWithIndex( ali->id(), ali->alignableObjectId() ) > 0 ) 
00082   {
00083     int covsize = theCovRang;
00084     int count=0;
00085     AlgebraicVector par(covsize, 0);
00086     AlgebraicSymMatrix cov(covsize, 0);
00087     for(int row=0;row<covsize;row++) 
00088     {
00089       par[row]=thePar[row];
00090       for(int col=0; col < covsize;col++) {
00091         if(row-1<col) {cov[row][col]=theCov[count];count++;}
00092       }
00093     }
00094 
00095     using namespace AlignmentParametersFactory;
00096     ParametersType parType = parametersType(theParamType);
00097     AlignmentParameters* alipar1; 
00098     if ( ali->alignmentParameters() )
00099     {
00100       const std::vector<bool>& sel = ali->alignmentParameters()->selector();
00101       alipar1 = createParameters(ali, parType, sel); 
00102     } else {
00103       const std::vector<bool> sel( theCovRang, true );
00104       alipar1 = createParameters(ali, parType, sel); 
00105     }
00106     AlignmentParameters* alipar = alipar1->clone(par,cov);
00107     alipar->setValid(true); 
00108     ierr=0;
00109     delete alipar1;
00110     return alipar;
00111   }
00112 
00113   ierr=-1;
00114   return(0);
00115 }
00116 
00117 
00118 int AlignmentParametersIORoot::close()
00119 {
00120   if ( bWrite )
00121   {
00122     int nIndices = tree->BuildIndex( "Id", "ObjId" );
00123     edm::LogInfo( "Alignment" ) << "@SUB=AlignmentParametersIORoot::setBranchAddresses"
00124                                 << "number of indexed entries: " << nIndices;
00125   }
00126 
00127   return closeRoot();
00128 }