Fork me on GitHub

source: git/classes/DelphesPileUpWriter.cc@ ffaa11a

ImprovedOutputFile Timing dual_readout llp
Last change on this file since ffaa11a was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

  • Property mode set to 100644
File size: 3.0 KB
Line 
1
2/** \class DelphesPileUpWriter
3 *
4 * Writes pile-up binary file
5 *
6 *
7 * $Date$
8 * $Revision$
9 *
10 *
11 * \author P. Demin - UCL, Louvain-la-Neuve
12 *
13 */
14
15#include "classes/DelphesPileUpWriter.h"
16
17#include <stdexcept>
18#include <iostream>
19#include <sstream>
20
21#include <stdio.h>
22#include <rpc/types.h>
23#include <rpc/xdr.h>
24
25using namespace std;
26
27static const int kIndexSize = 10000000;
28static const int kBufferSize = 1000000;
29static const int kRecordSize = 9;
30
31//------------------------------------------------------------------------------
32
33DelphesPileUpWriter::DelphesPileUpWriter(const char *fileName) :
34 fEntries(0), fEntrySize(0), fOffset(0),
35 fPileUpFile(0), fIndex(0), fBuffer(0),
36 fOutputXDR(0), fIndexXDR(0), fBufferXDR(0)
37{
38 stringstream message;
39
40 fIndex = new char[kIndexSize*8];
41 fBuffer = new char[kBufferSize*kRecordSize*4];
42 fOutputXDR = new XDR;
43 fIndexXDR = new XDR;
44 fBufferXDR = new XDR;
45 xdrmem_create(fIndexXDR, fIndex, kIndexSize*8, XDR_ENCODE);
46 xdrmem_create(fBufferXDR, fBuffer, kBufferSize*kRecordSize*4, XDR_ENCODE);
47
48 fPileUpFile = fopen(fileName, "w+");
49
50 if(fPileUpFile == NULL)
51 {
52 message << "can't open pile-up file " << fileName;
53 throw runtime_error(message.str());
54 }
55
56 xdrstdio_create(fOutputXDR, fPileUpFile, XDR_ENCODE);
57}
58
59//------------------------------------------------------------------------------
60
61DelphesPileUpWriter::~DelphesPileUpWriter()
62{
63 xdr_destroy(fOutputXDR);
64 if(fPileUpFile) fclose(fPileUpFile);
65 xdr_destroy(fBufferXDR);
66 xdr_destroy(fIndexXDR);
67 if(fBufferXDR) delete fBufferXDR;
68 if(fIndexXDR) delete fIndexXDR;
69 if(fOutputXDR) delete fOutputXDR;
70 if(fBuffer) delete[] fBuffer;
71 if(fIndex) delete[] fIndex;
72}
73
74//------------------------------------------------------------------------------
75
76void DelphesPileUpWriter::WriteParticle(int pid,
77 float x, float y, float z, float t,
78 float px, float py, float pz, float e)
79{
80 if(fEntrySize >= kBufferSize)
81 {
82 throw runtime_error("too many particles in pile-up event");
83 }
84
85 xdr_int(fBufferXDR, &pid);
86 xdr_float(fBufferXDR, &x);
87 xdr_float(fBufferXDR, &y);
88 xdr_float(fBufferXDR, &z);
89 xdr_float(fBufferXDR, &t);
90 xdr_float(fBufferXDR, &px);
91 xdr_float(fBufferXDR, &py);
92 xdr_float(fBufferXDR, &pz);
93 xdr_float(fBufferXDR, &e);
94
95 ++fEntrySize;
96}
97
98//------------------------------------------------------------------------------
99
100void DelphesPileUpWriter::WriteEntry()
101{
102 if(fEntries >= kIndexSize)
103 {
104 throw runtime_error("too many pile-up events");
105 }
106
107 xdr_int(fOutputXDR, &fEntrySize);
108 xdr_opaque(fOutputXDR, fBuffer, fEntrySize*kRecordSize*4);
109
110 xdr_hyper(fIndexXDR, &fOffset);
111 fOffset += fEntrySize*kRecordSize*4 + 4;
112
113 xdr_setpos(fBufferXDR, 0);
114 fEntrySize = 0;
115
116 ++fEntries;
117}
118
119//------------------------------------------------------------------------------
120
121void DelphesPileUpWriter::WriteIndex()
122{
123 xdr_opaque(fOutputXDR, fIndex, fEntries*8);
124 xdr_hyper(fOutputXDR, &fEntries);
125}
126
127//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.