Commit 4facbee8 authored by dino's avatar dino
Browse files

Updates to CycleServer and HistoServer, non fully tested

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@1288 170316e4-aea8-4b27-aad4-0380ec0519c9
parent a271a778
......@@ -140,7 +140,7 @@ bool EventBuilder::Reset(int nque, int wminfold, int wsumbusL, int wsumbusR)
noBuild2 = 0;
nevCount = oevCount = 0;
cServer.Reset();
//cServer.Reset();
return true;
}
......@@ -410,7 +410,7 @@ void EventBuilder::Process(void *obuffer, unsigned int osize, unsigned int *used
obuf += opos; // advance pointer to output buffer
oevCount++;
cServer.Exec(minTstamp);
if(firstTstamp == 0)
firstTstamp = minTstamp;
}
......@@ -424,6 +424,8 @@ void EventBuilder::Process(void *obuffer, unsigned int osize, unsigned int *used
*used_osize = osiz*4;
*error_code = 0;
cServer.Exec(minTstamp, oevCount);
LOCK_COUT;
if (cServer.Prompt(-1, oevCount, *used_osize, false) >= 0 ) {
cout << " tst = " << fixed << setprecision(1) << setw(8) << firstTstamp / double(tst1second);
......@@ -683,31 +685,40 @@ UInt_t EventBuilder::GetParameters(const std::string& confFile, Bool_t doList)
UInt_t secMin, secMax;
ConfReader conf;
conf.Add("ActualClass", "name of daughter class", &gActualClass);
conf.Add("SaveDataDir", "where to write data and spectra", &fOdirPrefix);
//conf.Add("BuilderType", "builder type(TimeStamp | EventNumber) coincidence_window start_from(default = 0)", &bType, &btV1, &btV2);
conf.Add("KeyIn", "symbolic_name (e.g. data:psa) of the input frames", &inpKey);
conf.Add("KeyOut", "symbolic_name (e.g. event:data:psa) of \"\". 'None' to avoid the surrounding frame", &sKeyOut);
conf.Add("Window", "time-stamp coincidence window 'width' or 'from to'", &sumbusL, &sumbusR);
conf.Add("MinFold", "minimum number of detectors for valid events", &minFold);
conf.Add("TstampCorrect", "Queue Value", &ind1, &val1);
conf.Add("TstampLimits", "discard events outside this data-timestamp interval (seconds)", &secMin, &secMax);
conf.Add("TstampRegions", "tStampMin, tStampStep, TxtFile with 0/1 for each timestamp step", &tStampOffset, &tStampStep, &tStampFile);
conf.Add("RateProfile", "tStampMin, tStampStep, Length of rate-profile spectrum", &tStampOffset, &tStampStep, &tStampSize);
conf.Add("Details", "bit1=tstamp_snapshots, bit2=queue_tstamp_diff, bit3=TAC for all pairs", &fDetails);
conf.Add("NoMultiHist", "exclude flat binary spectra", &fUseMultiHist);
conf.Add("Verbose", "verbosity of printouts", &fVerbose);
conf.Add("ActualClass", "name of daughter class"
, &gActualClass);
conf.Add("SaveDataDir", "where to write data and spectra"
, &fOdirPrefix);
//conf.Add("BuilderType", "builder type(TimeStamp | EventNumber) coincidence_window start_from(default = 0)"
// , &bType, &btV1, &btV2).SetRequired(2);
conf.Add("KeyIn", "symbolic_name (e.g. data:psa) of the input frames"
, &inpKey);
conf.Add("KeyOut", "symbolic_name (e.g. event:data:psa) of \"\". 'None' to avoid the surrounding frame"
, &sKeyOut);
conf.Add("Window", "time-stamp coincidence window 'width' or 'from to'"
, &sumbusL, &sumbusR).SetDefault(1, "0");
conf.Add("MinFold", "minimum number of detectors for valid events"
, &minFold);
conf.Add("TstampCorrect", "Queue Value"
, &ind1, &val1);
conf.Add("TstampLimits", "discard events outside this data-timestamp interval (seconds)"
, &secMin, &secMax);
conf.Add("TstampRegions", "tStampMin, tStampStep, TxtFile with 0/1 for each timestamp step"
, &tStampOffset, &tStampStep, &tStampFile);
conf.Add("RateProfile", "tStampMin, tStampStep, Length of rate-profile spectrum"
, &tStampOffset, &tStampStep, &tStampSize);
conf.Add("Details", "bit1=tstamp_snapshots, bit2=queue_tstamp_diff, bit3=TAC for all pairs"
, &fDetails).SetDefault(0, "1");
conf.Add("NoMultiHist", "exclude flat binary spectra"
, &fUseMultiHist);
conf.Add("Verbose", "verbosity of printouts"
, &fVerbose);
conf.Info("The keyword 'BuilderType' has been removed and the \'EventNumber\' variant is no more supported");
conf.Info("The time-stamp coincidence window for the Builder should be defined using the mandatory keyword");
conf.Info("'Window width' for EventBuilder behaviour");
conf.Info("'Window from to' for EventMerger behaviour");
// refine behaviour
//conf.Require("BuilderType", 2);
conf.Default("Window", 1, "0"); // second parameter defaults to 0
conf.Default("Details", 0, "1");
if(doList) {conf.Show(gMotherClass); return 0;}
int rv = conf.Read(gMotherClass, confFile);
......@@ -775,7 +786,7 @@ void EventBuilder::process_reset ( UInt_t *error_code )
cout << fActualClass << "::process_reset called " << endl;
*error_code = 0;
cServer.Reset();
//cServer.Reset();
nevCount = 0;
}
......@@ -987,7 +998,7 @@ void EventBuilder::InitMultiHist(bool reset)
// done in evQueue::Reset()
}
if(fDetails&3) {
if(fDetails&4) {
EvbSpecTAC = new MultiHist<unsigned int>(nQueues, nQueues, specTacSize);
EvbSpecTAC->setFileName(fOdirPrefix+"Evb?TS.spec");
EvbSpecTAC->setComment("timestamp differences, pairwise");
......
......@@ -10,7 +10,7 @@
// as chainLocker takes the whole buffer at once, the dispatching chain is free to restart running.
// After locking myMutex, the BUILDER reads the data in one or more passes and releases the lock only after
// having read all data.
// All methods are of ChainLocker called with an ID which should unique among the objects accessing a given exchange buffer;
// All methods of ChainLocker are called with an ID which should be unique among the objects accessing a given exchange buffer;
// -Lock() returns true if the buffer is unlocked but also if it is already locked with the same ID of the caller
// -all other other methods (Unlock() included) check that the buffer is in a locked state with the same ID
// To have unique ID's
......
#include "ConfReader.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <memory.h>
#include <cstring>
#include <algorithm>
#include "Misc.h"
#include "ConfReader.h"
using namespace std;
int ConfReader::Find(const std::string& name)
int ConfReader::Find(const std::string& name) const
{
string nameLow = name;
transform(nameLow.begin(), nameLow.end(), nameLow.begin(), ::tolower);
// compare with the lower case version of the command
for(size_t nn = 0; nn < vcom.size(); nn++) {
if( stringEq(name, vcom[nn]->Keyw) ) { // case insensitive
if(nameLow == vcom[nn]->KeyLow)
return int(nn);
}
}
return -1;
}
void ConfReader::Show(const std::string& className) {
void ConfReader::Show(const std::string& className) const {
if( !className.empty() )
cout << "\nKEYWORDS ACCEPTED BY " << className << endl;
size_t lkeyw = 0, ltype = 0;
......@@ -61,7 +64,7 @@ void ConfReader::Show(const std::string& className) {
}
}
int ConfReader::Read(const std::string& className, const std::string& confFile, bool verbose)
int ConfReader::Read(const std::string& className, const std::string& confFile, bool strict, bool verbose)
{
ifstream confStream;
confStream.open(confFile.c_str() );
......@@ -82,48 +85,46 @@ int ConfReader::Read(const std::string& className, const std::string& confFile,
int which = Find(keyw);
if(which < 0) {
cout << " ==========> UNKNOWN KEYWORD <==========" << endl;
Show(className);
return 110;
if (strict) {
Show(className);
return 110;
}
continue; // ignore
}
// Repetition of keywords:
// - backup previous data
// - rewind the parameters and input again
// In this way the last instance is directly visible while other instances have to be reloaded
if (vcom[which]->Disabled) {
cout << " ----------> DISABLED KEYWORD" << endl;
continue;
}
Com* pcom = vcom[which];
if(pcom->keyCount > 0) {
if(!pcom->Backup()) {
cout << " ====> ConfReader:: internal error in Backup()" << endl;
return 140;
}
pcom->Rewind();
}
pcom->Rewind();
// decode data
if(verbose) cout << " --> ";
if (verbose) cout << " --> ";
int rv = pcom->GetData(data, verbose);
if(rv > 0) {
if (rv > 0) {
Show(className);
return rv;
}
cout << endl;
}
// Before normal return save also the last instance of repeated commands
for(size_t nn = 0; nn < vcom.size(); nn++) {
if(vcom[nn]->keyCount > 1) {
if( !vcom[nn]->Backup() ) {
cout << " ====> ConfReader:: internal error in Backup()" << endl;
return 140;
}
if (verbose) cout << endl;
// save it to allow repeated keywords
if (!pcom->Backup()) {
cout << " ====> ConfReader:: internal error in Backup()" << endl;
return 140;
}
if (!verbose)
cout << endl;
}
return 0;
}
bool ConfReader::Com::SetSmartDefaults() {
bool ConfReader::Com::SmartDefaults() {
if( vpar.size() != 1)
return false;
......@@ -136,11 +137,11 @@ bool ConfReader::Com::SetSmartDefaults() {
Required = 0; // to have a default input the parameter must be optional
return true;
}
if(vpar[0]->type == std::string("str") ) {
if(Keyw.size() < 7 || !stringEq("DataDir", Keyw.substr(Keyw.size()-7)) ) // case insensitive comparison
return false;
else
else
return vpar[0]->SetCallBack(forceTailSlash);
}
......@@ -239,7 +240,7 @@ bool ConfReader::Com::Restore(int which)
size_t totSize = 0;
memcpy(&totSize, storage, sizeof(size_t));
memcpy(&parCount, storage+sizeof(size_t), sizeof(size_t));
size_t readSize = 2*sizeof(size_t);
for(size_t nn = 0; nn < vpar.size(); nn++) {
readSize += vpar[nn]->Restore(storage+readSize);
......@@ -407,7 +408,7 @@ bool ConfReader::Par::GetItem(const std::string& item, bool verbose)
return true;
}
size_t ConfReader::Par::SizeOfData()
size_t ConfReader::Par::SizeOfData() const
{
size_t totSize = 0;
if(!strcmp(type, "str")) {
......
......@@ -3,7 +3,8 @@
#include <string>
#include <vector>
#include <memory.h>
#include <cstring>
#include <algorithm>
// todo:
// destructors to release memory of of the various "new";
......@@ -45,55 +46,66 @@ class ConfReader
bool SetCallBack (void(* funct)(std::string&)) {strCallBack = funct; return true;}
bool GetItem(const std::string& item, bool verbose);
void Rewind() {count = 0;}
size_t SizeOfData();
size_t SizeOfBackup() {return sizeof(int) + SizeOfData();}
size_t SizeOfData() const;
size_t SizeOfBackup() const {return sizeof(int) + SizeOfData();}
size_t Backup(char *storage);
size_t Restore(char *storage);
};
struct Com {
int keyCount; // how many time this keyw was given
int keyCount; // how many time this keyw was given
int parCount; // number of parameters decoded from the command line
int Required; // minimum number of parameters: -1=all
int Required; // minimum number of parameters: -1=all
bool Disabled; // ignore this keyword
bool HasError; // called with out of range parameters
std::string Keyw;
std::string KeyLow; // lower case version for fast search
std::string Help;
std::vector<Par *> vpar;
std::vector<char *> saved;
Com() : keyCount(0), parCount(0), Required(-1) {}
Com(std::string keyw, std::string help) : keyCount(0), parCount(0), Required(-1), Keyw(keyw), Help(help) {}
Com() : keyCount(0), parCount(0), Required(-1), Disabled(false), HasError(false) {}
Com(const std::string &keyw, const std::string &help) : keyCount(0), parCount(0), Required(-1), Disabled(false), HasError(false) {
Keyw = keyw;
KeyLow = keyw;
Help = help;
transform(KeyLow.begin(), KeyLow.end(), KeyLow.begin(), ::tolower);
}
int GetData(std::string data, bool verbose);
int GetCount(int par) {return ( par>=0 && par<int(vpar.size()) ) ? vpar[par]->count : 0;}
int GetCount(int par) const {return ( par>=0 && par<int(vpar.size()) ) ? vpar[par]->count : 0;}
void Rewind() {for(size_t nn = 0; nn < vpar.size(); nn++) vpar[nn]->Rewind();}
bool Backup();
bool Restore(int which);
bool SetSize(int index, int value) {
if(index>=0 && index<int(vpar.size()))
return vpar[index]->SetSize(value);
else
return false;
}
bool SetLimits(int index, const std::string& value) {
if( index>=0 && index<int(vpar.size()) )
return vpar[index]->SetLimits(value);
else
return false;
void Disable() { Disabled = true; }
void Enable() { Disabled = false; }
bool QueryError() { return HasError; }
void ClearError() { HasError = false; }
Com& SetRequired(int nn) {
Required = nn;
return *this;
}
bool SetDefault(int index, const std::string& value) {
if( index>=0 && index<int(vpar.size()) ) {
if(vpar[index]->SetDefault(value) ) {
Required = index; // to have a default input the parameter must be optional
return true;
}
}
return false;
Com& SetSize(int index, int value) {
if (index < 0 ||index>=int(vpar.size()) || !vpar[index]->SetSize(value) )
HasError = true;
return *this;
}
bool SetCallback(int index, void(* funct)(std::string&) ) {
if( index>=0 && index<int(vpar.size()) )
return vpar[index]->SetCallBack(funct);
Com& SetLimits(int index, const std::string& value) {
if (index < 0 || index<int(vpar.size()) || !vpar[index]->SetLimits(value) )
HasError = true;
return *this;
}
Com& SetDefault(int index, const std::string& value) {
if (index >= 0 && index<int(vpar.size()) && vpar[index]->SetDefault(value))
Required = index; // to have a default input the parameter must be optional
else
return false;
HasError = true;
return *this;
}
Com& SetCallback(int index, void(*funct)(std::string&)) {
if (index < 0 || index<int(vpar.size()) || !vpar[index]->SetCallBack(funct) )
HasError = true;
return *this;
}
bool SetSmartDefaults();
bool SmartDefaults();
//bool InferBoolean(std::string name);
//bool Directoryfy(std::string name);
};
......@@ -108,51 +120,48 @@ class ConfReader
public:
// ConfReader::Add defined with up to 8 parameters ==> should be done with variadic templates in C++11
// returns a reference to the created object in order to chain refinements
void Info(const std::string & info) {
infoLines.push_back(info);
}
int Add(std::string keyw, std::string help) {
Com& Add(const std::string &keyw, const std::string &help) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
template<typename P0>
int Add(std::string keyw, std::string help, P0 *p0) {
Com& Add(const std::string &keyw, const std::string &help, P0 *p0) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
cc->vpar.push_back(new Par(p0));
if(smartDefaults) cc->SetSmartDefaults();
if(smartDefaults) cc->SmartDefaults();
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
template<typename P0, typename P1>
int Add(std::string keyw, std::string help, P0 *p0, P1 *p1) {
Com& Add(const std::string &keyw, const std::string &help, P0 *p0, P1 *p1) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
cc->vpar.push_back(new Par(p0));
cc->vpar.push_back(new Par(p1));
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
template<typename P0, typename P1, typename P2>
int Add(std::string keyw, std::string help, P0 *p0, P1 *p1, P2 *p2) {
Com& Add(const std::string &keyw, const std::string &help, P0 *p0, P1 *p1, P2 *p2) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
cc->vpar.push_back(new Par(p0));
cc->vpar.push_back(new Par(p1));
cc->vpar.push_back(new Par(p2));
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
template<typename P0, typename P1, typename P2, typename P3>
int Add(std::string keyw, std::string help, P0 *p0, P1 *p1, P2 *p2, P3 *p3) {
Com& Add(const std::string &keyw, const std::string &help, P0 *p0, P1 *p1, P2 *p2, P3 *p3) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
cc->vpar.push_back(new Par(p0));
......@@ -160,11 +169,11 @@ public:
cc->vpar.push_back(new Par(p2));
cc->vpar.push_back(new Par(p3));
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
template<typename P0, typename P1, typename P2, typename P3, typename P4>
int Add(std::string keyw, std::string help, P0 *p0, P1 *p1, P2 *p2, P3 *p3, P4 *p4) {
Com& Add(const std::string &keyw, const std::string &help, P0 *p0, P1 *p1, P2 *p2, P3 *p3, P4 *p4) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
cc->vpar.push_back(new Par(p0));
......@@ -173,11 +182,11 @@ public:
cc->vpar.push_back(new Par(p3));
cc->vpar.push_back(new Par(p4));
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
int Add(std::string keyw, std::string help, P0 *p0, P1 *p1, P2 *p2, P3 *p3, P4 *p4, P5 *p5) {
int Add(const std::string &keyw, const std::string &help, P0 *p0, P1 *p1, P2 *p2, P3 *p3, P4 *p4, P5 *p5) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
cc->vpar.push_back(new Par(p0));
......@@ -187,11 +196,11 @@ public:
cc->vpar.push_back(new Par(p4));
cc->vpar.push_back(new Par(p5));
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
int Add(std::string keyw, std::string help, P0 *p0, P1 *p1, P2 *p2, P3 *p3, P4 *p4, P5 *p5, P6 *p6) {
Com& Add(const std::string &keyw, const std::string &help, P0 *p0, P1 *p1, P2 *p2, P3 *p3, P4 *p4, P5 *p5, P6 *p6) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
cc->vpar.push_back(new Par(p0));
......@@ -202,11 +211,11 @@ public:
cc->vpar.push_back(new Par(p5));
cc->vpar.push_back(new Par(p6));
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
int Add(std::string keyw, std::string help, P0 *p0, P1 *p1, P2 *p2, P3 *p3, P4 *p4, P5 *p5, P6 *p6, P6 *p7) {
Com& Add(const std::string &keyw, const std::string &help, P0 *p0, P1 *p1, P2 *p2, P3 *p3, P4 *p4, P5 *p5, P6 *p6, P6 *p7) {
Com* cc = new Com(keyw, help);
cc->Required = defaultRequired;
cc->vpar.push_back(new Par(p0));
......@@ -218,78 +227,81 @@ public:
cc->vpar.push_back(new Par(p6));
cc->vpar.push_back(new Par(p7));
vcom.push_back(cc);
return int(vcom.size()-1);
return *cc;
}
ConfReader (bool inf = true) {
defaultRequired = -1; // by default, all parameters of a command must be given
smartDefaults = inf; // single-bool keywords default to true unless they start with No/Dont
}
int Size() {return int(vcom.size());}
int Find(const std::string& name);
void Show(const std::string& className = "");
int Read(const std::string& className, const std::string& confFile, bool verbose = true);
smartDefaults = inf; // single-bool keywords default to true unless they start with No/Dont
}
int Size() const {return int(vcom.size());}
int Find(const std::string& name) const;
void Show(const std::string& className = "") const;
int Read(const std::string& className, const std::string& confFile, bool strict = true, bool verbose = true);
void Info(const std::string & info) { infoLines.push_back(info); }
bool Restore(const std::string& keyw, int instance) {return Restore(Find(keyw), instance);}
bool Restore(int which, int instance) {
if(which>=0 && which<Size())
return vcom[which]->Restore(instance);
else
return false;
return which>=0 && which<Size() && vcom[which]->Restore(instance);
}
bool Seen(const std::string& keyw) {return Seen(Find(keyw));}
bool Seen(int which) {return (which>=0 && which<Size())? (vcom[which]->keyCount>0) : false;}
void Disable(const std::string& keyw) { Disable(Find(keyw)); }
void Disable(int which) {
if (which >= 0 && which < Size())
vcom[which]->Disable();
}
int Times(const std::string& keyw) {return Times(Find(keyw));}
int Times(int which) {return (which>=0 && which<Size())? vcom[which]->keyCount : 0;}
void Enable (const std::string& keyw) { Enable (Find(keyw)); }
void Enable (int which) {
if (which >= 0 && which < Size())
vcom[which]->Enable ();
}
int Count(const std::string& keyw) {return Count(Find(keyw));}
int Count(int which) {return (which>=0 && which<Size())? vcom[which]->parCount : 0;}
bool Seen(const std::string& keyw) const {return Seen(Find(keyw));}
bool Seen(int which) const {
return (which>=0 && which<Size())? (vcom[which]->keyCount>0) : false;
}
int Count(const std::string& keyw, int par) {return Count(Find(keyw), par);}
int Count(int which, int par) {return (which>=0 && which<Size())? vcom[which]->GetCount(par) : 0;}
int Times(const std::string& keyw) const {return Times(Find(keyw));}
int Times(int which) const {
return (which>=0 && which<Size())? vcom[which]->keyCount : 0;
}
int Count(const std::string& keyw) const {return Count(Find(keyw));}
int Count(int which) const {
return (which>=0 && which<Size())? vcom[which]->parCount : 0;
}
int Count(const std::string& keyw, int par) const {return Count(Find(keyw), par);}
int Count(int which, int par) const {
return (which>=0 && which<Size())? vcom[which]->GetCount(par) : 0;
}
void Require(int cmin = -1) {defaultRequired = cmin;} // default is require-all
void Require(int cmin = -1) {defaultRequired = cmin;} // default is requre-all
bool Require(const std::string& keyw, int cmin) {return Require(Find(keyw), cmin);}
bool Require(int which, int cmin) {
if(which>=0 && which<Size()) {
vcom[which]->Required = cmin;
return true;
}
else
return false;
return which >= 0 && which < Size() && vcom[which]->SetRequired(cmin).QueryError();
}
bool SetSize(const std::string& keyw, int index, int value) {return SetSize(Find(keyw), index, value);}
bool SetSize(int which, int index, int value) {
if(which>=0 && which<Size())
return vcom[which]->SetSize(index, value);
else
return false;
return which >= 0 && which < Size() && vcom[which]->SetSize(index, value).QueryError();
}
bool Limits(const std::string& keyw, int index, const std::string& value) {return Limits(Find(keyw), index, value);}
bool Limits(int which, int index, const std::string& value) {
if(which>=0 && which<Size())