Fork me on GitHub

source: git/classes/DelphesPileUpWriter.cc

Last change on this file 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: 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/** \class DelphesPileUpWriter
20 *
21 * Writes pile-up binary file
22 *
23 * \author P. Demin - UCL, Louvain-la-Neuve
24 *
25 */
26
27#include "classes/DelphesPileUpWriter.h"
28
29#include <iostream>
30#include <sstream>
31#include <stdexcept>
32
33#include <stdint.h>
34#include <stdio.h>
35
36#include "classes/DelphesXDRWriter.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 fOutputWriter(0), fIndexWriter(0), fBufferWriter(0)
50{
51 stringstream message;
52
53 fIndex = new uint8_t[kIndexSize * 8];
54 fBuffer = new uint8_t[kBufferSize * kRecordSize * 4];
55 fOutputWriter = new DelphesXDRWriter;
56 fIndexWriter = new DelphesXDRWriter;
57 fBufferWriter = new DelphesXDRWriter;
58
59 fIndexWriter->SetBuffer(fIndex);
60 fBufferWriter->SetBuffer(fBuffer);
61
62 fPileUpFile = fopen(fileName, "wb");
63
64 if(fPileUpFile == NULL)
65 {
66 message << "can't open pile-up file " << fileName;
67 throw runtime_error(message.str());
68 }
69
70 fOutputWriter->SetFile(fPileUpFile);
71}
72
73//------------------------------------------------------------------------------
74
75DelphesPileUpWriter::~DelphesPileUpWriter()
76{
77 if(fPileUpFile) fclose(fPileUpFile);
78 if(fBufferWriter) delete fBufferWriter;
79 if(fIndexWriter) delete fIndexWriter;
80 if(fOutputWriter) delete fOutputWriter;
81 if(fBuffer) delete[] fBuffer;
82 if(fIndex) delete[] fIndex;
83}
84
85//------------------------------------------------------------------------------
86
87void DelphesPileUpWriter::WriteParticle(int32_t pid,
88 float x, float y, float z, float t,
89 float px, float py, float pz, float e)
90{
91 if(fEntrySize >= kBufferSize)
92 {
93 throw runtime_error("too many particles in pile-up event");
94 }
95
96 fBufferWriter->WriteValue(&pid, 4);
97 fBufferWriter->WriteValue(&x, 4);
98 fBufferWriter->WriteValue(&y, 4);
99 fBufferWriter->WriteValue(&z, 4);
100 fBufferWriter->WriteValue(&t, 4);
101 fBufferWriter->WriteValue(&px, 4);
102 fBufferWriter->WriteValue(&py, 4);
103 fBufferWriter->WriteValue(&pz, 4);
104 fBufferWriter->WriteValue(&e, 4);
105
106 ++fEntrySize;
107}
108
109//------------------------------------------------------------------------------
110
111void DelphesPileUpWriter::WriteEntry()
112{
113 if(fEntries >= kIndexSize)
114 {
115 throw runtime_error("too many pile-up events");
116 }
117
118 fOutputWriter->WriteValue(&fEntrySize, 4);
119 fOutputWriter->WriteRaw(fBuffer, fEntrySize * kRecordSize * 4);
120
121 fIndexWriter->WriteValue(&fOffset, 8);
122 fOffset += fEntrySize * kRecordSize * 4 + 4;
123
124 fBufferWriter->SetOffset(0);
125 fEntrySize = 0;
126
127 ++fEntries;
128}
129
130//------------------------------------------------------------------------------
131
132void DelphesPileUpWriter::WriteIndex()
133{
134 fOutputWriter->WriteRaw(fIndex, fEntries * 8);
135 fOutputWriter->WriteValue(&fEntries, 8);
136}
137
138//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.