Fork me on GitHub

source: git/classes/DelphesPileUpWriter.cc@ 538edc4

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 538edc4 was b8b29f1, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

open pileup and STDHEP files in binary mode

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