BmnRoot
Loading...
Searching...
No Matches
BmnMille.cxx
Go to the documentation of this file.
1#include "BmnMille.h"
2//___________________________________________________________________________
3
5
11BmnMille::BmnMille(const Char_t* outFileName, Bool_t asBinary, Bool_t writeZero) :
12myOutFile(outFileName, (asBinary ? (std::ios::binary | std::ios::out) : std::ios::out)),
13myAsBinary(asBinary), myWriteZero(writeZero), myBufferPos(-1), myHasSpecial(kFALSE) {
14 // Instead myBufferPos(-1), myHasSpecial(false) and the following two lines
15 // we could call newSet() and kill()...
16 myBufferInt[0] = 0;
17 myBufferFloat[0] = 0.;
18
19 if (!myOutFile.is_open()) {
20 cerr << "Mille::Mille: Could not open " << outFileName
21 << " as output file." << endl;
22 }
23}
24
25//___________________________________________________________________________
27
29 myOutFile.close();
30}
31
32//___________________________________________________________________________
34
44void BmnMille::mille(Int_t NLC, const Double_t* derLc,
45 Int_t NGL, const Double_t* derGl, const Int_t* label,
46 Double_t rMeas, Double_t sigma) {
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;
54 myBufferInt [myBufferPos] = 0;
55
56 // store local derivatives and local 'lables' 1,...,NLC
57 for (Int_t 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;
68 myBufferInt [myBufferPos] = 0;
69
70 // store global derivatives and their labels
71 for (Int_t 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 cerr << "Mille::mille: Invalid label " << label[i]
79 << " <= 0 or > " << myMaxLabel << endl;
80 }
81 }
82 }
83}
84
85//___________________________________________________________________________
87
93void BmnMille::special(Int_t nSpecial, const Double_t* floatings, const Int_t* integers) {
94 if (nSpecial == 0) return;
95 if (myBufferPos == -1) this->newSet(); // start, e.g. new track
96 if (myHasSpecial) {
97 cerr << "Mille::special: Special values already stored for this record."
98 << endl;
99 return;
100 }
101 if (!this->checkBufferSize(nSpecial, 0)) return;
102 myHasSpecial = kTRUE; // after newSet() (Note: MILLSP sets to buffer position...)
103
104 // myBufferFloat[.] | myBufferInt[.]
105 // ------------------------------------
106 // 0.0 | 0
107 // -float(nSpecial) | 0
108 // The above indicates special data, following are nSpecial floating and nSpecial integer data.
109
110 ++myBufferPos; // zero pair
111 myBufferFloat[myBufferPos] = 0.;
112 myBufferInt [myBufferPos] = 0;
113
114 ++myBufferPos; // nSpecial and zero
115 myBufferFloat[myBufferPos] = -nSpecial; // automatic conversion to float
116 myBufferInt [myBufferPos] = 0;
117
118 for (Int_t i = 0; i < nSpecial; ++i) {
119 ++myBufferPos;
120 myBufferFloat[myBufferPos] = floatings[i];
121 myBufferInt [myBufferPos] = integers[i];
122 }
123}
124
125//___________________________________________________________________________
127
129 myBufferPos = -1;
130}
131
132//___________________________________________________________________________
134
136 if (myBufferPos > 0) { // only if anything stored...
137 const Int_t numWordsToWrite = (myBufferPos + 1)*2;
138
139 if (myAsBinary) {
140 myOutFile.write(reinterpret_cast<const char*> (&numWordsToWrite),
141 sizeof (numWordsToWrite));
142 myOutFile.write(reinterpret_cast<char*> (myBufferFloat),
143 (myBufferPos + 1) * sizeof (myBufferFloat[0]));
144 myOutFile.write(reinterpret_cast<char*> (myBufferInt),
145 (myBufferPos + 1) * sizeof (myBufferInt[0]));
146 } else {
147 myOutFile << numWordsToWrite << "\n";
148 for (Int_t i = 0; i < myBufferPos + 1; ++i) {
149 myOutFile << myBufferFloat[i] << " ";
150 }
151 myOutFile << "\n";
152
153 for (Int_t i = 0; i < myBufferPos + 1; ++i) {
154 myOutFile << myBufferInt[i] << " ";
155 }
156 myOutFile << "\n";
157 }
158 }
159 myBufferPos = -1; // reset buffer for next set of derivatives
160}
161
162//___________________________________________________________________________
164
165void BmnMille::newSet() {
166 myBufferPos = 0;
167 myHasSpecial = kFALSE;
168 myBufferFloat[0] = 0.0;
169 myBufferInt [0] = 0; // position 0 used as error counter
170}
171
172//___________________________________________________________________________
174
180bool BmnMille::checkBufferSize(Int_t nLocal, Int_t nGlobal) {
181 if (myBufferPos + nLocal + nGlobal + 2 >= myBufferSize) {
182 ++(myBufferInt[0]); // increase error count
183 std::cerr << "Mille::checkBufferSize: Buffer too short ("
184 << myBufferSize << "),"
185 << "\n need space for nLocal (" << nLocal << ")"
186 << "/nGlobal (" << nGlobal << ") local/global derivatives, "
187 << myBufferPos + 1 << " already stored!"
188 << std::endl;
189 return kFALSE;
190 } else {
191 return kTRUE;
192 }
193}
int i
Definition P4_F32vec4.h:22
void end()
Write buffer (set of derivatives with same local parameters) to file.
Definition BmnMille.cxx:135
void mille(Int_t NLC, const Double_t *derLc, Int_t NGL, const Double_t *derGl, const Int_t *label, Double_t rMeas, Double_t sigma)
Add measurement to buffer.
Definition BmnMille.cxx:44
~BmnMille()
Closes file.
Definition BmnMille.cxx:28
BmnMille(const Char_t *outFileName, Bool_t asBinary=kTRUE, Bool_t writeZero=kFALSE)
Opens outFileName (by default as binary file).
Definition BmnMille.cxx:11
void kill()
Reset buffers, i.e. kill derivatives accumulated for current set.
Definition BmnMille.cxx:128
void special(Int_t nSpecial, const Double_t *floatings, const Int_t *integers)
Add special data to buffer.
Definition BmnMille.cxx:93
STL namespace.