Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 8825d3a0 authored by dino's avatar dino
Browse files

Refactoring of GetParameters() methods using a macro to improve readability

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@1122 170316e4-aea8-4b27-aad4-0380ec0519c9
parent 68e5eb38
......@@ -145,7 +145,7 @@ vector<builder_t *> theBuilders;
void getparams(int, char **);
void numparams(char *, int);
void listKeysAndExit(); // call GetParameters() and exit
void listKeysAndExit(); // call ListParameters() and exit
bool checkADFpath(); // check presence of ADF.conf
int eventLoop1(); // non-threaded
int eventLoop2(); // threaded
......@@ -671,42 +671,42 @@ void topologyPrint(int nchains)
}
}
// Call GetParameters() for the relevant classes to get the list of accepted keys
// Creation of the objects is done on the stack to avoid coredumps in the destructors
// which happen due to the fact that to properly setup things we should call process_init
// This is an acceptable way to proceed as we exit immediately (otherwise it is just wasted memory).
// Call ListParameters() for the relevant classes to get the list of accepted keys.
// Creation of the objects is done on the heap to avoid coredumps in the destructors.
// These are due to pointers initialized in process_init(...), which we don't (weant to) call.
// We preceed in this way because we exit immediately (otherwise it would be waste of memory).
void listKeysAndExit()
{
// get rid of the adf messages
CentralLog::theCentralLog()->GetCurrentLogCollector()->SetLevelFiltering(LogMessage::kError, (unsigned short)(0));
AncillaryProducerTCP *pa1 = new AncillaryProducerTCP;
pa1->GetParameters();
pa1->ListParameters();
AncillaryFilter *pa2 = new AncillaryFilter;
pa2->GetParameters();
pa2->ListParameters();
CrystalProducer *pp1 = new CrystalProducer;
pp1->GetParameters();
pp1->ListParameters();
PreprocessingFilter *pp2 = new PreprocessingFilter;
pp2->GetParameters();
pp2->ListParameters();
PSAFilter *pp3 = new PSAFilter;
pp3->GetParameters();
pp3->ListParameters();
PostPSAFilter *pp4 = new PostPSAFilter;
pp4->GetParameters();
pp4->ListParameters();
EventBuilder *pp5 = new EventBuilder("EventBuilder");
pp5->GetParameters();
pp5->ListParameters();
// not really developed and used
//GlobalFilter *pp6 = new GlobalFilter;
//pp6->GetParameters();
//pp6->ListParameters();
TrackingFilter *pp7 = new TrackingFilter;
pp7->GetParameters();
pp7->ListParameters();
exit(EXIT_SUCCESS);
}
......
......@@ -569,7 +569,7 @@ bool EventBuilder::InitBuilder()
return true;
}
void EventBuilder::GetParameters()
void EventBuilder::ListParameters()
{
printInfo("\nKEYWORDS ACCEPTED BY EventBuilder");
......@@ -579,6 +579,8 @@ void EventBuilder::GetParameters()
void EventBuilder::GetParameters(UInt_t *error_code)
{
#define KPAR(s1,s2,s3) if(doList) printInfo(s1, s2, s3); else if( !found && stringEq(keyw, s1) ) { found = true;
bool doList = *error_code == 0xFFFFFFFF;
*error_code = 0;
......@@ -594,7 +596,7 @@ void EventBuilder::GetParameters(UInt_t *error_code)
cout << endl << gMotherClass + "::GetParameters() reading from --> " << configFileName << endl;
}
string kcmd, line, keyw, data, value;
string line, keyw, data, value;
bool ok = true;
bool found = false;
while(doList || getline(configfile, line)) {
......@@ -607,31 +609,19 @@ void EventBuilder::GetParameters(UInt_t *error_code)
found = false;
}
kcmd = "ActualClass";
if(doList)
printInfo(kcmd, "%s", "name of daughter class");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("ActualClass", "%s", "name of daughter class")
ok = data.size() > 0;
gActualClass = data;
//fActualClass = gActualClass = data;
}
kcmd = "SaveDataDir";
if(doList)
printInfo(kcmd, "%s", "where to write data and spectra");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("SaveDataDir", "%s", "where to write data and spectra")
ok = data.size() > 0;
fOdirPrefix = data;
forceTailSlash(fOdirPrefix);
}
kcmd = "BuilderType";
if(doList)
printInfo(kcmd, "%s", "builder type (TimeStamp | EventNumber)");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("BuilderType", "%s", "builder type (TimeStamp | EventNumber)")
stringSplit(data, " \t", keyw, value);
if( stringEq(keyw, "TimeStamp") ) {
useEventNumber = false;
......@@ -651,37 +641,21 @@ void EventBuilder::GetParameters(UInt_t *error_code)
}
}
kcmd = "KeyIn";
if(doList)
printInfo(kcmd, "%s", "symbolic_name (e.g. data:psa)");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("KeyIn", "%s", "symbolic_name (e.g. data:psa)")
ok = (data.length() > 1);
sKeyIn.push_back(data);
}
kcmd = "KeyOut";
if(doList)
printInfo(kcmd, "%s", "symbolic_name (e.g. event:data:psa)");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("KeyOut", "%s", "symbolic_name (e.g. event:data:psa)")
ok = (data.length() > 1);
sKeyOut = data;
}
kcmd = "MinFold";
if(doList)
printInfo(kcmd, "%d", "minimum number of detectors for valid events");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("MinFold", "%d", "minimum number of detectors for valid events")
ok = 1 == sscanf(data.c_str(), "%d", &minFold);
}
kcmd = "TimestampCorrect";
if(doList)
printInfo(kcmd, "%d %d", "Queue Value");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("TimestampCorrect", "%d %d", "Queue Value")
UInt_t ind(nchains);
Int_t val(0);
ok = 2 == sscanf(data.c_str(), "%d %d", &ind, &val);
......@@ -690,11 +664,7 @@ void EventBuilder::GetParameters(UInt_t *error_code)
}
}
kcmd = "TimestampFixBug24";
if(doList)
printInfo(kcmd, "%d", "Queue");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("TimestampFixBug24", "%d", "Queue")
UInt_t ind(nchains);
Int_t val(0);
ok = 1 == sscanf(data.c_str(), "%d", &ind);
......@@ -703,28 +673,16 @@ void EventBuilder::GetParameters(UInt_t *error_code)
}
}
kcmd = "NoMultiHist";
if(doList)
printInfo(kcmd, "", "exclude flat binary spectra");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
fUseMultiHist = false;
ok = true;
KPAR("Details", "%d", "b1=tstamp_snapshot for all events b2=tstamp_diff for all input queues")
ok = 1 == sscanf(data.c_str(), "%d", &details);
}
kcmd = "Details";
if(doList)
printInfo(kcmd, "%d", "b1=tstamp_snapshot for all events b2=tstamp_diff for all input queues");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
ok = 1 == sscanf(data.c_str(), "%d", &details);
KPAR("NoMultiHist", "", "exclude flat binary spectra")
fUseMultiHist = false;
ok = true;
}
kcmd = "Verbose";
if(doList)
printInfo(kcmd, "", "verbosity of printouts");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("Verbose", "", "verbosity of printouts")
verbose = true;
ok = true;
}
......@@ -735,14 +693,14 @@ void EventBuilder::GetParameters(UInt_t *error_code)
if(!found) {
cout << " --> ignored";
cout << endl;
GetParameters();
ListParameters();
ok = true;
}
if(!ok) {
cout << " --> error reading argument(s)" << endl;
cout << endl;
GetParameters();
ListParameters();
cout << endl;
*error_code = 103;
return;
......
......@@ -174,7 +174,7 @@ private:
private:
void GetParameters(UInt_t *error_code);
public:
void GetParameters();
void ListParameters();
};
......
#include "misc.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
......@@ -256,31 +257,15 @@ void printInfo(const std::string &s1) {
}
void printInfo(const std::string &s1, const std::string &s2) {
const int p2 = 23;
cout << s1;
int n1 = p2-int(s1.size());
for(int ii = 0; ii < n1; ii++)
cout << " ";
const int w1 = 22;
cout << left << setw(w1) << s1 << right << " ";
cout << s2 << endl;
}
void printInfo(const std::string &s1, const std::string &s2, const std::string &s3) {
const int p2 = 23;
const int p3 = 45;
cout << s1;
int n1 = p2 - int(s1.size());
if(n1 < 0) n1 = 0;
for(int ii = 0; ii < n1; ii++)
std::cout << " ";
cout << s2;
int n2 = p3 - (int(s1.size()) + n1 + int(s2.size()));
if(n2 < 0) n2 = 0;
for(int ii = 0; ii < n2; ii++)
cout << " ";
const int w1 = 22;
const int w2 = 22;
cout << left << setw(w1) << s1 << right << " ";
cout << left << setw(w2) << s2 << right << " ";
cout << s3 << endl;
}
......@@ -212,7 +212,7 @@ void AncillaryFilter::process_initialise ( UInt_t *error_code )
Log << dolog;
}
void AncillaryFilter::GetParameters()
void AncillaryFilter::ListParameters()
{
printInfo("\nKEYWORDS ACCEPTED BY AncillaryFilter");
......@@ -222,6 +222,8 @@ void AncillaryFilter::GetParameters()
void AncillaryFilter::GetParameters(UInt_t *error_code)
{
#define KPAR(s1,s2,s3) if(doList) printInfo(s1, s2, s3); else if( !found && stringEq(keyw, s1) ) { found = true;
bool doList = *error_code == 0xFFFFFFFF;
*error_code = 0;
......@@ -237,7 +239,7 @@ void AncillaryFilter::GetParameters(UInt_t *error_code)
cout << endl << gMotherClass + "::GetParameters() reading from --> " << configFileName << endl;
}
string kcmd, line, keyw, data;
string line, keyw, data;
bool ok = true;
bool found = false;
while(doList || getline(configfile, line)) {
......@@ -250,57 +252,33 @@ void AncillaryFilter::GetParameters(UInt_t *error_code)
found = false;
}
kcmd = "ActualClass";
if(doList)
printInfo(kcmd, "%s", "name of daughter class");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("ActualClass", "%s", "name of daughter class")
ok = data.size() > 0;
gActualClass = data;
}
kcmd = "SaveDataDir";
if(doList)
printInfo(kcmd, "%s", "where to write data and spectra");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("SaveDataDir", "%s", "where to write data and spectra")
ok = data.size() > 0;
fOdirPrefix = data;
forceTailSlash(fOdirPrefix);
}
kcmd = "AllPairsMat";
if(doList)
printInfo(kcmd, "", "generate matrix of all pairs of parameters");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("AllPairsMat", "", "generate matrix of all pairs of parameters")
fAllPairsMat = true;
ok = true;
}
kcmd = "PRISMALUTFile";
if(doList)
printInfo(kcmd, "%s", "lookup table for PRISMA");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("PRISMALUTFile", "%s", "lookup table for PRISMA")
ok = data.size() > 0;
fPRISMALUTFile = data;
}
kcmd = "PRISMAManager";
if(doList)
printInfo(kcmd, "%s", "configuration file for the PRISMA manager");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("PRISMAManager", "%s", "configuration file for the PRISMA manager")
ok = data.size() > 0;
fPRISMAManager = data;
}
kcmd = "WriteRootTree";
if(doList)
printInfo(kcmd, "", "produce root-tree of ancillary data");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("WriteRootTree", "", "produce root-tree of ancillary data")
#ifdef ANF_ROOTTREE
fWriteRootTree = true;
#else
......@@ -309,11 +287,7 @@ void AncillaryFilter::GetParameters(UInt_t *error_code)
ok = true;
}
kcmd = "TstampFile";
if(doList)
printInfo(kcmd, "%s %d", "File_with_timestams_to_selct Width_of_selection");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("TstampFile", "%s %d", "File_with_timestams_to_selct Width_of_selection")
ok = data.size() > 0;
string value1, value2;
stringSplit(data, " \t", value1, value2);
......@@ -322,87 +296,47 @@ void AncillaryFilter::GetParameters(UInt_t *error_code)
fTolerance = atoi(value2.c_str());
}
kcmd = "DanteChan";
if(doList)
printInfo(kcmd, "%d %d %d", "T X Y channels of DANTE data");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("DanteChan", "%d %d %d", "T X Y channels of DANTE data")
ok = 3 == sscanf(data.c_str(), "%d %d %d", &fDanteChT, &fDanteChX, &fDanteChY);
}
kcmd = "DantePos";
if(doList)
printInfo(kcmd, "%f %f %f %f %f", "DanteDz DanteRz, DanteRy DanteRz2 DanteRx (positioning Dante)");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("DantePos", "%f %f %f %f %f", "DanteDz DanteRz, DanteRy DanteRz2 DanteRx (positioning Dante)")
ok = 5 == sscanf(data.c_str(), "%f %f %f %f %f", &fDanteDz, &fDanteRz1, &fDanteRy, &fDanteRz2, &fDanteRx);
}
kcmd = "DanteBeta";
if(doList)
printInfo(kcmd, "%f", "recoil v/c");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("DanteBeta", "%f", "recoil v/c")
ok = 1 == sscanf(data.c_str(), "%f", &fDanteVc);
}
kcmd = "DanteCalX";
if(doList)
printInfo(kcmd, "%f %f", "x-calibration (offset, gain)");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("DanteCalX", "%f %f", "x-calibration (offset, gain)")
ok = 2 == sscanf(data.c_str(), "%f %f", &fDanteChXcal0, &fDanteChXcal1);
}
kcmd = "DanteCalY";
if(doList)
printInfo(kcmd, "%f %f", "y-calibration (offset, gain)");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("DanteCalY", "%f %f", "y-calibration (offset, gain)")
ok = 2 == sscanf(data.c_str(), "%f %f", &fDanteChYcal0, &fDanteChYcal1);
}
kcmd = "ReferenceTDC";
if(doList)
printInfo(kcmd, "%d %d %f", "TDCModule, TDCIndex, TDCOffset for subsample interpolation");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("ReferenceTDC", "%d %d %f", "TDCModule, TDCIndex, TDCOffset for subsample interpolation")
ok = 3 == sscanf(data.c_str(), "%d %d %f", &fRefTDCModule, &fRefTDCIndex, &fRefTDCOffset);
if(ok) fRefTDC = true;
}
kcmd = "DanteTDC";
if(doList)
printInfo(kcmd, "%d %d %d %d", "DanteTDCModule DanteTDCIndex DanteTDCMin DanteTDCMax");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("DanteTDC", "%d %d %d %d", "DanteTDCModule DanteTDCIndex DanteTDCMin DanteTDCMax")
ok = 4 == sscanf(data.c_str(), "%d %d %d %d", &fDanteTDCModule, &fDanteTDCIndex, &fDanteTDCMin, &fDanteTDCMax);
if(ok) fDanteTDC = true;
}
kcmd = "PrismaTDC";
if(doList)
printInfo(kcmd, "%d %d %d %d", "PrismaTDCModule PrismaTDCIndex PrismaTDCMin PrismaTDCMax");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("PrismaTDC", "%d %d %d %d", "PrismaTDCModule PrismaTDCIndex PrismaTDCMin PrismaTDCMax")
ok = 4 == sscanf(data.c_str(), "%d %d %d %d", &fPrismaTDCModule, &fPrismaTDCIndex, &fPrismaTDCMin, &fPrismaTDCMax);
if(ok) fPrismaTDC = true;
}
kcmd = "NoMultiHist";
if(doList)
printInfo(kcmd, "", "exclude flat binary spectra");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("NoMultiHist", "", "exclude flat binary spectra")
fUseMultiHist = false;
ok = true;
}
kcmd = "Verbose";
if(doList)
printInfo(kcmd, "", "verbosity of printouts");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("Verbose", "", "verbosity of printouts")
fVerbose = true;
ok = true;
}
......@@ -413,7 +347,7 @@ void AncillaryFilter::GetParameters(UInt_t *error_code)
if(!found) {
cout << " --> ignored";
cout << endl;
GetParameters();
ListParameters();
cout << endl;
ok = true;
}
......@@ -421,7 +355,7 @@ void AncillaryFilter::GetParameters(UInt_t *error_code)
if(!ok) {
cout << " --> missing argument(s)" << endl;
cout << endl;
GetParameters();
ListParameters();
*error_code = 103;
return;
}
......
......@@ -153,7 +153,7 @@ protected:
protected:
void GetParameters(UInt_t *error_code);
public:
void GetParameters();
void ListParameters();
};
......
......@@ -1006,7 +1006,7 @@ int GlobalFilter::PreProcessEvent()
return 0;
}
void GlobalFilter::GetParameters()
void GlobalFilter::ListParameters()
{
printInfo("\nKEYWORDS ACCEPTED BY GlobalFilter");
......@@ -1016,6 +1016,8 @@ void GlobalFilter::GetParameters()
void GlobalFilter::GetParameters(UInt_t *error_code)
{
#define KPAR(s1,s2,s3) if(doList) printInfo(s1, s2, s3); else if( !found && stringEq(keyw, s1) ) { found = true;
bool doList = *error_code == 0xFFFFFFFF;
*error_code = 0;
......@@ -1031,7 +1033,7 @@ void GlobalFilter::GetParameters(UInt_t *error_code)
cout << endl << gMotherClass + "::GetParameters() reading from --> " << configFileName << endl;
}
string kcmd, line, keyw, data;
string line, keyw, data;
bool ok = true;
bool found = false;
while(doList || getline(configfile, line)) {
......@@ -1044,142 +1046,74 @@ void GlobalFilter::GetParameters(UInt_t *error_code)
found = false;
}
kcmd = "ActualClass";
if(doList)
printInfo(kcmd, "%s", "name of daughter class");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("ActualClass", "%s", "name of daughter class")
ok = data.size() > 0;
gActualClass = data;
}
kcmd = "SaveDataDir";
if(doList)
printInfo(kcmd, "%s", "where to write data and spectra");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("SaveDataDir", "%s", "where to write data and spectra")
ok = data.size() > 0;
fOdirPrefix = data;
forceTailSlash(fOdirPrefix);
}
kcmd = "Ancillary";
if(doList)
printInfo(kcmd, "", "process events with ancillary data");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("Ancillary", "", "process events with ancillary data")
fAncillary = true;
ok = true;
}
kcmd = "Recoiling";
if(doList)
printInfo(kcmd, "", "process events with rawanc1 containing recoil vector");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("Recoiling", "", "process events with rawanc1 containing recoil vector")
fRecoiling = true;
fAncillary = true;
ok = true;
}
kcmd = "RotoTranslations";
if(doList)
printInfo(kcmd, "%s", "file to transform coordinates from intrinsic to space");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("RotoTranslations", "%s", "file to transform coordinates from intrinsic to space")
ok = data.size() > 0;
fWhichRotoTranslations = data;
}
kcmd = "GeometrySummary";
if(doList)
printInfo(kcmd, "%s", "for the header of the Mgt_Hits.txt file of input hits");
else if( !found && stringEq(kcmd, keyw) ) {
found = true;
KPAR("GeometrySummary", "%s", "for the header of the Mgt_Hits.txt file of input hits")
ok = data.size() > 0;
fGeometrySummary = data;
}