Fork me on GitHub

source: git/classes/DelphesPileUpWriter.cc@ a1f329b

ImprovedOutputFile Timing dual_readout llp
Last change on this file since a1f329b 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
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
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>
35#include <stdint.h>
36
37#include "classes/DelphesXDRWriter.h"
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),
50 fOutputWriter(0), fIndexWriter(0), fBufferWriter(0)
51{
52 stringstream message;
53
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);
62
63 fPileUpFile = fopen(fileName, "wb");
64
65 if(fPileUpFile == NULL)
66 {
67 message << "can't open pile-up file " << fileName;
68 throw runtime_error(message.str());
69 }
70
71 fOutputWriter->SetFile(fPileUpFile);
72}
73
74//------------------------------------------------------------------------------
75
76DelphesPileUpWriter::~DelphesPileUpWriter()
77{
78 if(fPileUpFile) fclose(fPileUpFile);
79 if(fBufferWriter) delete fBufferWriter;
80 if(fIndexWriter) delete fIndexWriter;
81 if(fOutputWriter) delete fOutputWriter;
82 if(fBuffer) delete[] fBuffer;
83 if(fIndex) delete[] fIndex;
84}
85
86//------------------------------------------------------------------------------
87
88void DelphesPileUpWriter::WriteParticle(int32_t pid,
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
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);
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
119 fOutputWriter->WriteValue(&fEntrySize, 4);
120 fOutputWriter->WriteRaw(fBuffer, fEntrySize*kRecordSize*4);
121
122 fIndexWriter->WriteValue(&fOffset, 8);
123 fOffset += fEntrySize*kRecordSize*4 + 4;
124
125 fBufferWriter->SetOffset(0);
126 fEntrySize = 0;
127
128 ++fEntries;
129}
130
131//------------------------------------------------------------------------------
132
133void DelphesPileUpWriter::WriteIndex()
134{
135 fOutputWriter->WriteRaw(fIndex, fEntries*8);
136 fOutputWriter->WriteValue(&fEntries, 8);
137}
138
139//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.