CMS 3D CMS Logo

PedeReader Class Reference

read in result from pede text file More...

#include <Alignment/MillePedeAlignmentAlgorithm/src/PedeReader.h>

List of all members.

Public Member Functions

AlignmentParameterscheckAliParams (Alignable *alignable, bool createUserVars) const
 returns parameters of alignable (creates if not yet existing, but MillePedeVariables are only created if createUserVars == true)
 PedeReader (const edm::ParameterSet &config, const PedeSteerer &steerer, const PedeLabeler &labels)
bool read (std::vector< Alignable * > &alignables, bool setUserVars)
 Read pede output into AlignmentParameters attached to 'alignables', if (setUserVars == true) also care about MillePedeVariables.
template<class T>
bool readIfSameLine (std::ifstream &aStream, T &outValue) const
 true if 'outValue' could be read via operator >> from the current line (!) of aStream, false otherwise
AlignablesetParameter (unsigned int paramLabel, unsigned int bufLength, float *buf, bool setUserVars) const
 Set pede results stored in 'buf' to AlignmentParameters and (if setUserVars == true) to MillePedeVariables, return corresponding Alignable.
 ~PedeReader ()
 non virtual destructor: do not inherit from this class

Private Attributes

const PedeLabelermyLabels
std::ifstream myPedeResult
const PedeSteerermySteerer

Static Private Attributes

static const unsigned int myMaxNumValPerParam = 5


Detailed Description

read in result from pede text file

Author:
: Gero Flucke date : November 2006
Revision
1.3
Date
2007/12/17 18:59:52
(last update by
Author
flucke
)

Definition at line 30 of file PedeReader.h.


Constructor & Destructor Documentation

PedeReader::PedeReader ( const edm::ParameterSet config,
const PedeSteerer steerer,
const PedeLabeler labels 
)

Definition at line 32 of file PedeReader.cc.

References PedeSteerer::directory(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), in, and myPedeResult.

00034   : mySteerer(steerer), myLabels(labels)
00035 {
00036   std::string pedeResultFile(config.getUntrackedParameter<std::string>("fileDir"));
00037   if (pedeResultFile.empty()) pedeResultFile = steerer.directory(); // includes final '/'
00038   else if (pedeResultFile.find_last_of('/') != pedeResultFile.size() - 1) {
00039     pedeResultFile += '/'; // directory may need '/'
00040   }
00041 
00042   pedeResultFile += config.getParameter<std::string>("readFile");
00043   myPedeResult.open(pedeResultFile.c_str(), std::ios::in);
00044   if (!myPedeResult.is_open()) {
00045     edm::LogError("Alignment") << "@SUB=PedeReader"
00046                                << "Problem opening pede output file " << pedeResultFile;
00047   }
00048 }

PedeReader::~PedeReader (  )  [inline]

non virtual destructor: do not inherit from this class

Definition at line 36 of file PedeReader.h.

00036 {}


Member Function Documentation

AlignmentParameters * PedeReader::checkAliParams ( Alignable alignable,
bool  createUserVars 
) const

returns parameters of alignable (creates if not yet existing, but MillePedeVariables are only created if createUserVars == true)

Definition at line 185 of file PedeReader.cc.

References PedeLabeler::alignableLabel(), Alignable::alignmentParameters(), myLabels, params, Alignable::setAlignmentParameters(), AlignmentParameters::setUserVariables(), AlignmentParameters::size(), and AlignmentParameters::userVariables().

Referenced by setParameter().

00186 {
00187   // first check that we have parameters
00188   AlignmentParameters *params = alignable->alignmentParameters();
00189   if (!params) {
00190     // How to check in future what kind of parameters are needed?
00191     params = new RigidBodyAlignmentParameters(alignable, false);
00192 
00193     edm::LogInfo("Alignment") << "@SUB=PedeReader::checkAliParams"
00194                               << "Build RigidBodyAlignmentParameters for alignable with label "
00195                               << myLabels.alignableLabel(alignable);
00196     alignable->setAlignmentParameters(params); // transferred memory responsibility
00197   }
00198   
00199   // now check that we have user parameters of correct type if requested:
00200   if (createUserVars && !dynamic_cast<MillePedeVariables*>(params->userVariables())) {
00201     edm::LogInfo("Alignment") << "@SUB=PedeReader::checkAliParams"
00202                               << "Add user variables for alignable with label " 
00203                               << myLabels.alignableLabel(alignable);
00204     params->setUserVariables(new MillePedeVariables(params->size()));
00205   }
00206   
00207   return params;
00208 }

bool PedeReader::read ( std::vector< Alignable * > &  alignables,
bool  setUserVars 
)

Read pede output into AlignmentParameters attached to 'alignables', if (setUserVars == true) also care about MillePedeVariables.

Definition at line 51 of file PedeReader.cc.

References myMaxNumValPerParam, myPedeResult, setParameter(), and Alignable::size().

Referenced by MillePedeAlignmentAlgorithm::readFromPede().

00052 {
00053   alignables.clear();
00054   myPedeResult.seekg(0, std::ios::beg); // back to start
00055   bool isAllOk = true;
00056 
00057   std::map<Alignable*,Alignable*> uniqueList; // Probably should use a std::set here...
00058   
00059   // loop on lines of text file
00060   unsigned int nParam = 0;
00061   while (myPedeResult.good() && !myPedeResult.eof()) {
00062     // read label
00063     unsigned int paramLabel = 0;
00064     if (!this->readIfSameLine<unsigned int>(myPedeResult, paramLabel)) continue; // empty line?
00065 
00066     // read up to maximal number of pede result per parameter
00067     float buffer[myMaxNumValPerParam] = {0.};
00068     unsigned int bufferPos = 0;
00069     for ( ; bufferPos < myMaxNumValPerParam; ++bufferPos) {
00070       if (!this->readIfSameLine<float>(myPedeResult, buffer[bufferPos])) break;
00071     }
00072 
00073     Alignable *alignable = this->setParameter(paramLabel, bufferPos, buffer, setUserVars);
00074     if (!alignable) {
00075       isAllOk = false;  // or error?
00076       continue;
00077     }
00078     uniqueList[alignable] = alignable;
00079     ++nParam;
00080   }
00081 
00082   // add Alignables to output
00083   for ( std::map<Alignable*,Alignable*>::const_iterator iAli = uniqueList.begin();
00084         iAli != uniqueList.end(); ++iAli) {
00085     alignables.push_back((*iAli).first);
00086   }
00087 
00088   edm::LogInfo("Alignment") << "@SUB=PedeReader::read" << nParam << " parameters for "
00089                             << alignables.size() << " alignables";
00090 
00091   return isAllOk && nParam; // nParam == 0: empty or bad file
00092 }

template<class T>
bool PedeReader::readIfSameLine ( std::ifstream &  aStream,
T &  outValue 
) const [inline]

true if 'outValue' could be read via operator >> from the current line (!) of aStream, false otherwise

Definition at line 97 of file PedeReader.cc.

00098 {
00099 
00100   while (true) {
00101     const int aChar = aStream.get();
00102     if (!aStream.good()) return false;
00103 
00104     switch(aChar) {
00105     case ' ':
00106     case '\t':
00107       continue; // to next character
00108     case '\n':
00109       return false; // end of line
00110     default:
00111       aStream.unget();
00112       aStream >> outValue;
00113       if (aStream.fail()) {// not correct type 'T' (!aStream.good() is true also in case of EOF)
00114         aStream.clear();
00115         while (aStream.good() && aStream.get() != '\n'); // forward to end of line
00116         return false; 
00117       } else {
00118         return true;
00119       }
00120     } // switch
00121   } // while
00122 
00123   edm::LogError("Alignment") << "@SUB=PedeReader::readIfSameLine" << "Should never come here!";
00124   return false;
00125 }

Alignable * PedeReader::setParameter ( unsigned int  paramLabel,
unsigned int  bufLength,
float *  buf,
bool  setUserVars 
) const

Set pede results stored in 'buf' to AlignmentParameters and (if setUserVars == true) to MillePedeVariables, return corresponding Alignable.

Definition at line 128 of file PedeReader.cc.

References PedeLabeler::alignableFromLabel(), PedeLabeler::alignableLabelFromLabel(), checkAliParams(), AlignmentParameters::clone(), PedeSteerer::cmsToPedeFactor(), AlignmentParameters::covariance(), MillePedeVariables::diffBefore(), MillePedeVariables::globalCor(), MillePedeVariables::isFixed(), MillePedeVariables::isValid(), myLabels, mySteerer, MillePedeVariables::parameter(), AlignmentParameters::parameters(), PedeSteerer::parameterSign(), PedeLabeler::paramNumFromLabel(), params, MillePedeVariables::preSigma(), Alignable::setAlignmentParameters(), MillePedeVariables::setAllDefault(), MillePedeVariables::setLabel(), MillePedeVariables::sigma(), and AlignmentParameters::userVariables().

Referenced by read().

00130 {
00131   Alignable *alignable = myLabels.alignableFromLabel(paramLabel);
00132   if (alignable) {
00133     AlignmentParameters *params = this->checkAliParams(alignable, setUserVars);
00134     MillePedeVariables *userParams = // static cast ensured by previous checkAliParams
00135       (setUserVars ? static_cast<MillePedeVariables*>(params->userVariables()) : 0);
00136     if (userParams) userParams->setLabel(myLabels.alignableLabelFromLabel(paramLabel));
00137 
00138     AlgebraicVector parVec(params->parameters());
00139     AlgebraicSymMatrix covMat(params->covariance());
00140     const unsigned int paramNum = myLabels.paramNumFromLabel(paramLabel);
00141 
00142     if (userParams) userParams->setAllDefault(paramNum);
00143     const double cmsToPede = mySteerer.cmsToPedeFactor(paramNum);
00144 
00145     switch (bufLength) {
00146     case 5: // global correlation
00147       if (userParams) userParams->globalCor()[paramNum] = buf[4]; // no break
00148     case 4: // uncertainty
00149       if (userParams) userParams->sigma()[paramNum] = buf[3] / cmsToPede;
00150       covMat[paramNum][paramNum] = buf[3]*buf[3] / (cmsToPede*cmsToPede);
00151       // no break;
00152     case 3: // difference to start value
00153       if (userParams) userParams->diffBefore()[paramNum] = buf[2] / cmsToPede;
00154       // no break
00155     case 2: 
00156       parVec[paramNum] = buf[0] / cmsToPede * mySteerer.parameterSign(); // parameter
00157       if (userParams) {
00158         userParams->parameter()[paramNum] = parVec[paramNum]; // duplicate in millepede parameters
00159         userParams->preSigma()[paramNum] = buf[1];  // presigma given, probably means fixed
00160         if (!userParams->isFixed(paramNum)) {
00161           userParams->preSigma()[paramNum] /= cmsToPede;
00162           if (bufLength == 2) {
00163             edm::LogError("Alignment") << "@SUB=PedeReader::setParameter"
00164                                        << "Param " << paramLabel << " (from "
00165                                        << typeid(*alignable).name() << ") without result!";
00166             userParams->isValid()[paramNum] = false;
00167           }
00168         }
00169       }
00170       break;
00171     case 0:
00172     case 1:
00173     default:
00174       edm::LogError("Alignment") << "@SUB=PedeReader::setParameter"
00175                                  << "Expect 2 to 5 values, got " << bufLength 
00176                                  << " for label " << paramLabel;
00177       break;
00178     }
00179     alignable->setAlignmentParameters(params->clone(parVec, covMat));//transferred mem. responsib.
00180   }
00181   return alignable;
00182 }


Member Data Documentation

const PedeLabeler& PedeReader::myLabels [private]

Definition at line 56 of file PedeReader.h.

Referenced by checkAliParams(), and setParameter().

const unsigned int PedeReader::myMaxNumValPerParam = 5 [static, private]

Definition at line 58 of file PedeReader.h.

Referenced by read().

std::ifstream PedeReader::myPedeResult [private]

Definition at line 54 of file PedeReader.h.

Referenced by PedeReader(), and read().

const PedeSteerer& PedeReader::mySteerer [private]

Definition at line 55 of file PedeReader.h.

Referenced by setParameter().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:29:31 2009 for CMSSW by  doxygen 1.5.4