Fork me on GitHub

source: git/classes/DelphesXDRWriter.cc@ 4689481

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

add DelphesXDRReader and DelphesXDRWriter

  • Property mode set to 100644
File size: 2.4 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 DelphesXDRWriter
21 *
22 * Writes XDR
23 *
24 * \author P. Demin - UCL, Louvain-la-Neuve
25 *
26 */
27
28#include "classes/DelphesXDRWriter.h"
29
30#include <stdio.h>
31#include <stdint.h>
32#include <string.h>
33
34//------------------------------------------------------------------------------
35
36DelphesXDRWriter::DelphesXDRWriter() :
37 fFile(0), fBuffer(0), fOffset(0)
38{
39}
40
41//------------------------------------------------------------------------------
42
43void DelphesXDRWriter::SetFile(FILE *file)
44{
45 fFile = file;
46}
47
48//------------------------------------------------------------------------------
49
50void DelphesXDRWriter::SetBuffer(void *buffer)
51{
52 fBuffer = (uint8_t *)buffer;
53 fOffset = 0;
54}
55
56//------------------------------------------------------------------------------
57
58void DelphesXDRWriter::SetOffset(int offset)
59{
60 fOffset = offset;
61}
62
63//------------------------------------------------------------------------------
64
65void DelphesXDRWriter::WriteRaw(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 fwrite(value, 1, size + rndup, fFile);
78 }
79}
80
81//------------------------------------------------------------------------------
82
83void DelphesXDRWriter::WriteValue(void *value, int size)
84{
85 int i;
86 uint8_t *src, buffer[8];
87
88 src = (uint8_t *)value;
89
90 if(fBuffer)
91 {
92 for(i = 0; i < size; ++i) fBuffer[fOffset + i] = src[size - 1 - i];
93 fOffset += size;
94 }
95 else if(fFile)
96 {
97 for(i = 0; i < size; ++i) buffer[i] = src[size - 1 - i];
98 WriteRaw(buffer, size);
99 }
100 else
101 {
102 return;
103 }
104}
105
106//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.