[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 | /** \class DelphesStream
|
---|
| 20 | *
|
---|
| 21 | * Provides an interface to manipulate c strings as if they were input streams
|
---|
| 22 | *
|
---|
| 23 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
| 24 | *
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | #include "classes/DelphesStream.h"
|
---|
| 28 |
|
---|
| 29 | #include <errno.h>
|
---|
[341014c] | 30 | #include <limits.h>
|
---|
[d7d2da3] | 31 | #include <math.h>
|
---|
[341014c] | 32 | #include <stdio.h>
|
---|
| 33 | #include <stdlib.h>
|
---|
| 34 | #include <string.h>
|
---|
[d7d2da3] | 35 |
|
---|
| 36 | #include <iostream>
|
---|
| 37 |
|
---|
| 38 | using namespace std;
|
---|
| 39 |
|
---|
| 40 | //------------------------------------------------------------------------------
|
---|
| 41 |
|
---|
| 42 | bool DelphesStream::fFirstLongMin = true;
|
---|
| 43 | bool DelphesStream::fFirstLongMax = true;
|
---|
| 44 | bool DelphesStream::fFirstHugePos = true;
|
---|
| 45 | bool DelphesStream::fFirstHugeNeg = true;
|
---|
| 46 | bool DelphesStream::fFirstZero = true;
|
---|
| 47 |
|
---|
| 48 | //------------------------------------------------------------------------------
|
---|
| 49 |
|
---|
| 50 | DelphesStream::DelphesStream(char *buffer) :
|
---|
| 51 | fBuffer(buffer)
|
---|
| 52 | {
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | //------------------------------------------------------------------------------
|
---|
| 56 |
|
---|
| 57 | bool DelphesStream::ReadDbl(double &value)
|
---|
| 58 | {
|
---|
| 59 | char *start = fBuffer;
|
---|
| 60 | errno = 0;
|
---|
| 61 | value = strtod(start, &fBuffer);
|
---|
| 62 | if(errno == ERANGE)
|
---|
| 63 | {
|
---|
| 64 | if(fFirstHugePos && value == HUGE_VAL)
|
---|
| 65 | {
|
---|
[341014c] | 66 | fFirstHugePos = false;
|
---|
[d7d2da3] | 67 | cout << "** WARNING: too large positive value, return " << value << endl;
|
---|
| 68 | }
|
---|
| 69 | else if(fFirstHugeNeg && value == -HUGE_VAL)
|
---|
| 70 | {
|
---|
[341014c] | 71 | fFirstHugeNeg = false;
|
---|
[d7d2da3] | 72 | cout << "** WARNING: too large negative value, return " << value << endl;
|
---|
| 73 | }
|
---|
| 74 | else if(fFirstZero)
|
---|
| 75 | {
|
---|
[341014c] | 76 | fFirstZero = false;
|
---|
[d7d2da3] | 77 | value = 0.0;
|
---|
| 78 | cout << "** WARNING: too small value, return " << value << endl;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | return start != fBuffer;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | //------------------------------------------------------------------------------
|
---|
| 85 |
|
---|
| 86 | bool DelphesStream::ReadInt(int &value)
|
---|
| 87 | {
|
---|
| 88 | char *start = fBuffer;
|
---|
| 89 | errno = 0;
|
---|
| 90 | value = strtol(start, &fBuffer, 10);
|
---|
| 91 | if(errno == ERANGE)
|
---|
| 92 | {
|
---|
| 93 | if(fFirstLongMin && value == LONG_MIN)
|
---|
| 94 | {
|
---|
[341014c] | 95 | fFirstLongMin = false;
|
---|
[d7d2da3] | 96 | cout << "** WARNING: too large positive value, return " << value << endl;
|
---|
| 97 | }
|
---|
| 98 | else if(fFirstLongMax && value == LONG_MAX)
|
---|
| 99 | {
|
---|
[341014c] | 100 | fFirstLongMax = false;
|
---|
[d7d2da3] | 101 | cout << "** WARNING: too large negative value, return " << value << endl;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | return start != fBuffer;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | //------------------------------------------------------------------------------
|
---|