CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MilleBinary.cc
Go to the documentation of this file.
1 /*
2  * MilleBinary.cpp
3  *
4  * Created on: Aug 31, 2011
5  * Author: kleinwrt
6  */
7 
9 
11 namespace gbl {
12 
14 
20  unsigned int aSize) :
21  binaryFile(fileName.c_str(), std::ios::binary | std::ios::out), intBuffer(), floatBuffer(), doubleBuffer(), doublePrecision(
22  doublePrec) {
23  intBuffer.reserve(aSize);
24  intBuffer.push_back(0); // first word is error counter
25  if (doublePrecision) {
26  doubleBuffer.reserve(aSize);
27  doubleBuffer.push_back(0.);
28 
29  } else {
30  floatBuffer.reserve(aSize);
31  floatBuffer.push_back(0.);
32  }
33 }
34 
36  binaryFile.close();
37 }
38 
40 
48 void MilleBinary::addData(double aMeas, double aErr,
49  const std::vector<unsigned int> &indLocal,
50  const std::vector<double> &derLocal, const std::vector<int> &labGlobal,
51  const std::vector<double> &derGlobal) {
52 
53  if (doublePrecision) {
54  // double values
55  intBuffer.push_back(0);
56  doubleBuffer.push_back(aMeas);
57  for (unsigned int i = 0; i < indLocal.size(); ++i) {
58  intBuffer.push_back(indLocal[i]);
59  doubleBuffer.push_back(derLocal[i]);
60  }
61  intBuffer.push_back(0);
62  doubleBuffer.push_back(aErr);
63  for (unsigned int i = 0; i < labGlobal.size(); ++i) {
64  if (derGlobal[i]) {
65  intBuffer.push_back(labGlobal[i]);
66  doubleBuffer.push_back(derGlobal[i]);
67  }
68  }
69  } else {
70  // float values
71  intBuffer.push_back(0);
72  floatBuffer.push_back(aMeas);
73  for (unsigned int i = 0; i < indLocal.size(); ++i) {
74  intBuffer.push_back(indLocal[i]);
75  floatBuffer.push_back(derLocal[i]);
76  }
77  intBuffer.push_back(0);
78  floatBuffer.push_back(aErr);
79  for (unsigned int i = 0; i < labGlobal.size(); ++i) {
80  if (derGlobal[i]) {
81  intBuffer.push_back(labGlobal[i]);
82  floatBuffer.push_back(derGlobal[i]);
83  }
84  }
85  }
86 }
87 
90 
91  const int recordLength =
92  (doublePrecision) ? -intBuffer.size() * 2 : intBuffer.size() * 2;
93  binaryFile.write(reinterpret_cast<const char*>(&recordLength),
94  sizeof(recordLength));
95  if (doublePrecision)
96  binaryFile.write(reinterpret_cast<char*>(&doubleBuffer[0]),
97  doubleBuffer.size() * sizeof(doubleBuffer[0]));
98  else
99  binaryFile.write(reinterpret_cast<char*>(&floatBuffer[0]),
100  floatBuffer.size() * sizeof(floatBuffer[0]));
101  binaryFile.write(reinterpret_cast<char*>(&intBuffer[0]),
102  intBuffer.size() * sizeof(intBuffer[0]));
103 // start with new record
104  intBuffer.resize(1);
105  if (doublePrecision)
106  doubleBuffer.resize(1);
107  else
108  floatBuffer.resize(1);
109 }
110 }
int i
Definition: DBlmapReader.cc:9
void writeRecord()
Write record to file.
Definition: MilleBinary.cc:89
MilleBinary(const std::string fileName="milleBinaryISN.dat", bool doublePrec=false, unsigned int aSize=2000)
Create binary file.
Definition: MilleBinary.cc:19
std::vector< int > intBuffer
Integer buffer.
Definition: MilleBinary.h:60
std::vector< double > doubleBuffer
Double buffer.
Definition: MilleBinary.h:62
tuple out
Definition: dbtoconf.py:99
virtual ~MilleBinary()
Definition: MilleBinary.cc:35
bool doublePrecision
Flag for storage in as double values.
Definition: MilleBinary.h:63
std::ofstream binaryFile
Binary File.
Definition: MilleBinary.h:59
void addData(double aMeas, double aPrec, const std::vector< unsigned int > &indLocal, const std::vector< double > &derLocal, const std::vector< int > &labGlobal, const std::vector< double > &derGlobal)
Add data block to (end of) record.
Definition: MilleBinary.cc:48
std::vector< float > floatBuffer
Float buffer.
Definition: MilleBinary.h:61