forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.h
More file actions
221 lines (216 loc) · 8.34 KB
/
Configuration.h
File metadata and controls
221 lines (216 loc) · 8.34 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// 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.
/// \file Configuration.h
/// \brief definition of CTPConfiguration and related CTP structures
/// \author Roman Lietava
#ifndef _CTP_CONFIGURATION_H_
#define _CTP_CONFIGURATION_H_
#include "DetectorsCommonDataFormats/DetID.h"
#include "CommonConstants/LHCConstants.h"
#include "DataFormatsCTP/Scalers.h"
#include <string>
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <iosfwd>
namespace o2
{
namespace ctp
{
/// Database constants
const std::string CCDBPathCTPConfig = "CTP/Config/Config";
///
/// CTP Config items
///
// Bunch Crossing (BC) mask
struct BCMask {
BCMask() = default;
std::string name = "";
std::string mask = "";
std::bitset<o2::constants::lhc::LHCMaxBunches> BCmask;
int setBCmask(std::vector<std::string>& tokens);
void printStream(std::ostream& stream) const;
ClassDefNV(BCMask, 1);
};
/// CTP internal generator: 4 for L0 and 4 for LM levels
struct CTPGenerator {
static const std::set<std::string> Generators;
std::string name = "";
std::string frequency = "";
void printStream(std::ostream& stream) const;
ClassDefNV(CTPGenerator, 1);
};
/// CTP inputs
/// Default input config is in CTPConfiguration
struct CTPInput {
const static std::map<std::string, std::string> run2DetToRun3Det;
CTPInput() = default;
CTPInput(std::string& name, std::string& det, uint32_t index);
CTPInput(const char* name, const char* det, uint32_t index);
std::string name = "";
std::string level = "";
std::uint64_t inputMask = 0;
o2::detectors::DetID::ID detID = 16; // CTP
bool neg = 1;
uint32_t getIndex() const { return ((inputMask > 0) ? 1 + log2(inputMask) : 0xff); }
std::string getInputDetName() const { return o2::detectors::DetID::getName(detID); }
void setRun3DetName(std::string& run2Name);
void printStream(std::ostream& strem) const;
ClassDefNV(CTPInput, 3);
};
/// Descriptor = Generator or List of [negated] inputs
struct CTPDescriptor {
CTPDescriptor() = default;
std::string name = "";
std::vector<CTPInput const*> inputs;
std::uint64_t getInputsMask() const;
// void createInputsFromName();
void printStream(std::ostream& strem) const;
ClassDefNV(CTPDescriptor, 2)
};
/// The main part is Local Trigger Generator (LTG)
struct CTPDetector {
CTPDetector() = default;
o2::detectors::DetID::ID detID;
o2::detectors::DetID::mask_t getMask() const { return o2::detectors::DetID(detID).getMask(); }
const char* getName() const { return o2::detectors::DetID::getName(detID); }
uint32_t HBaccepted; /// Number of HB frames in TF to be accepted
std::string mode = "";
uint32_t ferst = 0;
void printStream(std::ostream& stream) const;
ClassDefNV(CTPDetector, 1)
};
/// List of detectors
struct CTPCluster {
CTPCluster() = default;
std::string name = "";
uint32_t hwMask = 0;
o2::detectors::DetID::mask_t maskCluster;
std::string getClusterDetNames() const { return o2::detectors::DetID::getNames(maskCluster, ' '); }
void printStream(std::ostream& strem) const;
ClassDefNV(CTPCluster, 3)
};
/// Class = Mask+Descriptor+Cluster
struct CTPClass {
CTPClass() = default;
std::string name = "";
std::uint64_t classMask = 0;
CTPDescriptor const* descriptor = nullptr;
CTPCluster const* cluster = nullptr;
int clusterIndex = 0xff;
int descriptorIndex = 0xff;
uint32_t downScale = 1;
std::vector<BCMask const*> BCClassMask;
int getIndex() const { return ((classMask > 0) ? log2(classMask) : 0xff); }
void printStream(std::ostream& strem) const;
ClassDefNV(CTPClass, 4);
};
struct CTPInputsConfiguration {
CTPInputsConfiguration() = default;
std::vector<CTPInput> CTPInputs;
static const std::vector<CTPInput> CTPInputsDefault;
int createInputsConfigFromFile(std::string& filename);
void printStream(std::ostream& strem) const;
static CTPInputsConfiguration defaultInputConfig;
static void initDefaultInputConfig();
static std::string getInputNameFromIndex100(uint32_t index);
static std::string getInputNameFromIndex(uint32_t index);
static int getInputIndexFromName(std::string& name);
ClassDefNV(CTPInputsConfiguration, 0);
};
class CTPConfiguration
{
public:
// static CTPInputsConfiguration mCTPInputsConfiguration;
const static std::map<std::string, std::string> detName2LTG;
CTPConfiguration() = default;
bool isDetector(const o2::detectors::DetID& det);
static void capitaliseString(std::string& str);
static bool isNumber(const std::string& s);
int addInput(std::string& inp, int clsindex, std::map<int, std::vector<int>>& descInputsIndex);
enum ConfigPart { START,
VERSION,
RUN,
INPUTS,
MASKS,
GENS,
DESCRIPTORS,
LTG,
LTGitems,
CLUSTER,
CLASS,
UNKNOWN };
int loadConfigurationRun3(const std::string& ctpconfiguartion);
void printStream(std::ostream& stream) const;
void setRunNumber(uint32_t runnumber) { mRunNumber = runnumber; }
std::vector<CTPInput>& getCTPInputs() { return mInputs; }
std::vector<CTPClass>& getCTPClasses() { return mCTPClasses; }
const std::vector<CTPInput>& getCTPInputs() const { return mInputs; } // Read-only interface
const std::vector<CTPClass>& getCTPClasses() const { return mCTPClasses; } // Read-only interface
uint64_t getInputMask(const std::string& name) const;
int getInputIndex(const std::string& name) const;
std::string getClassNameFromIndex(int index);
std::string getClassNameFromHWIndex(int index);
const CTPClass* getCTPClassFromHWIndex(const int index) const;
bool isMaskInInputs(const uint64_t& mask) const;
bool isBCMaskInConfig(const std::string maskname) const;
const BCMask* isBCMaskInConfigP(const std::string bcmask) const;
const CTPInput* isInputInConfig(const std::string inpname) const;
const CTPInput* isInputInConfig(const uint32_t index) const;
const CTPDescriptor* isDescriptorInConfig(const std::string descname, int& index) const;
void createInputsInDecriptorsFromNames();
uint64_t getDecrtiptorInputsMask(const std::string& name) const;
std::map<o2::detectors::DetID::ID, std::vector<CTPInput>> getDet2InputMap();
uint64_t getTriggerClassMask() const;
uint64_t getTriggerClassMaskWInputs() const;
uint64_t getTriggerClassMaskWInputsNoTrgDets() const;
std::vector<int> getTriggerClassList() const;
uint32_t getRunNumber() { return mRunNumber; };
std::vector<std::string> getDetectorList() const;
o2::detectors::DetID::mask_t getDetectorMask() const;
uint64_t getClassMaskForInputMask(uint64_t inputMask) const;
void printConfigString();
std::string getConfigString() { return mConfigString; };
CTPDescriptor* getDescriptor(int index) { return &mDescriptors[index]; };
int assignDescriptors();
int checkConfigConsistency() const;
private:
std::string mConfigString = "";
uint32_t mRunNumber = 0;
std::string mName = "";
std::string mVersion = "0";
std::vector<BCMask> mBCMasks;
std::vector<CTPGenerator> mGenerators;
std::vector<CTPInput> mInputs;
std::vector<CTPDescriptor> mDescriptors;
std::vector<CTPDetector> mDetectors;
std::vector<CTPCluster> mClusters;
std::vector<CTPClass> mCTPClasses;
int processConfigurationLineRun3(std::string& line, int& level, std::map<int, std::vector<int>>& descInputsIndex);
int processConfigurationLineRun3v2(std::string& line, int& level, std::map<int, std::vector<int>>& descInputsIndex);
ClassDefNV(CTPConfiguration, 6);
};
std::ostream& operator<<(std::ostream& in, const CTPConfiguration& conf);
struct CtpCfg {
CtpCfg() = default;
std::string filename = "ctp.cfg";
int readAndSave(std::string& path);
uint32_t TFOrbits = 0;
int ccdb = -1; // -1 means def constructor was called
uint32_t orbitShift = 0;
uint32_t irInputs_1_24 = 0;
uint32_t irInputs_25_48 = 0;
ClassDefNV(CtpCfg, 1)
};
} // namespace ctp
} // namespace o2
#endif //_CTP_CONFIGURATION_H_