Fork me on GitHub

source: git/classes/DelphesPileUpReader.cc@ 2eaa9fd

Last change on this file since 2eaa9fd was 341014c, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

apply .clang-format to all .h, .cc and .cpp files

  • 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/** \class DelphesPileUpReader
20 *
21 * Reads pile-up binary file
22 *
23 * \author P. Demin - UCL, Louvain-la-Neuve
24 *
25 */
26
27#include "classes/DelphesPileUpReader.h"
28
29#include <iostream>
30#include <sstream>
[341014c]31#include <stdexcept>
[d7d2da3]32
[1716933]33#include <stdint.h>
[341014c]34#include <stdio.h>
[1716933]35
36#include "classes/DelphesXDRReader.h"
[d7d2da3]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),
[1716933]49 fInputReader(0), fIndexReader(0), fBufferReader(0)
[d7d2da3]50{
51 stringstream message;
52
[341014c]53 fIndex = new uint8_t[kIndexSize * 8];
54 fBuffer = new uint8_t[kBufferSize * kRecordSize * 4];
[1716933]55 fInputReader = new DelphesXDRReader;
56 fIndexReader = new DelphesXDRReader;
57 fBufferReader = new DelphesXDRReader;
58
59 fIndexReader->SetBuffer(fIndex);
60 fBufferReader->SetBuffer(fBuffer);
[d7d2da3]61
[b8b29f1]62 fPileUpFile = fopen(fileName, "rb");
[d7d2da3]63
64 if(fPileUpFile == NULL)
65 {
66 message << "can't open pile-up file " << fileName;
67 throw runtime_error(message.str());
68 }
69
[1716933]70 fInputReader->SetFile(fPileUpFile);
[d7d2da3]71
72 // read number of events
[3a61449]73 fseeko(fPileUpFile, -8, SEEK_END);
[1716933]74 fInputReader->ReadValue(&fEntries, 8);
[d7d2da3]75
76 if(fEntries >= kIndexSize)
77 {
78 message << "too many events in pile-up file " << fileName;
79 throw runtime_error(message.str());
80 }
81
82 // read index of events
[341014c]83 fseeko(fPileUpFile, -8 - 8 * fEntries, SEEK_END);
84 fInputReader->ReadRaw(fIndex, fEntries * 8);
[d7d2da3]85}
86
87//------------------------------------------------------------------------------
88
89DelphesPileUpReader::~DelphesPileUpReader()
90{
91 if(fPileUpFile) fclose(fPileUpFile);
[1716933]92 if(fBufferReader) delete fBufferReader;
93 if(fIndexReader) delete fIndexReader;
94 if(fInputReader) delete fInputReader;
[d7d2da3]95 if(fBuffer) delete[] fBuffer;
96 if(fIndex) delete[] fIndex;
97}
98
99//------------------------------------------------------------------------------
100
[1716933]101bool DelphesPileUpReader::ReadParticle(int32_t &pid,
[d7d2da3]102 float &x, float &y, float &z, float &t,
103 float &px, float &py, float &pz, float &e)
104{
105 if(fCounter >= fEntrySize) return false;
106
[1716933]107 fBufferReader->ReadValue(&pid, 4);
108 fBufferReader->ReadValue(&x, 4);
109 fBufferReader->ReadValue(&y, 4);
110 fBufferReader->ReadValue(&z, 4);
111 fBufferReader->ReadValue(&t, 4);
112 fBufferReader->ReadValue(&px, 4);
113 fBufferReader->ReadValue(&py, 4);
114 fBufferReader->ReadValue(&pz, 4);
115 fBufferReader->ReadValue(&e, 4);
[d7d2da3]116
117 ++fCounter;
118
119 return true;
120}
121
122//------------------------------------------------------------------------------
123
[1716933]124bool DelphesPileUpReader::ReadEntry(int64_t entry)
[d7d2da3]125{
[1716933]126 int64_t offset;
[d7d2da3]127
128 if(entry >= fEntries) return false;
129
130 // read event position
[341014c]131 fIndexReader->SetOffset(8 * entry);
[1716933]132 fIndexReader->ReadValue(&offset, 8);
[d7d2da3]133
134 // read event
[3a61449]135 fseeko(fPileUpFile, offset, SEEK_SET);
[1716933]136 fInputReader->ReadValue(&fEntrySize, 4);
[d7d2da3]137
138 if(fEntrySize >= kBufferSize)
139 {
140 throw runtime_error("too many particles in pile-up event");
141 }
142
[341014c]143 fInputReader->ReadRaw(fBuffer, fEntrySize * kRecordSize * 4);
[1716933]144 fBufferReader->SetOffset(0);
[d7d2da3]145 fCounter = 0;
146
147 return true;
148}
149
150//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.