CbmRecoUnpack.cxx 5.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
/** @file CbmRecoUnpack.cxx
 ** @copyright Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
 ** @license SPDX-License-Identifier: GPL-3.0-only
 ** @author Volker Friese [originator]
 **/


#include "CbmRecoUnpack.h"

10
#include "CbmTrdDigi.h"
11
12
#include "CbmTsEventHeader.h"

13
14
15
16
17
#include "MicrosliceDescriptor.hpp"

#include <FairRootManager.h>
#include <Logger.h>

18
19
20
21
#include <RtypesCore.h>

#include <cstddef>
#include <memory>
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <utility>
#include <vector>


using fles::Timeslice;
using std::unique_ptr;


// -----   Constructor   ------------------------------------------------------
CbmRecoUnpack::CbmRecoUnpack() {}
// ----------------------------------------------------------------------------


// -----   Initialisation   ---------------------------------------------------
void CbmRecoUnpack::Finish()
{
38
  LOG(info) << "CbmRecoUnpack::Finish() I do let the unpackers talk first :\n";
39
40
41
42

  if (fPsdConfig) fPsdConfig->GetUnpacker()->Finish();
  if (fRichConfig) fRichConfig->GetUnpacker()->Finish();
  if (fStsConfig) fStsConfig->GetUnpacker()->Finish();
43
  if (fTofConfig) fTofConfig->GetUnpacker()->Finish();
44
45
  if (fTrdConfig) fTrdConfig->GetUnpacker()->Finish();
  if (fTrdConfig2D) fTrdConfig2D->GetUnpacker()->Finish();
46
47
48
49
50
51
52
53
54
55
56
}

// ----------------------------------------------------------------------------

// -----   Initialisation   ---------------------------------------------------
Bool_t CbmRecoUnpack::Init()
{

  FairRootManager* ioman = FairRootManager::Instance();
  assert(ioman);

57
58
59
60
61
62
63

  auto eh = FairRun::Instance()->GetEventHeader();
  if (eh->IsA() == CbmTsEventHeader::Class()) fCbmTsEventHeader = static_cast<CbmTsEventHeader*>(eh);
  else
    LOG(fatal)
      << "CbmRecoUnpack::Init() no CbmTsEventHeader was added to the run. Without it, we can not store the UTC of the "
         "Timeslices correctly. Hence, this causes a fatal. Please add it in the steering macro to the Run.";
64
65
66
67
68
69
70
71
72
73
74
75
76


  // --- Psd
  if (fPsdConfig) fPsdConfig->Init(ioman);
  // --- Rich
  if (fRichConfig) fRichConfig->Init(ioman);
  // --- Sts
  if (fStsConfig) fStsConfig->Init(ioman);
  // --- Tof
  // if (fTofConfig) fTofConfig->Init(ioman);
  // --- Trd
  if (fTrdConfig) fTrdConfig->Init(ioman);
  // --- TRD2D
77
  if (fTrdConfig2D->GetOutputBranchName() == fTrdConfig->GetOutputBranchName()) {
78
79
80
81
    fTrdConfig2D->SetOutputVec(fTrdConfig->GetOutputVec());
    if (fTrdConfig2D) fTrdConfig2D->InitUnpacker();
  }
  else {
82
    if (fTrdConfig2D) fTrdConfig2D->Init(ioman);
83
84
  }
  // This is an ugly work around, because the TRD and TRD2D want to access the same vector and there is no function to retrieve a writeable vector<obj> from the FairRootManager, especially before the branches are created, as far as I am aware. The second option workaround is in in Init() to look for the fasp config and create a separate branch for fasp created CbmTrdDigis PR 072021
85
86
  // --- Tof
  if (fTofConfig) fTofConfig->Init(ioman);
87
88
89
90
91
92
93
94
95
96
97

  return kTRUE;
}
// ----------------------------------------------------------------------------


// -----   Reset   ------------------------------------------------------------
void CbmRecoUnpack::Reset()
{
  // Reset the unpackers for a new timeslice, e.g. clear the output vectors

98
  // ---- Psd ----
Pascal Raisig's avatar
Pascal Raisig committed
99
  if (fPsdConfig) fPsdConfig->Reset();
100
  // ---- Rich ----
Pascal Raisig's avatar
Pascal Raisig committed
101
  if (fRichConfig) fRichConfig->Reset();
102
  // ---- Sts ----
Pascal Raisig's avatar
Pascal Raisig committed
103
  if (fStsConfig) fStsConfig->Reset();
104
  // ---- Tof ----
Pascal Raisig's avatar
Pascal Raisig committed
105
  // if (fTofConfig) fTofConfig->Reset();
106
  // ---- Trd ----
Pascal Raisig's avatar
Pascal Raisig committed
107
  if (fTrdConfig) fTrdConfig->Reset();
108
  // ---- Trd2D ----
Pascal Raisig's avatar
Pascal Raisig committed
109
  if (fTrdConfig2D) fTrdConfig2D->Reset();
110
111
  // ---- Tof ----
  if (fTofConfig) fTofConfig->Reset();
112
113
114
115
116
117
118
119
120
121
}

// ----------------------------------------------------------------------------

// -----   Unpacking   --------------------------------------------------------
void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts)
{
  // Prepare timeslice
  const fles::Timeslice& timeslice = *ts;

122
123
  fCbmTsEventHeader->SetTsStartTime(ts->start_time());

124
  uint64_t nComponents = ts->num_components();
Pascal Raisig's avatar
Pascal Raisig committed
125
126
  // if (fDoDebugPrints) LOG(info) << "Unpack: TS index " << ts->index() << " components " << nComponents;
  LOG(info) << "Unpack: TS index " << ts->index() << " components " << nComponents;
127
128
129
130
131
132

  for (uint64_t component = 0; component < nComponents; component++) {

    auto systemId = static_cast<std::uint16_t>(ts->descriptor(component, 0).sys_id);

    switch (systemId) {
133
134
      case fkFlesPsd: {
        if (fPsdConfig)
Pascal Raisig's avatar
Pascal Raisig committed
135
          fCbmTsEventHeader->SetNDigisPsd(
136
137
138
            unpack(&timeslice, component, fPsdConfig, fPsdConfig->GetOptOutAVec(), fPsdConfig->GetOptOutBVec()));
        break;
      }
139
140
141
142
143
144
      case fkFlesRich: {
        if (fRichConfig)
          fCbmTsEventHeader->SetNDigisRich(
            unpack(&timeslice, component, fRichConfig, fRichConfig->GetOptOutAVec(), fRichConfig->GetOptOutBVec()));
        break;
      }
145
146
147
148
149
150
      case fkFlesSts: {
        if (fStsConfig)
          fCbmTsEventHeader->SetNDigisSts(
            unpack(&timeslice, component, fStsConfig, fStsConfig->GetOptOutAVec(), fStsConfig->GetOptOutBVec()));
        break;
      }
151
152
      case fkFlesTrd: {
        if (fTrdConfig)
153
154
155
156
157
158
159
160
          fCbmTsEventHeader->SetNDigisTrd(
            unpack(&timeslice, component, fTrdConfig, fTrdConfig->GetOptOutAVec(), fTrdConfig->GetOptOutBVec()));
        break;
      }
      case fkFlesTrd2D: {
        if (fTrdConfig2D)
          fCbmTsEventHeader->SetNDigisTrd2D(
            unpack(&timeslice, component, fTrdConfig2D, fTrdConfig2D->GetOptOutAVec(), fTrdConfig2D->GetOptOutBVec()));
161
        break;
162
      }
163
164
165
166
167
168
      case fkFlesTof: {
        if (fTofConfig)
          fCbmTsEventHeader->SetNDigisTof(
            unpack(&timeslice, component, fTofConfig, fTofConfig->GetOptOutAVec(), fTofConfig->GetOptOutBVec()));
        break;
      }
169
170
171
172
173
174
175
176
177
178
179
180

      default: {
        if (fDoDebugPrints) LOG(error) << "Unpack: Unknown system ID " << systemId << " for component " << component;
        break;
      }
    }
  }
}
// ----------------------------------------------------------------------------


ClassImp(CbmRecoUnpack)