SND@LHC Software
Loading...
Searching...
No Matches
Mille Class Reference

Class to write C binary file. More...

#include <Mille.h>

Public Member Functions

 Mille (const char *outFileName, bool asBinary=true, bool writeZero=false)
 Opens outFileName (by default as binary file).
 
 ~Mille ()
 Closes file.
 
void mille (int NLC, const float *derLc, int NGL, const float *derGl, const int *label, float rMeas, float sigma)
 Add measurement to buffer.
 
void special (int nSpecial, const float *floatings, const int *integers)
 Add special data to buffer.
 
void kill ()
 Reset buffers, i.e. kill derivatives accumulated for current set.
 
void end ()
 Write buffer (set of derivatives with same local parameters) to file.
 

Private Types

enum  { myBufferSize = 5000 }
 buffer size for ints and floats More...
 
enum  { myMaxLabel = (0xFFFFFFFF - (1 << 31)) }
 largest label allowed: 2^31 - 1 More...
 

Private Member Functions

void newSet ()
 Initialize for new set of locals, e.g. new track.
 
bool checkBufferSize (int nLocal, int nGlobal)
 Enough space for next nLocal + nGlobal derivatives incl. measurement?
 

Private Attributes

std::ofstream myOutFile
 C-binary for output.
 
bool myAsBinary
 if false output as text
 
bool myWriteZero
 
int myBufferInt [myBufferSize]
 to collect labels etc.
 
float myBufferFloat [myBufferSize]
 to collect derivatives etc.
 
int myBufferPos
 position in buffer
 
bool myHasSpecial
 

Detailed Description

Class to write C binary file.

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 labels 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.3
Date
2007/04/16 17:47:38

(last update by

Author
flucke

)

Definition at line 50 of file Mille.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

buffer size for ints and floats

Enumerator
myBufferSize 

Definition at line 70 of file Mille.h.

70{myBufferSize = 5000};
@ myBufferSize
Definition Mille.h:70

◆ anonymous enum

anonymous enum
private

largest label allowed: 2^31 - 1

Enumerator
myMaxLabel 

Definition at line 76 of file Mille.h.

76{myMaxLabel = (0xFFFFFFFF - (1 << 31))};
@ myMaxLabel
Definition Mille.h:76

Constructor & Destructor Documentation

◆ Mille()

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

Opens outFileName (by default as binary file).

author : Gero Flucke, University Hamburg, 2006 date : October 2006

Revision
1.3
Date
2007/04/16 17:47:38

(last update by

Author
flucke

)

Parameters
[in]outFileNamefile name
[in]asBinaryflag for binary
[in]writeZeroflag for keeping of zeros

Definition at line 45 of file Mille.cc.

45 :
46 myOutFile(outFileName, (asBinary ? (std::ios::binary | std::ios::out) : std::ios::out)),
47 myAsBinary(asBinary), myWriteZero(writeZero), myBufferPos(-1), myHasSpecial(false)
48{
49 // Instead myBufferPos(-1), myHasSpecial(false) and the following two lines
50 // we could call newSet() and kill()...
51 myBufferInt[0] = 0;
52 myBufferFloat[0] = 0.;
53
54 if (!myOutFile.is_open()) {
55 std::cerr << "Mille::Mille: Could not open " << outFileName
56 << " as output file." << std::endl;
57 }
58}
int myBufferInt[myBufferSize]
to collect labels etc.
Definition Mille.h:71
bool myAsBinary
if false output as text
Definition Mille.h:67
std::ofstream myOutFile
C-binary for output.
Definition Mille.h:66
bool myHasSpecial
Definition Mille.h:74
float myBufferFloat[myBufferSize]
to collect derivatives etc.
Definition Mille.h:72
int myBufferPos
position in buffer
Definition Mille.h:73
bool myWriteZero
Definition Mille.h:68

◆ ~Mille()

Mille::~Mille ( )

Closes file.

Definition at line 62 of file Mille.cc.

63{
64 myOutFile.close();
65}

Member Function Documentation

◆ checkBufferSize()

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

Enough space for next nLocal + nGlobal derivatives incl. measurement?

Parameters
[in]nLocalnumber of local derivatives
[in]nGlobalnumber of global derivatives
Returns
true if sufficient space available (else false)

Definition at line 214 of file Mille.cc.

215{
216 if (myBufferPos + nLocal + nGlobal + 2 >= myBufferSize) {
217 ++(myBufferInt[0]); // increase error count
218 std::cerr << "Mille::checkBufferSize: Buffer too short ("
219 << myBufferSize << "),"
220 << "\n need space for nLocal (" << nLocal<< ")"
221 << "/nGlobal (" << nGlobal << ") local/global derivatives, "
222 << myBufferPos + 1 << " already stored!"
223 << std::endl;
224 return false;
225 } else {
226 return true;
227 }
228}

◆ end()

void Mille::end ( )

Write buffer (set of derivatives with same local parameters) to file.

Definition at line 169 of file Mille.cc.

170{
171 if (myBufferPos > 0) { // only if anything stored...
172 const int numWordsToWrite = (myBufferPos + 1)*2;
173
174 if (myAsBinary) {
175 myOutFile.write(reinterpret_cast<const char*>(&numWordsToWrite),
176 sizeof(numWordsToWrite));
177 myOutFile.write(reinterpret_cast<char*>(myBufferFloat),
178 (myBufferPos+1) * sizeof(myBufferFloat[0]));
179 myOutFile.write(reinterpret_cast<char*>(myBufferInt),
180 (myBufferPos+1) * sizeof(myBufferInt[0]));
181 } else {
182 myOutFile << numWordsToWrite << "\n";
183 for (int i = 0; i < myBufferPos+1; ++i) {
184 myOutFile << myBufferFloat[i] << " ";
185 }
186 myOutFile << "\n";
187
188 for (int i = 0; i < myBufferPos+1; ++i) {
189 myOutFile << myBufferInt[i] << " ";
190 }
191 myOutFile << "\n";
192 }
193 }
194 myBufferPos = -1; // reset buffer for next set of derivatives
195}
int i
Definition ShipAna.py:86

◆ kill()

void Mille::kill ( )

Reset buffers, i.e. kill derivatives accumulated for current set.

Definition at line 162 of file Mille.cc.

163{
164 myBufferPos = -1;
165}

◆ mille()

void Mille::mille ( int  NLC,
const float *  derLc,
int  NGL,
const float *  derGl,
const int *  label,
float  rMeas,
float  sigma 
)

Add measurement to buffer.

Parameters
[in]NLCnumber of local derivatives
[in]derLclocal derivatives
[in]NGLnumber of global derivatives
[in]derGlglobal derivatives
[in]labelglobal labels
[in]rMeasmeasurement (residuum)
[in]sigmaerror

Definition at line 78 of file Mille.cc.

81{
82 if (sigma <= 0.) return;
83 if (myBufferPos == -1) this->newSet(); // start, e.g. new track
84 if (!this->checkBufferSize(NLC, NGL)) return;
85
86 // first store measurement
90
91 // store local derivatives and local 'lables' 1,...,NLC
92 for (int i = 0; i < NLC; ++i) {
93 if (derLc[i] || myWriteZero) { // by default store only non-zero derivatives
95 myBufferFloat[myBufferPos] = derLc[i]; // local derivatives
96 myBufferInt [myBufferPos] = i+1; // index of local parameter
97 }
98 }
99
100 // store uncertainty of measurement in between locals and globals
101 ++myBufferPos;
104
105 // store global derivatives and their labels
106 for (int i = 0; i < NGL; ++i) {
107 if (derGl[i] || myWriteZero) { // by default store only non-zero derivatives
108 if ((label[i] > 0 || myWriteZero) && label[i] <= myMaxLabel) { // and for valid labels
109 ++myBufferPos;
110 myBufferFloat[myBufferPos] = derGl[i]; // global derivatives
111 myBufferInt [myBufferPos] = label[i]; // index of global parameter
112 } else {
113 std::cerr << "Mille::mille: Invalid label " << label[i]
114 << " <= 0 or > " << myMaxLabel << std::endl;
115 }
116 }
117 }
118}
bool checkBufferSize(int nLocal, int nGlobal)
Enough space for next nLocal + nGlobal derivatives incl. measurement?
Definition Mille.cc:214
void newSet()
Initialize for new set of locals, e.g. new track.
Definition Mille.cc:199

◆ newSet()

void Mille::newSet ( )
private

Initialize for new set of locals, e.g. new track.

Definition at line 199 of file Mille.cc.

200{
201 myBufferPos = 0;
202 myHasSpecial = false;
203 myBufferFloat[0] = 0.0;
204 myBufferInt [0] = 0; // position 0 used as error counter
205}

◆ special()

void Mille::special ( int  nSpecial,
const float *  floatings,
const int *  integers 
)

Add special data to buffer.

Parameters
[in]nSpecialnumber of floats/ints
[in]floatingsfloats
[in]integersints

Definition at line 127 of file Mille.cc.

128{
129 if (nSpecial == 0) return;
130 if (myBufferPos == -1) this->newSet(); // start, e.g. new track
131 if (myHasSpecial) {
132 std::cerr << "Mille::special: Special values already stored for this record."
133 << std::endl;
134 return;
135 }
136 if (!this->checkBufferSize(nSpecial, 0)) return;
137 myHasSpecial = true; // after newSet() (Note: MILLSP sets to buffer position...)
138
139 // myBufferFloat[.] | myBufferInt[.]
140 // ------------------------------------
141 // 0.0 | 0
142 // -float(nSpecial) | 0
143 // The above indicates special data, following are nSpecial floating and nSpecial integer data.
144
145 ++myBufferPos; // zero pair
148
149 ++myBufferPos; // nSpecial and zero
150 myBufferFloat[myBufferPos] = -nSpecial; // automatic conversion to float
152
153 for (int i = 0; i < nSpecial; ++i) {
154 ++myBufferPos;
155 myBufferFloat[myBufferPos] = floatings[i];
156 myBufferInt [myBufferPos] = integers[i];
157 }
158}

Member Data Documentation

◆ myAsBinary

bool Mille::myAsBinary
private

if false output as text

Definition at line 67 of file Mille.h.

◆ myBufferFloat

float Mille::myBufferFloat[myBufferSize]
private

to collect derivatives etc.

Definition at line 72 of file Mille.h.

◆ myBufferInt

int Mille::myBufferInt[myBufferSize]
private

to collect labels etc.

Definition at line 71 of file Mille.h.

◆ myBufferPos

int Mille::myBufferPos
private

position in buffer

Definition at line 73 of file Mille.h.

◆ myHasSpecial

bool Mille::myHasSpecial
private

if true, special(..) already called for this record

Definition at line 74 of file Mille.h.

◆ myOutFile

std::ofstream Mille::myOutFile
private

C-binary for output.

Definition at line 66 of file Mille.h.

◆ myWriteZero

bool Mille::myWriteZero
private

if true also write out derivatives/labels ==0

Definition at line 68 of file Mille.h.


The documentation for this class was generated from the following files: