Commit 56b63ce0 authored by dino's avatar dino
Browse files

Many changes to nDhist and the management of LOCALSPECTRA

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@565 170316e4-aea8-4b27-aad4-0380ec0519c9
parent daae3eda
......@@ -119,6 +119,7 @@ bool topologyConfigure(); // process_config
bool topologyInitialise(); // process_initialize
bool topologyStart(); // process_start
bool topologyStop(); // process_stop
bool topologyDelete(); // call the destructors of the created objects
bool topologyUpdate(); // add the global objects to the processing chains
void runOneChain(int nn);
......@@ -232,6 +233,8 @@ int main(int argc, char **argv)
// exit(-1);
//goto AGAIN;
topologyDelete();
return 1;
}
......@@ -1115,6 +1118,76 @@ bool topologyStop()
return true;
}
bool topologyDelete()
{
for(size_t nc = 0; nc < theChains.size(); nc++) {
chain * cc = theChains[nc];
cout << "\n DELETING CHAIN " << nc << endl;
for(int na = 0; na < cc->rActors; na++) {
if(!cc->pActors[na])
continue;
switch (cc->libType[na]) {
// Builders
case 0:
delete static_cast<EventBuilder *>(cc->pActors[na]);
break;
// Producers
case 1:
switch (cc->libReal[na]) {
case 0:
delete static_cast<CrystalProducerATCA *>(cc->pActors[na]);
break;
case 1:
delete static_cast<AncillaryProducerATCA *>(cc->pActors[na]);
break;
case 2:
delete static_cast<AncillaryProducerTCP *>(cc->pActors[na]);
break;
default:
return false;
}
break;
// Filters
case 2:
switch (cc->libReal[na]) {
case 0:
delete static_cast<PreprocessingFilterPSA *>(cc->pActors[na]);
break;
case 1:
delete static_cast<PSAFilterGridSearch *>(cc->pActors[na]);
break;
case 2:
delete static_cast<TrackingFilterOFT *>(cc->pActors[na]);
break;
case 3:
delete static_cast<AncillaryFilterDante *>(cc->pActors[na]);
break;
default:
return false;
}
break;
// Consumers
case 3:
// consumer still to be done
break;
// Unknown
default:
cout << "Unknown type for chain " << nc << " actor " << na << endl;
return false;
}
cout << cc->libName[na] << " delete ... done." << endl << endl;
}
}
return true;
}
// The detector chains (those beginning with a producer) are extended by appending
// the calls to the global chains (thise that beging with a builder)
// In this way the execution proceeds linearly along the whole history of an event
......
......@@ -10,8 +10,8 @@
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory="E:\tdata\agava\NT-02"
CommandArguments="Topology.conf"
WorkingDirectory="E:\tdata\agava\NT-03"
CommandArguments="Conf/Topology.conf Conf"
Attach="false"
DebuggerType="3"
Remote="1"
......
......@@ -20,8 +20,9 @@ ULong64_t EventBuilder::tsumbus = 300 ;
Int_t EventBuilder::minfold = 1 ;
Bool_t EventBuilder::verbose = false;
const UInt_t inpKey = 0xFA010102;
const UInt_t outKey = 0xFA010103;
const UInt_t inpKey1 = 0xFA010102;
const UInt_t inpKey2 = 0xFA0201A1;
const UInt_t outKey = 0xFA010104;
bool EventQueue::Add(UInt_t * i4dat, UInt_t n4dat)
{
......@@ -57,6 +58,7 @@ bool EventQueue::Add(UInt_t * i4dat, UInt_t n4dat)
evnFirst = getEvnumb(data + indFirst + 2);
tstLast = getTstamp(data + indLast + 3);
evnLast = getEvnumb(data + indLast + 2);
return true;
}
......@@ -99,6 +101,8 @@ EventBuilder::EventBuilder(int nch) :
isGood(NULL), minEvnum(0), minTstamp(0), errState(0), noBuild1(0), noBuild2(0)
{
Reset(nch);
Tdiff = NULL;
tkey1 = tkey2 = 0;
}
EventBuilder::~EventBuilder() {
......@@ -298,6 +302,13 @@ void EventBuilder::process_block( int ichain,
oevs++;
osiz += opos; // total size used sofar
obuf += opos; // advance pointer to output buffer
int tdiff = 0;
if(tkey1 > tkey2)
tdiff = 1000 - (int)(tkey1-tkey2);
else
tdiff = 1000 + (int)(tkey2-tkey1);
Tdiff->Incr(0, tdiff);
}
opos = 5; // where to start writing next event, relative to obuf
......@@ -378,13 +389,18 @@ Int_t EventBuilder::CheckEvent_Evnum()
continue; // not in this event
// valid if it has the right key
UInt_t iky = evq[nn].getKey();
if(iky != inpKey)
//if(iky != inpKey)
if(iky != inpKey1 && iky != inpKey2)
return -1;
// preset to move this frame to the output buffer
minTstamp = min(minTstamp, evq[nn].tstFirst);
evq[nn].totCount++;
isGood[nn] = true;
nfr++;
if(iky==inpKey1)
tkey1 = evq[nn].tstFirst;
else
tkey2 = evq[nn].tstFirst;
}
return nfr;
}
......@@ -412,7 +428,8 @@ Int_t EventBuilder::CheckEvent_Tstamp()
continue; // out of time window
// valid if it has the right key
UInt_t iky = evq[nn].getKey();
if(iky != inpKey)
//if(iky != inpKey)
if(iky != inpKey1 && iky != inpKey2)
return -1;
// preset to move this frame to the output buffer
minEvnum = min(minEvnum, evq[nn].evnFirst);
......@@ -498,6 +515,9 @@ void EventBuilder::process_config ( const Char_t *directory_path, UInt_t *error_
void EventBuilder::process_initialise (UInt_t *error_code)
{
Tdiff = new nDhist<int>(1, 2000);
Tdiff->setFileName("Tdiff.lspe");
Tdiff->setComment("timestamp difference");
*error_code = 0;
}
......@@ -511,6 +531,9 @@ void EventBuilder::process_stop ( UInt_t *error_code )
{
cout << "\nEventBuilder::process_stop called " << endl;
PrintStat();
if(Tdiff)
Tdiff->write(true);
*error_code = 0;
}
......
......@@ -3,6 +3,7 @@
#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
......@@ -87,6 +88,11 @@ public:
UInt_t noBuild1;
UInt_t noBuild2;
nDhist<int> *Tdiff;
ULong64_t tkey1;
ULong64_t tkey2;
public:
EventBuilder(int nch = 1);
......
......@@ -6,94 +6,81 @@
// Should also move part of the definitions to a cpp file
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
template <typename T>
class nDhist
class nDhist_t
{
protected:
std::string fname;
std::string comment;
bool fullname;
std::string padString;
unsigned int padSize;
int ndim;
int size[4];
int lentot;
T *data;
int counts;
public:
nDhist(int dim1) {
ndim = 2;
size[3] = 0;
size[2] = 0;
size[1] = 0;
size[0] = dim1;
data = NULL;
lentot = 0;
reset();
}
nDhist(int dim1, int dim2) {
ndim = 2;
size[3] = 0;
size[2] = 0;
size[1] = dim2;
size[0] = dim1;
data = NULL;
lentot = 0;
reset();
bool initialized;
nDhist_t() {
ndim = 0;
size[0] = size[1] = size[2] = size[3] = 0;
lentot = 0;
padSize = 20;
initialized = false;
}
nDhist(int dim1, int dim2, int dim3) {
ndim = 3;
size[3] = 0;
size[2] = dim3;
size[1] = dim2;
size[0] = dim1;
data = NULL;
void setup(int dim1, int dim2 = 0, int dim3 = 0, int dim4 = 0) {
initialized = false;
ndim = 0;
if(dim1) {
size[ndim++] = dim1;
if(dim2) {
size[ndim++] = dim2;
if(dim3) {
size[ndim++] = dim3;
if(dim4)
size[ndim++] = dim4;
}
}
}
lentot = 0;
reset();
}
nDhist(int dim1, int dim2, int dim3, int dim4) {
ndim = 4;
size[3] = dim4;
size[2] = dim3;
size[1] = dim2;
size[0] = dim1;
data = NULL;
lentot = 0;
reset();
void makePadString() {
if(!padString.size())
makePadString(padSize);
if(padSize && padString.size() < padSize)
padPadString(padSize);
}
void reset() {
int lenold = lentot;
lentot = 1;
for(int nn = 0; nn < ndim; nn++)
lentot *= size[nn];
if(data) {
if(lentot != lenold)
delete [] data;
data = new T[lentot];
void makePadString(unsigned int pad) {
std::ostringstream ofn;
if(fullname) {
padString = fname + " ";
}
else {
data = new T[lentot];
std::ostringstream ofn;
ofn << fname << " ";
for(int nn = 0; nn < ndim-1; nn++) {
if(size[nn] > 0)
ofn << size[nn] << "*";
}
ofn << size[ndim-1] << " ";
padString = ofn.str();
}
memset(data, 0, sizeof(T)*lentot);
counts = 0;
padPadString(pad);
}
void setFileName(const std::string fn/*, int dimpos = 0*/) {
void padPadString(unsigned int pad) {
if( pad > padString.size() )
padString += std::string(pad - padString.size(), ' ');
}
public:
void setFileName(const std::string fn) {
if(fn.length() > 0)
fname = fn;
fullname = 0; // dimpos != 0;
//if(fullname) {
// char tmp[100];
// sprintf(tmp, "%d", size[0]);
// std::string strdim = std::string(tmp);
// for(int nn = 1; nn < ndim; nn++) {
// sprintf(tmp, "-%d", size[nn]);
// strdim += tmp;
// }
// if(dimpos < 0) // prepend
// fname = strdim+"_"+fname;
// else
// fname = fname+"_"+strdim; // append
//}
fullname = false;
}
void setFileName(const std::string fn1, const std::string fn2) {
fullname = fn1.length() > 0 && fn2.length() > 0;
......@@ -126,8 +113,130 @@ public:
int getLenSpec(int nn) {
return (nn >= 0 && nn <ndim) ? size[nn] : 0;
}
int getCounts() {
return counts;
}
void setPadSize(unsigned int pd) {padSize = pd;}
unsigned int getPadSize() {
makePadString(0);
return padString.size();
}
bool write(bool erase = false, bool verbose = true) {
if(!initialized) {
std::cout << "Cannot write histogram due to inconsistent internal structures" << std::endl;
return false;
}
if(fname.length() < 1) {
std::cout << "\nFile name not given" << std::endl;
return false;
}
FILE *sFILE = fopen(fname.c_str(), "wb");
if (sFILE==0) {
std::cout << "\nBad fopen on " << fname << std::endl;
return false;
}
bool stat = write(sFILE, erase); // should tell if wrong status
fclose(sFILE);
if(!stat) {
std::cout << "Error writing " << fname << std::endl;
}
else if (verbose) {
makePadString();
std::cout << padString;
if(comment.length() > 0)
std::cout << " " << comment;
std::cout << std::endl;
}
return stat;
}
virtual void erase() = 0;
virtual void remove() = 0;
virtual bool write(FILE *fp, bool erase = false) = 0;
};
template <typename T>
class nDhist : public nDhist_t
{
private:
T *data;
bool reset() {
if(!initialized)
return false;
int lenold = lentot;
lentot = 1;
for(int nn = 0; nn < ndim; nn++)
lentot *= size[nn];
if(data && lentot != lenold ) {
delete [] data;
data = NULL;
}
if(!data) {
data = new T[lentot];
if(!data) {
initialized = false;
return false;
}
}
erase();
return true;
}
public:
nDhist(int dim1) {
data = NULL;
setup(dim1);
if(ndim == 1) {
initialized = true;
reset();
}
}
nDhist(int dim1, int dim2) {
data = NULL;
setup(dim1, dim2);
if(ndim == 2) {
initialized = true;
reset();
}
}
nDhist(int dim1, int dim2, int dim3) {
data = NULL;
setup(dim1, dim2, dim3);
if(ndim == 3) {
initialized = true;
reset();
}
}
nDhist(int dim1, int dim2, int dim3, int dim4) {
data = NULL;
setup(dim1, dim2, dim3, dim4);
if(ndim == 4) {
initialized = true;
reset();
}
}
virtual ~nDhist() {
remove();
}
void remove() {
if(data)
delete [] data;
data = NULL;
initialized = false;
}
void erase() {
if(data)
memset(data, 0, sizeof(T)*lentot);
counts = 0;
}
// off-range (for the last index) moved to borders
void incr(int n0) {
if(!initialized) return;
if(n0 < 0) n0 = 0;
else if(n0 >= size[0]) n0 = size[0]-1;
int jj = n0;
......@@ -135,6 +244,7 @@ public:
counts++;
}
void incr(int n0, int n1) {
if(!initialized) return;
if(n0 < 0 || n0 >= size[0]) return;
if(n1 < 0) n1 = 0;
else if(n1 >= size[1]) n1 = size[1]-1;
......@@ -143,6 +253,7 @@ public:
counts++;
}
void incr(int n0, int n1, int n2) {
if(!initialized) return;
if(n0 < 0 || n0 >= size[0]) return;
if(n1 < 0 || n1 >= size[1]) return;
if(n2 < 0) n2 = 0;
......@@ -152,6 +263,7 @@ public:
counts++;
}
void incr(int n0, int n1, int n2, int n3) {
if(!initialized) return;
if(n0 < 0 || n0 >= size[0]) return;
if(n1 < 0 || n1 >= size[1]) return;
if(n2 < 0 || n2 >= size[2]) return;
......@@ -163,12 +275,14 @@ public:
}
// off-range discarded
void Incr(int n0) {
if(!initialized) return;
if(n0 < 0 || n0 >= size[0]) return;
int jj = n0;
data[jj]++;
counts++;
}
void Incr(int n0, int n1) {
if(!initialized) return;
if(n0 < 0 || n0 >= size[0]) return;
if(n1 < 0 || n1 >= size[1]) return;
int jj = n0*size[1] + n1;
......@@ -176,6 +290,7 @@ public:
counts++;
}
void Incr(int n0, int n1, int n2) {
if(!initialized) return;
if(n0 < 0 || n0 >= size[0]) return;
if(n1 < 0 || n1 >= size[1]) return;
if(n2 < 0 || n2 >= size[2]) return;
......@@ -184,6 +299,7 @@ public:
counts++;
}
void Incr(int n0, int n1, int n2, int n3) {
if(!initialized) return;
if(n0 < 0 || n0 >= size[0]) return;
if(n1 < 0 || n1 >= size[1]) return;
if(n2 < 0 || n2 >= size[2]) return;
......@@ -194,18 +310,22 @@ public:
}
// get pointer to data
T *getData() {
return data;
if(!initialized) return NULL;
return data;
}
T *getData(int n0) {
if(!initialized) return NULL;
if(n0 < 0 || n0 >= size[0]) return NULL;
return data+ n0*size[1];
}
T *getData(int n0, int n1) {
if(!initialized) return NULL;
if(n0 < 0 || n0 >= size[0]) return NULL;
if(n1 < 0 || n1 >= size[1]) return NULL;
return data+ (n0*size[1] + n1)*size[2];
}
T *getData(int n0, int n1, int n2) {
if(!initialized) return NULL;
if(n0 < 0 || n0 >= size[0]) return NULL;
if(n1 < 0 || n1 >= size[1]) return NULL;
if(n2 < 0 || n2 >= size[2]) return NULL;
......@@ -213,17 +333,20 @@ public:
}
// get data
T getValue(int n0) {
if(!initialized) return 0;
if(n0 < 0 || n0 >= size[0]) return 0;
int jj = n0;
return data[jj];
}
T getValue(int n0, int n1) {
if(!initialized) return 0;
if(n0 < 0 || n0 >= size[0]) return 0;
if(n1 < 0 || n1 >= size[1]) return 0;
int jj = n0*size[1] + n1;
return data[jj];
}
T getValue(int n0, int n1, int n2) {
if(!initialized) return 0;
if(n0 < 0 || n0 >= size[0]) return 0;
if(n1 < 0 || n1 >= size[1]) return 0;
if(n2 < 0 || n2 >= size[2]) return 0;
......@@ -231,6 +354,7 @@ public:
return data[jj];
}
T getValue(int n0, int n1, int n2, int n3) {
if(!initialized) return 0;
if(n0 < 0 || n0 >= size[0]) return 0;
if(n1 < 0 || n1 >= size[1]) return 0;
if(n2 < 0 || n2 >= size[2]) return 0;
......@@ -239,48 +363,64 @@ public:
return data[jj];
}
int getCounts() {
return counts;
}
bool write(bool verbose) {
if(fname.length() < 1) {
std::cout << "\nFile name not given" << std::endl;
return false;
}
FILE *sFILE = fopen(fname.c_str(), "wb");
if (sFILE==0) {
std::cout << "\nBad fopen on " << fname << std::endl;
bool write(FILE *fp, bool doErase = false) {
if(!initialized) {
std::cout << "Cannot write histogram due to inconsistent i