Project
Loading...
Searching...
No Matches
Mille.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17/*
18 RS: original Mille.cc from http://svnsrv.desy.de/public/MillepedeII/tags/V04-02-03
19*/
20
21#include "Align/Mille.h"
22#include "Framework/Logger.h"
23#include <fstream>
24#include <iostream>
25
26namespace o2
27{
28namespace align
29{
30//___________________________________________________________________________
31Mille::Mille(const std::string& outFileName, bool asBinary, bool writeZero)
32 : mOutFile(outFileName, (asBinary ? (std::ios::binary | std::ios::out | std::ios::trunc) : (std::ios::out | std::ios::trunc))),
33 mAsBinary(asBinary),
34 mWriteZero(writeZero)
35{
36 if (!mOutFile.is_open()) {
37 LOG(fatal) << "Failed to open Mille file " << outFileName;
38 }
39 mBufferInt.reserve(1024);
40 mBufferFloat.reserve(1024);
41 clear();
42}
43
44//___________________________________________________________________________
46
55void Mille::mille(int NLC, const float* derLc,
56 int NGL, const float* derGl, const int* label,
57 float rMeas, float sigma)
58{
59 if (sigma <= 0.) {
60 return;
61 }
62 // first store measurement
63 mBufferFloat.push_back(rMeas);
64 mBufferInt.push_back(0);
65
66 // store local derivatives and local 'lables' 1,...,NLC
67 for (int i = 0; i < NLC; ++i) {
68 if (derLc[i] || mWriteZero) { // by default store only non-zero derivatives
69 mBufferFloat.push_back(derLc[i]); // local derivatives
70 mBufferInt.push_back(i + 1); // index of local parameter
71 }
72 }
73
74 // store uncertainty of measurement in between locals and globals
75 mBufferFloat.push_back(sigma);
76 mBufferInt.push_back(0);
77
78 // store global derivatives and their labels
79 for (int i = 0; i < NGL; ++i) {
80 if (derGl[i] || mWriteZero) { // by default store only non-zero derivatives
81 if ((label[i] > 0 || mWriteZero) && label[i] <= MaxLabel) { // and for valid labels
82 mBufferFloat.push_back(derGl[i]); // global derivatives
83 mBufferInt.push_back(label[i]); // index of global parameter
84 } else {
85 LOGP(error, "Mille: invalid label {} <=0 or > {}", label[i], MaxLabel);
86 }
87 }
88 }
89}
90
91//___________________________________________________________________________
93
98void Mille::special(int nSpecial, const float* floats, const int* ints)
99{
100 if (nSpecial == 0) {
101 return;
102 }
103 if (mHasSpecial) {
104 LOG(error) << "Mille: special values already stored for this record.";
105 return;
106 }
107 mHasSpecial = true;
108 // mBufferFloat[.] | mBufferInt[.]
109 // ------------------------------------
110 // 0.0 | 0
111 // -float(nSpecial) | 0
112 // The above indicates special data, following are nSpecial floating and nSpecial integer data.
113 //
114 // zero pair
115 mBufferFloat.push_back(0.);
116 mBufferInt.push_back(0);
117 // nSpecial and zero
118 mBufferFloat.push_back(-nSpecial); // automatic conversion to float
119 mBufferInt.push_back(0);
120
121 for (int i = 0; i < nSpecial; ++i) {
122 mBufferFloat.push_back(floats[i]);
123 mBufferInt.push_back(ints[i]);
124 }
125}
126
127//___________________________________________________________________________
130{
131 int wrote = 0;
132 int nw = mBufferInt.size();
133 if (nw) { // only if anything stored...
134 const int numWordsToWrite = nw * 2;
135
136 if (mAsBinary) {
137 mOutFile.write(reinterpret_cast<const char*>(&numWordsToWrite), sizeof(int));
138 mOutFile.write(reinterpret_cast<const char*>(mBufferFloat.data()), nw * sizeof(mBufferFloat[0]));
139 mOutFile.write(reinterpret_cast<const char*>(mBufferInt.data()), nw * sizeof(mBufferInt[0]));
140 } else {
141 mOutFile << numWordsToWrite << "\n";
142 for (int i = 0; i < nw; i++) {
143 mOutFile << mBufferFloat[i] << " ";
144 }
145 mOutFile << "\n";
146 for (int i = 0; i < nw; i++) {
147 mOutFile << mBufferInt[i] << " ";
148 }
149 mOutFile << "\n";
150 }
151 wrote = nw * (sizeof(mBufferFloat[0]) + sizeof(mBufferInt[0])) + sizeof(int);
152 }
153 clear();
154 return wrote;
155}
156
157//___________________________________________________________________________
160{
161 mHasSpecial = false;
162 mBufferInt.clear();
163 mBufferFloat.clear();
164 mBufferFloat.push_back(0.f);
165 mBufferInt.push_back(0); // position 0 used as error counter
166}
167
168} // namespace align
169} // namespace o2
int32_t i
Class to write C binary file.
Mille(const std::string &outFileName, bool asBinary=true, bool writeZero=false)
Definition Mille.cxx:31
void mille(int NLC, const float *derLc, int NGL, const float *derGl, const int *label, float rMeas, float sigma)
Add measurement to buffer.
Definition Mille.cxx:55
void clear()
Initialize for new set of locals, e.g. new track.
Definition Mille.cxx:159
void special(int nSpecial, const float *floatings, const int *integers)
Add special data to buffer.
Definition Mille.cxx:98
int finalise()
Write buffer (set of derivatives with same local parameters) to file.
Definition Mille.cxx:129
const GLuint GLenum const void * binary
Definition glcorearb.h:1898
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
void align(gsl::span< ElinkEncoder< BareFormat, CHARGESUM > > elinks)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
std::string asBinary(uint64_t value)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"