slic/include
diff -N lStdHep.hh
--- lStdHep.hh 24 Jan 2006 18:39:27 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,397 +0,0 @@
-//// lStdHep.hh
-//
-// Header file for a light-weight StdHep class.
-// This class is based on the light-weight XDR class lXDR,
-// and parses/writes StdHep files. It was mainly written,
-// to provide a faster alternative to the more cumdersome
-// methods using mcfio in CLHEP.
-//
-// W.G.J. Langeveld, 24 May 2002
-//
-// Release notes:
-// - Version 1.0 (23-Oct-2003, WGL):
-// o Implements "read" but not "write" functions
-// o Standalone (previous versions depended on sgarray,
-// which comes with the "vec" package in the Lelaps
-// distribution). It now uses one std::vector.
-// - Version 1.1 (18-Mar-2004, WGL):
-// o Fixed a file positioning bug which made it fail to
-// read some files.
-// - Version 1.2 (18-Mar-2004, WGL):
-// o Fixed a bug where it would skip one event at the
-// boundaries between event blocks.
-// - Version 1.3 (19-Mar-2004, WGL):
-// o Improved handling of end-of-file. Now, when there
-// are no more events, readEvent() returns an error.
-// The error code is LSH_ENDOFFILE.
-// - Version 1.4 (30-Mar-2004, WGL):
-// o Fixed memory leak
-// - Version 1.5 (10-Aug-2004, WGL):
-// o Added numEvents() method by request.
-//
-////
-#ifndef LSTDHEP__HH
-#define LSTDHEP__HH
-
-#include "lXDR.hh"
-#include <vector>
-
-//
-// MCFIO block codes
-//
-#define LSH_GENERIC 0
-#define LSH_FILEHEADER 1 // supported 5/28/2002
-#define LSH_EVENTTABLE 2 // supported 5/28/2002
-#define LSH_SEQUENTIALHEADER 3
-#define LSH_EVENTHEADER 4 // supported 5/28/2002
-#define LSH_NOTHING 5
-//
-// lStdHepError codes
-//
-#define LSH_SUCCESS 0
-#define LSH_BLOCKERROR 101
-#define LSH_NOEVENTTABLE 102
-#define LSH_NOEVENT 103
-#define LSH_NOTSUPPORTED 104
-#define LSH_EVTABLECORRUPT 105
-#define LSH_ENDOFFILE 106
-//
-// StdHep block codes
-//
-#define LSH_STDHEP 101 // supported 5/28/2002
-#define LSH_OFFTRACKARRAYS 102
-#define LSH_OFFTRACKSTRUCT 103
-#define LSH_TRACEARRAYS 104
-#define LSH_STDHEPM 105
-#define LSH_STDHEPBEG 106 // supported 5/28/2002
-#define LSH_STDHEPEND 107 // supported 5/28/2002
-#define LSH_STDHEPCXX 108
-#define LSH_STDHEPEV4 201 // supported 1/23/2006
-
-////
-//
-// The basic lStdHep track. Note that access controls are
-// unneeded here since this is an old standard unlikely to
-// change.
-//
-////
-struct lStdTrack {
- double X;
- double Y;
- double Z;
- double T;
- double Px;
- double Py;
- double Pz;
- double E;
- double M;
- long pid;
- long status;
- long mother1;
- long mother2;
- long daughter1;
- long daughter2;
-};
-
-
-////
-//
-// The basic lStdHep event
-//
-////
-struct lStdEvent : public std::vector<lStdTrack> {
- long evtNum;
- long nTracks(void) { return(size()); };
-};
-
-////
-//
-// The lStdHep class is the "handle" for the StdHep file, and
-// provides the access mechanism to the events.
-//
-////
-class lStdHep : public lXDR {
-private:
-//
-// The current version/revision is:
-//
- enum { MAJOR = 2, MINOR = 0, DAY = 23, MONTH = 1, YEAR = 2006 };
-// ========================================================
-public:
- static int getMajor(void) { return(MAJOR); };
- static int getMinor(void) { return(MINOR); };
- static const char *getText(void) {
- static char buff[80];
- sprintf(buff, "lStdHep version %d.%d (%02d.%02d.%d) by W.G.J. Langeveld, SLAC",
- MAJOR, MINOR, DAY, MONTH, YEAR);
- return(buff);
- };
-
-
-//
-// Constructors, destructor
-// ------------------------
-// Constructor opens file, destructor closes file. Once opened for
-// reading, the file cannot be written to, and v.v.
-//
- lStdHep(const char *filename = 0, bool open_for_write = false);
-//
-// Prevent copying:
-//
-private:
- lStdHep(const lStdHep &);
-public:
- virtual ~lStdHep();
-//
-// Prevent assignment:
-//
-private:
- lStdHep &operator=(const lStdHep &);
-public:
-//
-// See if there are more events
-//
- bool more(void);
-//
-// Event reading functions. They return the last error encountered,
-// or LSH_SUCCESS.
-// - Read the next event into the event buffer:
-//
- long readEvent(void);
-//
-// - Fill the provided lStdEvent with the current event:
-//
- long getEvent(lStdEvent &lse) const;
-//
-// - Combine readEvent() with getEvent():
-//
- long readEvent(lStdEvent &lse);
-//
-// Get the number of events in the input file
-//
- long numEvents() const { return(numevts); };
-//
-// Direct access to the event buffer. Note that using readEvent(void)
-// in combination with the functions below is faster than using
-// readEvent(lStdEvent &), especially when only a few quantities are
-// needed.
-//
- long blockId() const { return(event.blockid); };
- long nTracks(void) const { return(event.nhep); };
- long evtNum(void) const { return(event.nevhep); };
- long runNum(void) const { return(event.runnum); };
-
- double X(int i) const { return(event.vhep[i * 4 + 0]); };
- double Y(int i) const { return(event.vhep[i * 4 + 1]); };
- double Z(int i) const { return(event.vhep[i * 4 + 2]); };
- double T(int i) const { return(event.vhep[i * 4 + 3]); };
- double Px(int i) const { return(event.phep[i * 5 + 0]); };
- double Py(int i) const { return(event.phep[i * 5 + 1]); };
- double Pz(int i) const { return(event.phep[i * 5 + 2]); };
- double E(int i) const { return(event.phep[i * 5 + 3]); };
- double M(int i) const { return(event.phep[i * 5 + 4]); };
- long pid(int i) const { return(event.idhep[i]); };
- long status(int i) const { return(event.isthep[i]); };
- long mother1(int i) const { return(event.jmohep[i + i + 0]); };
- long mother2(int i) const { return(event.jmohep[i + i + 1]); };
- long daughter1(int i) const { return(event.jdahep[i + i + 0]); };
- long daughter2(int i) const { return(event.jdahep[i + i + 1]); };
- double eventweight(void) const { return(event.eventweight); };
- double alphaQED(void) const { return(event.alphaqed); };
- double alphaQCD(void) const { return(event.alphaqcd); };
- double scale(int i, int j) const { return(event.scale[i * 10 + j] ); };
- double spinX(int i) const { return(event.spin[i * 3 + 0] ); };
- double spinY(int i) const { return(event.spin[i * 3 + 1] ); };
- double spinZ(int i) const { return(event.spin[i * 3 + 2] ); };
- long colorflow(int i, int j) const { return(event.colorflow[i * 2 + j] ); };
- long idrup(void) const { return(event.idrup); };
-//
-// Call this to make sure you can call things like scale, spin and colorflow:
-//
- bool isStdHepEv4(void) const { return(event.scale != 0); };
-//
-// Event writing functions. They return the last error encountered,
-// or LSH_SUCCESS.
-// - Write the current event buffer to thefile:
-//
- long writeEvent(void);
-//
-// - Fill the event buffer with the data from the provided lStdEvent:
-//
- long setEvent(const lStdEvent &lse);
-//
-// - Combine setEvent() with writeEvent():
-//
- long writeEvent(lStdEvent &lse);
-//
-// Direct access to the event buffer.
-//
- void setNTracks(long n) { event.nhep = n; return; };
- void setEvtNum(long n) { event.nevhep = n; return; };
-
- void setX(int i, double x) { event.vhep[i * 4 + 0] = x; return; };
- void setY(int i, double y) { event.vhep[i * 4 + 1] = y; return; };
- void setZ(int i, double z) { event.vhep[i * 4 + 2] = z; return; };
- void setT(int i, double t) { event.vhep[i * 4 + 3] = t; return; };
- void setPx(int i, double px) { event.phep[i * 5 + 0] = px; return; };
- void setPy(int i, double py) { event.phep[i * 5 + 1] = py; return; };
- void setPz(int i, double pz) { event.phep[i * 5 + 2] = pz; return; };
- void setE(int i, double e) { event.phep[i * 5 + 3] = e; return; };
- void setM(int i, double m) { event.phep[i * 5 + 4] = m; return; };
- void setPid(int i, long pid) { event.idhep[i] = pid; return; };
- void setStatus(int i, long s) { event.isthep[i] = s; return; };
- void setMother1(int i, long n) { event.jmohep[i + i + 0] = n; return; };
- void setMother2(int i, long n) { event.jmohep[i + i + 1] = n; return; };
- void setDaughter1(int i, long n) { event.jdahep[i + i + 0] = n; return; };
- void setDaughter2(int i, long n) { event.jdahep[i + i + 1] = n; return; };
-//
-// Informational printout
-//
- void printFileHeader(FILE *fp = 0);
- void printBeginRunRecord(FILE *fp = 0);
- void printEndRunRecord(FILE *fp = 0);
- void printEventTable(FILE *fp = 0);
- void printEventHeader(FILE *fp = 0);
- void printEvent(FILE *fp = 0);
- void printTrack(int i, FILE *fp = 0);
-
-private:
- long readFileHeader(void);
-//
-// File Header
-//
- long ntot;
- const char *version;
- const char *title;
- const char *comment;
- const char *date;
- const char *closingDate;
-
- long numevts_expect;
- long numevts;
- long firstTable;
- long dimTable;
- long nNTuples;
- long nBlocks;
- long *blockIds;
- const char **blockNames;
-//
-// Event table
-//
- class EventTable {
- public:
- EventTable();
- ~EventTable();
- void cleanup(void);
- long read(lStdHep &ls);
- long print(FILE *fp);
-//
-// ...Empty flag
-//
- long isEmpty;
-//
-// Index into the event table
-//
- long ievt;
-//
-// ...MCFIO header
-//
- long blockid;
- long ntot;
- const char *version;
-//
-// ...Location of next table
-//
- long nextlocator;
-//
-// ...The event table itself
-//
- long numEvts;
- long *evtnums;
- long *storenums;
- long *runnums;
- long *trigMasks;
- long *ptrEvents;
- };
- EventTable eventTable;
-//
-// The event
-//
- class Event {
- public:
- Event();
- ~Event();
- void cleanup(void);
- long read(lStdHep &ls);
- long printHeader(FILE *fp);
- long print(FILE *fp);
-//
-// ...Empty flag
-//
- long isEmpty;
-//
-// ...MCFIO header
-//
- long blockid;
- long ntot;
- const char *version;
-//
-// ...Event header:
-//
- long evtnum;
- long storenum;
- long runnum;
- long trigMask;
- long nBlocks;
- long dimBlocks;
- long nNTuples;
- long dimNTuples;
- long *blockIds;
- long *ptrBlocks;
-//
-// ...Event:
-//
- long nevhep;
- long nhep;
- long *isthep;
- long *idhep;
- long *jmohep;
- long *jdahep;
- double *phep;
- double *vhep;
-//
-// ...New for STDHEPEV4:
-//
- double eventweight;
- double alphaqed;
- double alphaqcd;
- double *scale;
- double *spin;
- long *colorflow;
- long idrup;
-//
-// ...Begin run record:
-//
- long bnevtreq;
- long bnevtgen;
- long bnevtwrt;
- double bstdecom;
- double bstdxsec;
- double bstdseed1;
- double bstdseed2;
-//
-// ...End run record:
-//
- long enevtreq;
- long enevtgen;
- long enevtwrt;
- double estdecom;
- double estdxsec;
- double estdseed1;
- double estdseed2;
- };
- Event event;
-};
-
-
-#endif
slic/include
diff -N lXDR.hh
--- lXDR.hh 4 Mar 2005 22:54:33 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,147 +0,0 @@
-//// lXDR.hh
-//
-// Header file for a light-weight XDR class
-// This class does not support the full XDR protocol, and
-// neither does it work for all platforms. It was mainly
-// written, in combination with lStdHep, to provide a faster
-// alternative to the more cumdersome methods using mcfio in
-// CLHEP.
-//
-// W.G.J. Langeveld, 24 May 2002
-//
-// Release notes:
-// - Version 1.0 (23-Oct-2003)
-//
-////
-#ifndef LXDR__HH
-#define LXDR__HH
-
-#include <stdio.h>
-
-////
-//
-// The main lXDR class.
-//
-////
-/**
- @class lXDR
- @author Willy Langeveld
- @brief Light-weight XDR interface class.
-*/
-class lXDR {
-private:
-//
-// The current version/revision is:
-//
- enum { MAJOR = 1, MINOR = 0, DAY = 23, MONTH = 10, YEAR = 2003 };
-// ========================================================
-public:
- static int getMajor(void) { return(MAJOR); };
- static int getMinor(void) { return(MINOR); };
- static const char *getText(void) {
- static char buff[80];
- sprintf(buff, "lXDR version %d.%d (%02d.%02d.%d) by W.G.J. Langeveld, SLAC",
- MAJOR, MINOR, DAY, MONTH, YEAR);
- return(buff);
- };
-public:
-//
-// Constructors, destructor
-// ------------------------
-// Constructor opens file, destructor closes file. Once opened for
-// reading, the file cannot be written to, and v.v.
-//
- lXDR(const char *filename = 0, bool open_for_write = false);
-private: // Prevent copying
- lXDR(const lXDR &);
-public:
- virtual ~lXDR();
-//
-// Change the file being read/written. If another file is currently
-// being read or written, it is first closed. The new file position
-// is the start of the file.
-//
- void setFileName(const char *filename, bool open_for_write = false);
- const char *getFileName(void) const { return(_fileName); };
-//
-// Prevent assignment:
-//
-private:
- lXDR &operator=(const lXDR &);
-public:
-//
-// Check for errors in the last operation.
-//
- long getError(void) const { return(_error); };
-//
-// Read data.
-// ----------
-// The following routines read single longs floats or doubles.
-// Check getError() for succes or failure.
-//
- long readLong(void);
- double readFloat(void); // Note that this returns a double!!
- double readDouble(void);
-//
-// The following routines read the length of an array of char, long or double
-// from the file, allocate a suitably large array, and read the data from the
-// file. Character strings are null terminated.
-// Check getError() for succes or failure.
-//
- const char *readString(long &length);
- long *readLongArray(long &length);
- double *readFloatArray(long &length); // Note that this returns an array of doubles!!
- double *readDoubleArray(long &length);
-//
-// Write data
-// ----------
-// The following routines write single longs or doubles.
-// They return getError().
-//
- long writeLong(long data);
- long writeDouble(double data);
-//
-// The following routines write the length of an array of char, long or double
-// to the file, then write the data itself.
-// The functions return getError().
-//
- long writeString(const char *data);
- long writeString(const char *data, long length);
- long writeLongArray(const long *data, long length);
- long writeDoubleArray(const double *data, long length);
-
- void setError(long error) { _error = error; return; };
-//
-// Set or get (with no arguments) file position.
-//
- long filePosition(long pos = -1);
-
-private:
- char *_fileName;
- FILE *_fp;
- long _error;
- bool _openForWrite;
-
- bool _hasNetworkOrder;
- double ntohd(double d) const;
- double htond(double d) const { return(ntohd(d)); };
-
- long checkRead(long *);
- long checkRead(float *);
- long checkRead(double *);
- long checkWrite(long *);
- long checkWrite(double *);
-};
-
-#define LXDR_SUCCESS 0
-#define LXDR_OPENFAILURE 1
-#define LXDR_READONLY 2
-#define LXDR_WRITEONLY 3
-#define LXDR_NOFILE 4
-#define LXDR_READERROR 5
-#define LXDR_WRITEERROR 6
-#define LXDR_SEEKERROR 7
-
-
-#endif
-
slic/src
diff -N lStdHep.cc
--- lStdHep.cc 6 Jun 2006 19:53:41 -0000 1.5
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,544 +0,0 @@
-//// lStdHep.cc
-//
-// This class is based on the light-weight XDR class lXDR,
-// and parses/writes StdHep files. It was mainly written,
-// to provide a faster alternative to the more cumbersome
-// methods using mcfio in StdHep.
-//
-// W.G.J. Langeveld, 24 May 2002
-//
-////
-#include "lStdHep.hh"
-#include "string.h"
-#include "stdlib.h"
-
-////
-//
-// The main lStdHep class.
-//
-////
-
-//
-// Constructors, destructor
-// ------------------------
-// Constructor opens file, destructor closes file. Once opened for
-// reading, the file cannot be written to, and v.v.
-//
-lStdHep::lStdHep(const char *filename, bool open_for_write) : lXDR(filename, open_for_write),
- version(0), title(0), comment(0), date(0), closingDate(0), blockIds(0), blockNames(0)
-{
- if (open_for_write) {
- setError(LSH_NOTSUPPORTED);
- }
- else {
- readFileHeader();
- }
- return;
-}
-
-lStdHep::~lStdHep()
-{
- delete [] version;
- delete [] date;
- delete [] closingDate;
- delete [] comment;
- delete [] title;
- delete [] blockIds;
- if (blockNames) {
- for (int i = 0; i < nBlocks; i++) {
- delete [] blockNames[i];
- }
- delete [] blockNames;
- }
- return;
-}
-
-void lStdHep::printFileHeader(FILE *fp)
-{
- if (fp == 0) fp = stdout;
-
- fprintf(fp, "====== File Header ===========\n");
- fprintf(fp, " total blocks: %ld\n", ntot);
- fprintf(fp, " version: %s\n", version);
- fprintf(fp, " title: %s\n", title);
- fprintf(fp, " comment: %s\n", comment);
- fprintf(fp, " date: %s", date);
- fprintf(fp, " closing date: %s", closingDate);
- fprintf(fp, " expected events: %ld\n", numevts_expect);
- fprintf(fp, " events: %ld\n", numevts);
- fprintf(fp, " firstTable: %ld\n", firstTable);
- fprintf(fp, " dimTable: %ld\n", dimTable);
- fprintf(fp, " nNTuples: %ld\n", nNTuples);
- fprintf(fp, " nBlocks: %ld\n", nBlocks);
- if (nBlocks) fprintf(fp, " block names:\n");
- for (int i = 0; i < nBlocks; i++) {
- fprintf(fp, " : %s\n", blockNames[i]);
- }
- fprintf(fp, "=============================\n");
- return;
-}
-
-void lStdHep::printEventTable(FILE *fp)
-{
- if (fp == 0) fp = stdout;
- eventTable.print(fp);
- return;
-}
-
-void lStdHep::printEventHeader(FILE *fp)
-{
- if (fp == 0) fp = stdout;
- event.printHeader(fp);
- return;
-}
-
-void lStdHep::printEvent(FILE *fp)
-{
- if (fp == 0) fp = stdout;
- event.print(fp);
- return;
-}
-
-void lStdHep::printTrack(int i, FILE *fp)
-{
- if (fp == 0) fp = stdout;
- if (i < event.nhep) {
- fprintf(fp, " Track: id: %ld, vtx: (%g, %g, %g, %g), mom: (%g, %g, %g, %g, %g)\n",
- pid(i), X(i), Y(i), Z(i), T(i), Px(i), Py(i), Pz(i), E(i), M(i));
- fprintf(fp, " Track: wgt: %g, alpha QED: %g, alpha QCD: %g, idrup: %ld\n",
- eventweight(), alphaQED(), alphaQCD(), idrup());
- }
- return;
-}
-
-void lStdHep::printBeginRunRecord(FILE *fp)
-{
- if (fp == 0) fp = stdout;
- return;
-}
-
-void lStdHep::printEndRunRecord(FILE *fp)
-{
- if (fp == 0) fp = stdout;
- return;
-}
-
-bool lStdHep::more(void)
-{
- return(getError() == LSH_SUCCESS);
-}
-
-long lStdHep::readEvent(void)
-{
-//
-// Look for an event or an event table
-//
- event.isEmpty = 1;
- while (1) {
- if (eventTable.ievt < eventTable.numEvts) {
- if (filePosition(eventTable.ptrEvents[eventTable.ievt]) !=
- eventTable.ptrEvents[eventTable.ievt]) return(getError());
-
- if (event.read(*this) != LSH_SUCCESS) return(getError());
- eventTable.ievt++;
-
- if (event.isEmpty) continue;
- return(getError());
- }
-
- eventTable.isEmpty = 1;
- while (eventTable.isEmpty) {
- if (eventTable.nextlocator == -2) {
-//
-// This was the last event table, signal quitting. Not an error.
-//
- setError(LSH_ENDOFFILE);
- return(getError());
- }
- else if (eventTable.nextlocator == -1) {
- setError(LSH_EVTABLECORRUPT);
- return(getError());
- }
-//
-// Go to the next event table
-//
- if (filePosition(eventTable.nextlocator) != eventTable.nextlocator) return(getError());
- if (eventTable.read(*this) != LSH_SUCCESS) return(getError());
- }
- }
- return(getError());
-}
-
-long lStdHep::getEvent(lStdEvent &lse) const
-{
- if (long status = getError() != LSH_SUCCESS) return(status);
-
- lse.evtNum = event.nevhep;
-
- lse.clear();
- for (int i = 0; i < event.nhep; i++) {
- lStdTrack lst;
- lst.X = X(i);
- lst.Y = Y(i);
- lst.Z = Z(i);
- lst.T = T(i);
- lst.Px = Px(i);
- lst.Py = Py(i);
- lst.Pz = Pz(i);
- lst.E = E(i);
- lst.M = M(i);
- lst.pid = pid(i);
- lst.status = status(i);
- lst.mother1 = mother1(i);
- lst.mother2 = mother2(i);
- lst.daughter1 = daughter1(i);
- lst.daughter2 = daughter2(i);
- lse.push_back(lst);
- }
- return(LSH_SUCCESS);
-}
-
-long lStdHep::readEvent(lStdEvent &lse)
-{
- long status = readEvent();
- if (status != LSH_SUCCESS) return(status);
- return(getEvent(lse));
-}
-
-long lStdHep::readFileHeader(void)
-{
- long len, blockid;
-
- blockid = readLong();
- if (blockid != LSH_FILEHEADER) {
- setError(LSH_BLOCKERROR);
- return(getError());
- }
- ntot = readLong();
- version = readString(len);
-
- title = readString(len);
- comment = readString(len);
- date = readString(len);
- if ((strcmp(version, "2.00") == 0) || (strcmp(version, "1.00") == 0)) {
- closingDate = new char[len + 1];
- strcpy((char *) closingDate, date);
- }
- else {
- closingDate = readString(len);
- }
-
- numevts_expect = readLong();
- numevts = readLong();
- firstTable = readLong();
- dimTable = readLong();
- nBlocks = readLong();
- if (*version != '2') {
- nNTuples = 0;
- }
- else {
- nNTuples = readLong();
- }
-
- blockIds = readLongArray(nBlocks);
- blockNames = new const char *[nBlocks];
- for (int i = 0; i < nBlocks; i++) blockNames[i] = readString(len);
- if (nNTuples > 0) setError(LSH_NOTSUPPORTED);
-//
-// Read the first event table
-//
- eventTable.read(*this);
- return(getError());
-}
-
-long lStdHep::writeEvent(void)
-{
- return(LSH_NOTSUPPORTED);
-}
-
-long lStdHep::setEvent(const lStdEvent &lse)
-{
-// ***************set up event buffer!
- setNTracks(lse.size());
- setEvtNum(lse.evtNum);
-
- for (int i = 0; i < event.nhep; i++) {
- setX (i, lse[i].X);
- setY (i, lse[i].Y);
- setZ (i, lse[i].Z);
- setT (i, lse[i].T);
- setPx (i, lse[i].Px);
- setPy (i, lse[i].Py);
- setPz (i, lse[i].Pz);
- setE (i, lse[i].E);
- setM (i, lse[i].M);
- setPid (i, lse[i].pid);
- setStatus (i, lse[i].status);
- setMother1 (i, lse[i].mother1);
- setMother2 (i, lse[i].mother2);
- setDaughter1(i, lse[i].daughter1);
- setDaughter2(i, lse[i].daughter2);
- }
- return(LSH_SUCCESS);
-}
-
-long lStdHep::writeEvent(lStdEvent &lse)
-{
- long status = writeEvent();
- if (status != LSH_SUCCESS) return(status);
- return(setEvent(lse));
-}
-
-lStdHep::EventTable::EventTable() :
- isEmpty(1), ievt(0), blockid(0), ntot(0), version(0),
- nextlocator(-3), numEvts(0), evtnums(0),
- storenums(0), runnums(0), trigMasks(0), ptrEvents(0)
-{
- return;
-}
-
-lStdHep::EventTable::~EventTable()
-{
- cleanup();
- return;
-}
-
-void lStdHep::EventTable::cleanup(void)
-{
- delete [] version; version = 0;
- delete [] evtnums; evtnums = 0;
- delete [] storenums; storenums = 0;
- delete [] runnums; runnums = 0;
- delete [] trigMasks; trigMasks = 0;
- delete [] ptrEvents; ptrEvents = 0;
- isEmpty = 1;
- ievt = ntot = blockid = numEvts = 0; // leave nextlocator alone!
- return;
-}
-
-long lStdHep::EventTable::read(lStdHep &ls)
-{
- long len;
-
- cleanup();
-
- blockid = ls.readLong();
- ntot = ls.readLong();
- version = ls.readString(len);
-
- if (blockid != LSH_EVENTTABLE) {
- ls.setError(LSH_NOEVENTTABLE);
- return(ls.getError());
- }
- nextlocator = ls.readLong();
- numEvts = ls.readLong();
- evtnums = ls.readLongArray(len);
- storenums = ls.readLongArray(len);
- runnums = ls.readLongArray(len);
- trigMasks = ls.readLongArray(len);
- ptrEvents = ls.readLongArray(len);
- if (numEvts > 0) isEmpty = 0;
- return(ls.getError());
-}
-
-long lStdHep::EventTable::print(FILE *fp)
-{
- fprintf(fp, " EventTable: blockid: %ld, ntot: %ld, version: %s\n", blockid, ntot, version);
- fprintf(fp, " EventTable: nextlocator: %ld, numEvts: %ld\n", nextlocator, numEvts);
- for (int i = 0; i < numEvts; i++) {
- fprintf(fp, " EventTable: %d: evtnums %ld storenums %ld runnums %ld trigMasks %ld ptrEvents %ld\n",
- i, evtnums[i], storenums[i], runnums[i], trigMasks[i], ptrEvents[i]);
- if (i == 10) {
- fprintf(fp, " EventTable: etc.\n");
- break;
- }
- }
- return(0);
-}
-
-lStdHep::Event::Event() :
- isEmpty(1), blockid(0), ntot(0), version(0), blockIds(0),
- ptrBlocks(0), nevhep(0), nhep(0), isthep(0), idhep(0),
- jmohep(0), jdahep(0), phep(0), vhep(0), eventweight(0.0),
- alphaqed(0.0), alphaqcd(0.0), scale(0), spin(0), colorflow(0),
- idrup(0)
-{
- return;
-}
-
-lStdHep::Event::~Event()
-{
- cleanup();
-}
-
-void lStdHep::Event::cleanup(void)
-{
- delete [] version; version = 0;
- delete [] ptrBlocks; ptrBlocks = 0;
- delete [] blockIds; blockIds = 0;
- delete [] isthep; isthep = 0;
- delete [] idhep; idhep = 0;
- delete [] jmohep; jmohep = 0;
- delete [] jdahep; jdahep = 0;
- delete [] phep; phep = 0;
- delete [] vhep; vhep = 0;
- delete [] scale; scale = 0;
- delete [] spin; spin = 0;
- delete [] colorflow; colorflow = 0;
- blockid = ntot = nevhep = nhep = 0;
- isEmpty = 1;
- return;
-}
-
-long lStdHep::Event::read(lStdHep &ls)
-{
-//
-// Read event header
-//
- long len;
-
- cleanup();
-
- blockid = ls.readLong();
- ntot = ls.readLong();
- version = ls.readString(len);
- if (blockid != LSH_EVENTHEADER) ls.setError(LSH_NOEVENT);
-
- evtnum = ls.readLong();
- storenum = ls.readLong();
- runnum = ls.readLong();
- trigMask = ls.readLong();
- nBlocks = ls.readLong();
- dimBlocks = ls.readLong();
-
- if (*version == '2') {
- nNTuples = ls.readLong();
- dimNTuples = ls.readLong();
- if (dimBlocks) {
- blockIds = ls.readLongArray(len);
- ptrBlocks = ls.readLongArray(len);
- }
- if (dimNTuples) {
- ls.setError(LSH_NOTSUPPORTED);
- return(ls.getError());
- }
- }
- else {
- nNTuples = 0;
- dimNTuples = 0;
- blockIds = ls.readLongArray(len);
- ptrBlocks = ls.readLongArray(len);
- }
-//
-// Read event
-//
- for (int i = 0; i < nBlocks; i++) {
- blockid = ls.readLong();
- ntot = ls.readLong();
- if (version) delete [] version;
- version = ls.readString(len);
-
- isEmpty = 0;
- switch (blockIds[i]) {
- case LSH_STDHEP : // 101
- nevhep = ls.readLong();
- nhep = ls.readLong();
- if (isthep) delete [] isthep;
- isthep = ls.readLongArray(len);
- if (idhep) delete [] idhep;
- idhep = ls.readLongArray(len);
- if (jmohep) delete [] jmohep;
- jmohep = ls.readLongArray(len);
- if (jdahep) delete [] jdahep;
- jdahep = ls.readLongArray(len);
- if (phep) delete [] phep;
- phep = ls.readDoubleArray(len);
- if (vhep) delete [] vhep;
- vhep = ls.readDoubleArray(len);
- break;
- case LSH_STDHEPEV4 : // 201
- nevhep = ls.readLong();
- nhep = ls.readLong();
- if (isthep) delete [] isthep;
- isthep = ls.readLongArray(len);
- if (idhep) delete [] idhep;
- idhep = ls.readLongArray(len);
- if (jmohep) delete [] jmohep;
- jmohep = ls.readLongArray(len);
- if (jdahep) delete [] jdahep;
- jdahep = ls.readLongArray(len);
- if (phep) delete [] phep;
- phep = ls.readDoubleArray(len);
- if (vhep) delete [] vhep;
- vhep = ls.readDoubleArray(len);
-//
-// New stuff for STDHEPEV4:
-//
- eventweight = ls.readDouble();
- alphaqed = ls.readDouble();
- alphaqcd = ls.readDouble();
- if (scale) delete [] scale;
- scale = ls.readDoubleArray(len);
- if (spin) delete [] spin;
- spin = ls.readDoubleArray(len);
- if (colorflow) delete [] colorflow;
- colorflow = ls.readLongArray(len);
- idrup = ls.readLong();
- break;
- case LSH_OFFTRACKARRAYS : // 102
- case LSH_OFFTRACKSTRUCT : // 103
- case LSH_TRACEARRAYS : // 104
- case LSH_STDHEPM : // 105
- break;
- case LSH_STDHEPBEG : // 106
- bnevtreq = ls.readLong();
- bnevtgen = ls.readLong();
- bnevtwrt = ls.readLong();
- bstdecom = ls.readFloat();
- bstdxsec = ls.readFloat();
- bstdseed1 = ls.readDouble();
- bstdseed2 = ls.readDouble();
- isEmpty = 1;
- break;
- case LSH_STDHEPEND : // 107
- enevtreq = ls.readLong();
- enevtgen = ls.readLong();
- enevtwrt = ls.readLong();
- estdecom = ls.readFloat();
- estdxsec = ls.readFloat();
- estdseed1 = ls.readDouble();
- estdseed2 = ls.readDouble();
- isEmpty = 1;
- break;
- case LSH_STDHEPCXX : // 108
- break;
- }
- }
- return(ls.getError());
-}
-
-long lStdHep::Event::printHeader(FILE *fp)
-{
- fprintf(fp, " EventHeader: blockid: %ld, ntot: %ld, version: %s\n", blockid, ntot, version);
- fprintf(fp, " : evtnum: %ld, storenum: %ld, runnum: %ld, trigMask: %ld, nBlocks: %ld, dimBlocks: %ld\n",
- evtnum, storenum, runnum, trigMask, nBlocks, dimBlocks);
- fprintf(fp, " : nNTuples: %ld, dimNTuples: %ld\n", nNTuples, dimNTuples);
-
- for (int i = 0; i < nBlocks; i++) {
- const char *labels[10] = {"Event", "Off-track arrays", "Off-track struct", "Trace arrays",
- "Event with multiple interactions", "Begin run", "End run", "StdHepCXX",
- "EventV4", "Unknown" };
- int j = blockIds[i] - 101;
- if (blockIds[i] == LSH_STDHEPEV4) j = 8;
- if ((j < 0) || (j > 9)) j = 9;
- fprintf(fp, " : %d: blockIds %ld (%s) ptrBlocks %ld\n",
- i, blockIds[i], labels[j], ptrBlocks[i]);
- }
- return(0);
-}
-
-long lStdHep::Event::print(FILE *fp)
-{
- fprintf(fp, " Event: nevhep: %ld, nhep: %ld\n", nevhep, nhep);
- return(0);
-}
slic/src
diff -N lXDR.cc
--- lXDR.cc 23 Nov 2004 21:19:31 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,314 +0,0 @@
-//// lXDR.cc
-//
-// Simple XDR class, see header
-//
-// WGL, 24 May 2002
-//
-////
-#include "lXDR.hh"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#if defined(__linux) || defined(__CYGWIN__)
-#include <netinet/in.h>
-#endif
-#ifdef _MSC_VER
-#include <winsock.h>
-#else
-#include <sys/socket.h>
-#endif
-////
-//
-// Constructor, destructor
-//
-////
-lXDR::~lXDR()
-{
- if (_fp) {
- fclose(_fp);
- _fp = 0;
- }
- if (_fileName) {
- delete [] _fileName;
- _fileName = 0;
- }
- return;
-}
-
-lXDR::lXDR(const char *filename, bool open_for_write) : _fileName(0), _fp(0)
-{
- setFileName(filename, open_for_write);
- if (htonl(1L) == 1L) _hasNetworkOrder = true;
- else _hasNetworkOrder = false;
- return;
-}
-
-void lXDR::setFileName(const char *filename, bool open_for_write)
-{
-//
-// First check if we can open this file
-//
- if (filename == 0) {
- _error = LXDR_OPENFAILURE;
- return;
- }
-#ifdef _MSC_VER
- FILE *fp = fopen(filename, open_for_write ? "wb" : "rb");
-#else
- FILE *fp = fopen(filename, open_for_write ? "w" : "r");
-#endif
- if (fp == 0) {
- _error = LXDR_OPENFAILURE;
- return;
- }
-
- if (_fp) fclose(_fp);
- _fp = fp;
-
- if (_fileName) {
- delete [] _fileName;
- _fileName = 0;
- }
-
- int n = strlen(filename);
- _fileName = new char [n + 1];
- strncpy(_fileName, filename, n);
- _fileName[n] = '\0';
-
- _openForWrite = open_for_write;
-
- _error = LXDR_SUCCESS;
- return;
-}
-
-double lXDR::ntohd(double d) const
-{
-//
-// If we already have network order, we don't swap
-//
- if (_hasNetworkOrder == false) {
- union {
- double d;
- unsigned char b[8];
- } dd;
- int i;
-
- dd.d = d;
- for (i = 0; i < 4; i++) {
- unsigned char c = dd.b[i];
- dd.b[i] = dd.b[7 - i];
- dd.b[7 - i] = c;
- }
- d = dd.d;
- }
- return(d);
-}
-
-long lXDR::checkRead(long *l)
-{
- if (_openForWrite) return(_error = LXDR_READONLY);
- if (_fp == 0) return(_error = LXDR_NOFILE);
- if (l) {
- long nr;
- if ((nr = fread(l, 4, 1, _fp)) != 1) return(_error = LXDR_READERROR);
- *l = ntohl(*l);
- }
- return(LXDR_SUCCESS);
-}
-
-long lXDR::checkRead(double *d)
-{
- if (_openForWrite) return(_error = LXDR_READONLY);
- if (_fp == 0) return(_error = LXDR_NOFILE);
- if (d) {
- if (fread(d, 8, 1, _fp) != 1) return(_error = LXDR_READERROR);
- *d = ntohd(*d);
- }
- return(LXDR_SUCCESS);
-}
-
-long lXDR::checkRead(float *f)
-{
- if (_openForWrite) return(_error = LXDR_READONLY);
- if (_fp == 0) return(_error = LXDR_NOFILE);
- if (f) {
- if (fread(f, 4, 1, _fp) != 1) return(_error = LXDR_READERROR);
- *((long *) f) = ntohl(*((long *) f));
- }
- return(LXDR_SUCCESS);
-}
-
-long lXDR::readLong(void)
-{
- long l = 0;
- checkRead(&l);
- return(l);
-}
-
-double lXDR::readDouble(void)
-{
- double d = 0.0;
- checkRead(&d);
- return(d);
-}
-
-double lXDR::readFloat(void)
-{
- float f = 0.0;
- checkRead(&f);
- return((double) f);
-}
-
-const char *lXDR::readString(long &length)
-{
- if (checkRead(&length)) return(0);
- long rl = (length + 3) & 0xFFFFFFFC;
- char *s = new char[rl + 1];
- if (fread(s, 1, rl, _fp) != (unsigned long) rl) {
- _error = LXDR_READERROR;
- delete [] s;
- return(0);
- }
- s[rl] = '\0';
- _error = LXDR_SUCCESS;
- return(s);
-}
-
-long *lXDR::readLongArray(long &length)
-{
- if (checkRead(&length)) return(0);
- long *s = new long[length];
- if (fread(s, 4, length, _fp) != (unsigned long) length) {
- _error = LXDR_READERROR;
- delete [] s;
- return(0);
- }
- if (_hasNetworkOrder == false) for (long i = 0; i < length; i++) s[i] = ntohl(s[i]);
- _error = LXDR_SUCCESS;
- return(s);
-}
-
-double *lXDR::readDoubleArray(long &length)
-{
- if (checkRead(&length)) return(0);
- double *s = new double[length];
- if (fread(s, 8, length, _fp) != (unsigned long) length) {
- _error = LXDR_READERROR;
- delete [] s;
- return(0);
- }
- if (_hasNetworkOrder == false) for (long i = 0; i < length; i++) s[i] = ntohd(s[i]);
- _error = LXDR_SUCCESS;
- return(s);
-}
-
-double *lXDR::readFloatArray(long &length)
-{
- if (checkRead(&length)) return(0);
- long *st = new long[length];
- if (fread(st, 4, length, _fp) != (unsigned long) length) {
- _error = LXDR_READERROR;
- delete [] st;
- return(0);
- }
- double *s = new double[length];
- if (_hasNetworkOrder == false) {
- for (long i = 0; i < length; i++) {
- long l = ntohl(st[i]);
- s[i] = (double) (*((float *) &l));
- }
- }
- _error = LXDR_SUCCESS;
- return(s);
-}
-
-long lXDR::checkWrite(long *l)
-{
- if (_openForWrite == false) return(_error = LXDR_WRITEONLY);
- if (_fp == 0) return(_error = LXDR_NOFILE);
- if (l) {
- long ll = htonl(*l);
- if (fwrite(&ll, 4, 1, _fp) != 4) return(_error = LXDR_WRITEERROR);
- }
- return(LXDR_SUCCESS);
-}
-
-long lXDR::checkWrite(double *d)
-{
- if (_openForWrite == false) return(_error = LXDR_WRITEONLY);
- if (_fp == 0) return(_error = LXDR_NOFILE);
- if (d) {
- double dd = htond(*d);
- if (fwrite(&dd, 8, 1, _fp) != 8) return(_error = LXDR_WRITEERROR);
- }
- return(LXDR_SUCCESS);
-}
-
-long lXDR::writeLong(long data)
-{
- return(checkWrite(&data));
-}
-
-long lXDR::writeDouble(double data)
-{
- return(checkWrite(&data));
-}
-
-long lXDR::writeString(const char *data)
-{
- return(writeString(data, strlen(data)));
-}
-
-long lXDR::writeString(const char *data, long length)
-{
- if (checkWrite(&length)) return(_error);
- if (fwrite(data, 1, length, _fp) != (unsigned long) length) return(_error = LXDR_WRITEERROR);
- long l = ((length + 3) & 0xFFFFFFFC) - length;
- if (fwrite(&l, 1, l, _fp) != (unsigned long) l) return(_error = LXDR_WRITEERROR);
- return(_error = LXDR_SUCCESS);
-}
-
-long lXDR::writeLongArray(const long *data, long length)
-{
- if (checkWrite(&length)) return(_error);
- long *s = (long *) data;
- if (_hasNetworkOrder == false) {
- s = new long[length];
- for (long i = 0; i < length; i++) s[i] = htonl(data[i]);
- }
- long l = fwrite(s, 4, length, _fp);
- if (_hasNetworkOrder == false) delete [] s;
- if (l != length) return(_error = LXDR_WRITEERROR);
- return(_error = LXDR_SUCCESS);
-}
-
-long lXDR::writeDoubleArray(const double *data, long length)
-{
- if (checkWrite(&length)) return(_error);
- double *s = (double *) data;
- if (_hasNetworkOrder == false) {
- s = new double[length];
- for (long i = 0; i < length; i++) s[i] = htond(data[i]);
- }
- long l = fwrite(s, 8, length, _fp);
- if (_hasNetworkOrder == false) delete [] s;
- if (l != length) return(_error = LXDR_WRITEERROR);
- return(_error = LXDR_SUCCESS);
-}
-
-
-long lXDR::filePosition(long pos)
-{
- if (_fp == 0) {
- _error = LXDR_NOFILE;
- return(-1);
- }
- if (pos == -1) return(ftell(_fp));
- if (fseek(_fp, pos, SEEK_SET)) {
- _error = LXDR_SEEKERROR;
- return(-1);
- }
- return(pos);
-}
-
-