#include <Mille.h>
Public Member Functions | |
void | end () |
void | kill () |
Mille (const char *outFileName, bool asBinary=true, bool writeZero=false) | |
void | mille (int NLC, const float *derLc, int NGL, const float *derGl, const int *label, float rMeas, float sigma) |
void | special (int nSpecial, const float *floatings, const int *integers) |
~Mille () | |
Private Types | |
enum | { myBufferSize = 5000 } |
enum | { myMaxLabel = (0xFFFFFFFF - (1 << 31)) } |
Private Member Functions | |
bool | checkBufferSize (int nLocal, int nGlobal) |
void | newSet () |
Private Attributes | |
bool | myAsBinary |
float | myBufferFloat [myBufferSize] |
int | myBufferInt [myBufferSize] |
int | myBufferPos |
bool | myHasSpecial |
std::ofstream | myOutFile |
bool | myWriteZero |
Class to write a C binary (cf. below) file of a given name and to fill it with information used as input to pede. Use its member functions mille(...), special(...), kill() and end() as you would use the fortran MILLE and its entry points MILLSP, KILLE and ENDLE.
For debugging purposes constructor flags enable switching to text output and/or to write also derivatives and lables which are ==0. But note that pede will not be able to read text output and has not been tested with derivatives/labels ==0.
(last update by
)
anonymous enum [private] |
anonymous enum [private] |
Definition at line 52 of file Mille.h.
{myMaxLabel = (0xFFFFFFFF - (1 << 31))}; // largest label allowed: 2^31 - 1
Mille::Mille | ( | const char * | outFileName, |
bool | asBinary = true , |
||
bool | writeZero = false |
||
) |
Definition at line 16 of file Mille.cc.
References benchmark_cfg::cerr, myBufferFloat, myBufferInt, and myOutFile.
: myOutFile(outFileName, (asBinary ? (std::ios::binary | std::ios::out) : std::ios::out)), myAsBinary(asBinary), myWriteZero(writeZero), myBufferPos(-1), myHasSpecial(false) { // opens outFileName, by default as binary file // Instead myBufferPos(-1), myHasSpecial(false) and the following two lines // we could call newSet() and kill()... myBufferInt[0] = 0; myBufferFloat[0] = 0.; if (!myOutFile.is_open()) { std::cerr << "Mille::Mille: Could not open " << outFileName << " as output file." << std::endl; } }
Mille::~Mille | ( | ) |
bool Mille::checkBufferSize | ( | int | nLocal, |
int | nGlobal | ||
) | [private] |
Definition at line 171 of file Mille.cc.
References benchmark_cfg::cerr, myBufferInt, myBufferPos, and myBufferSize.
Referenced by mille(), and special().
{ // enough space for next nLocal + nGlobal derivatives incl. measurement? if (myBufferPos + nLocal + nGlobal + 2 >= myBufferSize) { ++(myBufferInt[0]); // increase error count std::cerr << "Mille::checkBufferSize: Buffer too short (" << myBufferSize << ")," << "\n need space for nLocal (" << nLocal<< ")" << "/nGlobal (" << nGlobal << ") local/global derivatives, " << myBufferPos + 1 << " already stored!" << std::endl; return false; } else { return true; } }
void Mille::end | ( | ) |
Definition at line 129 of file Mille.cc.
References i, myAsBinary, myBufferFloat, myBufferInt, myBufferPos, and myOutFile.
Referenced by MillePedeAlignmentAlgorithm::addLasBeam(), MillePedeAlignmentAlgorithm::addPxbSurvey(), and MillePedeAlignmentAlgorithm::addReferenceTrajectory().
{ // write set of derivatives with same local parameters to file if (myBufferPos > 0) { // only if anything stored... const int numWordsToWrite = (myBufferPos + 1)*2; if (myAsBinary) { myOutFile.write(reinterpret_cast<const char*>(&numWordsToWrite), sizeof(numWordsToWrite)); myOutFile.write(reinterpret_cast<char*>(myBufferFloat), (myBufferPos+1) * sizeof(myBufferFloat[0])); myOutFile.write(reinterpret_cast<char*>(myBufferInt), (myBufferPos+1) * sizeof(myBufferInt[0])); } else { myOutFile << numWordsToWrite << "\n"; for (int i = 0; i < myBufferPos+1; ++i) { myOutFile << myBufferFloat[i] << " "; } myOutFile << "\n"; for (int i = 0; i < myBufferPos+1; ++i) { myOutFile << myBufferInt[i] << " "; } myOutFile << "\n"; } } myBufferPos = -1; // reset buffer for next set of derivatives }
void Mille::kill | ( | ) |
Definition at line 121 of file Mille.cc.
References myBufferPos.
Referenced by MillePedeAlignmentAlgorithm::addReferenceTrajectory().
{ // reset buffers, i.e. kill derivatives accumulated for current set myBufferPos = -1; }
void Mille::mille | ( | int | NLC, |
const float * | derLc, | ||
int | NGL, | ||
const float * | derGl, | ||
const int * | label, | ||
float | rMeas, | ||
float | sigma | ||
) |
Definition at line 43 of file Mille.cc.
References benchmark_cfg::cerr, checkBufferSize(), i, myBufferFloat, myBufferInt, myBufferPos, myMaxLabel, myWriteZero, and newSet().
Referenced by MillePedeAlignmentAlgorithm::addLasBeam(), and MillePedeAlignmentAlgorithm::addPxbSurvey().
{ if (sigma <= 0.) return; if (myBufferPos == -1) this->newSet(); // start, e.g. new track if (!this->checkBufferSize(NLC, NGL)) return; // first store measurement ++myBufferPos; myBufferFloat[myBufferPos] = rMeas; myBufferInt [myBufferPos] = 0; // store local derivatives and local 'lables' 1,...,NLC for (int i = 0; i < NLC; ++i) { if (derLc[i] || myWriteZero) { // by default store only non-zero derivatives ++myBufferPos; myBufferFloat[myBufferPos] = derLc[i]; // local derivatives myBufferInt [myBufferPos] = i+1; // index of local parameter } } // store uncertainty of measurement in between locals and globals ++myBufferPos; myBufferFloat[myBufferPos] = sigma; myBufferInt [myBufferPos] = 0; // store global derivatives and their lables for (int i = 0; i < NGL; ++i) { if (derGl[i] || myWriteZero) { // by default store only non-zero derivatives if ((label[i] > 0 || myWriteZero) && label[i] <= myMaxLabel) { // and for valid labels ++myBufferPos; myBufferFloat[myBufferPos] = derGl[i]; // global derivatives myBufferInt [myBufferPos] = label[i]; // index of global parameter } else { std::cerr << "Mille::mille: Invalid label " << label[i] << " <= 0 or > " << myMaxLabel << std::endl; } } } }
void Mille::newSet | ( | ) | [private] |
Definition at line 160 of file Mille.cc.
References myBufferFloat, myBufferInt, myBufferPos, and myHasSpecial.
Referenced by mille(), and special().
{ // initilise for new set of locals, e.g. new track myBufferPos = 0; myHasSpecial = false; myBufferFloat[0] = 0.0; myBufferInt [0] = 0; // position 0 used as error counter }
void Mille::special | ( | int | nSpecial, |
const float * | floatings, | ||
const int * | integers | ||
) |
Definition at line 86 of file Mille.cc.
References benchmark_cfg::cerr, checkBufferSize(), i, myBufferFloat, myBufferInt, myBufferPos, myHasSpecial, and newSet().
{ if (nSpecial == 0) return; if (myBufferPos == -1) this->newSet(); // start, e.g. new track if (myHasSpecial) { std::cerr << "Mille::special: Special values already stored for this record." << std::endl; return; } if (!this->checkBufferSize(nSpecial, 0)) return; myHasSpecial = true; // after newSet() (Note: MILLSP sets to buffer position...) // myBufferFloat[.] | myBufferInt[.] // ------------------------------------ // 0.0 | 0 // -float(nSpecial) | 0 // The above indicates special data, following are nSpecial floating and nSpecial integer data. ++myBufferPos; // zero pair myBufferFloat[myBufferPos] = 0.; myBufferInt [myBufferPos] = 0; ++myBufferPos; // nSpecial and zero myBufferFloat[myBufferPos] = -nSpecial; // automatic conversion to float myBufferInt [myBufferPos] = 0; for (int i = 0; i < nSpecial; ++i) { ++myBufferPos; myBufferFloat[myBufferPos] = floatings[i]; myBufferInt [myBufferPos] = integers[i]; } }
bool Mille::myAsBinary [private] |
float Mille::myBufferFloat[myBufferSize] [private] |
int Mille::myBufferInt[myBufferSize] [private] |
int Mille::myBufferPos [private] |
bool Mille::myHasSpecial [private] |
std::ofstream Mille::myOutFile [private] |
bool Mille::myWriteZero [private] |