CbmRoot
Loading...
Searching...
No Matches
CbmTrdUnpackAlgoBaseR.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 Goethe-University Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pascal Raisig [committer] */
4
6
8#include "CbmTrdDigi.h"
9#include "CbmTrdHardwareSetupR.h" // for channel address parameters
10#include "CbmTrdParSetAsic.h"
11
12#include <FairParGenericSet.h>
13#include <FairTask.h>
14#include <Logger.h>
15
16#include <Rtypes.h>
17#include <RtypesCore.h>
18
19
20CbmTrdUnpackAlgoBaseR::CbmTrdUnpackAlgoBaseR(std::string name) : CbmRecoUnpackAlgo(name) {}
21
23
24// ---- digestOutput ----
25void CbmTrdUnpackAlgoBaseR::digestOutput(std::unique_ptr<CbmTrdDigi> digi, CbmTrdRawMessageSpadic raw)
26{
27 // If requested lets monitor something
28 if (fMonitor) {
29 fMonitor->FillHistos(digi.get(), &raw);
30 }
31
32 // Save raw message:
33 if (fOptOutAVec) {
34 fOptOutAVec->emplace_back(raw);
35 }
36
37
38 // Save the digi
39 fOutputVec.emplace_back(*std::move(digi));
40}
41
42// ---- getAsicAddress ----
43std::uint32_t CbmTrdUnpackAlgoBaseR::getAsicAddress(std::uint32_t criid, std::uint32_t crobid, std::uint32_t elinkid)
44{
45 size_t spadicHwAddress = 0;
46 spadicHwAddress = elinkid + (CbmTrdParAsic::kCriIdPosition * criid) + (CbmTrdParAsic::kCrobIdPosition * crobid);
47 auto mapIt = fSpadicAddressMap.find(spadicHwAddress); // check if asic exists
48 if (mapIt == fSpadicAddressMap.end()) {
49 LOG(info) << fName
50 << "::makeDigi - No asic address "
51 "found for Spadic hardware address "
52 << spadicHwAddress;
53 return 0;
54 }
55
56 return mapIt->second;
57}
58
59// ---- getAsicAddress ----
60std::uint32_t CbmTrdUnpackAlgoBaseR::getChannelId(std::uint32_t asicaddress, std::uint32_t elinkid,
61 std::uint32_t elinkchannelid)
62{
63 // GetChannelId per eLink add NSPADICCH / 2 to the second(first) eLink in the case we start with odd(even) eLinks, since, our mapping is based on odd eLinks
64 auto asicChannelId =
65 (elinkid % 2) == fIsFirstChannelsElinkEven ? elinkchannelid : elinkchannelid + (CbmTrdSpadic::GetNrChannels() / 2);
66
67 auto channelId = (fAsicChannelMap.find(asicaddress))->second.at(asicChannelId);
68
69 return channelId;
70}
71
72// ---- initParSet(FairParGenericSet* parset) ----
73Bool_t CbmTrdUnpackAlgoBaseR::initParSet(FairParGenericSet* parset)
74{
75 LOG(info) << fName << "::initParSet - for container " << parset->ClassName();
76 if (parset->IsA() == CbmTrdParSetAsic::Class()) return initParSet(static_cast<CbmTrdParSetAsic*>(parset));
77
78 if (parset->IsA() == CbmTrdParSetDigi::Class()) return initParSet(static_cast<CbmTrdParSetDigi*>(parset));
79
80 if (parset->IsA() == CbmMcbm2020TrdTshiftPar::Class())
81 return initParSet(static_cast<CbmMcbm2020TrdTshiftPar*>(parset));
82
83 // If we do not know the derived ParSet class we return false
84 LOG(error)
85 << fName << "::initParSet - for container " << parset->ClassName()
86 << " failed, since CbmTrdUnpackAlgoBaseR::initParSet() does not know the derived ParSet and what to do with it!";
87 return kFALSE;
88}
89
90// ---- initParSet(CbmTrdParSetAsic* parset) ----
92{
93 LOG(debug) << fName << "::initParSetAsic - ";
96 if (fSpadicAddressMap.empty()) {
97 LOG(error) << fName << "::initParSetAsic - SpadicAddressMap creation failed, the map is empty";
98 return kFALSE;
99 }
100 // at least check that the loaded map is not empty
101
102 fAsicChannelMap = hwSetup.CreateAsicChannelMap(parset);
103 if (fAsicChannelMap.empty()) {
104 LOG(error) << fName << "::initParSetAsic - AsicChannelMap creation failed, the map is empty";
105 return kFALSE;
106 }
107
108
109 LOG(info) << fName << "::initParSetAsic - Successfully initialized Spadic hardware address map";
110
111 return kTRUE;
112}
113
114// ---- initParSet(CbmTrdParSetDigi* parset) ----
116{
117 Bool_t initOk = kTRUE;
118 // The monitor needs the ParSetDigi to extract module informations and other stuff
119 if (fMonitor) {
120 LOG(info) << fName << "::initParSet(CbmTrdParSetDigi) - Forwarding ParSetDigi to the monitor";
121 CbmTrdParSetAsic* asics(nullptr);
122 for (auto pair : fParContVec) {
123 if ((pair.second).get()->IsA() != CbmTrdParSetAsic::Class()) continue;
124 asics = static_cast<CbmTrdParSetAsic*>((pair.second).get());
125 }
126 initOk &= fMonitor->Init(parset, asics);
127 fMonitor->SetDigiOutputVec(&fOutputVec);
128 }
129
130 return initOk;
131}
132
133// ---- initParSet(CbmMcbm2020TrdTshiftPar* parset) ----
135{
136 auto maptimeshifts = parset->GetTimeshiftsMap();
137 fTimeshiftsMap.clear();
138 fTimeshiftsMap.insert(maptimeshifts->begin(), maptimeshifts->end());
139 LOG(info) << fName << "::initParSetTimeshift2020() - Parsing timeshift correction map to unpacker algo";
140
141 return (!fTimeshiftsMap.empty());
142}
143
144// ---- initR ----
146{
147 auto initOk = kTRUE;
148 // Check if we have already a Spadic object. If not check if we have a raw to digi object, it has by default a Spadic object. If we do not have a rtd object we create a default spadic object on our own.
149 if (!fSpadic) {
150 // First we check if there is a spadic definition stored in the raw to digi method
151 if (fRTDMethod) fSpadic = fRTDMethod->GetSpadicObject();
152 // If we still do not have spadic, we create it on our own
153 if (!fSpadic) fSpadic = std::make_shared<CbmTrdSpadic>();
154 }
155 if (!fSpadic) {
156 LOG(error) << fName
157 << "::initR - We are missing a CbmTrdSpadic object, to extract the basic spadic functionalities!";
158 initOk &= kFALSE;
159 }
160 if (fMonitor) fMonitor->SetSpadicObject(fSpadic);
161
162 return initOk;
163}
164
ClassImp(CbmConverterManager)
Baseclass for the TrdR unpacker algorithms.
std::map< size_t, std::vector< Int_t > > * GetTimeshiftsMap()
Return the timeshift map.
std::map< size_t, Int_t > CreateHwToSwAsicAddressTranslatorMap(bool isLoadedParameters)
Create a hardware to software asic addreess translator map, with hidden parameter loading.
std::map< Int_t, std::vector< Int_t > > CreateAsicChannelMap(bool isLoadedParameters)
Create a Asic Channel Map, with hidden parameter loading.
Describe TRD module ASIC settings (electronic gain, delays, etc)
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
static UInt_t GetNrChannels()
std::shared_ptr< CbmTrdRawToDigiBaseR > fRTDMethod
raw to digi extraction method, set in the task
std::map< Int_t, std::vector< Int_t > > fAsicChannelMap
Map to retrieve module channelId from asicAddress and asicChannel.
void digestOutput(std::unique_ptr< CbmTrdDigi > digi, CbmTrdRawMessageSpadic raw)
Handle the output created by the explicit algorithms. E.g. write to output vectors.
Bool_t initParSet(FairParGenericSet *parset)
Handles the distribution of the hidden derived classes to their explicit functions.
std::shared_ptr< CbmTrdUnpackMonitor > fMonitor
Potential (online) monitor for the unpacking process.
std::shared_ptr< CbmTrdSpadic > fSpadic
Spadic software reprensentation object.
virtual Bool_t init()
Additional initialisation function for all BaseR derived algorithms.
virtual std::uint32_t getAsicAddress(std::uint32_t criid, std::uint32_t crobid, std::uint32_t elinkid)
Get the Asic Address (CbmAddress scheme) for the given hardware Ids.
CbmTrdUnpackAlgoBaseR(std::string name)
Create the Cbm Trd Unpack AlgoBase object.
std::uint32_t getChannelId(std::uint32_t asicaddress, std::uint32_t elinkid, std::uint32_t elinkchannelid)
Get the Channel Id (CbmAddress scheme) for the given hardware Ids.
Bool_t fIsFirstChannelsElinkEven
Define if the first 16 channels (00..15) are found on the even (set true) or odd (false) eLinkId....
virtual ~CbmTrdUnpackAlgoBaseR()
Destroy the Cbm Trd Unpack Task object.
std::map< size_t, Int_t > fSpadicAddressMap
Map to retrieve asic address from CriId/CrobId/ElinkId (see CbmTrdHardwareSetupR)
std::map< size_t, std::vector< Int_t > > fTimeshiftsMap
Map containing the timeshift parameters for the correction of the µSlice timeshifts....