forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTOFFEElightReader.cxx
More file actions
130 lines (114 loc) · 5.26 KB
/
TOFFEElightReader.cxx
File metadata and controls
130 lines (114 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <TOFCalibration/TOFFEElightReader.h>
#include "Framework/Logger.h"
#include "TSystem.h"
#include <fstream>
using namespace o2::tof;
void TOFFEElightReader::loadFEElightConfig(const char* fileName)
{
// load FEElight config
char* expandedFileName = gSystem->ExpandPathName(fileName);
std::ifstream is;
is.open(expandedFileName, std::ios::binary);
mFileLoadBuff.reset(new char[sizeof(o2::tof::TOFFEElightConfig)]);
is.read(mFileLoadBuff.get(), sizeof(o2::tof::TOFFEElightConfig));
is.close();
mFEElightConfig = reinterpret_cast<const TOFFEElightConfig*>(mFileLoadBuff.get());
}
//_______________________________________________________________
void TOFFEElightReader::loadFEElightConfig(gsl::span<const char> configBuf)
{
// load FEElight config from buffer
if (configBuf.size() != sizeof(o2::tof::TOFFEElightConfig)) {
LOG(fatal) << "Incoming message with TOFFEE configuration does not match expected size: " << configBuf.size() << " received, " << sizeof(*mFEElightConfig) << " expected";
}
mFEElightConfig = reinterpret_cast<const TOFFEElightConfig*>(configBuf.data());
}
//_______________________________________________________________
int TOFFEElightReader::parseFEElightConfig(bool verbose)
{
// parse FEElight config
// loops over all FEE channels, checks whether they are enabled
// and sets channel enabled
mFEElightInfo.resetAll();
int version = mFEElightConfig->mVersion;
int runNumber = mFEElightConfig->mRunNumber;
int runType = mFEElightConfig->mRunType;
mFEElightInfo.mVersion = version;
mFEElightInfo.mRunNumber = runNumber;
mFEElightInfo.mRunType = runType;
int nEnabled = 0, index;
const TOFFEEchannelConfig* channelConfig = nullptr;
for (int crateId = 0; crateId < Geo::kNCrate; crateId++) {
for (int trmId = 0; trmId < Geo::kNTRM - 2; trmId++) { // in O2, the number of TRMs is 12, but in the FEE world it is 10
for (int chainId = 0; chainId < Geo::kNChain; chainId++) {
for (int tdcId = 0; tdcId < Geo::kNTdc; tdcId++) {
for (int channelId = 0; channelId < Geo::kNCh; channelId++) {
channelConfig = mFEElightConfig->getChannelConfig(crateId, trmId, chainId, tdcId, channelId);
if (verbose) {
LOG(info) << "Processing electronic channel with indices: crate = " << crateId << ", trm = " << trmId << ", chain = "
<< chainId << ", tdc = " << tdcId << ", tdcChannel = " << channelId << " -> " << channelConfig;
}
if (channelConfig) {
if (!channelConfig->isEnabled()) {
continue;
}
// get index DO from crate, trm, chain, tdc, tdcchannel
index = Geo::getCHFromECH(Geo::getECHFromIndexes(crateId, trmId + 3, chainId, tdcId, channelId)); // in O2, the TRM index is shifted by 3 because it corresponds to the VME slot
if (index == -1) {
continue;
}
nEnabled++;
if (verbose) {
LOG(info) << "Enabling channel " << index;
}
mFEElightInfo.mChannelEnabled[index] = channelConfig->isEnabled();
mFEElightInfo.mMatchingWindow[index] = channelConfig->mMatchingWindow;
mFEElightInfo.mLatencyWindow[index] = channelConfig->mLatencyWindow;
}
}
}
}
}
}
const int istripInPlate[Geo::NSECTORS] = {Geo::NSTRIPC, Geo::NSTRIPB, Geo::NSTRIPA, Geo::NSTRIPB, Geo::NSTRIPC};
const int channelInSector = Geo::NPADS * Geo::NSTRIPXSECTOR;
for (int isector = 0; isector < Geo::NSECTORS; isector++) {
int nstripInPrevPlates = 0;
for (int iplate = 0; iplate < Geo::NPLATES; iplate++) {
unsigned int mask = mFEElightConfig->getHVConfig(isector, iplate);
for (int istrip = 0; istrip < istripInPlate[iplate]; istrip++) {
bool isActive = mask & 1; // check first bit/current_strip
mask /= 2; // move to the next bit/strip
if (!isActive) { // switch off all channels in this strip
int index0 = isector * channelInSector + (nstripInPrevPlates + istrip) * Geo::NPADS;
int indexF = index0 + Geo::NPADS;
for (int index = index0; index < indexF; index++) {
mFEElightInfo.mChannelEnabled[index] = 0;
}
}
}
nstripInPrevPlates += istripInPlate[iplate];
}
}
const TOFFEEtriggerConfig* triggerConfig = nullptr;
for (Int_t iddl = 0; iddl < TOFFEElightConfig::NTRIGGERMAPS; iddl++) {
triggerConfig = mFEElightConfig->getTriggerConfig(iddl);
if (verbose) {
LOG(info) << "Processing trigger config " << iddl << ": " << triggerConfig;
}
if (triggerConfig) {
mFEElightInfo.mTriggerMask[iddl] = triggerConfig->mStatusMap;
}
}
return nEnabled;
}