1 | /*
|
---|
2 | * Delphes: a framework for fast simulation of a generic collider experiment
|
---|
3 | * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | /** \class DelphesStream
|
---|
21 | *
|
---|
22 | * Provides an interface to manipulate c strings as if they were input streams
|
---|
23 | *
|
---|
24 | *
|
---|
25 | * $Date: 2012-11-15 13:57:55 $
|
---|
26 | * $Revision: 1.1 $
|
---|
27 | *
|
---|
28 | *
|
---|
29 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
30 | *
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include "classes/DelphesStream.h"
|
---|
34 |
|
---|
35 | #include <stdlib.h>
|
---|
36 | #include <limits.h>
|
---|
37 | #include <string.h>
|
---|
38 | #include <stdio.h>
|
---|
39 | #include <errno.h>
|
---|
40 | #include <math.h>
|
---|
41 |
|
---|
42 | #include <iostream>
|
---|
43 |
|
---|
44 | using namespace std;
|
---|
45 |
|
---|
46 | //------------------------------------------------------------------------------
|
---|
47 |
|
---|
48 | bool DelphesStream::fFirstLongMin = true;
|
---|
49 | bool DelphesStream::fFirstLongMax = true;
|
---|
50 | bool DelphesStream::fFirstHugePos = true;
|
---|
51 | bool DelphesStream::fFirstHugeNeg = true;
|
---|
52 | bool DelphesStream::fFirstZero = true;
|
---|
53 |
|
---|
54 | //------------------------------------------------------------------------------
|
---|
55 |
|
---|
56 | DelphesStream::DelphesStream(char *buffer) :
|
---|
57 | fBuffer(buffer)
|
---|
58 | {
|
---|
59 | }
|
---|
60 |
|
---|
61 | //------------------------------------------------------------------------------
|
---|
62 |
|
---|
63 | bool DelphesStream::ReadDbl(double &value)
|
---|
64 | {
|
---|
65 | char *start = fBuffer;
|
---|
66 | errno = 0;
|
---|
67 | value = strtod(start, &fBuffer);
|
---|
68 | if(errno == ERANGE)
|
---|
69 | {
|
---|
70 | if(fFirstHugePos && value == HUGE_VAL)
|
---|
71 | {
|
---|
72 | fFirstHugePos = false;
|
---|
73 | cout << "** WARNING: too large positive value, return " << value << endl;
|
---|
74 | }
|
---|
75 | else if(fFirstHugeNeg && value == -HUGE_VAL)
|
---|
76 | {
|
---|
77 | fFirstHugeNeg = false;
|
---|
78 | cout << "** WARNING: too large negative value, return " << value << endl;
|
---|
79 | }
|
---|
80 | else if(fFirstZero)
|
---|
81 | {
|
---|
82 | fFirstZero = false;
|
---|
83 | value = 0.0;
|
---|
84 | cout << "** WARNING: too small value, return " << value << endl;
|
---|
85 | }
|
---|
86 | }
|
---|
87 | return start != fBuffer;
|
---|
88 | }
|
---|
89 |
|
---|
90 | //------------------------------------------------------------------------------
|
---|
91 |
|
---|
92 | bool DelphesStream::ReadInt(int &value)
|
---|
93 | {
|
---|
94 | char *start = fBuffer;
|
---|
95 | errno = 0;
|
---|
96 | value = strtol(start, &fBuffer, 10);
|
---|
97 | if(errno == ERANGE)
|
---|
98 | {
|
---|
99 | if(fFirstLongMin && value == LONG_MIN)
|
---|
100 | {
|
---|
101 | fFirstLongMin = false;
|
---|
102 | cout << "** WARNING: too large positive value, return " << value << endl;
|
---|
103 | }
|
---|
104 | else if(fFirstLongMax && value == LONG_MAX)
|
---|
105 | {
|
---|
106 | fFirstLongMax = false;
|
---|
107 | cout << "** WARNING: too large negative value, return " << value << endl;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | return start != fBuffer;
|
---|
111 | }
|
---|
112 |
|
---|
113 | //------------------------------------------------------------------------------
|
---|