Fork me on GitHub

source: git/classes/DelphesPileUpReader.cc@ 3d778cd

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 3d778cd was 1716933, checked in by Pavel Demin <pavel-demin@…>, 7 years ago

add DelphesXDRReader and DelphesXDRWriter

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[b443089]1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
[1fa50c2]4 *
[b443089]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.
[1fa50c2]9 *
[b443089]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.
[1fa50c2]14 *
[b443089]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
[d7d2da3]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>
[1716933]35#include <stdint.h>
36
37#include "classes/DelphesXDRReader.h"
[d7d2da3]38
39using namespace std;
40
41static const int kIndexSize = 10000000;
42static const int kBufferSize = 1000000;
43static const int kRecordSize = 9;
44
45//------------------------------------------------------------------------------
46
47DelphesPileUpReader::DelphesPileUpReader(const char *fileName) :
48 fEntries(0), fEntrySize(0), fCounter(0),
49 fPileUpFile(0), fIndex(0), fBuffer(0),
[1716933]50 fInputReader(0), fIndexReader(0), fBufferReader(0)
[d7d2da3]51{
52 stringstream message;
53
[1716933]54 fIndex = new uint8_t[kIndexSize*8];
55 fBuffer = new uint8_t[kBufferSize*kRecordSize*4];
56 fInputReader = new DelphesXDRReader;
57 fIndexReader = new DelphesXDRReader;
58 fBufferReader = new DelphesXDRReader;
59
60 fIndexReader->SetBuffer(fIndex);
61 fBufferReader->SetBuffer(fBuffer);
[d7d2da3]62
63 fPileUpFile = fopen(fileName, "r");
64
65 if(fPileUpFile == NULL)
66 {
67 message << "can't open pile-up file " << fileName;
68 throw runtime_error(message.str());
69 }
70
[1716933]71 fInputReader->SetFile(fPileUpFile);
[d7d2da3]72
73 // read number of events
[3a61449]74 fseeko(fPileUpFile, -8, SEEK_END);
[1716933]75 fInputReader->ReadValue(&fEntries, 8);
[d7d2da3]76
77 if(fEntries >= kIndexSize)
78 {
79 message << "too many events in pile-up file " << fileName;
80 throw runtime_error(message.str());
81 }
82
83 // read index of events
[3a61449]84 fseeko(fPileUpFile, -8 - 8*fEntries, SEEK_END);
[1716933]85 fInputReader->ReadRaw(fIndex, fEntries*8);
[d7d2da3]86}
87
88//------------------------------------------------------------------------------
89
90DelphesPileUpReader::~DelphesPileUpReader()
91{
92 if(fPileUpFile) fclose(fPileUpFile);
[1716933]93 if(fBufferReader) delete fBufferReader;
94 if(fIndexReader) delete fIndexReader;
95 if(fInputReader) delete fInputReader;
[d7d2da3]96 if(fBuffer) delete[] fBuffer;
97 if(fIndex) delete[] fIndex;
98}
99
100//------------------------------------------------------------------------------
101
[1716933]102bool DelphesPileUpReader::ReadParticle(int32_t &pid,
[d7d2da3]103 float &x, float &y, float &z, float &t,
104 float &px, float &py, float &pz, float &e)
105{
106 if(fCounter >= fEntrySize) return false;
107
[1716933]108 fBufferReader->ReadValue(&pid, 4);
109 fBufferReader->ReadValue(&x, 4);
110 fBufferReader->ReadValue(&y, 4);
111 fBufferReader->ReadValue(&z, 4);
112 fBufferReader->ReadValue(&t, 4);
113 fBufferReader->ReadValue(&px, 4);
114 fBufferReader->ReadValue(&py, 4);
115 fBufferReader->ReadValue(&pz, 4);
116 fBufferReader->ReadValue(&e, 4);
[d7d2da3]117
118 ++fCounter;
119
120 return true;
121}
122
123//------------------------------------------------------------------------------
124
[1716933]125bool DelphesPileUpReader::ReadEntry(int64_t entry)
[d7d2da3]126{
[1716933]127 int64_t offset;
[d7d2da3]128
129 if(entry >= fEntries) return false;
130
131 // read event position
[1716933]132 fIndexReader->SetOffset(8*entry);
133 fIndexReader->ReadValue(&offset, 8);
[d7d2da3]134
135 // read event
[3a61449]136 fseeko(fPileUpFile, offset, SEEK_SET);
[1716933]137 fInputReader->ReadValue(&fEntrySize, 4);
[d7d2da3]138
139 if(fEntrySize >= kBufferSize)
140 {
141 throw runtime_error("too many particles in pile-up event");
142 }
143
[1716933]144 fInputReader->ReadRaw(fBuffer, fEntrySize*kRecordSize*4);
145 fBufferReader->SetOffset(0);
[d7d2da3]146 fCounter = 0;
147
148 return true;
149}
150
151//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.