Fork me on GitHub

source: git/classes/DelphesPileUpReader.cc@ 181ff53

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