Fork me on GitHub

source: git/classes/DelphesPileUpWriter.cc@ 5862d1f

Last change on this file since 5862d1f 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
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 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>
[341014c]31#include <stdexcept>
[d7d2da3]32
[1716933]33#include <stdint.h>
[341014c]34#include <stdio.h>
[1716933]35
36#include "classes/DelphesXDRWriter.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
46DelphesPileUpWriter::DelphesPileUpWriter(const char *fileName) :
47 fEntries(0), fEntrySize(0), fOffset(0),
48 fPileUpFile(0), fIndex(0), fBuffer(0),
[1716933]49 fOutputWriter(0), fIndexWriter(0), fBufferWriter(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 fOutputWriter = new DelphesXDRWriter;
56 fIndexWriter = new DelphesXDRWriter;
57 fBufferWriter = new DelphesXDRWriter;
58
59 fIndexWriter->SetBuffer(fIndex);
60 fBufferWriter->SetBuffer(fBuffer);
[d7d2da3]61
[b8b29f1]62 fPileUpFile = fopen(fileName, "wb");
[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 fOutputWriter->SetFile(fPileUpFile);
[d7d2da3]71}
72
73//------------------------------------------------------------------------------
74
75DelphesPileUpWriter::~DelphesPileUpWriter()
76{
77 if(fPileUpFile) fclose(fPileUpFile);
[1716933]78 if(fBufferWriter) delete fBufferWriter;
79 if(fIndexWriter) delete fIndexWriter;
80 if(fOutputWriter) delete fOutputWriter;
[d7d2da3]81 if(fBuffer) delete[] fBuffer;
82 if(fIndex) delete[] fIndex;
83}
84
85//------------------------------------------------------------------------------
86
[1716933]87void DelphesPileUpWriter::WriteParticle(int32_t pid,
[d7d2da3]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
[1716933]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);
[d7d2da3]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
[1716933]118 fOutputWriter->WriteValue(&fEntrySize, 4);
[341014c]119 fOutputWriter->WriteRaw(fBuffer, fEntrySize * kRecordSize * 4);
[d7d2da3]120
[1716933]121 fIndexWriter->WriteValue(&fOffset, 8);
[341014c]122 fOffset += fEntrySize * kRecordSize * 4 + 4;
[d7d2da3]123
[1716933]124 fBufferWriter->SetOffset(0);
[d7d2da3]125 fEntrySize = 0;
[1716933]126
[d7d2da3]127 ++fEntries;
128}
129
130//------------------------------------------------------------------------------
131
132void DelphesPileUpWriter::WriteIndex()
133{
[341014c]134 fOutputWriter->WriteRaw(fIndex, fEntries * 8);
[1716933]135 fOutputWriter->WriteValue(&fEntries, 8);
[d7d2da3]136}
137
138//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.