CEventServer.h
//-----------------------------------------------------------------------------
// $Header: /tmp_mnt/asis/offline/ceres/cool/project/RCS/CEventServer.h,v 2.3 1996/10/04 08:43:03 voigt Exp $
//
// COOL Program Library
// Copyright (C) CERES collaboration, 1996
//
// Declaration of class CEventServer.
//
// This class reads raw data events from an connected input stream
// and stores all referring labels. It keeps one instance of the
// last SoR, EoR, SoB, EoB, OoB and Evt event, respectively. If a
// new event is read in the last event of the same type gets replaced.
// The class manages the allocated memory by itself.
// The user is responsible for checking the state of the input stream.
//
//-----------------------------------------------------------------------------
#ifndef CEVENTSERVER_H
#define CEVENTSERVER_H
#include "cool.h"
#include "CDataStream.h"
#include "CRawSoR.h"
#include "CRawEoR.h"
#include "CRawSoB.h"
#include "CRawEoB.h"
#include "CRawOoB.h"
#include "CRawEvt.h"
#include "rw/tpsrtvec.h"
#ifndef RW_NO_STL
#include <functional>
#endif
class CEventServer {
public:
CEventServer(); // constructs an event server without defining an input stream
CEventServer(const char*); // constructs a new event server already connected to an input file.
virtual ~CEventServer();
public:
CBoolean loadNextEvent(); // read next event, returns False on error
CBoolean loadEvent(unsigned); // read event with given event number, returns False on error
void setInput(const char*); // set new input file
void listLabels(ostream& = cout); // lists all currently available labels
void printIndex(ostream& = cout); // prints type, run, burst and event number
virtual void printSummary(ostream& = cout); // prints server summary (statistics)
const CLabel* getLabel(CLabelId); // returns constant pointer to label, null pointer if labels isn't present
const CLabel* getLabel(CLabelId, CEventType); // returns label from event of given type
CEventType getCurrentEventType() const; // returns type of the last loaded event
public:
CBoolean isEoF() { return ifs.eof(); } // end-of-file seen
CBoolean isFail() { return ifs.fail(); } // next operation will fail
CBoolean isBad() { return ifs.bad(); } // stream corrupted
CBoolean isGood() { return ifs.good(); } // next operation might succeed
public:
const CRawSoR* getSoR() const { return sor; } // returns pointer to last SoR event
const CRawEoR* getEoR() const { return eor; } // returns pointer to last EoR event
const CRawSoB* getSoB() const { return sob; } // returns pointer to last SoB event
const CRawEoB* getEoB() const { return eob; } // returns pointer to last EoB event
const CRawOoB* getOoB() const { return oob; } // returns pointer to last OoB event
const CRawEvt* getEvt() const { return evt; } // returns pointer to last Evt event
protected:
CEventServer(const CEventServer&);
CEventServer& operator= (const CEventServer&);
protected:
Cifstream ifs;
CString filename;
CRawDataEvent *currentEvent;
CRawSoR *sor;
CRawEoR *eor;
CRawSoB *sob;
CRawEoB *eob;
CRawOoB *oob;
CRawEvt *evt;
protected:
int evtCounter;
int sobCounter;
int eobCounter;
int sorCounter;
int eorCounter;
int oobCounter;
private:
class CEventTableEntry {
public:
CEventTableEntry(short en, streampos p)
: evtNr(en), pos(p) {}
int operator== (const CEventTableEntry& item) const
{ return (item.evtNr == evtNr); }
int operator< (const CEventTableEntry& item) const
{ return (evtNr < item.evtNr); }
public:
short evtNr;
streampos pos;
};
#ifdef RW_NO_STL
RWTPtrSortedVector<CEventTableEntry> eventTable;
#else
RWTPtrSortedVector<CEventTableEntry, less<CEventTableEntry> > eventTable;
#endif
};
#endif /* CEVENTSERVER_H */