stream  0.10.0
stream analysis framework
All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
Example with custom HADAQ processor

Here typical initialization script

#include <cstdlib>
#include "hadaq/TdcProcessor.h"
#include "hadaq/TrbProcessor.h"
#include "hadaq/HldProcessor.h"
#include "base/ProcMgr.h"
#include "custom.h"
void first()
{
//base::ProcMgr::instance()->SetRawAnalysis(true);
// configure ToT calibration parameters
// first - minimal number of counts in ToT histogram
// second - maximal RMS value
// all new instances get this value
// this limits used for liner calibrations when nothing else is available
// hadaq::TdcMessage::SetFineLimits(16, 500);
// First is range of fine time
// Second parameter determines the range of the ToT histograms in ns
// Third is reduction factor of bins for 2D histogram
// default channel numbers and edges mask
// 1 - use only rising edge, falling edge is ignore
// 2 - falling edge enabled and fully independent from rising edge
// 3 - falling edge enabled and uses calibration from rising edge
// 4 - falling edge enabled and common statistic is used for calibration
// default channel numbers and edges mask
// hadaq::TdcProcessor::SetDefaults(1024);
// [min..max] range for TDC ids
//hadaq::TrbProcessor::SetTDCRange(0x610, 0x613);
// [min..max] range for HUB ids
// when first argument true - TRB/TDC will be created on-the-fly
// second parameter is function name, called after elements are created
hadaq::HldProcessor* hld = new hadaq::HldProcessor(true, "after_create");
//--------------------------------------------------------------------------------------
// create TRB processor which holds custom data
hadaq::TrbProcessor* trb3 = new hadaq::TrbProcessor(0x83CC, hld);
// enable auto-creation only if TDCs expected on that TRB
trb3->SetAutoCreate(true);
// create custom processor
hadaq::CustomProcessor *custom = new hadaq::CustomProcessor(trb3, 0x8143, 32);
//--------------------------------------------------------------------------------------
const char* calname = getenv("CALNAME");
if ((calname==0) || (*calname==0)) calname = "test_";
const char* calmode = getenv("CALMODE");
int cnt = (calmode && *calmode) ? atoi(calmode) : 100000;
const char* caltrig = getenv("CALTRIG");
unsigned trig = (caltrig && *caltrig) ? atoi(caltrig) : 0xd;
const char* uset = getenv("USETEMP");
unsigned use_temp = 0; // 0x80000000;
if ((uset!=0) && (*uset!=0) && (strcmp(uset,"1")==0)) use_temp = 0x80000000;
printf("HLD configure calibration calfile:%s cnt:%d trig:%X temp:%X\n", calname, cnt, trig, use_temp);
// first parameter if filename prefix for calibration files
// and calibration mode (empty string - no file I/O)
// second parameter is hits count for autocalibration
// 0 - only load calibration
// -1 - accumulate data and store calibrations only at the end
// >0 - automatic calibration after N hits in each active channel
// third parameter is trigger type mask used for calibration
// (1 << 0xD) - special 0XD trigger with internal pulser, used also for TOT calibration
// 0x3FFF - all kinds of trigger types will be used for calibration (excluding 0xE and 0xF)
// 0x80000000 in mask enables usage of temperature correction
hld->ConfigureCalibration(calname, cnt, (1 << trig) | use_temp);
// only accept trigger type 0x1 when storing file
//new hadaq::HldFilter(0x1);
// create ROOT file store
//base::ProcMgr::instance()->CreateStore("td.root");
// 0 - disable store
// 1 - std::vector<hadaq::TdcMessageExt> - includes original TDC message
// 2 - std::vector<hadaq::MessageFloat> - compact form, without channel 0, stamp as float (relative to ch0)
// 3 - std::vector<hadaq::MessageDouble> - compact form, with channel 0, absolute time stamp as double
// when configured as output in DABC, one specifies:
// <OutputPort name="Output2" url="stream://file.root?maxsize=5000&kind=3"/>
}
// extern "C" required by DABC to find function from compiled code
//TH1* h1;
extern "C" void after_create(hadaq::HldProcessor* hld)
{
printf("Called after all sub-components are created\n");
if (hld==0) return;
for (unsigned k=0;k<hld->NumberOfTRB();k++) {
hadaq::TrbProcessor* trb = hld->GetTRB(k);
if (trb==0) continue;
//trb->DisableCalibrationFor(0,8);
printf("Configure %s!\n", trb->GetName());
trb->SetPrintErrors(10);
}
unsigned firsttdc = 0;
for (unsigned k=0;k<hld->NumberOfTDC();k++) {
hadaq::TdcProcessor* tdc = hld->GetTDC(k);
if (tdc==0) continue;
if (firsttdc == 0) firsttdc = tdc->GetID();
printf("Configure %s!\n", tdc->GetName());
tdc->SetUseLastHit(false);
for (int i=2;i<52;i++) {
tdc->SetRefChannel(i,i-1, tdc->GetID(), 30000, -50, 50); // LED DIFF
}
if (tdc->GetID() == 0x0507) {
tdc->SetToTRange(20, 15., 60.);
}
}
}
void SetHistFilling(int lvl)
Set histogram fill level for all processors.
Definition: ProcMgr.cxx:103
void SetTriggeredAnalysis(bool on=true)
Enabled/disable triggered analysis is configured.
Definition: ProcMgr.h:192
static ProcMgr * instance()
Return global instance of processor manager, provided by framework.
Definition: ProcMgr.cxx:46
virtual void SetStoreKind(unsigned kind=1)
Set store kind for all processors.
Definition: ProcMgr.cxx:119
unsigned GetID() const
Get processor ID.
Definition: base/Processor.h:222
const char * GetName() const
Get processor name.
Definition: base/Processor.h:220
HLD processor.
Definition: HldProcessor.h:93
TdcProcessor * GetTDC(unsigned indx) const
Get TDC by index.
Definition: HldProcessor.cxx:122
TrbProcessor * GetTRB(unsigned indx) const
Get TRB by index.
Definition: HldProcessor.cxx:89
void ConfigureCalibration(const std::string &fileprefix, long period, unsigned trig=0xFFFF)
Configure calibration modes.
Definition: HldProcessor.cxx:159
unsigned NumberOfTDC() const
Return number of TDCs in all TRBs.
Definition: HldProcessor.cxx:111
unsigned NumberOfTRB() const
Return number of TRBs.
Definition: HldProcessor.cxx:81
TDC processor.
Definition: TdcProcessor.h:32
static void SetAllHistos(bool on=true)
Automatically create histograms for all channels - even they not appear in data.
Definition: TdcProcessor.cxx:76
void SetToTRange(double tot_0xd, double hmin, double hmax)
set real ToT value for 0xD trigger and min/max for histogram accumulation default is 30ns,...
Definition: TdcProcessor.cxx:437
static void SetTriggerDWindow(double low=-25, double high=50)
Configure window (in nanoseconds), where time stamps from 0xD trigger will be accepted for calibratio...
Definition: TdcProcessor.cxx:93
static void SetToTCalibr(int minstat=100, double rms=0.15)
Configure ToT calibration parameters.
Definition: TdcProcessor.cxx:104
static void SetDefaults(unsigned numfinebins=600, unsigned totrange=100, unsigned hist2dreduced=10)
Set default values for TDC creation.
Definition: TdcProcessor.cxx:57
void SetRefChannel(unsigned ch, unsigned refch, unsigned reftdc=0xffff, int npoints=5000, double left=-10., double right=10., bool twodim=false)
Set reference signal for the TDC channel ch.
Definition: TdcProcessor.cxx:516
void SetUseLastHit(bool on=true)
When enabled, last hit time in the channel used for reference time calculations By default,...
Definition: TdcProcessor.h:686
TRB processor.
Definition: TrbProcessor.h:46
static void SetHUBRange(unsigned min, unsigned max)
Define range for HUBs, used when auto mode is enabled.
Definition: TrbProcessor.h:285
void SetAutoCreate(bool on=true)
enable autocreation mode if necessary, works for single event
Definition: TrbProcessor.h:152
static void SetDefaults(unsigned numch=65, unsigned edges=0x1, bool ignore_sync=true)
Set defaults for the next creation of TDC processors.
Definition: TrbProcessor.cxx:35
void SetPrintErrors(int cnt=100)
Set number of errors which could be printed.
Definition: TrbProcessor.h:191
static void SetTDCRange(unsigned min, unsigned max)
Define range for TDCs, used when auto mode is enabled.
Definition: TrbProcessor.h:278

And here is custom processor, which defined in custom.h file

#ifndef CustomProcessor_h
#define CustomProcessor_h
#include "hadaq/SubProcessor.h"
namespace hadaq {
class TrbProcessor;
class CustomProcessor : public SubProcessor {
friend class TrbProcessor;
protected:
unsigned fNumChannels;
base::H1handle fChannels;
public:
CustomProcessor(TrbProcessor* trb, unsigned subid, unsigned numchannels = 33);
virtual ~CustomProcessor() {}
unsigned NumChannels() const { return fNumChannels; }
virtual bool FirstBufferScan(const base::Buffer&);
virtual bool SecondBufferScan(const base::Buffer&) { return true; }
};
}
hadaq::CustomProcessor::CustomProcessor(TrbProcessor* trb, unsigned subid, unsigned numchannels) :
hadaq::SubProcessor(trb, "CUST_%04X", subid),
fNumChannels(numchannels)
{
fChannels = MakeH1("CustomChannels", "Messages per channels", numchannels, 0, numchannels, "ch");
}
bool hadaq::CustomProcessor::FirstBufferScan(const base::Buffer &buf)
{
unsigned len = buf.datalen()/4;
uint32_t* arr = (uint32_t*) buf.ptr();
// printf("Process sub data len %u\n", len);
// process subsubeven
for (unsigned n=0;n<len;n++) {
uint32_t data = arr[n];
// from here dummy code, just to fill histogram
unsigned chid = data & 0xff;
if (chid >= fNumChannels)
chid = chid % fNumChannels;
FillH1(fChannels, chid);
}
return true;
}
#endif
Memory management class.
Definition: Buffer.h:49
unsigned datalen() const
Returns length of memory buffer.
Definition: Buffer.h:81
void * ptr(unsigned shift=0) const
return pointer with shift
Definition: Buffer.h:87