Fork me on GitHub

source: git/classes/DelphesXDRWriter.cc@ 17cd992

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