#ifndef USER_HARD_TEST
#define USER_HARD_TEST
/*>-------------------------------------------------------------------------*/
/*
* HardTest.h
*
* userdefined class derived from class HardCallback base class
*/
/*<--------------------------------------------------------------------------*/
#include "HardCallback.h"
class HardTest : public HardCallback
{
private:
SelectedData<uint32> adc1;
SelectedData<uint32> adc2;
AccessedData<uint32> tdc;
GeneratedData<double> adcsum;
// variables managed by Broker
char *gainfile;
double globalgain;
double *tdc_offset;
//other variables
double gain[10];
public:
HardTest(const char*);
~HardTest();
virtual int init();
virtual int analyze();
virtual int finish();
virtual const char *help();
};
#endif
Its implementation could look like:
/*>-------------------------------------------------------------------------*/
/*
* HardTest.cc
*
* implementation of class HardTest
*/
/*<--------------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include "HardTest.h"
static const char *helpstring =
"this is HardTest, a sample hard callback!\n"
"here should be a description on what HardTest is doing!\n";
/*>--------------------------------------------------------------------------*/
HardTest::HardTest(const char *n) : HardCallback(n,1)
/*
* constructor, the second argument (here: 1) is the priority of the
* HardCallback (the callbacks are processed in the order with
* increasing prioity number)
*/
/*<--------------------------------------------------------------------------*/
{
// initialize variables managed by broker
global_gain=10;
gainfile = new char[strlen("dummy")+1];
strcpy(gainfile,dummy);
time_offset = new double[10];
for (int i=0 ; i<10 ; i++)
time_offset[i] = (double) i;
// link subevents:
selectInput( "ADC1" , adc1.instance() , DataType::UNSIGNED_LONG);
selectInput( "ADC2" , adc2.instance() , DataType::UNSIGNED_LONG);
selectInput( "TDC" , tdc.instance() , DataType::UNSIGNED_LONG);
selectOutput("ADCSUM", adcsum.instance(), DataType::DOUBLE);
// make variables known to the broker
announce("globalgain","global gain factor (for all channels)",globalgain);
announce("gainname","path to file containing gains",gainfile);
announce("time_offset","time offset for our TDCs", time_offset,10);
init();
}
/*>--------------------------------------------------------------------------*/
HardTest::~HardTest()
/*<--------------------------------------------------------------------------*/
{
delete[] gainfile;
delete[] time_offset;
}
/*>--------------------------------------------------------------------------*/
virtual int HardTest::init()
/*
* called by broker, when a variable has been set
*/
/*<--------------------------------------------------------------------------*/
{
// read gains
FILE *fp=fopen(gainfile,"r");
double *tmp = gain;
while( fscanf(fp,"%lf",tmp) == 1)
tmp++;
}
/*>--------------------------------------------------------------------------*/
virtual int HardTest::analyze()
/*
* called for every event which matches the selected subevents
* return 1 on success
*/
/*<--------------------------------------------------------------------------*/
{
accepted++; // this is for YODAs GUI: count number of accepted events
// do anything you like
for (int i=0 ; i < adc1.get_length() ; i++)
if ( tdc[i] - time_offset[i] > 777)
adcsum[i] = globalgain*(adc1[i] + adc2[i]*gain[i])
else
adcsum[i]=0;
adcsum.set_length(adc1.get_length());
write_data(); // write all GenereratedData to existing eventstream
return 1;
}
/*>--------------------------------------------------------------------------*/
virtual int HardTest::finish()
/*
* called when YODA goes offline
*/
/*<--------------------------------------------------------------------------*/
{
// do some nonsens
printf("HardTest: used global gain %f\n",globalgain);
return 1;
}
/*>--------------------------------------------------------------------------*/
virtual const char *HardTest::help()
/*
* return a string which tells the user what the hard callback does
* this text fills the textbox in YODAs GUI when help on this hard
* callback is requested.
*/
/*<--------------------------------------------------------------------------*/
{
return helpstring;
}
Finally the existence of our hard callback must be announced to YODAs
Eventstream class in the user.cc file:
/*>--------------------------------------------------------------------------*/
/*
* user.cc
*
* userdefined classes derived from class HardCallback
*
*/
/*<--------------------------------------------------------------------------*/
#include <eventstream.h>
#include "HardTest.h"
// now instanciate all used classes (needed for GNUs gcc compiler!)
#ifdef __GNUC__
template class SelectedData<uint32>;
template class AccessedData<uint32>;
template class GeneratedData<double>;
#endif
void user()
{
Eventstream::instance().link(new HardTest("HardTest"));
}