Diana Software
MCustomWaveform.cc
Go to the documentation of this file.
1 #include "MCustomWaveform.hh"
2 #include "QEvent.hh"
3 #include "QEventAssembler.hh"
4 #include "QPulse.hh"
5 #include "QPulseInfo.hh"
6 #include "QHeader.hh"
7 #include "QRunDataHandle.hh"
8 #include "QPulseFiller.hh"
9 #include <cmath>
10 
11 
13 
14 using namespace Diana;
15 
17 {
18  fInputOwner = GetString("InputOwner","DAQ");
19  fmSecLeft = GetInt("mSecLeft",0);
20  fmSecRight = GetInt("mSecRight",0);
21  fOverWritePulse = GetBool("Overwrite",true);
22  QEvent& ev = eva.GetEvent();
23  ev.Require<QPulse>(fInputOwner.c_str(),"Pulse");
24  ev.Require<QPulseInfo>(fInputOwner.c_str(),"PulseInfo");
25  if(!fOverWritePulse) {
26  ev.Add<QPulse>("Pulse");
27  ev.Add<QPulseInfo>("PulseInfo");
28  }
29  fRun = -1;
30  fRunDuration = 0;
31  fChannelInfos.clear();
32  return ACT_NEXTEV;
33 }
34 
36 {
37  QEvent& ev = eva.GetEvent();
38  const QPulse& inputPulse = ev.Get<QPulse>(fInputOwner.c_str(),"Pulse");
39  const QPulseFiller* filler = inputPulse.GetPulseFiller();
40  if(!filler || !filler->IsValid()) Panic("QPulse does not contain a valid QPulseFiller, access to continuous data not possible.");
41 
42  const QHeader& header = ev.Get<QHeader>(fInputOwner.c_str(),"Header");
43  const int run = header.GetRun();
44 
45  if(fRun != run) {
46  fChannelInfos.clear();
48  GlobalData().Get<QRunData>("",&rHandle,"");
49  fRunDuration = rHandle.Get().fDuration*1e9;
50  fRun = run;
51  const std::map<int,QChannelRunData*>& chanMap = rHandle.Get().GetChannelsRunData();
52  std::map<int,QChannelRunData*>::const_iterator iter = chanMap.begin();
53  while(iter != chanMap.end()) {
54  const int channel = iter->first;
55  const QChannelRunData& channelRunData = *(iter->second);
56 
57 
58  ChannelInfo& chInfo = fChannelInfos[channel];
59  chInfo.fdt = (Long64_t)1e9/channelRunData.fSamplingFrequency;
60 
61  // round to sample size
62  if(fmSecLeft != 0) chInfo.fCorrectednSecLeft = llround(fmSecLeft*1e6/chInfo.fdt)*chInfo.fdt;
63  else chInfo.fCorrectednSecLeft = 0LL;
64  if(fmSecRight != 0) chInfo.fCorrectednSecRight = llround(fmSecRight*1e6/chInfo.fdt)*chInfo.fdt;
65  else chInfo.fCorrectednSecRight = 0LL;
66  chInfo.fBlackSheep = false;
67 
68  // force even number of samples
69  int numberOfSamples = channelRunData.fNumberOfSamples + (chInfo.fCorrectednSecLeft + chInfo.fCorrectednSecRight) / chInfo.fdt;
70  if(numberOfSamples%2 != 0) {
71  if(fmSecLeft != 0) chInfo.fCorrectednSecLeft -= chInfo.fdt;
72  else if(fmSecRight != 0) chInfo.fCorrectednSecRight -= chInfo.fdt;
73  numberOfSamples = channelRunData.fNumberOfSamples + (chInfo.fCorrectednSecLeft + chInfo.fCorrectednSecRight) / chInfo.fdt;
74  }
75 
76  // overwrite QRunData. This hack is something you should not teach to younger generations.
77  if(fOverWritePulse) {
78  // void* cast to break the 'const' wall.
79  void* rdv = (void*)&channelRunData;
80  QChannelRunData* rd = (QChannelRunData*)rdv;
81  rd->fNumberOfSamples = numberOfSamples;
82  }
83  iter++;
84  }
85  GlobalData().Set(&rHandle,"CurrentWriter");
86  }
87 
88  const QPulseInfo& inputPI = ev.Get<QPulseInfo>(fInputOwner.c_str(),"PulseInfo");
89  const int channel = inputPI.GetChannelId();
90 
91  if(fChannelInfos.find(channel) == fChannelInfos.end()) {
92  Warn("Channel %d was not found in QRunData and will not be customized",channel);
93  ChannelInfo& chInfo = fChannelInfos[channel];
94  chInfo.fBlackSheep = true;
95 
96  }
97 
98  const ChannelInfo& chInfo = fChannelInfos[channel];
99  if(chInfo.fBlackSheep) return ACT_NEXTEV;
100 
101  Long64_t start = filler->GetStartTime()-chInfo.fCorrectednSecLeft;
102  Long64_t stop = filler->GetStopTime()+chInfo.fCorrectednSecRight;
103 
104  QPulse outputPulse;
105  QPulseInfo outputPI;
106  if(start >= 0 && stop <= fRunDuration) {
107  outputPulse.SetPulseFiller(*filler);
108  outputPulse.GetPulseFiller()->SetStartTime(start);
109  outputPulse.GetPulseFiller()->SetStopTime(stop);
110  outputPulse.Validate();
111  outputPI = inputPI;
112  QSampleInfo& MS = outputPI.GetMasterSample();
113  MS.SetSampleIndex(MS.GetSampleIndex()+chInfo.fCorrectednSecLeft/chInfo.fdt);
114  std::vector<QSampleInfo>& SI = outputPI.GetSamplesInfo();
115  for(size_t s = 0; s < SI.size(); s++)
116  SI[s].SetSampleIndex(SI[s].GetSampleIndex()+chInfo.fCorrectednSecLeft/chInfo.fdt);
117  outputPI.Validate();
118  } else {
119  Warn("Event number %d (Channel %d) is skipped since there are not enough data to build the waveform",header.GetEventNumber(),channel);
120  return ACT_SKIP;
121  }
122  if(fOverWritePulse) {
123  eva.Get<QPulse>(fInputOwner.c_str(),"Pulse") = outputPulse;
124  eva.Get<QPulseInfo>(fInputOwner.c_str(),"PulseInfo") = outputPI;
125  } else {
126  ev.Get<QPulse>("Pulse") = outputPulse ;
127  ev.Get<QPulseInfo>("PulseInfo") = outputPI ;
128  }
129  return ACT_NEXTEV;
130 
131 }
132 
134 {
135  return ACT_NEXTEV;
136 }
137 
QRunDataHandle rHandle(753)
const int channel
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
modifies pretrigger and lenght of an input QPulse
QDriver::Action Do(Diana::QEventAssembler &ev)
Do method. Declare and implement only one of the two versions.
QDriver::Action Done()
Done method.
QDriver::Action Init(Diana::QEventAssembler &ev)
Init method.
basic channel and run based info. Used in the QRunData object.
double fSamplingFrequency
sampling frequency in Hz
int fNumberOfSamples
number of samples in ADC window
class to store ActionId and fEventNumber (in case fActionId=ACT_GOTOEV)
Definition: QDriver.hh:59
Visitor class of QEvent that provides full handling of QEvent.
QEvent & GetEvent()
Get the QEvent.
void Get(const char *owner, WriteHandle< Q > &handle)
Get QObject from the event in write mode. This method has to be called in the event loop,...
diana event
Definition: QEvent.hh:46
void Require(const std::string &owner, const std::string &name) const
notify the QEvent that we need a QObject, if not found an exception is thrown
Definition: QEvent.hh:232
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
Definition: QEvent.hh:193
Raw event: basic information like run number and time.
Definition: QHeader.hh:16
int GetRun() const
destructor
Definition: QHeader.hh:22
int GetEventNumber() const
get EventNumber
Definition: QHeader.hh:25
coordinates to filla QPulse from a continuous file
Definition: QPulseFiller.hh:19
void SetStopTime(Long64_t stop)
Definition: QPulseFiller.hh:44
void SetStartTime(Long64_t start)
Definition: QPulseFiller.hh:42
Raw event: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
const QSampleInfo & GetMasterSample() const
Get MasterSample.
Definition: QPulseInfo.hh:26
const std::vector< QSampleInfo > & GetSamplesInfo() const
Get Samples Info.
Definition: QPulseInfo.hh:31
const int & GetChannelId() const
Get ChannelId.
Definition: QPulseInfo.hh:22
Raw event: sampled waveform.
Definition: QPulse.hh:22
const QPulseFiller * GetPulseFiller() const
Get QPulseFiller.
Definition: QPulse.hh:48
void SetPulseFiller(const QPulseFiller &filler)
Set QPulseFiller as input from continuous files.
Definition: QPulse.cc:81
global handle for QRunData
Basic run based info.
Definition: QRunData.hh:20
contains information on flagged samples
Definition: QSampleInfo.hh:24
Int_t GetSampleIndex() const
Get SampleIndex from the beginning of the waveform.
Definition: QSampleInfo.hh:51
void SetSampleIndex(Int_t index)
Set SampleIndex.
Definition: QSampleInfo.hh:79
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...