Commit ce7de143 authored by dino's avatar dino
Browse files

AncillaryProducerTCP::process_initialise returns with a fatal error if the...

AncillaryProducerTCP::process_initialise returns with a fatal error if the file event_vmedata.bdat exists already

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@639 170316e4-aea8-4b27-aad4-0380ec0519c9
parent 14f77b75
......@@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\Program Files\boost\boost_1_36_0&quot;;..\myADF0.2;..\myADF0.2\standalone;..\common;..\producers\Crystal;..\producers\Crystal\includeATCA;..\producers\AncillaryTCP;..\producers\AncillaryATCA;..\filters\Preprocessing;..\filters\Preprocessing\includePrePSA;..\filters\Ancillary;..\filters\Ancillary\includeVME;..\filters\PSA;..\filters\PSA\includePSA;..\filters\Tracking;..\filters\Tracking\includeOFT;..\builders;C:\root\include"
AdditionalIncludeDirectories="&quot;C:\Program Files\boost\boost_1_40&quot;;..\myADF0.2;..\myADF0.2\standalone;..\common;..\producers\Crystal;..\producers\Crystal\includeATCA;..\producers\AncillaryTCP;..\producers\AncillaryATCA;..\filters\Preprocessing;..\filters\Preprocessing\includePrePSA;..\filters\Ancillary;..\filters\Ancillary\includeVME;..\filters\PSA;..\filters\PSA\includePSA;..\filters\Tracking;..\filters\Tracking\includeOFT;..\builders;C:\root\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
......@@ -64,7 +64,7 @@
UseLibraryDependencyInputs="true"
AdditionalDependencies="libCore.lib libTree.lib libRIO.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="C:\Program Files\boost;C:\root\lib"
AdditionalLibraryDirectories="C:\Program Files\boost\boost_1_40\lib;C:\root\lib"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
......@@ -118,7 +118,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;C:\Program Files\boost\boost_1_36_0&quot;;..\myADF0.2;..\myADF0.2\standalone;..\common;..\producers\Crystal;..\producers\Crystal\includeATCA;..\producers\AncillaryATCA;..\producers\AncillaryTCP;..\filters\Preprocessing;..\filters\Preprocessing\includePrePSA;..\filters\Ancillary;..\filters\Ancillary\includeVME;..\filters\PSA;..\filters\PSA\includePSA;..\filters\Tracking;..\filters\Tracking\includeOFT;..\builders;C:\root\include"
AdditionalIncludeDirectories="&quot;C:\Program Files\boost\boost_1_40&quot;;..\myADF0.2;..\myADF0.2\standalone;..\common;..\producers\Crystal;..\producers\Crystal\includeATCA;..\producers\AncillaryATCA;..\producers\AncillaryTCP;..\filters\Preprocessing;..\filters\Preprocessing\includePrePSA;..\filters\Ancillary;..\filters\Ancillary\includeVME;..\filters\PSA;..\filters\PSA\includePSA;..\filters\Tracking;..\filters\Tracking\includeOFT;..\builders;C:\root\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;THREADED"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
......@@ -140,7 +140,7 @@
UseLibraryDependencyInputs="false"
AdditionalDependencies="libCore.lib libTree.lib libRIO.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="C:\Program Files\boost;C:\root\lib"
AdditionalLibraryDirectories="C:\Program Files\boost\boost_1_40\lib;C:\root\lib"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
......
#ifndef EVENTBUILDER_H_INCLUDED
#define EVENTBUILDER_H_INCLUDED
#include "ADFConfig.h"
#include <memory>
#include "nDhist.h"
const ULong64_t onesecond = 100000000; // used (?) for timeout purposes
const UInt_t dataSize = 2*1024*1024; // size of input queues
const UInt_t maxHalfBuffs = 2; // max number of input half-buffers held in queue
const UInt_t maxErrors = 40; // max number "errors"
class EventQueue
{
public:
EventQueue() :
tstFirst(0), tstLast(0), evnFirst(0), evnLast(0),
indFirst(0), indLast(0), indNext(0), numEvts(0),
endCount(0), errCount(0), totCount(0), statChan(0), maxSize(5)
{
memset(data, 0, sizeof(data));
}
ULong64_t getTstamp(UInt_t *ibuf)
{
return ((ULong64_t)ibuf[1] << 32) | (ULong64_t)ibuf[0];
}
ULong64_t getTstamp()
{
return getTstamp(data + indFirst + 3);
}
UInt_t getEvnumb(UInt_t *ibuf)
{
return ibuf[0];
}
UInt_t getKey()
{
return data[indFirst+1];
}
bool Add(UInt_t * i4dat, UInt_t n4dat);
UInt_t moveOut(UInt_t *dest);
void Error(int ich);
UInt_t Size()
{
return indNext-indFirst;
}
bool hasDat() {
return indFirst < indNext;
}
bool isEmpty()
{
return indFirst >= indNext;
}
UInt_t data[dataSize]; // the data
ULong64_t tstFirst; // timestamp of first event in queue
ULong64_t tstLast; // timestamp of last event in queue
UInt_t evnFirst; // evnumber of first event in queue
UInt_t evnLast; // evnumber of last event in queue
UInt_t indFirst; // index of first event in data
UInt_t indLast; // index of last event in data
UInt_t indNext; // one past the last data item
UInt_t numEvts; // number of events in queue
UInt_t endCount; // counts the number of shifts to the bottom of the queue
UInt_t errCount; // counts the number of errors (decided by EventBuilder)
UInt_t totCount; // total number of events passed to the output
UInt_t statChan; // good (>threshold) number of events
UInt_t maxSize; // maximum size of added data in Add() (initialized to just one key)
};
class EventBuilder
{
public:
static std::string fMotherClass; // Static string containing the name of the base class
static std::string fActualClass; // Static string to choose daughter class at run time
static std::string gConfPath; // set by the static method process_config
std::string fConfPath;
std::string fOdirPrefix;
Bool_t useEventNumber;
ULong64_t timeout;
ULong64_t tsumbus;
UInt_t minfold;
Bool_t verbose;
Bool_t bMerger;
Bool_t bKeepAll;
UInt_t nchains;
UInt_t gevCount; // total number of events in the event-builder
UInt_t bevCount; // total number of events in the merger
UInt_t oevCount; // number of events from the event-builder in this call
EventQueue *evq;
UInt_t *statMult;
UInt_t *iqueSize;
Bool_t *isGood;
ULong64_t minTstamp;
UInt_t minEvnum;
UInt_t errState;
UInt_t noBuild1;
UInt_t noBuild2;
nDhistGroup hGroup;
nDhist<int> *Tdiff;
ULong64_t tkey1;
ULong64_t tkey2;
UInt_t inpKey1;
UInt_t inpKey2;
UInt_t outKey1;
UInt_t outKey2;
UInt_t *mBuff; // the buffer for the fake merger;
UInt_t mSize;
public:
EventBuilder(int nch = 1);
virtual ~EventBuilder();
bool Reset( int nch );
bool isEmpty(int ichain)
{
return evq[ichain].isEmpty();
}
bool isReady(int ichain)
{
// 1) refill only if empty
//return evq[ichain].isEmpty();
// 2) refill if not too full
UInt_t size = evq[ichain].Size();
return 2*size <= maxHalfBuffs*evq[ichain].maxSize;
}
void PrintStat();
Int_t CheckEvent_Evnum();
Int_t CheckEvent_Tstamp();
void process_block( int ichain,
void *ibuffer, unsigned int isize,
void *obuffer, unsigned int osize,
unsigned int *used_osize,
unsigned int *error_code);
void makeMerged (void *obuffer, unsigned int osize,
unsigned int *used_osize,
unsigned int *error_code);
static void process_config(const Char_t *, UInt_t *);
virtual void process_initialise (UInt_t *error_code);
virtual void process_start (UInt_t *error_code);
virtual void process_stop (UInt_t *error_code);
virtual void process_pause (UInt_t *error_code);
virtual void process_resume(UInt_t *error_code);
virtual void process_reset (UInt_t *error_code);
private:
void getParameters(UInt_t *error_code);
};
#endif // EVENTBUILDER_H_INCLUDED
#ifndef EVENTBUILDER_H_INCLUDED
#define EVENTBUILDER_H_INCLUDED
#include "ADFConfig.h"
#include <memory.h>
#include "nDhist.h"
const ULong64_t onesecond = 100000000; // used (?) for timeout purposes
const UInt_t dataSize = 2*1024*1024; // size of input queues
const UInt_t maxHalfBuffs = 2; // max number of input half-buffers held in queue
const UInt_t maxErrors = 40; // max number "errors"
class EventQueue
{
public:
EventQueue() :
tstFirst(0), tstLast(0), evnFirst(0), evnLast(0),
indFirst(0), indLast(0), indNext(0), numEvts(0),
endCount(0), errCount(0), totCount(0), statChan(0), maxSize(5)
{
memset(data, 0, sizeof(data));
}
ULong64_t getTstamp(UInt_t *ibuf)
{
return ((ULong64_t)ibuf[1] << 32) | (ULong64_t)ibuf[0];
}
ULong64_t getTstamp()
{
return getTstamp(data + indFirst + 3);
}
UInt_t getEvnumb(UInt_t *ibuf)
{
return ibuf[0];
}
UInt_t getKey()
{
return data[indFirst+1];
}
bool Add(UInt_t * i4dat, UInt_t n4dat);
UInt_t moveOut(UInt_t *dest);
void Error(int ich);
UInt_t Size()
{
return indNext-indFirst;
}
bool hasDat() {
return indFirst < indNext;
}
bool isEmpty()
{
return indFirst >= indNext;
}
UInt_t data[dataSize]; // the data
ULong64_t tstFirst; // timestamp of first event in queue
ULong64_t tstLast; // timestamp of last event in queue
UInt_t evnFirst; // evnumber of first event in queue
UInt_t evnLast; // evnumber of last event in queue
UInt_t indFirst; // index of first event in data
UInt_t indLast; // index of last event in data
UInt_t indNext; // one past the last data item
UInt_t numEvts; // number of events in queue
UInt_t endCount; // counts the number of shifts to the bottom of the queue
UInt_t errCount; // counts the number of errors (decided by EventBuilder)
UInt_t totCount; // total number of events passed to the output
UInt_t statChan; // good (>threshold) number of events
UInt_t maxSize; // maximum size of added data in Add() (initialized to just one key)
};
class EventBuilder
{
public:
static std::string fMotherClass; // Static string containing the name of the base class
static std::string fActualClass; // Static string to choose daughter class at run time
static std::string gConfPath; // set by the static method process_config
std::string fConfPath;
std::string fOdirPrefix;
Bool_t useEventNumber;
ULong64_t timeout;
ULong64_t tsumbus;
UInt_t minfold;
Bool_t verbose;
Bool_t bMerger;
Bool_t bKeepAll;
UInt_t nchains;
UInt_t gevCount; // total number of events in the event-builder
UInt_t bevCount; // total number of events in the merger
UInt_t oevCount; // number of events from the event-builder in this call
EventQueue *evq;
UInt_t *statMult;
UInt_t *iqueSize;
Bool_t *isGood;
ULong64_t minTstamp;
UInt_t minEvnum;
UInt_t errState;
UInt_t noBuild1;
UInt_t noBuild2;
nDhistGroup hGroup;
nDhist<int> *Tdiff;
ULong64_t tkey1;
ULong64_t tkey2;
UInt_t inpKey1;
UInt_t inpKey2;
UInt_t outKey1;
UInt_t outKey2;
UInt_t *mBuff; // the buffer for the fake merger;
UInt_t mSize;
public:
EventBuilder(int nch = 1);
virtual ~EventBuilder();
bool Reset( int nch );
bool isEmpty(int ichain)
{
return evq[ichain].isEmpty();
}
bool isReady(int ichain)
{
// 1) refill only if empty
//return evq[ichain].isEmpty();
// 2) refill if not too full
UInt_t size = evq[ichain].Size();
return 2*size <= maxHalfBuffs*evq[ichain].maxSize;
}
void PrintStat();
Int_t CheckEvent_Evnum();
Int_t CheckEvent_Tstamp();
void process_block( int ichain,
void *ibuffer, unsigned int isize,
void *obuffer, unsigned int osize,
unsigned int *used_osize,
unsigned int *error_code);
void makeMerged (void *obuffer, unsigned int osize,
unsigned int *used_osize,
unsigned int *error_code);
static void process_config(const Char_t *, UInt_t *);
virtual void process_initialise (UInt_t *error_code);
virtual void process_start (UInt_t *error_code);
virtual void process_stop (UInt_t *error_code);
virtual void process_pause (UInt_t *error_code);
virtual void process_resume(UInt_t *error_code);
virtual void process_reset (UInt_t *error_code);
private:
void getParameters(UInt_t *error_code);
};
#endif // EVENTBUILDER_H_INCLUDED
......@@ -204,3 +204,12 @@ void forceTailSlash(std::string &dr) {
if( dr.size()>0 && dr.at(dr.size()-1)!= '/' ) dr += '/';
}
bool fileExists(std::string fname)
{
FILE *fp = fopen(fname.c_str(), "r");
if(fp) {
fclose(fp);
return true;
}
return false;
}
#ifndef MISC_H_INCLUDED
#define MISC_H_INCLUDED
#include <string>
#include <memory>
#include <ctime>
#ifdef THREADED
# include <boost/thread/mutex.hpp>
# define LOCK_COUT boost::mutex::scoped_lock lock(io_mutex)
extern boost::mutex io_mutex;
#else
# define LOCK_COUT
#endif
// the randomness of this generator is not too good, but sufficient for our needs
#define dRAND() ( rand()/(RAND_MAX+1.0) )
#define fRAND() ( rand()/(RAND_MAX+1.f) )
// bit values
enum retValue { EvNormal = 0,
EvNewBuffer = 1,
EvNewFile = 2,
EvFinish = 4,
EvSkip = 8 };
void stringTrim(std::string &str);
bool stringSplit(std::string &line, const std::string sepa, std::string &keyw);
bool stringSplit(std::string &line, const std::string sepa, std::string &keyw, std::string &data);
bool stringIncrement(std::string &fn, int count = 1);
bool stringIncrement(std::string &fn, const std::string sp, int count = 1);
int getKeyFromFile(const std::string filename, const std::string theKey, std::string &theValue, bool verbose = false);
void forceTailSlash(std::string &dr);
class ratemeter
{
time_t *tStart;
unsigned int *tCount;
unsigned int mod;
unsigned int pos;
double dmod;
public:
ratemeter(int imod = 5) {
mod = imod > 2 ? imod : 5;
tStart = new time_t [mod];
tCount = new unsigned int[mod];
reset();
}
void reset() {
time_t tstart;
time(&tstart);
for(unsigned int nn = 0; nn < mod; nn++) {
tStart[nn] = tstart;
tCount[nn] = 0;
}
pos = 0;
}
// the problem with the rate estimate is that time() returns elapsed seconds, which
// is too rough, and there seems to be no portable solution with higher precision.
int rate(unsigned int counts) {
time_t tNow; time(&tNow);
time_t tOld = tStart[pos];
unsigned int cOld = tCount[pos];
double sdiff = difftime(tNow, tOld);
if(sdiff < 1) sdiff = 1;
int srate = int((counts-cOld)/sdiff);
// update only if at least mod elapsed seconds since previous update
tOld = tStart[((pos+mod)-1)%mod];
sdiff = difftime(tNow, tOld);
if(sdiff > mod) {
tStart[pos] = tNow;
tCount[pos] = counts;
pos = (pos+1)%mod;
}
return srate;
}
};
template<class T>
class median
{
public:
median() : a1(0), a2(0), an(0) {}
void reset(const T &a3) {a1=a3; a2=a3; an=a3;}
T exec(const T &a3) {
if(a1 < a2) {
if (a3 > a2) an = a2;
else if(a3 < a1) an = a1;
else an = a3;
}
else {
if (a3 > a1) an = a1;
else if(a3 < a2) an = a2;
else an = a3;
}
a1 = a2;
a2 = a3;
return an;
}
int myID;
T a1;
T a2;
T an;
};
#endif
#ifndef MISC_H_INCLUDED
#define MISC_H_INCLUDED
#include <string>
#include <memory.h>
#include <ctime>
#ifdef THREADED
# include <boost/thread/mutex.hpp>
# define LOCK_COUT boost::mutex::scoped_lock lock(io_mutex)
extern boost::mutex io_mutex;
#else
# define LOCK_COUT
#endif
// the randomness of this generator is not too good, but sufficient for our needs
#define dRAND() ( rand()/(RAND_MAX+1.0) )
#define fRAND() ( rand()/(RAND_MAX+1.f) )
// bit values
enum retValue { EvNormal = 0,
EvNewBuffer = 1,
EvNewFile = 2,
EvFinish = 4,
EvSkip = 8 };
void stringTrim(std::string &str);
bool stringSplit(std::string &line, const std::string sepa, std::string &keyw);
bool stringSplit(std::string &line, const std::string sepa, std::string &keyw, std::string &data);
bool stringIncrement(std::string &fn, int count = 1);
bool stringIncrement(std::string &fn, const std::string sp, int count = 1);
int getKeyFromFile(const std::string filename, const std::string theKey, std::string &theValue, bool verbose = false);
void forceTailSlash(std::string &dr);
bool fileExists(std::string fname);
class ratemeter
{
time_t *tStart;
unsigned int *tCount;
unsigned int mod;
unsigned int pos;
double dmod;
public:
ratemeter(int imod = 5) {
mod = imod > 2 ? imod : 5;
tStart = new time_t [mod];
tCount = new unsigned int[mod];
reset();
}
void reset() {
time_t tstart;
time(&tstart);
for(unsigned int nn = 0; nn < mod; nn++) {
tStart[nn] = tstart;
tCount[nn] = 0;
}
pos = 0;
}
// the problem with the rate estimate is that time() returns elapsed seconds, which
// is too rough, and there seems to be no portable solution with higher precision.
int rate(unsigned int counts) {
time_t tNow; time(&tNow);
time_t tOld = tStart[pos];
unsigned int cOld = tCount[pos];
double sdiff = difftime(tNow, tOld);
if(sdiff < 1) sdiff = 1;
int srate = int((counts-cOld)/sdiff);
// update only if at least mod elapsed seconds since previous update
tOld = tStart[((pos+mod)-1)%mod];
sdiff = difftime(tNow, tOld);
if(sdiff > mod) {
tStart[pos] = tNow;
tCount[pos] = counts;
pos = (pos+1)%mod;
}
return srate;
}
};
template<class T>
class median
{
public:
median() : a1(0), a2(0), an(0) {}
void reset(const T &a3) {a1=a3; a2=a3; an=a3;}
T exec(const T &a3) {
if(a1 < a2) {
if (a3 > a2) an = a2;
else if(a3 < a1) an = a1;
else an = a3;
}
else {
if (a3 > a1) an = a1;
else if(a3 < a2) an = a2;
else an = a3;
}
a1 = a2;
a2 = a3;
return an;
}
int myID;
T a1;
T a2;