Fork me on GitHub

source: git/classes/DelphesXDRReader.cc@ 0518688

ImprovedOutputFile Timing llp
Last change on this file since 0518688 was 1716933, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

add DelphesXDRReader and DelphesXDRWriter

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