Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • classes/DelphesPileUpReader.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/DelphesXDRReader.h"
    3738
    3839using namespace std;
     
    4748  fEntries(0), fEntrySize(0), fCounter(0),
    4849  fPileUpFile(0), fIndex(0), fBuffer(0),
    49   fInputXDR(0), fIndexXDR(0), fBufferXDR(0)
     50  fInputReader(0), fIndexReader(0), fBufferReader(0)
    5051{
    5152  stringstream message;
    5253
    53   fIndex = new char[kIndexSize*8];
    54   fBuffer = new char[kBufferSize*kRecordSize*4];
    55   fInputXDR = new XDR;
    56   fIndexXDR = new XDR;
    57   fBufferXDR = new XDR;
    58   xdrmem_create(fIndexXDR, fIndex, kIndexSize*8, XDR_DECODE);
    59   xdrmem_create(fBufferXDR, fBuffer, kBufferSize*kRecordSize*4, XDR_DECODE);
     54  fIndex = new uint8_t[kIndexSize*8];
     55  fBuffer = new uint8_t[kBufferSize*kRecordSize*4];
     56  fInputReader = new DelphesXDRReader;
     57  fIndexReader = new DelphesXDRReader;
     58  fBufferReader = new DelphesXDRReader;
     59
     60  fIndexReader->SetBuffer(fIndex);
     61  fBufferReader->SetBuffer(fBuffer);
    6062
    6163  fPileUpFile = fopen(fileName, "r");
     
    6769  }
    6870
    69   xdrstdio_create(fInputXDR, fPileUpFile, XDR_DECODE);
     71  fInputReader->SetFile(fPileUpFile);
    7072
    7173  // read number of events
    7274  fseeko(fPileUpFile, -8, SEEK_END);
    73   xdr_hyper(fInputXDR, &fEntries);
     75  fInputReader->ReadValue(&fEntries, 8);
    7476
    7577  if(fEntries >= kIndexSize)
     
    8183  // read index of events
    8284  fseeko(fPileUpFile, -8 - 8*fEntries, SEEK_END);
    83   xdr_opaque(fInputXDR, fIndex, fEntries*8);
     85  fInputReader->ReadRaw(fIndex, fEntries*8);
    8486}
    8587
     
    8890DelphesPileUpReader::~DelphesPileUpReader()
    8991{
    90   xdr_destroy(fInputXDR);
    9192  if(fPileUpFile) fclose(fPileUpFile);
    92   xdr_destroy(fBufferXDR);
    93   xdr_destroy(fIndexXDR);
    94   if(fBufferXDR) delete fBufferXDR;
    95   if(fIndexXDR) delete fIndexXDR;
    96   if(fInputXDR) delete fInputXDR;
     93  if(fBufferReader) delete fBufferReader;
     94  if(fIndexReader) delete fIndexReader;
     95  if(fInputReader) delete fInputReader;
    9796  if(fBuffer) delete[] fBuffer;
    9897  if(fIndex) delete[] fIndex;
     
    101100//------------------------------------------------------------------------------
    102101
    103 bool DelphesPileUpReader::ReadParticle(int &pid,
     102bool DelphesPileUpReader::ReadParticle(int32_t &pid,
    104103  float &x, float &y, float &z, float &t,
    105104  float &px, float &py, float &pz, float &e)
     
    107106  if(fCounter >= fEntrySize) return false;
    108107
    109   xdr_int(fBufferXDR, &pid);
    110   xdr_float(fBufferXDR, &x);
    111   xdr_float(fBufferXDR, &y);
    112   xdr_float(fBufferXDR, &z);
    113   xdr_float(fBufferXDR, &t);
    114   xdr_float(fBufferXDR, &px);
    115   xdr_float(fBufferXDR, &py);
    116   xdr_float(fBufferXDR, &pz);
    117   xdr_float(fBufferXDR, &e);
     108  fBufferReader->ReadValue(&pid, 4);
     109  fBufferReader->ReadValue(&x, 4);
     110  fBufferReader->ReadValue(&y, 4);
     111  fBufferReader->ReadValue(&z, 4);
     112  fBufferReader->ReadValue(&t, 4);
     113  fBufferReader->ReadValue(&px, 4);
     114  fBufferReader->ReadValue(&py, 4);
     115  fBufferReader->ReadValue(&pz, 4);
     116  fBufferReader->ReadValue(&e, 4);
    118117
    119118  ++fCounter;
     
    124123//------------------------------------------------------------------------------
    125124
    126 bool DelphesPileUpReader::ReadEntry(quad_t entry)
     125bool DelphesPileUpReader::ReadEntry(int64_t entry)
    127126{
    128   quad_t offset;
     127  int64_t offset;
    129128
    130129  if(entry >= fEntries) return false;
    131130
    132131  // read event position
    133   xdr_setpos(fIndexXDR, 8*entry);
    134   xdr_hyper(fIndexXDR, &offset);
     132  fIndexReader->SetOffset(8*entry);
     133  fIndexReader->ReadValue(&offset, 8);
    135134
    136135  // read event
    137136  fseeko(fPileUpFile, offset, SEEK_SET);
    138   xdr_int(fInputXDR, &fEntrySize);
     137  fInputReader->ReadValue(&fEntrySize, 4);
    139138
    140139  if(fEntrySize >= kBufferSize)
     
    143142  }
    144143
    145   xdr_opaque(fInputXDR, fBuffer, fEntrySize*kRecordSize*4);
    146   xdr_setpos(fBufferXDR, 0);
     144  fInputReader->ReadRaw(fBuffer, fEntrySize*kRecordSize*4);
     145  fBufferReader->SetOffset(0);
    147146  fCounter = 0;
    148147
Note: See TracChangeset for help on using the changeset viewer.