REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorDaqChannelSwitchingProcess.cxx
1
16
17#include "TRestDetectorDaqChannelSwitchingProcess.h"
18
19#include <TLegend.h>
20#include <TPaveText.h>
21
22using namespace std;
23
25
26TRestDetectorDaqChannelSwitchingProcess::TRestDetectorDaqChannelSwitchingProcess() { Initialize(); }
27
28TRestDetectorDaqChannelSwitchingProcess::~TRestDetectorDaqChannelSwitchingProcess() {}
29
31 SetLibraryVersion(LIBRARY_VERSION);
32 SetSectionName(this->ClassName());
33
34 fFirstDaqChannelDef.clear();
35 fIgnoreUndefinedModules = false;
36 fReadout = nullptr;
37 fEvent = nullptr;
38}
39
41 fReadout = GetMetadata<TRestDetectorReadout>();
42 if (fReadout != nullptr) {
43 auto iter = fFirstDaqChannelDef.begin();
44 while (iter != fFirstDaqChannelDef.end()) {
45 auto mod = fReadout->GetReadoutModuleWithID(iter->first);
46 if (mod == nullptr) continue;
47 // finding out the old "firstdaqchannel" value
48 int mindaq = std::numeric_limits<Int_t>::max();
49 for (size_t i = 0; i < mod->GetNumberOfChannels(); i++) {
50 if (mod->GetChannel(i)->GetDaqID() < mindaq) {
51 mindaq = mod->GetChannel(i)->GetDaqID();
52 }
53 }
54
55 // re-setting the value
56 for (size_t i = 0; i < mod->GetNumberOfChannels(); i++) {
57 mod->GetChannel(i)->SetDaqID(mod->GetChannel(i)->GetDaqID() - mindaq + iter->second);
58 }
59
60 iter++;
61 }
62
63 if (fIgnoreUndefinedModules) {
64 for (int i = 0; i < fReadout->GetNumberOfReadoutPlanes(); i++) {
65 TRestDetectorReadoutPlane& plane = (*fReadout)[i];
66
67 for (size_t j = 0; j < plane.GetNumberOfModules(); j++) {
68 TRestDetectorReadoutModule& mod = plane[j];
69 if (fFirstDaqChannelDef.count(mod.GetModuleID()) == 0) {
70 for (size_t i = 0; i < mod.GetNumberOfChannels(); i++) {
71 mod.GetChannel(i)->SetDaqID(-1e9);
72 }
73 }
74 }
75 }
76 }
77 }
78}
79
81 fEvent = inputEvent;
82 return inputEvent;
83}
84
86
87// redefining module's first daq channel:
88// <module id="1" firstdaqchannel="136*3" />
89// ignore undefined modules modules by setting their channel's daq id to -1e9
90// <parameter name="ignoreUndefinedModules" value="true" />
92 TiXmlElement* ele = fElement->FirstChildElement("module");
93 while (ele != nullptr) {
94 int id = StringToInteger(GetParameter("id", ele));
95 int channel = StringToInteger(GetParameter("firstdaqchannel", ele));
96 if (id == -1 || channel == -1) continue;
97 fFirstDaqChannelDef[id] = channel;
98 ele = ele->NextSiblingElement("module");
99 }
100 fIgnoreUndefinedModules = StringToBool(GetParameter("ignoreUndefinedModules", "false"));
101}
void EndProcess() override
To be executed at the end of the run (outside event loop)
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void SetDaqID(Int_t id)
Sets the daq channel number id.
Int_t GetModuleID() const
Returns the module id.
TRestDetectorReadoutChannel * GetChannel(size_t n)
Returns a pointer to a readout channel by index.
size_t GetNumberOfChannels() const
Returns the total number of channels defined inside the module.
size_t GetNumberOfModules() const
Returns the total number of modules in the readout plane.
TRestDetectorReadoutModule * GetReadoutModuleWithID(int id)
Returns a pointer to the readout module by ID.
A base class for any REST event.
Definition: TRestEvent.h:38
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
TiXmlElement * fElement
Saving the sectional element together with global element.
Int_t StringToInteger(std::string in)
Gets an integer from a string.