Fork me on GitHub

source: git/classes/DelphesXDRReader.cc@ 08d82fe

Last change on this file since 08d82fe was 341014c, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

apply .clang-format to all .h, .cc and .cpp files

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2018 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 DelphesXDRReader
20 *
21 * Reads XDR
22 *
23 * \author P. Demin - UCL, Louvain-la-Neuve
24 *
25 */
26
27#include "classes/DelphesXDRReader.h"
28
29#include <stdint.h>
30#include <stdio.h>
31#include <string.h>
32
33//------------------------------------------------------------------------------
34
35DelphesXDRReader::DelphesXDRReader() :
36 fFile(0), fBuffer(0), fOffset(0)
37{
38}
39
40//------------------------------------------------------------------------------
41
42void DelphesXDRReader::SetFile(FILE *file)
43{
44 fFile = file;
45}
46
47//------------------------------------------------------------------------------
48
49void DelphesXDRReader::SetBuffer(void *buffer)
50{
51 fBuffer = (uint8_t *)buffer;
52 fOffset = 0;
53}
54
55//------------------------------------------------------------------------------
56
57void DelphesXDRReader::SetOffset(int offset)
58{
59 fOffset = offset;
60}
61
62//------------------------------------------------------------------------------
63
64void DelphesXDRReader::ReadRaw(void *value, int size)
65{
66 int rndup;
67
68 rndup = size % 4;
69 if(rndup > 0)
70 {
71 rndup = 4 - rndup;
72 }
73
74 if(fFile)
75 {
76 fread(value, 1, size + rndup, fFile);
77 }
78}
79
80//------------------------------------------------------------------------------
81
82void DelphesXDRReader::ReadValue(void *value, int size)
83{
84 int i;
85 uint8_t *dst, buffer[8];
86
87 dst = (uint8_t *)value;
88
89 if(fBuffer)
90 {
91 fOffset += size;
92 for(i = 0; i < size; ++i) dst[i] = fBuffer[fOffset - 1 - i];
93 }
94 else if(fFile)
95 {
96 ReadRaw(buffer, size);
97 for(i = 0; i < size; ++i) dst[i] = buffer[size - 1 - i];
98 }
99}
100
101//------------------------------------------------------------------------------
102
103void DelphesXDRReader::ReadString(void *value, int maxSize)
104{
105 int32_t size;
106
107 ReadValue(&size, 4);
108
109 if(size > maxSize) size = maxSize;
110
111 if(fBuffer)
112 {
113 memcpy(value, fBuffer + fOffset, size);
114 fOffset += size;
115 }
116 else if(fFile)
117 {
118 ReadRaw(value, size);
119 }
120}
121
122//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.