test
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 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
private
Enumerator
bufferSize_ 

Definition at line 50 of file Mille.h.

50 {bufferSize_ = 5000};
anonymous enum
private
Enumerator
maxLabel_ 

Definition at line 56 of file Mille.h.

56 {maxLabel_ = (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 17 of file Mille.cc.

References bufferFloat_, bufferInt_, fileName_, and outFile_.

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

Definition at line 38 of file Mille.cc.

References outFile_.

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

Member Function Documentation

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

Definition at line 196 of file Mille.cc.

References bufferInt_, bufferPos_, and bufferSize_.

Referenced by mille(), and special().

197 {
198  // enough space for next nLocal + nGlobal derivatives incl. measurement?
199 
200  if (bufferPos_ + nLocal + nGlobal + 2 >= bufferSize_) {
201  ++(bufferInt_[0]); // increase error count
202  edm::LogError("Alignment")
203  << "Mille::checkBufferSize: Buffer too short ("
204  << bufferSize_ << "),"
205  << "\n need space for nLocal (" << nLocal<< ")"
206  << "/nGlobal (" << nGlobal << ") local/global derivatives, "
207  << bufferPos_ + 1 << " already stored!";
208  return false;
209  } else {
210  return true;
211  }
212 }
int bufferInt_[bufferSize_]
Definition: Mille.h:51
int bufferPos_
Definition: Mille.h:53
void Mille::end ( )

Definition at line 154 of file Mille.cc.

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

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

155 {
156  // write set of derivatives with same local parameters to file
157  if (bufferPos_ > 0) { // only if anything stored...
158  const int numWordsToWrite = (bufferPos_ + 1)*2;
159 
160  if (asBinary_) {
161  outFile_.write(reinterpret_cast<const char*>(&numWordsToWrite),
162  sizeof(numWordsToWrite));
163  outFile_.write(reinterpret_cast<char*>(bufferFloat_),
164  (bufferPos_+1) * sizeof(bufferFloat_[0]));
165  outFile_.write(reinterpret_cast<char*>(bufferInt_),
166  (bufferPos_+1) * sizeof(bufferInt_[0]));
167  } else {
168  outFile_ << numWordsToWrite << "\n";
169  for (int i = 0; i < bufferPos_+1; ++i) {
170  outFile_ << bufferFloat_[i] << " ";
171  }
172  outFile_ << "\n";
173 
174  for (int i = 0; i < bufferPos_+1; ++i) {
175  outFile_ << bufferInt_[i] << " ";
176  }
177  outFile_ << "\n";
178  }
179  }
180  bufferPos_ = -1; // reset buffer for next set of derivatives
181 }
int i
Definition: DBlmapReader.cc:9
int bufferInt_[bufferSize_]
Definition: Mille.h:51
float bufferFloat_[bufferSize_]
Definition: Mille.h:52
std::ofstream outFile_
Definition: Mille.h:46
bool asBinary_
Definition: Mille.h:47
int bufferPos_
Definition: Mille.h:53
void Mille::flushOutputFile ( )

Definition at line 134 of file Mille.cc.

References outFile_.

134  {
135  // flush output file
136  outFile_.flush();
137 }
std::ofstream outFile_
Definition: Mille.h:46
void Mille::kill ( )

Definition at line 125 of file Mille.cc.

References bufferPos_.

126 {
127  // reset buffers, i.e. kill derivatives accumulated for current set
128  bufferPos_ = -1;
129 }
int bufferPos_
Definition: Mille.h:53
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(), i, maxLabel_, newSet(), and writeZero_.

49 {
50  if (sigma <= 0.) return;
51  if (bufferPos_ == -1) this->newSet(); // start, e.g. new track
52  if (!this->checkBufferSize(NLC, NGL)) return;
53 
54  // first store measurement
55  ++bufferPos_;
56  bufferFloat_[bufferPos_] = rMeas;
57  bufferInt_ [bufferPos_] = 0;
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;
71  bufferInt_ [bufferPos_] = 0;
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")
82  << "Mille::mille: Invalid label " << label[i]
83  << " <= 0 or > " << maxLabel_;
84  }
85  }
86  }
87 }
int i
Definition: DBlmapReader.cc:9
void newSet()
Definition: Mille.cc:185
bool writeZero_
Definition: Mille.h:48
int bufferInt_[bufferSize_]
Definition: Mille.h:51
float bufferFloat_[bufferSize_]
Definition: Mille.h:52
bool checkBufferSize(int nLocal, int nGlobal)
Definition: Mille.cc:196
int bufferPos_
Definition: Mille.h:53
void Mille::newSet ( )
private

Definition at line 185 of file Mille.cc.

References bufferFloat_, bufferInt_, bufferPos_, and hasSpecial_.

Referenced by mille(), and special().

186 {
187  // initilise for new set of locals, e.g. new track
188  bufferPos_ = 0;
189  hasSpecial_ = false;
190  bufferFloat_[0] = 0.0;
191  bufferInt_ [0] = 0; // position 0 used as error counter
192 }
int bufferInt_[bufferSize_]
Definition: Mille.h:51
float bufferFloat_[bufferSize_]
Definition: Mille.h:52
bool hasSpecial_
Definition: Mille.h:54
int bufferPos_
Definition: Mille.h:53
void Mille::resetOutputFile ( )

Definition at line 142 of file Mille.cc.

References fileMode_, fileName_, and outFile_.

142  {
143  // flush output file
144  outFile_.close();
146  if (!outFile_.is_open()) {
147  edm::LogError("Alignment")
148  << "Mille::resetOutputFile: Could not reopen " << fileName_ << ".";
149  }
150 }
std::ofstream outFile_
Definition: Mille.h:46
const std::ios_base::openmode fileMode_
Definition: Mille.h:44
const std::string fileName_
Definition: Mille.h:45
void Mille::special ( int  nSpecial,
const float *  floatings,
const int *  integers 
)

Definition at line 90 of file Mille.cc.

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

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

Member Data Documentation

bool Mille::asBinary_
private

Definition at line 47 of file Mille.h.

Referenced by end().

float Mille::bufferFloat_[bufferSize_]
private

Definition at line 52 of file Mille.h.

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

int Mille::bufferInt_[bufferSize_]
private

Definition at line 51 of file Mille.h.

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

int Mille::bufferPos_
private

Definition at line 53 of file Mille.h.

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

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

Definition at line 44 of file Mille.h.

Referenced by resetOutputFile().

const std::string Mille::fileName_
private

Definition at line 45 of file Mille.h.

Referenced by Mille(), and resetOutputFile().

bool Mille::hasSpecial_
private

Definition at line 54 of file Mille.h.

Referenced by newSet(), and special().

std::ofstream Mille::outFile_
private

Definition at line 46 of file Mille.h.

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

bool Mille::writeZero_
private

Definition at line 48 of file Mille.h.

Referenced by mille().