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 ----
43uint32_t CbmTrdUnpackAlgoBaseR::getAsicAddress(uint32_t criid, uint32_t crobid, 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 ----
60uint32_t CbmTrdUnpackAlgoBaseR::getChannelId(uint32_t asicaddress, uint32_t elinkid, uint32_t elinkchannelid)
61{
62 // 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
63 auto asicChannelId =
64 (elinkid % 2) == fIsFirstChannelsElinkEven ? elinkchannelid : elinkchannelid + (CbmTrdSpadic::GetNrChannels() / 2);
65
66 auto channelId = (fAsicChannelMap.find(asicaddress))->second.at(asicChannelId);
67
68 return channelId;
69}
70
71// ---- initParSet(FairParGenericSet* parset) ----
72Bool_t CbmTrdUnpackAlgoBaseR::initParSet(FairParGenericSet* parset)
73{
74 LOG(info) << fName << "::initParSet - for container " << parset->ClassName();
75 if (parset->IsA() == CbmTrdParSetAsic::Class()) return initParSet(static_cast<CbmTrdParSetAsic*>(parset));
76
77 if (parset->IsA() == CbmTrdParSetDigi::Class()) return initParSet(static_cast<CbmTrdParSetDigi*>(parset));
78
79 if (parset->IsA() == CbmMcbm2020TrdTshiftPar::Class())
80 return initParSet(static_cast<CbmMcbm2020TrdTshiftPar*>(parset));
81
82 // If we do not know the derived ParSet class we return false
83 LOG(error)
84 << fName << "::initParSet - for container " << parset->ClassName()
85 << " failed, since CbmTrdUnpackAlgoBaseR::initParSet() does not know the derived ParSet and what to do with it!";
86 return kFALSE;
87}
88
89// ---- initParSet(CbmTrdParSetAsic* parset) ----
91{
92 LOG(debug) << fName << "::initParSetAsic - ";
95 if (fSpadicAddressMap.empty()) {
96 LOG(error) << fName << "::initParSetAsic - SpadicAddressMap creation failed, the map is empty";
97 return kFALSE;
98 }
99 // at least check that the loaded map is not empty
100
101 fAsicChannelMap = hwSetup.CreateAsicChannelMap(parset);
102 if (fAsicChannelMap.empty()) {
103 LOG(error) << fName << "::initParSetAsic - AsicChannelMap creation failed, the map is empty";
104 return kFALSE;
105 }
106
107
108 LOG(info) << fName << "::initParSetAsic - Successfully initialized Spadic hardware address map";
109
110 return kTRUE;
111}
112
113// ---- initParSet(CbmTrdParSetDigi* parset) ----
115{
116 Bool_t initOk = kTRUE;
117 // The monitor needs the ParSetDigi to extract module informations and other stuff
118 if (fMonitor) {
119 LOG(info) << fName << "::initParSet(CbmTrdParSetDigi) - Forwarding ParSetDigi to the monitor";
120 CbmTrdParSetAsic* asics(nullptr);
121 for (auto pair : fParContVec) {
122 if ((pair.second).get()->IsA() != CbmTrdParSetAsic::Class()) continue;
123 asics = static_cast<CbmTrdParSetAsic*>((pair.second).get());
124 }
125 initOk &= fMonitor->Init(parset, asics);
126 fMonitor->SetDigiOutputVec(&fOutputVec);
127 }
128
129 return initOk;
130}
131
132// ---- initParSet(CbmMcbm2020TrdTshiftPar* parset) ----
134{
135 auto maptimeshifts = parset->GetTimeshiftsMap();
136 fTimeshiftsMap.clear();
137 fTimeshiftsMap.insert(maptimeshifts->begin(), maptimeshifts->end());
138 LOG(info) << fName << "::initParSetTimeshift2020() - Parsing timeshift correction map to unpacker algo";
139
140 return (!fTimeshiftsMap.empty());
141}
142
143// ---- initR ----
145{
146 auto initOk = kTRUE;
147 // 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.
148 if (!fSpadic) {
149 // First we check if there is a spadic definition stored in the raw to digi method
150 if (fRTDMethod) fSpadic = fRTDMethod->GetSpadicObject();
151 // If we still do not have spadic, we create it on our own
152 if (!fSpadic) fSpadic = std::make_shared<CbmTrdSpadic>();
153 }
154 if (!fSpadic) {
155 LOG(error) << fName
156 << "::initR - We are missing a CbmTrdSpadic object, to extract the basic spadic functionalities!";
157 initOk &= kFALSE;
158 }
159 if (fMonitor) fMonitor->SetSpadicObject(fSpadic);
160
161 return initOk;
162}
163
ClassImp(CbmConverterManager)
Baseclass for the TrdR unpacker algorithms.
bool Bool_t
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.
virtual uint32_t getAsicAddress(uint32_t criid, uint32_t crobid, uint32_t elinkid)
Get the Asic Address (CbmAddress scheme) for the given hardware Ids.
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.
uint32_t getChannelId(uint32_t asicaddress, uint32_t elinkid, uint32_t elinkchannelid)
Get the Channel Id (CbmAddress scheme) for the given hardware Ids.
CbmTrdUnpackAlgoBaseR(std::string name)
Create the Cbm Trd Unpack AlgoBase object.
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 micro-Slice timeshifts....