WarpVeto.cc
00001 #include "WarpVeto.hh"
00002 #include "Smoother.hh"
00003 #include "SumChannels.hh"
00004 #include <algorithm>
00005
00006 WarpVeto::WarpVeto() :
00007 BaseModule(GetDefaultName(), "Simple online analysis for the WARP veto DAQ")
00008 {
00009 RegisterParameter("max_channels",max_channels = 40,
00010 "Maximum number of channels to store");
00011 AddDependency<Smoother>();
00012 AddDependency<SumChannels>();
00013 }
00014
00015 WarpVeto::~WarpVeto() {}
00016
00017 int WarpVeto::Initialize()
00018 {
00019 return 0;
00020 }
00021
00022 int WarpVeto::Finalize()
00023 {
00024 return 0;
00025 }
00026
00027 int WarpVeto::Process(EventPtr event)
00028 {
00029 int nchans = event->GetEventData()->channels.size();
00030 ChannelData& sum = event->GetEventData()->channels.back();
00031 if(sum.channel_id != ChannelData::CH_SUM){
00032 Message(ERROR)<<"The last channel in event "
00033 <<event->GetEventData()->event_id<<" has id "<<sum.channel_id
00034 <<"; expected sum with id "<<ChannelData::CH_SUM<<"\n";
00035 return 1;
00036 }
00037 uint32_t pulsesize = sum.channel_end - sum.channel_start;
00038 int bufsize = 2*sizeof(uint32_t) + max_channels * sizeof(double) + pulsesize;
00039 _buffer.resize(bufsize);
00040
00041 char* rawbuffer = &(_buffer[0]);
00042
00043 ((uint32_t*)rawbuffer)[0] = max_channels;
00044 ((uint32_t*)rawbuffer)[1] = pulsesize;
00045 double* ch_amp = (double*)( rawbuffer + 2*sizeof(uint32_t));
00046 char* sum_pulse = rawbuffer + 2*sizeof(uint32_t) +max_channels*sizeof(double);
00047
00048 std::fill_n(ch_amp, max_channels, 0);
00049 for(int i=0; i<nchans; i++){
00050 ChannelData& chdata = event->GetEventData()->channels[i];
00051 int id = chdata.channel_id;
00052 if(id >=0 && id < (int)max_channels)
00053 ch_amp[id] = chdata.smoothed_max - chdata.smoothed_min;
00054 else if(id >= 0){
00055 Message(WARNING)<<"Channel with ID "<<id<<" present in event "
00056 <<event->GetEventData()->event_id
00057 <<"; expected max_channels is "<<max_channels<<"\n";
00058 }
00059 }
00060 std::copy( sum.channel_start, sum.channel_end, sum_pulse);
00061 return 0;
00062 }