5#include "TRestRawReadoutMetadataProcess.h"
7#include <TRestDetectorReadout.h>
8#include <TRestRawPeaksFinderProcess.h>
9#include <TRestRawReadoutMetadata.h>
10#include <TRestRawSignalAnalysisProcess.h>
20mutex TRestRawReadoutMetadataProcess::fMetadataMutex = {};
24 cerr <<
"TRestRawReadoutMetadata::InitializeFromReadout: readout is null" << endl;
28 for (
int planeIndex = 0; planeIndex < readout->GetNumberOfReadoutPlanes(); planeIndex++) {
30 for (
unsigned int moduleIndex = 0; moduleIndex < plane->GetNumberOfModules(); moduleIndex++) {
31 const auto module = plane->
GetModule(moduleIndex);
32 for (
unsigned int channelIndex = 0; channelIndex < module->GetNumberOfChannels();
34 const auto channel = module->
GetChannel(channelIndex);
35 const UShort_t channelDaqId = channel->
GetDaqID();
37 if (fChannelInfo.find(channelDaqId) != fChannelInfo.end()) {
38 cerr <<
"TRestRawReadoutMetadata::InitializeFromReadout: channel id " << channelDaqId
39 <<
" already in the map. Channels on the readout should be unique" << endl;
43 info.type = channel->GetChannelType();
44 info.name = channel->GetChannelName();
45 info.channelId = channel->GetChannelId();
46 if (info.name.empty()) {
47 info.name =
"daqid" + to_string(info.channelId);
50 fChannelInfo[channel->GetDaqID()] = info;
56 if (fChannelInfo.empty() || fChannelInfo.size() != (
size_t)readout->
GetNumberOfChannels()) {
57 cerr <<
"TRestRawReadoutMetadata::InitializeFromReadout: channel info is empty or size is different "
58 "from readout number of channels"
64 for (
const auto& channel : fChannelInfo) {
65 const auto& info = channel.second;
66 channelIds.insert(info.channelId);
68 if (channelIds.size() != fChannelInfo.size()) {
69 cerr <<
"TRestRawReadoutMetadata::InitializeFromReadout: channel ids are not unique" << endl;
72 map<string, int> namesCount;
73 for (
const auto& channel : fChannelInfo) {
74 const auto& info = channel.second;
75 namesCount[info.name]++;
77 for (
const auto& name : namesCount) {
78 if (name.second > 1) {
79 cerr <<
"TRestRawReadoutMetadata::InitializeFromReadout: channel name " << name.first
80 <<
" is not unique" << endl;
86Int_t TRestRawReadoutMetadata::GetChannelIdForChannelDaqId(UShort_t channel)
const {
87 if (fChannelInfo.find(channel) == fChannelInfo.end()) {
90 return fChannelInfo.at(channel).channelId;
94 fReadout = GetMetadata<TRestDetectorReadout>();
96 cerr <<
"TRestRawReadoutMetadataProcess::InitProcess: readout is null" << endl;
100 std::lock_guard<std::mutex> lock(fMetadataMutex);
102 if (!fReadoutMetadata) {
103 fReadoutMetadata = GetMetadata<TRestRawReadoutMetadata>();
104 if (!fReadoutMetadata) {
106 fReadoutMetadata->InitializeFromReadout(fReadout);
109 fReadoutMetadata->SetName(
"readoutRawMetadata");
Int_t GetDaqID() const
Returns the corresponding daq channel id.
TRestDetectorReadoutChannel * GetChannel(size_t n)
Returns a pointer to a readout channel by index.
TRestDetectorReadoutModule * GetModule(size_t mod)
Returns a pointer to a readout module using its std::vector index.
A metadata class to generate/store a readout description.
Int_t GetNumberOfChannels()
Returns the total number of channels implemented in all the readout planes and modules.
TRestDetectorReadoutPlane * GetReadoutPlane(int p)
Returns a pointer to the readout plane by index.
TRestRun * GetRunInfo() const
Return the pointer of the hosting TRestRun object.
A base class for any REST event.
An event container for time rawdata signals with fixed length.
void AddMetadata(TRestMetadata *meta)
add metadata object to the metadata list