CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
Mille Class Reference

#include <Mille.h>

Public Member Functions

void end ()
 
void flushOutputFile ()
 
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
 

Detailed Description

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.

Author
: Gero Flucke date : October 2006
Revision:
1.2
Date:
2007/03/16 16:44:47

(last update by

Author:
flucke

)

Definition at line 26 of file Mille.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
myBufferSize 

Definition at line 47 of file Mille.h.

47 {myBufferSize = 5000};
anonymous enum
private
Enumerator
myMaxLabel 

Definition at line 53 of file Mille.h.

53 {myMaxLabel = (0xFFFFFFFF - (1 << 31))}; // largest label allowed: 2^31 - 1

Constructor & Destructor Documentation

Mille::Mille ( const char *  outFileName,
bool  asBinary = true,
bool  writeZero = false 
)

Definition at line 16 of file Mille.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, myBufferFloat, myBufferInt, and myOutFile.

16  :
17  myOutFile(outFileName, (asBinary ? (std::ios::binary | std::ios::out) : std::ios::out)),
18  myAsBinary(asBinary), myWriteZero(writeZero), myBufferPos(-1), myHasSpecial(false)
19 {
20  // opens outFileName, by default as binary file
21 
22  // Instead myBufferPos(-1), myHasSpecial(false) and the following two lines
23  // we could call newSet() and kill()...
24  myBufferInt[0] = 0;
25  myBufferFloat[0] = 0.;
26 
27  if (!myOutFile.is_open()) {
28  std::cerr << "Mille::Mille: Could not open " << outFileName
29  << " as output file." << std::endl;
30  }
31 }
bool myAsBinary
Definition: Mille.h:44
int myBufferInt[myBufferSize]
Definition: Mille.h:48
int myBufferPos
Definition: Mille.h:50
std::ofstream myOutFile
Definition: Mille.h:43
bool myWriteZero
Definition: Mille.h:45
float myBufferFloat[myBufferSize]
Definition: Mille.h:49
bool myHasSpecial
Definition: Mille.h:51
Mille::~Mille ( )

Definition at line 35 of file Mille.cc.

References myOutFile.

36 {
37  // closes file
38  myOutFile.close();
39 }
std::ofstream myOutFile
Definition: Mille.h:43

Member Function Documentation

bool Mille::checkBufferSize ( int  nLocal,
int  nGlobal 
)
private

Definition at line 179 of file Mille.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, myBufferInt, myBufferPos, and myBufferSize.

Referenced by mille(), and special().

180 {
181  // enough space for next nLocal + nGlobal derivatives incl. measurement?
182 
183  if (myBufferPos + nLocal + nGlobal + 2 >= myBufferSize) {
184  ++(myBufferInt[0]); // increase error count
185  std::cerr << "Mille::checkBufferSize: Buffer too short ("
186  << myBufferSize << "),"
187  << "\n need space for nLocal (" << nLocal<< ")"
188  << "/nGlobal (" << nGlobal << ") local/global derivatives, "
189  << myBufferPos + 1 << " already stored!"
190  << std::endl;
191  return false;
192  } else {
193  return true;
194  }
195 }
int myBufferInt[myBufferSize]
Definition: Mille.h:48
int myBufferPos
Definition: Mille.h:50
void Mille::end ( )

Definition at line 137 of file Mille.cc.

References i, myAsBinary, myBufferFloat, myBufferInt, myBufferPos, and myOutFile.

Referenced by MillePedeAlignmentAlgorithm::addLasBeam(), MillePedeAlignmentAlgorithm::addPxbSurvey(), MillePedeAlignmentAlgorithm::addReferenceTrajectory(), Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

138 {
139  // write set of derivatives with same local parameters to file
140  if (myBufferPos > 0) { // only if anything stored...
141  const int numWordsToWrite = (myBufferPos + 1)*2;
142 
143  if (myAsBinary) {
144  myOutFile.write(reinterpret_cast<const char*>(&numWordsToWrite),
145  sizeof(numWordsToWrite));
146  myOutFile.write(reinterpret_cast<char*>(myBufferFloat),
147  (myBufferPos+1) * sizeof(myBufferFloat[0]));
148  myOutFile.write(reinterpret_cast<char*>(myBufferInt),
149  (myBufferPos+1) * sizeof(myBufferInt[0]));
150  } else {
151  myOutFile << numWordsToWrite << "\n";
152  for (int i = 0; i < myBufferPos+1; ++i) {
153  myOutFile << myBufferFloat[i] << " ";
154  }
155  myOutFile << "\n";
156 
157  for (int i = 0; i < myBufferPos+1; ++i) {
158  myOutFile << myBufferInt[i] << " ";
159  }
160  myOutFile << "\n";
161  }
162  }
163  myBufferPos = -1; // reset buffer for next set of derivatives
164 }
int i
Definition: DBlmapReader.cc:9
bool myAsBinary
Definition: Mille.h:44
int myBufferInt[myBufferSize]
Definition: Mille.h:48
int myBufferPos
Definition: Mille.h:50
std::ofstream myOutFile
Definition: Mille.h:43
float myBufferFloat[myBufferSize]
Definition: Mille.h:49
void Mille::flushOutputFile ( )

Definition at line 130 of file Mille.cc.

References myOutFile.

Referenced by MillePedeAlignmentAlgorithm::endRun().

130  {
131  // flush output file
132  myOutFile.flush();
133 }
std::ofstream myOutFile
Definition: Mille.h:43
void Mille::kill ( )

Definition at line 121 of file Mille.cc.

References myBufferPos.

Referenced by MillePedeAlignmentAlgorithm::addReferenceTrajectory().

122 {
123  // reset buffers, i.e. kill derivatives accumulated for current set
124  myBufferPos = -1;
125 }
int myBufferPos
Definition: Mille.h:50
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 ecal_dqm_sourceclient-live_cfg::cerr, checkBufferSize(), i, myBufferFloat, myBufferInt, myBufferPos, myMaxLabel, myWriteZero, and newSet().

Referenced by MillePedeAlignmentAlgorithm::addLasBeam(), and MillePedeAlignmentAlgorithm::addPxbSurvey().

46 {
47  if (sigma <= 0.) return;
48  if (myBufferPos == -1) this->newSet(); // start, e.g. new track
49  if (!this->checkBufferSize(NLC, NGL)) return;
50 
51  // first store measurement
52  ++myBufferPos;
53  myBufferFloat[myBufferPos] = rMeas;
55 
56  // store local derivatives and local 'lables' 1,...,NLC
57  for (int i = 0; i < NLC; ++i) {
58  if (derLc[i] || myWriteZero) { // by default store only non-zero derivatives
59  ++myBufferPos;
60  myBufferFloat[myBufferPos] = derLc[i]; // local derivatives
61  myBufferInt [myBufferPos] = i+1; // index of local parameter
62  }
63  }
64 
65  // store uncertainty of measurement in between locals and globals
66  ++myBufferPos;
67  myBufferFloat[myBufferPos] = sigma;
69 
70  // store global derivatives and their lables
71  for (int i = 0; i < NGL; ++i) {
72  if (derGl[i] || myWriteZero) { // by default store only non-zero derivatives
73  if ((label[i] > 0 || myWriteZero) && label[i] <= myMaxLabel) { // and for valid labels
74  ++myBufferPos;
75  myBufferFloat[myBufferPos] = derGl[i]; // global derivatives
76  myBufferInt [myBufferPos] = label[i]; // index of global parameter
77  } else {
78  std::cerr << "Mille::mille: Invalid label " << label[i]
79  << " <= 0 or > " << myMaxLabel << std::endl;
80  }
81  }
82  }
83 }
int i
Definition: DBlmapReader.cc:9
void newSet()
Definition: Mille.cc:168
int myBufferInt[myBufferSize]
Definition: Mille.h:48
int myBufferPos
Definition: Mille.h:50
bool myWriteZero
Definition: Mille.h:45
bool checkBufferSize(int nLocal, int nGlobal)
Definition: Mille.cc:179
float myBufferFloat[myBufferSize]
Definition: Mille.h:49
void Mille::newSet ( )
private

Definition at line 168 of file Mille.cc.

References myBufferFloat, myBufferInt, myBufferPos, and myHasSpecial.

Referenced by mille(), and special().

169 {
170  // initilise for new set of locals, e.g. new track
171  myBufferPos = 0;
172  myHasSpecial = false;
173  myBufferFloat[0] = 0.0;
174  myBufferInt [0] = 0; // position 0 used as error counter
175 }
int myBufferInt[myBufferSize]
Definition: Mille.h:48
int myBufferPos
Definition: Mille.h:50
float myBufferFloat[myBufferSize]
Definition: Mille.h:49
bool myHasSpecial
Definition: Mille.h:51
void Mille::special ( int  nSpecial,
const float *  floatings,
const int *  integers 
)

Definition at line 86 of file Mille.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, checkBufferSize(), i, myBufferFloat, myBufferInt, myBufferPos, myHasSpecial, and newSet().

87 {
88  if (nSpecial == 0) return;
89  if (myBufferPos == -1) this->newSet(); // start, e.g. new track
90  if (myHasSpecial) {
91  std::cerr << "Mille::special: Special values already stored for this record."
92  << std::endl;
93  return;
94  }
95  if (!this->checkBufferSize(nSpecial, 0)) return;
96  myHasSpecial = true; // after newSet() (Note: MILLSP sets to buffer position...)
97 
98  // myBufferFloat[.] | myBufferInt[.]
99  // ------------------------------------
100  // 0.0 | 0
101  // -float(nSpecial) | 0
102  // The above indicates special data, following are nSpecial floating and nSpecial integer data.
103 
104  ++myBufferPos; // zero pair
106  myBufferInt [myBufferPos] = 0;
107 
108  ++myBufferPos; // nSpecial and zero
109  myBufferFloat[myBufferPos] = -nSpecial; // automatic conversion to float
110  myBufferInt [myBufferPos] = 0;
111 
112  for (int i = 0; i < nSpecial; ++i) {
113  ++myBufferPos;
114  myBufferFloat[myBufferPos] = floatings[i];
115  myBufferInt [myBufferPos] = integers[i];
116  }
117 }
int i
Definition: DBlmapReader.cc:9
void newSet()
Definition: Mille.cc:168
int myBufferInt[myBufferSize]
Definition: Mille.h:48
int myBufferPos
Definition: Mille.h:50
bool checkBufferSize(int nLocal, int nGlobal)
Definition: Mille.cc:179
float myBufferFloat[myBufferSize]
Definition: Mille.h:49
bool myHasSpecial
Definition: Mille.h:51

Member Data Documentation

bool Mille::myAsBinary
private

Definition at line 44 of file Mille.h.

Referenced by end().

float Mille::myBufferFloat[myBufferSize]
private

Definition at line 49 of file Mille.h.

Referenced by end(), Mille(), mille(), newSet(), and special().

int Mille::myBufferInt[myBufferSize]
private

Definition at line 48 of file Mille.h.

Referenced by checkBufferSize(), end(), Mille(), mille(), newSet(), and special().

int Mille::myBufferPos
private

Definition at line 50 of file Mille.h.

Referenced by checkBufferSize(), end(), kill(), mille(), newSet(), and special().

bool Mille::myHasSpecial
private

Definition at line 51 of file Mille.h.

Referenced by newSet(), and special().

std::ofstream Mille::myOutFile
private

Definition at line 43 of file Mille.h.

Referenced by end(), flushOutputFile(), Mille(), and ~Mille().

bool Mille::myWriteZero
private

Definition at line 45 of file Mille.h.

Referenced by mille().