Fork me on GitHub

source: git/classes/DelphesPileUpWriter.cc@ 3d10d1f

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 3d10d1f was b443089, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

fix EOL characters in GPLv3 header

  • Property mode set to 100644
File size: 3.8 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
20/** \class DelphesPileUpWriter
21 *
22 * Writes pile-up binary file
23 *
24 *
25 * $Date$
26 * $Revision$
27 *
28 *
29 * \author P. Demin - UCL, Louvain-la-Neuve
30 *
31 */
32
33#include "classes/DelphesPileUpWriter.h"
34
35#include <stdexcept>
36#include <iostream>
37#include <sstream>
38
39#include <stdio.h>
40#include <rpc/types.h>
41#include <rpc/xdr.h>
42
43using namespace std;
44
45static const int kIndexSize = 10000000;
46static const int kBufferSize = 1000000;
47static const int kRecordSize = 9;
48
49//------------------------------------------------------------------------------
50
51DelphesPileUpWriter::DelphesPileUpWriter(const char *fileName) :
52 fEntries(0), fEntrySize(0), fOffset(0),
53 fPileUpFile(0), fIndex(0), fBuffer(0),
54 fOutputXDR(0), fIndexXDR(0), fBufferXDR(0)
55{
56 stringstream message;
57
58 fIndex = new char[kIndexSize*8];
59 fBuffer = new char[kBufferSize*kRecordSize*4];
60 fOutputXDR = new XDR;
61 fIndexXDR = new XDR;
62 fBufferXDR = new XDR;
63 xdrmem_create(fIndexXDR, fIndex, kIndexSize*8, XDR_ENCODE);
64 xdrmem_create(fBufferXDR, fBuffer, kBufferSize*kRecordSize*4, XDR_ENCODE);
65
66 fPileUpFile = fopen(fileName, "w+");
67
68 if(fPileUpFile == NULL)
69 {
70 message << "can't open pile-up file " << fileName;
71 throw runtime_error(message.str());
72 }
73
74 xdrstdio_create(fOutputXDR, fPileUpFile, XDR_ENCODE);
75}
76
77//------------------------------------------------------------------------------
78
79DelphesPileUpWriter::~DelphesPileUpWriter()
80{
81 xdr_destroy(fOutputXDR);
82 if(fPileUpFile) fclose(fPileUpFile);
83 xdr_destroy(fBufferXDR);
84 xdr_destroy(fIndexXDR);
85 if(fBufferXDR) delete fBufferXDR;
86 if(fIndexXDR) delete fIndexXDR;
87 if(fOutputXDR) delete fOutputXDR;
88 if(fBuffer) delete[] fBuffer;
89 if(fIndex) delete[] fIndex;
90}
91
92//------------------------------------------------------------------------------
93
94void DelphesPileUpWriter::WriteParticle(int pid,
95 float x, float y, float z, float t,
96 float px, float py, float pz, float e)
97{
98 if(fEntrySize >= kBufferSize)
99 {
100 throw runtime_error("too many particles in pile-up event");
101 }
102
103 xdr_int(fBufferXDR, &pid);
104 xdr_float(fBufferXDR, &x);
105 xdr_float(fBufferXDR, &y);
106 xdr_float(fBufferXDR, &z);
107 xdr_float(fBufferXDR, &t);
108 xdr_float(fBufferXDR, &px);
109 xdr_float(fBufferXDR, &py);
110 xdr_float(fBufferXDR, &pz);
111 xdr_float(fBufferXDR, &e);
112
113 ++fEntrySize;
114}
115
116//------------------------------------------------------------------------------
117
118void DelphesPileUpWriter::WriteEntry()
119{
120 if(fEntries >= kIndexSize)
121 {
122 throw runtime_error("too many pile-up events");
123 }
124
125 xdr_int(fOutputXDR, &fEntrySize);
126 xdr_opaque(fOutputXDR, fBuffer, fEntrySize*kRecordSize*4);
127
128 xdr_hyper(fIndexXDR, &fOffset);
129 fOffset += fEntrySize*kRecordSize*4 + 4;
130
131 xdr_setpos(fBufferXDR, 0);
132 fEntrySize = 0;
133
134 ++fEntries;
135}
136
137//------------------------------------------------------------------------------
138
139void DelphesPileUpWriter::WriteIndex()
140{
141 xdr_opaque(fOutputXDR, fIndex, fEntries*8);
142 xdr_hyper(fOutputXDR, &fEntries);
143}
144
145//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.