Fork me on GitHub

source: git/classes/DelphesStream.cc

Last change on this file was b4786d3, checked in by Pavel Demin <pavel.demin@…>, 3 years ago

add DelphesHepMC3

  • Property mode set to 100644
File size: 3.6 KB
Line 
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/** \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>
30#include <limits.h>
31#include <math.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35
36#include <iostream>
37
38using namespace std;
39
40//------------------------------------------------------------------------------
41
42bool DelphesStream::fFirstLongMin = true;
43bool DelphesStream::fFirstLongMax = true;
44bool DelphesStream::fFirstHugePos = true;
45bool DelphesStream::fFirstHugeNeg = true;
46bool DelphesStream::fFirstZero = true;
47
48//------------------------------------------------------------------------------
49
50DelphesStream::DelphesStream(char *buffer) :
51 fBuffer(buffer)
52{
53}
54
55//------------------------------------------------------------------------------
56
57bool 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 {
66 fFirstHugePos = false;
67 cout << "** WARNING: too large positive value, return " << value << endl;
68 }
69 else if(fFirstHugeNeg && value == -HUGE_VAL)
70 {
71 fFirstHugeNeg = false;
72 cout << "** WARNING: too large negative value, return " << value << endl;
73 }
74 else if(fFirstZero)
75 {
76 fFirstZero = false;
77 value = 0.0;
78 cout << "** WARNING: too small value, return " << value << endl;
79 }
80 }
81 return start != fBuffer;
82}
83
84//------------------------------------------------------------------------------
85
86bool 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 {
95 fFirstLongMin = false;
96 cout << "** WARNING: too large positive value, return " << value << endl;
97 }
98 else if(fFirstLongMax && value == LONG_MAX)
99 {
100 fFirstLongMax = false;
101 cout << "** WARNING: too large negative value, return " << value << endl;
102 }
103 }
104 return start != fBuffer;
105}
106
107//------------------------------------------------------------------------------
108
109bool DelphesStream::FindChr(int value)
110{
111 char *position;
112 bool result = false;
113
114 position = strchr(fBuffer, value);
115
116 if(position)
117 {
118 result = true;
119 fBuffer = position + 1;
120 }
121
122 return result;
123}
124
125//------------------------------------------------------------------------------
126
127bool DelphesStream::FindStr(const char *value)
128{
129 char *position;
130 bool result = false;
131
132 position = strstr(fBuffer, value);
133
134 if(position)
135 {
136 result = true;
137 fBuffer = position + strlen(value);
138 }
139
140 return result;
141}
142
143//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.