Fork me on GitHub

source: git/classes/DelphesStream.cc@ fc4143c

ImprovedOutputFile Timing dual_readout llp
Last change on this file since fc4143c was cab38f6, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

remove svn tags and fix formatting

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[b443089]1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
[1fa50c2]4 *
[b443089]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.
[1fa50c2]9 *
[b443089]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.
[1fa50c2]14 *
[b443089]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
[d7d2da3]19
20/** \class DelphesStream
21 *
22 * Provides an interface to manipulate c strings as if they were input streams
23 *
24 * \author P. Demin - UCL, Louvain-la-Neuve
25 *
26 */
27
28#include "classes/DelphesStream.h"
29
30#include <stdlib.h>
31#include <limits.h>
32#include <string.h>
33#include <stdio.h>
34#include <errno.h>
35#include <math.h>
36
37#include <iostream>
38
39using namespace std;
40
41//------------------------------------------------------------------------------
42
43bool DelphesStream::fFirstLongMin = true;
44bool DelphesStream::fFirstLongMax = true;
45bool DelphesStream::fFirstHugePos = true;
46bool DelphesStream::fFirstHugeNeg = true;
47bool DelphesStream::fFirstZero = true;
48
49//------------------------------------------------------------------------------
50
51DelphesStream::DelphesStream(char *buffer) :
52 fBuffer(buffer)
53{
54}
55
56//------------------------------------------------------------------------------
57
58bool DelphesStream::ReadDbl(double &value)
59{
60 char *start = fBuffer;
61 errno = 0;
62 value = strtod(start, &fBuffer);
63 if(errno == ERANGE)
64 {
65 if(fFirstHugePos && value == HUGE_VAL)
66 {
67 fFirstHugePos = false;
68 cout << "** WARNING: too large positive value, return " << value << endl;
69 }
70 else if(fFirstHugeNeg && value == -HUGE_VAL)
71 {
72 fFirstHugeNeg = false;
73 cout << "** WARNING: too large negative value, return " << value << endl;
74 }
75 else if(fFirstZero)
76 {
77 fFirstZero = false;
78 value = 0.0;
79 cout << "** WARNING: too small value, return " << value << endl;
80 }
81 }
82 return start != fBuffer;
83}
84
85//------------------------------------------------------------------------------
86
87bool DelphesStream::ReadInt(int &value)
88{
89 char *start = fBuffer;
90 errno = 0;
91 value = strtol(start, &fBuffer, 10);
92 if(errno == ERANGE)
93 {
94 if(fFirstLongMin && value == LONG_MIN)
95 {
96 fFirstLongMin = false;
97 cout << "** WARNING: too large positive value, return " << value << endl;
98 }
99 else if(fFirstLongMax && value == LONG_MAX)
100 {
101 fFirstLongMax = false;
102 cout << "** WARNING: too large negative value, return " << value << endl;
103 }
104 }
105 return start != fBuffer;
106}
107
108//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.