Fork me on GitHub

source: git/classes/DelphesStream.cc@ be42bf4

ImprovedOutputFile Timing dual_readout llp
Last change on this file since be42bf4 was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

  • Property mode set to 100644
File size: 2.2 KB
Line 
1
2/** \class DelphesStream
3 *
4 * Provides an interface to manipulate c strings as if they were input streams
5 *
6 *
7 * $Date: 2012-11-15 13:57:55 $
8 * $Revision: 1.1 $
9 *
10 *
11 * \author P. Demin - UCL, Louvain-la-Neuve
12 *
13 */
14
15#include "classes/DelphesStream.h"
16
17#include <stdlib.h>
18#include <limits.h>
19#include <string.h>
20#include <stdio.h>
21#include <errno.h>
22#include <math.h>
23
24#include <iostream>
25
26using namespace std;
27
28//------------------------------------------------------------------------------
29
30bool DelphesStream::fFirstLongMin = true;
31bool DelphesStream::fFirstLongMax = true;
32bool DelphesStream::fFirstHugePos = true;
33bool DelphesStream::fFirstHugeNeg = true;
34bool DelphesStream::fFirstZero = true;
35
36//------------------------------------------------------------------------------
37
38DelphesStream::DelphesStream(char *buffer) :
39 fBuffer(buffer)
40{
41}
42
43//------------------------------------------------------------------------------
44
45bool DelphesStream::ReadDbl(double &value)
46{
47 char *start = fBuffer;
48 errno = 0;
49 value = strtod(start, &fBuffer);
50 if(errno == ERANGE)
51 {
52 if(fFirstHugePos && value == HUGE_VAL)
53 {
54 fFirstHugePos = false;
55 cout << "** WARNING: too large positive value, return " << value << endl;
56 }
57 else if(fFirstHugeNeg && value == -HUGE_VAL)
58 {
59 fFirstHugeNeg = false;
60 cout << "** WARNING: too large negative value, return " << value << endl;
61 }
62 else if(fFirstZero)
63 {
64 fFirstZero = false;
65 value = 0.0;
66 cout << "** WARNING: too small value, return " << value << endl;
67 }
68 }
69 return start != fBuffer;
70}
71
72//------------------------------------------------------------------------------
73
74bool DelphesStream::ReadInt(int &value)
75{
76 char *start = fBuffer;
77 errno = 0;
78 value = strtol(start, &fBuffer, 10);
79 if(errno == ERANGE)
80 {
81 if(fFirstLongMin && value == LONG_MIN)
82 {
83 fFirstLongMin = false;
84 cout << "** WARNING: too large positive value, return " << value << endl;
85 }
86 else if(fFirstLongMax && value == LONG_MAX)
87 {
88 fFirstLongMax = false;
89 cout << "** WARNING: too large negative value, return " << value << endl;
90 }
91 }
92 return start != fBuffer;
93}
94
95//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.