Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • classes/DelphesPileUpWriter.cc

    rcab38f6 r1716933  
    3333
    3434#include <stdio.h>
    35 #include <rpc/types.h>
    36 #include <rpc/xdr.h>
     35#include <stdint.h>
     36
     37#include "classes/DelphesXDRWriter.h"
    3738
    3839using namespace std;
     
    4748  fEntries(0), fEntrySize(0), fOffset(0),
    4849  fPileUpFile(0), fIndex(0), fBuffer(0),
    49   fOutputXDR(0), fIndexXDR(0), fBufferXDR(0)
     50  fOutputWriter(0), fIndexWriter(0), fBufferWriter(0)
    5051{
    5152  stringstream message;
    5253
    53   fIndex = new char[kIndexSize*8];
    54   fBuffer = new char[kBufferSize*kRecordSize*4];
    55   fOutputXDR = new XDR;
    56   fIndexXDR = new XDR;
    57   fBufferXDR = new XDR;
    58   xdrmem_create(fIndexXDR, fIndex, kIndexSize*8, XDR_ENCODE);
    59   xdrmem_create(fBufferXDR, fBuffer, kBufferSize*kRecordSize*4, XDR_ENCODE);
     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);
    6062
    6163  fPileUpFile = fopen(fileName, "w+");
     
    6769  }
    6870
    69   xdrstdio_create(fOutputXDR, fPileUpFile, XDR_ENCODE);
     71  fOutputWriter->SetFile(fPileUpFile);
    7072}
    7173
     
    7476DelphesPileUpWriter::~DelphesPileUpWriter()
    7577{
    76   xdr_destroy(fOutputXDR);
    7778  if(fPileUpFile) fclose(fPileUpFile);
    78   xdr_destroy(fBufferXDR);
    79   xdr_destroy(fIndexXDR);
    80   if(fBufferXDR) delete fBufferXDR;
    81   if(fIndexXDR) delete fIndexXDR;
    82   if(fOutputXDR) delete fOutputXDR;
     79  if(fBufferWriter) delete fBufferWriter;
     80  if(fIndexWriter) delete fIndexWriter;
     81  if(fOutputWriter) delete fOutputWriter;
    8382  if(fBuffer) delete[] fBuffer;
    8483  if(fIndex) delete[] fIndex;
     
    8786//------------------------------------------------------------------------------
    8887
    89 void DelphesPileUpWriter::WriteParticle(int pid,
     88void DelphesPileUpWriter::WriteParticle(int32_t pid,
    9089  float x, float y, float z, float t,
    9190  float px, float py, float pz, float e)
     
    9695  }
    9796
    98   xdr_int(fBufferXDR, &pid);
    99   xdr_float(fBufferXDR, &x);
    100   xdr_float(fBufferXDR, &y);
    101   xdr_float(fBufferXDR, &z);
    102   xdr_float(fBufferXDR, &t);
    103   xdr_float(fBufferXDR, &px);
    104   xdr_float(fBufferXDR, &py);
    105   xdr_float(fBufferXDR, &pz);
    106   xdr_float(fBufferXDR, &e);
     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);
    107106
    108107  ++fEntrySize;
     
    118117  }
    119118
    120   xdr_int(fOutputXDR, &fEntrySize);
    121   xdr_opaque(fOutputXDR, fBuffer, fEntrySize*kRecordSize*4);
     119  fOutputWriter->WriteValue(&fEntrySize, 4);
     120  fOutputWriter->WriteRaw(fBuffer, fEntrySize*kRecordSize*4);
    122121
    123   xdr_hyper(fIndexXDR, &fOffset);
     122  fIndexWriter->WriteValue(&fOffset, 8);
    124123  fOffset += fEntrySize*kRecordSize*4 + 4;
    125124
    126   xdr_setpos(fBufferXDR, 0);
     125  fBufferWriter->SetOffset(0);
    127126  fEntrySize = 0;
    128        
     127
    129128  ++fEntries;
    130129}
     
    134133void DelphesPileUpWriter::WriteIndex()
    135134{
    136   xdr_opaque(fOutputXDR, fIndex, fEntries*8);
    137   xdr_hyper(fOutputXDR, &fEntries);
     135  fOutputWriter->WriteRaw(fIndex, fEntries*8);
     136  fOutputWriter->WriteValue(&fEntries, 8);
    138137}
    139138
Note: See TracChangeset for help on using the changeset viewer.