Fork me on GitHub

source: git/classes/DelphesPileUpReader.cc@ b443089

ImprovedOutputFile Timing dual_readout llp
Last change on this file since b443089 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: 4.0 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 DelphesPileUpReader
21 *
22 * Reads 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/DelphesPileUpReader.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
51DelphesPileUpReader::DelphesPileUpReader(const char *fileName) :
52 fEntries(0), fEntrySize(0), fCounter(0),
53 fPileUpFile(0), fIndex(0), fBuffer(0),
54 fInputXDR(0), fIndexXDR(0), fBufferXDR(0)
55{
56 stringstream message;
57
58 fIndex = new char[kIndexSize*8];
59 fBuffer = new char[kBufferSize*kRecordSize*4];
60 fInputXDR = new XDR;
61 fIndexXDR = new XDR;
62 fBufferXDR = new XDR;
63 xdrmem_create(fIndexXDR, fIndex, kIndexSize*8, XDR_DECODE);
64 xdrmem_create(fBufferXDR, fBuffer, kBufferSize*kRecordSize*4, XDR_DECODE);
65
66 fPileUpFile = fopen(fileName, "r");
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(fInputXDR, fPileUpFile, XDR_DECODE);
75
76 // read number of events
77 fseeko(fPileUpFile, -8, SEEK_END);
78 xdr_hyper(fInputXDR, &fEntries);
79
80 if(fEntries >= kIndexSize)
81 {
82 message << "too many events in pile-up file " << fileName;
83 throw runtime_error(message.str());
84 }
85
86 // read index of events
87 fseeko(fPileUpFile, -8 - 8*fEntries, SEEK_END);
88 xdr_opaque(fInputXDR, fIndex, fEntries*8);
89}
90
91//------------------------------------------------------------------------------
92
93DelphesPileUpReader::~DelphesPileUpReader()
94{
95 xdr_destroy(fInputXDR);
96 if(fPileUpFile) fclose(fPileUpFile);
97 xdr_destroy(fBufferXDR);
98 xdr_destroy(fIndexXDR);
99 if(fBufferXDR) delete fBufferXDR;
100 if(fIndexXDR) delete fIndexXDR;
101 if(fInputXDR) delete fInputXDR;
102 if(fBuffer) delete[] fBuffer;
103 if(fIndex) delete[] fIndex;
104}
105
106//------------------------------------------------------------------------------
107
108bool DelphesPileUpReader::ReadParticle(int &pid,
109 float &x, float &y, float &z, float &t,
110 float &px, float &py, float &pz, float &e)
111{
112 if(fCounter >= fEntrySize) return false;
113
114 xdr_int(fBufferXDR, &pid);
115 xdr_float(fBufferXDR, &x);
116 xdr_float(fBufferXDR, &y);
117 xdr_float(fBufferXDR, &z);
118 xdr_float(fBufferXDR, &t);
119 xdr_float(fBufferXDR, &px);
120 xdr_float(fBufferXDR, &py);
121 xdr_float(fBufferXDR, &pz);
122 xdr_float(fBufferXDR, &e);
123
124 ++fCounter;
125
126 return true;
127}
128
129//------------------------------------------------------------------------------
130
131bool DelphesPileUpReader::ReadEntry(quad_t entry)
132{
133 quad_t offset;
134
135 if(entry >= fEntries) return false;
136
137 // read event position
138 xdr_setpos(fIndexXDR, 8*entry);
139 xdr_hyper(fIndexXDR, &offset);
140
141 // read event
142 fseeko(fPileUpFile, offset, SEEK_SET);
143 xdr_int(fInputXDR, &fEntrySize);
144
145 if(fEntrySize >= kBufferSize)
146 {
147 throw runtime_error("too many particles in pile-up event");
148 }
149
150 xdr_opaque(fInputXDR, fBuffer, fEntrySize*kRecordSize*4);
151 xdr_setpos(fBufferXDR, 0);
152 fCounter = 0;
153
154 return true;
155}
156
157//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.