Fork me on GitHub

source: git/classes/DelphesPileUpWriter.cc@ fa7f333

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

remove svn tags and fix formatting

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