CMS 3D CMS Logo

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 resetOutputFile ()
 
void special (int nSpecial, const float *floatings, const int *integers)
 
 ~Mille ()
 

Private Types

enum  { bufferSize_ = 5000 }
 
enum  { maxLabel_ = (0xFFFFFFFF - (1 << 31)) }
 

Private Member Functions

bool checkBufferSize (int nLocal, int nGlobal)
 
void newSet ()
 

Private Attributes

bool asBinary_
 
float bufferFloat_ [bufferSize_]
 
int bufferInt_ [bufferSize_]
 
int bufferPos_
 
const std::ios_base::openmode fileMode_
 
const std::string fileName_
 
bool hasSpecial_
 
std::ofstream outFile_
 
bool writeZero_
 

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

anonymous enum
private
Enumerator
bufferSize_ 

Definition at line 48 of file Mille.h.

48 { bufferSize_ = 5000 };

◆ anonymous enum

anonymous enum
private
Enumerator
maxLabel_ 

Definition at line 54 of file Mille.h.

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

Constructor & Destructor Documentation

◆ Mille()

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

Definition at line 17 of file Mille.cc.

References bufferFloat_, bufferInt_, fileName_, and outFile_.

18  : fileMode_(asBinary ? (std::ios::binary | std::ios::out) : std::ios::out),
21  asBinary_(asBinary),
22  writeZero_(writeZero),
23  bufferPos_(-1),
24  hasSpecial_(false) {
25  // opens outFileName, by default as binary file
26 
27  // Instead bufferPos_(-1), hasSpecial_(false) and the following two lines
28  // we could call newSet() and kill()...
29  bufferInt_[0] = 0;
30  bufferFloat_[0] = 0.;
31 
32  if (!outFile_.is_open()) {
33  edm::LogError("Alignment") << "Mille::Mille: Could not open " << fileName_ << " as output file.";
34  }
35 }
bool writeZero_
Definition: Mille.h:46
int bufferInt_[bufferSize_]
Definition: Mille.h:49
Log< level::Error, false > LogError
float bufferFloat_[bufferSize_]
Definition: Mille.h:50
std::ofstream outFile_
Definition: Mille.h:44
bool asBinary_
Definition: Mille.h:45
bool hasSpecial_
Definition: Mille.h:52
const std::ios_base::openmode fileMode_
Definition: Mille.h:42
int bufferPos_
Definition: Mille.h:51
const std::string fileName_
Definition: Mille.h:43

◆ ~Mille()

Mille::~Mille ( )

Definition at line 39 of file Mille.cc.

References outFile_.

39  {
40  // closes file
41  outFile_.close();
42 }
std::ofstream outFile_
Definition: Mille.h:44

Member Function Documentation

◆ checkBufferSize()

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

Definition at line 186 of file Mille.cc.

References bufferInt_, bufferPos_, and bufferSize_.

Referenced by mille(), and special().

186  {
187  // enough space for next nLocal + nGlobal derivatives incl. measurement?
188 
189  if (bufferPos_ + nLocal + nGlobal + 2 >= bufferSize_) {
190  ++(bufferInt_[0]); // increase error count
191  edm::LogError("Alignment") << "Mille::checkBufferSize: Buffer too short (" << bufferSize_ << "),"
192  << "\n need space for nLocal (" << nLocal << ")"
193  << "/nGlobal (" << nGlobal << ") local/global derivatives, " << bufferPos_ + 1
194  << " already stored!";
195  return false;
196  } else {
197  return true;
198  }
199 }
int bufferInt_[bufferSize_]
Definition: Mille.h:49
Log< level::Error, false > LogError
int bufferPos_
Definition: Mille.h:51

◆ end()

void Mille::end ( )

Definition at line 149 of file Mille.cc.

References asBinary_, bufferFloat_, bufferInt_, bufferPos_, mps_fire::i, and outFile_.

Referenced by Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

149  {
150  // write set of derivatives with same local parameters to file
151  if (bufferPos_ > 0) { // only if anything stored...
152  const int numWordsToWrite = (bufferPos_ + 1) * 2;
153 
154  if (asBinary_) {
155  outFile_.write(reinterpret_cast<const char *>(&numWordsToWrite), sizeof(numWordsToWrite));
156  outFile_.write(reinterpret_cast<char *>(bufferFloat_), (bufferPos_ + 1) * sizeof(bufferFloat_[0]));
157  outFile_.write(reinterpret_cast<char *>(bufferInt_), (bufferPos_ + 1) * sizeof(bufferInt_[0]));
158  } else {
159  outFile_ << numWordsToWrite << "\n";
160  for (int i = 0; i < bufferPos_ + 1; ++i) {
161  outFile_ << bufferFloat_[i] << " ";
162  }
163  outFile_ << "\n";
164 
165  for (int i = 0; i < bufferPos_ + 1; ++i) {
166  outFile_ << bufferInt_[i] << " ";
167  }
168  outFile_ << "\n";
169  }
170  }
171  bufferPos_ = -1; // reset buffer for next set of derivatives
172 }
int bufferInt_[bufferSize_]
Definition: Mille.h:49
float bufferFloat_[bufferSize_]
Definition: Mille.h:50
std::ofstream outFile_
Definition: Mille.h:44
bool asBinary_
Definition: Mille.h:45
int bufferPos_
Definition: Mille.h:51

◆ flushOutputFile()

void Mille::flushOutputFile ( )

Definition at line 131 of file Mille.cc.

References outFile_.

131  {
132  // flush output file
133  outFile_.flush();
134 }
std::ofstream outFile_
Definition: Mille.h:44

◆ kill()

void Mille::kill ( )

Definition at line 124 of file Mille.cc.

References bufferPos_.

124  {
125  // reset buffers, i.e. kill derivatives accumulated for current set
126  bufferPos_ = -1;
127 }
int bufferPos_
Definition: Mille.h:51

◆ mille()

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

Definition at line 46 of file Mille.cc.

References bufferFloat_, bufferInt_, bufferPos_, checkBufferSize(), mps_fire::i, label, maxLabel_, newSet(), and writeZero_.

46  {
47  if (sigma <= 0.)
48  return;
49  if (bufferPos_ == -1)
50  this->newSet(); // start, e.g. new track
51  if (!this->checkBufferSize(NLC, NGL))
52  return;
53 
54  // first store measurement
55  ++bufferPos_;
56  bufferFloat_[bufferPos_] = rMeas;
58 
59  // store local derivatives and local 'lables' 1,...,NLC
60  for (int i = 0; i < NLC; ++i) {
61  if (derLc[i] || writeZero_) { // by default store only non-zero derivatives
62  ++bufferPos_;
63  bufferFloat_[bufferPos_] = derLc[i]; // local derivatives
64  bufferInt_[bufferPos_] = i + 1; // index of local parameter
65  }
66  }
67 
68  // store uncertainty of measurement in between locals and globals
69  ++bufferPos_;
70  bufferFloat_[bufferPos_] = sigma;
72 
73  // store global derivatives and their lables
74  for (int i = 0; i < NGL; ++i) {
75  if (derGl[i] || writeZero_) { // by default store only non-zero derivatives
76  if ((label[i] > 0 || writeZero_) && label[i] <= maxLabel_) { // and for valid labels
77  ++bufferPos_;
78  bufferFloat_[bufferPos_] = derGl[i]; // global derivatives
79  bufferInt_[bufferPos_] = label[i]; // index of global parameter
80  } else {
81  edm::LogError("Alignment") << "Mille::mille: Invalid label " << label[i] << " <= 0 or > " << maxLabel_;
82  }
83  }
84  }
85 }
void newSet()
Definition: Mille.cc:176
bool writeZero_
Definition: Mille.h:46
int bufferInt_[bufferSize_]
Definition: Mille.h:49
Log< level::Error, false > LogError
float bufferFloat_[bufferSize_]
Definition: Mille.h:50
char const * label
bool checkBufferSize(int nLocal, int nGlobal)
Definition: Mille.cc:186
int bufferPos_
Definition: Mille.h:51

◆ newSet()

void Mille::newSet ( )
private

Definition at line 176 of file Mille.cc.

References bufferFloat_, bufferInt_, bufferPos_, and hasSpecial_.

Referenced by mille(), and special().

176  {
177  // initilise for new set of locals, e.g. new track
178  bufferPos_ = 0;
179  hasSpecial_ = false;
180  bufferFloat_[0] = 0.0;
181  bufferInt_[0] = 0; // position 0 used as error counter
182 }
int bufferInt_[bufferSize_]
Definition: Mille.h:49
float bufferFloat_[bufferSize_]
Definition: Mille.h:50
bool hasSpecial_
Definition: Mille.h:52
int bufferPos_
Definition: Mille.h:51

◆ resetOutputFile()

void Mille::resetOutputFile ( )

Definition at line 138 of file Mille.cc.

References fileMode_, fileName_, and outFile_.

138  {
139  // flush output file
140  outFile_.close();
142  if (!outFile_.is_open()) {
143  edm::LogError("Alignment") << "Mille::resetOutputFile: Could not reopen " << fileName_ << ".";
144  }
145 }
Log< level::Error, false > LogError
std::ofstream outFile_
Definition: Mille.h:44
const std::ios_base::openmode fileMode_
Definition: Mille.h:42
const std::string fileName_
Definition: Mille.h:43

◆ special()

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

Definition at line 88 of file Mille.cc.

References bufferFloat_, bufferInt_, bufferPos_, checkBufferSize(), hasSpecial_, mps_fire::i, and newSet().

88  {
89  if (nSpecial == 0)
90  return;
91  if (bufferPos_ == -1)
92  this->newSet(); // start, e.g. new track
93  if (hasSpecial_) {
94  edm::LogError("Alignment") << "Mille::special: Special values already stored for this record.";
95  return;
96  }
97  if (!this->checkBufferSize(nSpecial, 0))
98  return;
99  hasSpecial_ = true; // after newSet() (Note: MILLSP sets to buffer position...)
100 
101  // bufferFloat_[.] | bufferInt_[.]
102  // ------------------------------------
103  // 0.0 | 0
104  // -float(nSpecial) | 0
105  // The above indicates special data, following are nSpecial floating and nSpecial integer data.
106 
107  ++bufferPos_; // zero pair
108  bufferFloat_[bufferPos_] = 0.;
109  bufferInt_[bufferPos_] = 0;
110 
111  ++bufferPos_; // nSpecial and zero
112  bufferFloat_[bufferPos_] = -nSpecial; // automatic conversion to float
113  bufferInt_[bufferPos_] = 0;
114 
115  for (int i = 0; i < nSpecial; ++i) {
116  ++bufferPos_;
117  bufferFloat_[bufferPos_] = floatings[i];
118  bufferInt_[bufferPos_] = integers[i];
119  }
120 }
void newSet()
Definition: Mille.cc:176
int bufferInt_[bufferSize_]
Definition: Mille.h:49
Log< level::Error, false > LogError
float bufferFloat_[bufferSize_]
Definition: Mille.h:50
bool checkBufferSize(int nLocal, int nGlobal)
Definition: Mille.cc:186
bool hasSpecial_
Definition: Mille.h:52
int bufferPos_
Definition: Mille.h:51

Member Data Documentation

◆ asBinary_

bool Mille::asBinary_
private

Definition at line 45 of file Mille.h.

Referenced by end().

◆ bufferFloat_

float Mille::bufferFloat_[bufferSize_]
private

Definition at line 50 of file Mille.h.

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

◆ bufferInt_

int Mille::bufferInt_[bufferSize_]
private

Definition at line 49 of file Mille.h.

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

◆ bufferPos_

int Mille::bufferPos_
private

Definition at line 51 of file Mille.h.

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

◆ fileMode_

const std::ios_base::openmode Mille::fileMode_
private

Definition at line 42 of file Mille.h.

Referenced by resetOutputFile().

◆ fileName_

const std::string Mille::fileName_
private

Definition at line 43 of file Mille.h.

Referenced by Mille(), and resetOutputFile().

◆ hasSpecial_

bool Mille::hasSpecial_
private

Definition at line 52 of file Mille.h.

Referenced by newSet(), and special().

◆ outFile_

std::ofstream Mille::outFile_
private

Definition at line 44 of file Mille.h.

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

◆ writeZero_

bool Mille::writeZero_
private

Definition at line 46 of file Mille.h.

Referenced by mille().