Commit 8d324bfc authored by dino's avatar dino
Browse files

Several changes an bug fixes. In principle this is the last update before...

Several changes an bug fixes. In principle this is the last update before removing myADF0.2 and merging back to the main adf development trail

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@972 170316e4-aea8-4b27-aad4-0380ec0519c9
parent 0c6c19ef
......@@ -8,9 +8,9 @@ default:
@echo " clean"
library:
make -C $(WD)/producers library GRUMACRO=$(GRUMACRO) PCI_EXPRESS=$(PCI_EXPRESS)
make -C $(WD)/filters library GRUMACRO=$(GRUMACRO) PCI_EXPRESS=$(PCI_EXPRESS)
make -C $(WD)/consumers library GRUMACRO=$(GRUMACRO) PCI_EXPRESS=$(PCI_EXPRESS)
make -C $(WD)/producers library GRUMACRO=$(GRUMACRO) NRV_TYPE=$(NRV_TYPE)
make -C $(WD)/filters library GRUMACRO=$(GRUMACRO) NRV_TYPE=$(NRV_TYPE)
make -C $(WD)/consumers library GRUMACRO=$(GRUMACRO) NRV_TYPE=$(NRV_TYPE)
psa-tests-install:
......
# sln2make autogenerated Makefile.ag
# not a real Makefile because it always rebuilds all
DEFINES = -DHAVE_VISIBILITY_HIDDEN_ATTRIBUTE=1
DEFINES += -DHAVE_VISIBILITY_PRAGMA=1
DEFINES += -DXP_UNIX=1
DEFINES += -D_GNU_SOURCE=1
DEFINES += -DHAVE_FCNTL_FILE_LOCKING=1
DEFINES += -DLINUX=1
DEFINES += -Di386=1
DEFINES += -DHAVE_LCHOWN=1
DEFINES += -DHAVE_STRERROR=1
DEFINES += -D_REENTRANT=1
DEFINES += -DHAVE_EXPAT_CONFIG_H=1
DEFINES += -DTHREADED
DEFINES += -DNRV_OFFLINE
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_LARGEFILE64_SOURCE=1
#DEFINES += -DNOT_USING_ADF=1
DEFINES =
DEFINES += -DNRV_TYPE=NRV_OFFLINE
ifeq ($(OS),Windows_NT)
LDFLAGS= -L.
......@@ -30,6 +16,9 @@ LFLAGS=
CC=g++
ADF=../../adf
PRISMA=../PRISMA/src/lib_prisma
CFLAGS =
CFLAGS += -O3
CFLAGS += $(DEFINES)
......@@ -43,13 +32,14 @@ CFLAGS += -I../filters/PSA/ -I../filters/PSA/includePSA
CFLAGS += -I../filters/Tracking/ -I../filters/Tracking/includeOFT -I../filters/Tracking/includeMGT
CFLAGS += -I../consumers/Basic
CFLAGS += -I../builders/
CFLAGS += -I../myADF0.2/ -I../myADF0.2/standalone/
CFLAGS += -I../PRISMA/src/lib_prisma/include/
CFLAGS += -I$(ADF)/ -I$(ADF)/standalone/
CFLAGS += -I$(PRISMA)/include/
CFLAGS += -I/usr/include/boost/
CFLAGS += -I/usr/include/skstream-0.3/ -I/usr/lib/skstream-0.3/include/
#CFLAGS += -fprofile-arcs -ftest-coverage
#CFLAGS += -pg
CFLAGS += -g
CFLAGS += -funroll-loops -msse4 # -fexceptions -ffast-math # -ftree-vectorizer-verbose=5 #-pthread
SRCS =
SRCS += femul.cpp
......@@ -68,8 +58,8 @@ SRCS += ../filters/Tracking/includeOFT/tracking_cluster.c ../filters/Tracking/in
SRCS += ../filters/Tracking/includeMGT/mgt.c ../filters/Tracking/includeMGT/mgt_eclust.c ../filters/Tracking/includeMGT/mgt_etrack.c ../filters/Tracking/includeMGT/mgt_event.c ../filters/Tracking/includeMGT/mgt_geoagata.c ../filters/Tracking/includeMGT/mgt_vectorlib.c
#SRCS += ../producers/Basic/myBasicAFC.cpp
SRCS += ../builders/EventBuilder.cpp
SRCS += ../myADF0.2/ADFConfig.cpp ../myADF0.2/ADFObjects.cpp ../myADF0.2/AgataConfigurationFrame.cpp ../myADF0.2/AgataFrameFactory.cpp ../myADF0.2/AgataKeyFactory.cpp ../myADF0.2/BaseBuffer.cpp ../myADF0.2/BufferIO.cpp ../myADF0.2/CompositeFrame.cpp ../myADF0.2/ConfAgent.cpp ../myADF0.2/ConfigurationFrame.cpp ../myADF0.2/Counter.cpp ../myADF0.2/DataHandling.cpp ../myADF0.2/DefaultKeyFactory.cpp ../myADF0.2/FactoryItem.cpp ../myADF0.2/Frame.cpp ../myADF0.2/FrameBlock.cpp ../myADF0.2/FrameFactory.cpp ../myADF0.2/GObject.cpp ../myADF0.2/FrameIO.cpp ../myADF0.2/GenericFrame.cpp ../myADF0.2/AgataRawFrame.cpp ../myADF0.2/CrystalFrame.cpp ../myADF0.2/MetaFrame.cpp ../myADF0.2/Hits.cpp ../myADF0.2/Key.cpp ../myADF0.2/KeyFactory.cpp ../myADF0.2/NarvalInterface.cpp ../myADF0.2/Signals.cpp ../myADF0.2/Trigger.cpp ../myADF0.2/Version.cpp ../myADF0.2/standalone/LogCollector.cpp ../myADF0.2/standalone/CentralLog.cpp ../myADF0.2/standalone/LogMessage.cpp ../myADF0.2/BasicAFC.cpp ../myADF0.2/BasicAFP.cpp
SRCS += ../PRISMA/src/lib_prisma/src/prismaManager.cc ../PRISMA/src/lib_prisma/src/banGate.cc ../PRISMA/src/lib_prisma/src/banManager.cc ../PRISMA/src/lib_prisma/src/calCoef.cc ../PRISMA/src/lib_prisma/src/calManager.cc ../PRISMA/src/lib_prisma/src/CGaspBuffer.cc ../PRISMA/src/lib_prisma/src/ConfigurationFile.cc ../PRISMA/src/lib_prisma/src/detData.cc ../PRISMA/src/lib_prisma/src/fastSolver.cc ../PRISMA/src/lib_prisma/src/fullEvent.cc ../PRISMA/src/lib_prisma/src/massCalculator.cc ../PRISMA/src/lib_prisma/src/prismaIonCh.cc ../PRISMA/src/lib_prisma/src/prismaMcp.cc ../PRISMA/src/lib_prisma/src/prismaPPAC.cc ../PRISMA/src/lib_prisma/src/prismaSide.cc ../PRISMA/src/lib_prisma/src/RandomGenerator.cc ../PRISMA/src/lib_prisma/src/Vectors.cc ../PRISMA/src/lib_prisma/src/zedCalculator.cc
SRCS += $(ADF)/ADFConfig.cpp $(ADF)/ADFObjects.cpp $(ADF)/AgataConfigurationFrame.cpp $(ADF)/AgataFrameFactory.cpp $(ADF)/AgataKeyFactory.cpp $(ADF)/BaseBuffer.cpp $(ADF)/BufferIO.cpp $(ADF)/CompositeFrame.cpp $(ADF)/ConfAgent.cpp $(ADF)/ConfigurationFrame.cpp $(ADF)/Counter.cpp $(ADF)/DataHandling.cpp $(ADF)/DefaultKeyFactory.cpp $(ADF)/FactoryItem.cpp $(ADF)/Frame.cpp $(ADF)/FrameBlock.cpp $(ADF)/FrameFactory.cpp $(ADF)/GObject.cpp $(ADF)/FrameIO.cpp $(ADF)/GenericFrame.cpp $(ADF)/AgataRawFrame.cpp $(ADF)/CrystalFrame.cpp $(ADF)/MetaFrame.cpp $(ADF)/Hits.cpp $(ADF)/Key.cpp $(ADF)/KeyFactory.cpp $(ADF)/NarvalInterface.cpp $(ADF)/Signals.cpp $(ADF)/Trigger.cpp $(ADF)/Version.cpp $(ADF)/standalone/LogCollector.cpp $(ADF)/standalone/CentralLog.cpp $(ADF)/standalone/LogMessage.cpp $(ADF)/BasicAFC.cpp $(ADF)/BasicAFP.cpp
SRCS += $(PRISMA)/src/prismaManager.cc $(PRISMA)/src/banGate.cc $(PRISMA)/src/banManager.cc $(PRISMA)/src/calCoef.cc $(PRISMA)/src/calManager.cc $(PRISMA)/src/CGaspBuffer.cc $(PRISMA)/src/ConfigurationFile.cc $(PRISMA)/src/detData.cc $(PRISMA)/src/fastSolver.cc $(PRISMA)/src/fullEvent.cc $(PRISMA)/src/massCalculator.cc $(PRISMA)/src/prismaIonCh.cc $(PRISMA)/src/prismaMcp.cc $(PRISMA)/src/prismaPPAC.cc $(PRISMA)/src/prismaSide.cc $(PRISMA)/src/RandomGenerator.cc $(PRISMA)/src/Vectors.cc $(PRISMA)/src/zedCalculator.cc
PROG=femul
......@@ -82,16 +72,16 @@ default:
plain:
ifeq ($(OS),Windows_NT)
$(CC) $(CFLAGS) $(SRCS) -o $(PROG) /lib/libboost_thread-gcc-mt.a
$(CC) $(CFLAGS) $(SRCS) -o $(PROG) /lib/libboost_thread-mt.a
else
$(CC) $(CFLAGS) $(SRCS) -o $(PROG) -L/usr/lib -lboost_thread-mt -lpthread $(LDFLAGS) -DNRV_OFFLINE
$(CC) $(CFLAGS) $(SRCS) -o $(PROG) -L/usr/lib -lboost_thread-mt -lpthread $(LDFLAGS)
endif
root:
ifeq ($(OS),Windows_NT)
$(CC) $(CFLAGS) $(SRCS) -o $(PROG) /lib/libboost_thread-gcc-mt.a -I/usr/include/ $(shell root-config --cflags)
$(CC) $(CFLAGS) $(SRCS) -o $(PROG) /lib/libboost_thread-mt.a -I/usr/include/ $(shell root-config --cflags)
else
$(CC) $(CFLAGS) $(SRCS) -o $(PROG) -L/usr/lib -lboost_thread-mt -lpthread $(LDFLAGS) -I/usr/include/ $(shell root-config --cflags) $(shell root-config --libs) -L/usr/lib -lfreetype -DNRV_OFFLINE
$(CC) $(CFLAGS) $(SRCS) -o $(PROG) -L/usr/lib -lboost_thread-mt -lpthread $(LDFLAGS) -I/usr/include/ $(shell root-config --cflags) $(shell root-config --libs) -L/usr/lib -lfreetype
endif
clean:
......
This diff is collapsed.
......@@ -45,7 +45,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\PRISMA\src\lib_prisma\include;"C:\Program Files (x86)\boost\boost_1_40";..\myADF0.2;..\myADF0.2\standalone;..\common;..\producers\Crystal;..\producers\Crystal\includeATCA;..\producers\AncillaryTCP;..\filters\Preprocessing;..\filters\Preprocessing\includePrePSA;..\filters\Ancillary;..\filters\Ancillary\includeVME;..\filters\PSA;..\filters\PSA\includePSA;..\filters\Tracking;..\filters\Tracking\includeOFT;..\filters\Tracking\includeMGT;..\builders;C:\root\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NRV_OFFLINE"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NRV_TYPE=NRV_OFFLINE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
......@@ -121,7 +121,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\PRISMA\src\lib_prisma\include;"C:\Program Files (x86)\boost\boost_1_40";..\myADF0.2;..\myADF0.2\standalone;..\common;..\producers\Crystal;..\producers\Crystal\includeATCA;..\producers\AncillaryTCP;..\filters\Preprocessing;..\filters\Preprocessing\includePrePSA;..\filters\Ancillary;..\filters\Ancillary\includeVME;..\filters\PSA;..\filters\PSA\includePSA;..\filters\Tracking;..\filters\Tracking\includeOFT;..\filters\Tracking\includeMGT;..\builders;C:\root\include"
PreprocessorDefinitions="WIN64;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NRV_OFFLINE"
PreprocessorDefinitions="WIN64;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NRV_TYPE=NRV_OFFLINE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
......@@ -274,10 +274,11 @@
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
Optimization="3"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="..\PRISMA\src\lib_prisma\include;&quot;C:\Program Files (x86)\boost\boost_1_40&quot;;..\myADF0.2;..\myADF0.2\standalone;..\common;..\producers\Crystal;..\producers\Crystal\includeATCA;..\producers\AncillaryTCP;..\filters\Preprocessing;..\filters\Preprocessing\includePrePSA;..\filters\Ancillary;..\filters\Ancillary\includeVME;..\filters\PSA;..\filters\PSA\includePSA;..\filters\Tracking;..\filters\Tracking\includeOFT;..\filters\Tracking\includeMGT;..\builders;C:\root\include"
PreprocessorDefinitions="WIN64;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NRV_OFFLINE"
PreprocessorDefinitions="WIN64;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NRV_TYPE=NRV_OFFLINE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
......
......@@ -158,7 +158,7 @@ EventBuilder::EventBuilder(unsigned int nch, int type) :
evq(NULL), iqueSize(NULL), isGood(NULL), minEvnum(0), minTstamp(0), minChain(0),
statKeys(NULL), errState(0), noBuild1(0), noBuild2(0), allPresent(false), obufFull(false)
{
fConfPath = gConfPath;
fConfPath = gConfPath; // done explicitely as this does not inherit from NarvalInterface
fOdirPrefix.clear();
useEventNumber = false;
timeout = 100*tst1second;
......@@ -167,6 +167,8 @@ EventBuilder::EventBuilder(unsigned int nch, int type) :
verbose = false;
if(type == 0) {
// used as EventBuilder all input queues have the same key (default is "data:psa")
// and the default output frame is "event:data:psa"
bBuilder = true;
bMerger = false;
for(unsigned int nn = 0; nn < nch; nn++)
......@@ -175,11 +177,13 @@ EventBuilder::EventBuilder(unsigned int nch, int type) :
fActualClass = gActualClass = "EventBuilder";
}
else {
// used as EventMerger each input queue has its own key (default is "data:ranc1" for all but the last one, which has "event:data:psa")
// and the default output frame is event:data
bBuilder = false;
bMerger = true;
for(unsigned int nn = 0; nn < nch-1; nn++) // forse sarebbe meglio limitare il numero di input a 2 ?
for(unsigned int nn = 0; nn < nch-1; nn++) // for the present use in agata, maybe we should limit the number of queues to 2
sKeyIn.push_back("data:ranc1");
sKeyIn.push_back("event:data:psa"); // attenzione che questo dipende dall' ordine con cui vengono dati
sKeyIn.push_back("event:data:psa"); // pay attention that this order depends from the actual topology; maybe we should not initialize them
sKeyOut = "event:data";
fActualClass = gActualClass = "EventMerger";
}
......@@ -281,8 +285,7 @@ void EventBuilder::process_block( int ichain,
oevCount = 0;
UInt_t rest = 0;
if(ichain>=0 && isize > 0) {
// Copy as much as possible of the input buffer at the end of its sibuf;
if(ichain>=0 && isize > 0 && evq[ichain].wantsData()) {
rest = evq[ichain].addData((UInt_t *)ibuffer, isize/4, vCorrection[ichain]);
*used_isize = isize - 4*rest;
//if(rest) {
......@@ -314,7 +317,7 @@ void EventBuilder::process_block( int ichain,
}
bool goAhead = allPresent; // normal condition to proceed
if(ichain == -2) // proceed even if not all queues empty
if(ichain == -2) // proceed even if not all queues have data
goAhead = true;
if(!goAhead)
......@@ -374,7 +377,7 @@ void EventBuilder::process_block( int ichain,
errState = 0;
// Remove valid event-fragments from their input queue
// Send them to the output buffer if multiplicity condition is matched
// Send them to the output buffer if multiplicity condition is matched; discard otherwise
for(UInt_t nn = 0; nn < nchains; nn++) {
if(!isGood[nn])
continue;
......@@ -441,32 +444,33 @@ void EventBuilder::process_block( int ichain,
obuf[3] = (unsigned int)( minTstamp & 0xFFFFFFFF);
obuf[4] = (unsigned int)((minTstamp>>32) & 0xFFFFFFFF);
oevCount++;
osiz += opos; // total size used so far
obuf += opos; // advance pointer to output buffer
oevCount++;
cServer.Exec(minTstamp);
}
if(osiz > osizMax) {
obufFull = true;
break;
}
opos = 5; // where to start writing next event, relative to obuf
opos = 5; // where to start writing next event, relative to obuf
}
*used_osize = osiz*4;
*error_code = 0;
LOCK_COUT;
cServer.Prompt(-1, oevCount, *used_osize, !verbose);
cServer.Prompt(ichain, oevCount, *used_osize, !verbose);
const int chainsPerLine = 6;
if(verbose) {
if(nchains > 4) cout << endl << " ";
if(nchains > chainsPerLine) cout << endl << " ";
cout << " {";
for(UInt_t nn = 0; nn < nchains; nn++) {
cout << " " << setw(5) << iqueSize[nn];
}
cout << " |";
if(nchains > 4) cout << endl << " |";
if(nchains > chainsPerLine) cout << endl << " |";
for(UInt_t nn = 0; nn < nchains; nn++) {
cout << " " << setw(5) << evq[nn].numEvts;
}
......@@ -553,14 +557,13 @@ void EventBuilder::CheckEvent_Tstamp()
continue; // empty
if(evq[nn].tstFirst > minTstamp)
continue; // out of time window
// preset to move this frame to the output buffer
// ok, preset to move this frame to the output buffer
minEvnum = min(minEvnum, evq[nn].evnFirst);
evq[nn].totCount++;
isGood[nn] = true;
numKeys++;
}
minTstamp -= tsumbus; // back to real minimum
minTstamp = minTstamp;
}
void EventBuilder::process_config ( const Char_t *directory_path, UInt_t *error_code )
......@@ -571,7 +574,7 @@ void EventBuilder::process_config ( const Char_t *directory_path, UInt_t *error_
gConfPath = string( directory_path );
forceTailSlash(gConfPath);
// Get name of daughter class from from configuration directory_path/gMotherClass.conf
// Get name of daughter class from configuration directory_path/gMotherClass.conf
// No daughter class foreseen for his actor; called just to check if configuraton file exists
int rv = getKeyFromFile(gConfPath + gMotherClass + ".conf", "ActualClass", gActualClass);
if(rv == 2)
......@@ -582,8 +585,6 @@ void EventBuilder::process_initialise (UInt_t *error_code)
{
*error_code = 0;
fConfPath = gConfPath;
GetParameters(error_code);
if(*error_code)
return;
......@@ -622,7 +623,7 @@ bool EventBuilder::InitAsBuilder()
hGroup.add(specTdiff);
#endif //EEB_LOCALSPECTRA
cServer.SetCommandFile(fConfPath+gMotherClass+".live");
cServer.SetCommandFile(GetConfPath() + gMotherClass + ".live");
#ifdef EEB_LOCALSPECTRA
cServer.SetHistGroup(&hGroup);
#endif //EEB_LOCALSPECTRA
......@@ -658,7 +659,7 @@ bool EventBuilder::InitAsMerger()
hGroup.add(specTdiff);
#endif //EEB_LOCALSPECTRA
cServer.SetCommandFile(fConfPath+gMotherClass+".live");
cServer.SetCommandFile(GetConfPath() + gMotherClass + ".live");
#ifdef EEB_LOCALSPECTRA
cServer.SetHistGroup(&hGroup);
#endif //EEB_LOCALSPECTRA
......@@ -707,7 +708,7 @@ void EventBuilder::GetParameters(UInt_t *error_code)
{
*error_code = 0;
string configFileName = fConfPath + fActualClass + ".conf";
string configFileName = GetConfPath() + fActualClass + ".conf";
ifstream configfile( configFileName.c_str() );
if( !configfile.good() ) {
cout << "Error opening " << configFileName << endl;
......
......@@ -11,8 +11,8 @@
#endif
#include "cycleServer.h"
//const UInt_t queueSize = 4*1024*1024; // size of input queues in sizeof(Int_t) units
const UInt_t queueSize = 128*1024; // size of input queues in sizeof(Int_t) units
const UInt_t queueSize = 4*1024*1024; // size of input queues in sizeof(Int_t) units
//const UInt_t queueSize = 128*1024; // size of input queues in sizeof(Int_t) units
const UInt_t maxHalfBuffs = 2; // max number of input half-buffers held in queue
const UInt_t maxErrors = 0; // max number "errors" which is equivalent to a timeout (0==infinite)
......@@ -70,6 +70,10 @@ public:
{
return indFirst >= indNext;
}
bool wantsData()
{
return indNext-indFirst <= queueSize/2; // to reduce costly re-shuffling of the queue, don't take events until half-empty
}
Int_t myID; // useful for debugging
UInt_t inpKey; // the only valid key for this chain
......@@ -156,6 +160,7 @@ public:
public:
EventBuilder(unsigned int nch = 1, int type = 0);
const std::string &GetConfPath() { return fConfPath; }
virtual ~EventBuilder();
......
......@@ -46,14 +46,21 @@
//////// Choose your version of the program(s) //////
/////////////////////////////////////////////////////
//#define NRV_ONLINE // One of the two symbols must be defined, but this
//#define NRV_OFFLINE // can of course be done in the project or makefile (e.g. for narval: make library PCI_EXPRESS=-DNRV_ONLINE)
#define NRV_ONLINE 1
#define NRV_OFFLINE 2
#if (!defined(NRV_ONLINE) && !defined(NRV_OFFLINE)) || (defined(NRV_ONLINE) && defined(NRV_OFFLINE))
#error Please define just one of the two macros: NRV_ONLINE or NRV_OFFLINE
//#define NRV_TYPE NRV_ONLINE // can/should be defined in the project or makefile (e.g. for narval: make library NRV_TYPE=-DNRV_ONLINE)
#ifndef NRV_TYPE
#error Please define NRV_TYPE to be either NRV_ONLINE or NRV_OFFLINE
#endif
#if NRV_TYPE != NRV_ONLINE
# undef NRV_TYPE
# define NRV_TYPE NRV_OFFLINE
#endif
#ifdef NRV_ONLINE
#if NRV_TYPE == NRV_ONLINE
#if (OS_TYPE != OS_LINUX)
#error The online version can only be built on Linux
#endif
......@@ -63,15 +70,15 @@
//////// constants, macros, enums, ... ////////
///////////////////////////////////////////////
#define DEBUG_LINE std::cout << __FUNCTION__ << "-" << __LINE__ << " "
#define DEBUG_LINE_N std::cout << "\n" << __FUNCTION__ << "-" << __LINE__ << " "
#define DEBUG_LINE std::cout << __FUNCTION__ << "-" << __LINE__ << " "
#define DEBUG_LINE_N std::cout << "\n" << __FUNCTION__ << "-" << __LINE__ << " "
#define DEBUG_LINE_F std::cout << __FILE__ << "::" << __FUNCTION__ << " "
// one second with a 100 MHz clock
const unsigned long long tst1second = 100000000;
// events after which to write spectra and perform cyclic checks
const unsigned int defaultCycleEvts = 10000;
const unsigned int defaultCycleTime = 600; //in (timpestamp) seconds
// interval (tstamp seconds) after which to write spectra and perform cyclic checks
const unsigned int defaultCycleTime = 900;
//const float RAD2DEG = float( 180./acos(-1.) );
const float RAD2DEG = float(57.29577951308232286464772187173366546630859375);
......@@ -99,8 +106,6 @@ const int defTriggerSample = 10; // 60-10 useful samples passed to the PS
/////////////////////////////////
//////// CrystalProducer ////////
/////////////////////////////////
#define PCI_EXPRESS // reading from the AGATA ATCA carriers via PCI express
#define CP_NO_ADF // CrystalProducerATCA does not use ADF to format the output buffer
#define CP_LOCALSPECTRA // enable nDhist spectra
//#define CP_FromGRU_ // enable GRU/ViGRU
......@@ -143,7 +148,7 @@ const int defTriggerSample = 10; // 60-10 useful samples passed to the PS
//#define EXTENDED_OUTPUT // Mgt_Hits (if requested in PSAFilter.conf) contain also timestamp and eventnumber
//#define WRITE_TRACKED // Write the tracked gammas into the Oft_TrackedEnergies ascii file
#define NTIMING 1 // processing of the Helena detectors for the neutron test
#define TF_ROOTTREE // Enable the root tree in this actor
//#define TF_ROOTTREE // Enable the root tree in this actor
//#define TREE_INPUT_HITS // Write input hits into the root tree
#define TF_LOCALSPECTRA // enable nDhist spectra
//#define TF_FromGRU_ // enable GRU/ViGRU
......@@ -189,9 +194,11 @@ const int defTriggerSample = 10; // 60-10 useful samples passed to the PS
# define LOCALSPECTRA // needed by cycleServer if any individual one is enabled
#endif
//////////////////////////////////////////////
// a global lock on printouts (may be slow) //
//////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// GLOBAL LOCK TO AVOID MIXUP OF PRINTOUTS IF USING THREADS //
// Using it slows the program. It also makes no sense with //
// narval where the outptut is anyway mixed up in "screen" //
//////////////////////////////////////////////////////////////
#if OS_TYPE == OS_WINDOWS
# define COUT_LOCKED
......@@ -200,7 +207,7 @@ const int defTriggerSample = 10; // 60-10 useful samples passed to the PS
#if defined(COUT_LOCKED)
# include <boost/thread/mutex.hpp>
# define LOCK_COUT boost::mutex::scoped_lock lock(ioMutex);
extern boost::mutex ioMutex; // the mutex is defined in WinCtest.cpp
extern boost::mutex ioMutex; // ioMutex is defined in femul.cpp
#else
# define LOCK_COUT ;
#endif
......
......@@ -6,37 +6,70 @@
using namespace std;
void cycleServer::Start(std::string name, unsigned int cycle)
void cycleServer::Start(std::string name, unsigned int cycleSeconds)
{
SetCycle(cycle);
SetPrompt(name);
SetCycle(cycleSeconds);
mRate.reset();
mCount = sCount = 0;
tStart = tLast = 0;
tstStart = tstCheck = tstWrite = 0;
}
// check if it exists and remove if requested (and possible)
bool cycleServer::CheckComFile(bool remove)
{
if( comFile.empty() )
return false;
FILE *fp = fopen(comFile.c_str(), "r");
if(!fp)
return false;
fclose(fp);
if(remove)
RemoveComFile();
return true;
}
bool cycleServer::CheckComFile(bool &erase, bool remove)
{
erase = false;
if( comFile.empty() )
return false;
FILE *fp = fopen(comFile.c_str(), "rb");
if(!fp)
return false;
// At the moment just check if it has some data
// Should be developed to decode command lines
char cbuf[10];
size_t nr = fread(cbuf, 1, 1, fp);
erase = (nr==1);
fclose(fp);
if(remove)
RemoveComFile();
return true;
}
bool cycleServer::RemoveComFile()
{
#if OS_TYPE == OS_WINDOWS
_unlink(comFile.c_str());
int done = _unlink(comFile.c_str());
#else
unlink(comFile.c_str());
int done = unlink(comFile.c_str());
#endif
return true;
return (done == 0);
}
void cycleServer::SetPrompt(std::string name)
{
myName = "-" + name + ":";
size_t ln = myName.length();
for(size_t nn = ln; nn < 24; nn++)
myName += " " ;
ln = myName.length();
//size_t ln = myName.length();
//for(size_t nn = ln; nn < 24; nn++)
// myName += " " ;
//ln = myName.length();
}
unsigned int cycleServer::Prompt(int id, unsigned int nevs, unsigned int bsize, bool isAll)
......@@ -47,11 +80,11 @@ unsigned int cycleServer::Prompt(int id, unsigned int nevs, unsigned int bsize,
cout << " ";
unsigned int irate = GetRate();
cout << myName
cout << left << setw(24) << myName << right
<< " " << setw(5) << nevs
<< " evts (" << setw(8) << bsize << ")"
<< " Tot = " << setw(7) << GetCounts()
<< " " << setw(4) << irate << "/s";
<< " Tot = " << setw(8) << GetCounts()
<< " " << setw(5) << irate << "/s";
if(isAll)
cout << endl;
return irate;
......@@ -67,7 +100,7 @@ unsigned int cycleServer::ExecLong()
#endif //LOCALSPECTRA
if(mCount <= sCount)
return actions; // to avoid useless re-writing
return actions; // to avoid re-writing if no new data
#ifdef LOCALSPECTRA
if( hGroup->write(false, true) ) {
......@@ -75,18 +108,19 @@ unsigned int cycleServer::ExecLong()
}
#endif //LOCALSPECTRA
sCount = mCount;
tLast = tThis;
if( comFile.empty() )
return actions;
sCount = mCount;
tstWrite = tstCheck = tstThis;
if( CheckComFile(true) ) {
#ifdef LOCALSPECTRA
hGroup->erase(true);
#endif //LOCALSPECTRA
actions |= 2;
bool erase = false;
if( CheckComFile(erase, true) ) {
if(erase) {
hGroup->erase(true);
actions |= 2;
tstStepSet(tst1second*100); // restart with smaller steps
}
}
#endif //LOCALSPECTRA
return actions;
}
......@@ -21,15 +21,17 @@ class ratemeter
public:
ratemeter(int imod = 5) {
ratemeter(int imod = 5)
{
mod = imod > 2 ? imod : 5;
tStart = new time_t [mod];
tCount = new unsigned int[mod];
reset();
}
void start() {reset();}
void reset() {
void start() { reset(); }
void reset()
{
time_t tstart;
time(&tstart);
for(unsigned int nn = 0; nn < mod; nn++) {
......@@ -41,7 +43,8 @@ public:
// 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.
unsigned int rate(unsigned int counts) {
unsigned int rate(unsigned int counts)
{
time_t tNow; time(&tNow);
time_t tOld = tStart[pos];
unsigned int cOld = tCount[pos];
......@@ -62,13 +65,14 @@ public:
class cycleServer
{
unsigned int rCount; // write spectra after rCount events
unsigned int mCount; // counter of analyzed events
unsigned int sCount; // mCount of last saved spectra
unsigned long long tstStep; // first few times is faster 1, 2, 4, ..., tStep
unsigned long long tstStart; // tst-seconds or the first timestamp
unsigned long long tstCheck; // tst-seconds of last check
unsigned long long tstWrite; // tst-seconds of last write
unsigned long long tstThis; // tst-seconds of this call
unsigned int mCount; // counter of Exec() calls
unsigned int sCount; // mCount of last ExecLong()
unsigned int tStep; // write spectra after tStep seconds (as derived from timestamp)
unsigned int tStart; // tst-seconds or the first timestamp
unsigned int tLast; // tst-seconds of last write
unsigned int tThis; // tst-seconds of this call
ratemeter mRate; // analysis-rate estimator
std::string myName; // name of the actor, used in Prompt()
std::string comFile; // where to look for commands to spectrum-erase and change rCount
......@@ -78,40 +82,57 @@ class cycleServer
unsigned int ExecLong(); // actions performed when it is time dump spectra
bool CheckComFile(bool remove = false);
bool CheckComFile(bool &erase, bool remove = false);
bool RemoveComFile();
void tstStepSet(unsigned long long tst = tst1second*60) { tstStep = (tst>tStep*tst1second) ? tStep*tst1second : tst; }
public:
cycleServer(unsigned int cycle = defaultCycleTime, bool isTime = true) :
rCount(defaultCycleEvts), tStep(cycle), mCount(0), sCount(0),
tStart(0), tLast(0), tThis(0)
{
rCount = isTime ? defaultCycleTime : defaultCycleEvts;
cycleServer(unsigned int cycleSeconds = defaultCycleTime) :
tStep(cycleSeconds), mCount(0), sCount(0), tstStep(0),
tstStart(0), tstCheck(0), tstWrite(0), tstThis(0)
{
#ifdef LOCALSPECTRA
hGroup = NULL;
hGroup = NULL;
#endif //LOCALSPECTRA
}
void SetCycle(unsigned int cycle = defaultCycleEvts) { rCount = cycle; }
}
void SetCycle(unsigned int cycleSeconds) { tStep = cycleSeconds; }
void SetCommandFile(std::string name) { comFile = name; }
#ifdef LOCALSPECTRA
void SetHistGroup(nDhistGroup *hg) { hGroup = hg; }