ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
ForwardDetectors
ZDC
ZdcConditions
ZdcConditions
ZdcInjPulserAmpMap.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef _ZDCINJPULSERAMPMAP_H
6
#define _ZDCINJPULSERAMPMAP_H
7
8
#include "
AsgMessaging/AsgMessaging.h
"
9
#include <nlohmann/json.hpp>
10
11
#include <string>
12
#include <vector>
13
#include <cmath>
14
15
16
#include <iostream>
17
#include <string>
18
#include <tuple>
19
#include <map>
20
#include <mutex>
21
#include <vector>
22
#include <utility>
23
24
class
ZdcInjPulserAmpMap
:
public
asg::AsgMessaging
25
{
26
public
:
27
class
Token
28
{
29
int
m_index
;
30
float
m_scaleFactor
;
31
32
int
value
()
const
{
return
m_index
;}
33
float
scaleFactor
()
const
{
return
m_scaleFactor
;}
34
35
Token
(
int
index
,
float
scaleFactor
) :
36
m_index
(
index
),
37
m_scaleFactor
(
scaleFactor
)
38
{}
39
40
public
:
41
friend
class
ZdcInjPulserAmpMap
;
42
43
Token
() :
44
m_index
(-1),
45
m_scaleFactor
(1)
46
{}
47
48
bool
isValid
()
const
{
return
m_index
!= -1;}
49
};
50
51
using
json
= nlohmann::json;
52
53
private
:
54
55
using
StepsVector
= std::vector<float>;
56
using
StepsDescr
= std::pair<unsigned int, StepsVector>;
57
58
using
RunRangeDescr
= std::tuple<unsigned int, unsigned int, std::string, float>;
59
60
// Mutex for thread safety
61
//
62
std::mutex
m_lock
;
63
64
//
65
// Data members
66
//
67
std::string
m_filePath
;
68
bool
m_validJSon
{
false
};
69
70
// List of run ranges in json file
71
//
72
std::vector<RunRangeDescr>
m_runRangeDescrs
;
73
74
// Map of step configurations indexed by config name
75
//
76
std::map<std::string, StepsDescr>
m_stepsConfigs
;
77
78
// For multi-threaded operation, we keep multiple active configurations with index as the token
79
//
80
std::vector<const StepsDescr*>
m_activeConfigs
;
81
82
// Private Methods
83
//
84
bool
parseJsonFile
(std::ifstream& ifs);
85
void
readPulserSteps
(
StepsDescr
& steps,
const
json
& stepsJson);
86
void
fillVVector
(
StepsVector
& stepVec,
const
nlohmann::json& entry);
87
88
std::pair<unsigned int, StepsVector>
getContext
(
const
Token
& token)
const
89
{
90
if
(!
m_validJSon
) {
91
throw
std::runtime_error(
"Invalid Injected Pulser configuration"
);
92
}
93
//coverity[MISSING_LOCK]
94
if
(!token.
isValid
() ||
size_t
(token.
value
()) >=
m_activeConfigs
.size()) {
95
throw
std::runtime_error(
"Invalid Injected Pulser configuration"
);
96
}
97
98
unsigned
int
index
= token.
value
();
99
const
StepsDescr
& stepsConfig = *(
m_activeConfigs
[
index
]);
100
101
unsigned
int
firstLB = stepsConfig.first;
102
const
StepsVector
& steps = stepsConfig.second;
103
104
return
std::make_pair(firstLB, steps);
105
}
106
107
public
:
108
109
ZdcInjPulserAmpMap
();
110
111
static
const
ZdcInjPulserAmpMap
*
getInstance
();
112
113
const
std::string&
getFilePath
()
const
{
return
m_filePath
;}
114
115
Token
lookupRun
(
unsigned
int
runNumber,
bool
allowDefault =
false
);
116
117
// Return the lumi block number at which we start stepping through the different aplitudes
118
//
119
unsigned
int
getFirstLumiBlock
(
const
Token
& token)
const
{
120
auto
result =
getContext
(token);
121
return
result.first;
122
}
123
124
unsigned
int
getNumSteps
(
const
Token
& token)
const
{
125
auto
result =
getContext
(token);
126
return
result.second.size();
127
}
128
129
// Return the cycle within which the lumi block falls
130
//
131
int
getCycleNumber
(
const
Token
& token,
unsigned
int
lumiBlock)
const
132
{
133
auto
[firstLB,
map
] =
getContext
(token);
134
135
if
(lumiBlock < firstLB)
return
-1;
136
return
std::floor(
float
(lumiBlock - firstLB)/
map
.size());
137
}
138
139
// Return the pulser amplitude for the given lumi block
140
//
141
float
getPulserAmplitude
(
const
Token
& token,
unsigned
int
lumiBlock)
const
142
{
143
auto
[firstLB,
map
] =
getContext
(token);
144
145
// We do a cyclic lookup of the pulser amplitude (in volts) starting from the first LB
146
//
147
if
(lumiBlock < firstLB)
return
-1000.;
148
unsigned
int
vecIndex = (lumiBlock - firstLB) %
map
.size();
149
return
map
.at(vecIndex) * token.
scaleFactor
();
150
}
151
};
152
153
#endif
//
AsgMessaging.h
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition
Token.h:22
ZdcInjPulserAmpMap::Token
Definition
ZdcInjPulserAmpMap.h:28
ZdcInjPulserAmpMap::Token::Token
Token()
Definition
ZdcInjPulserAmpMap.h:43
ZdcInjPulserAmpMap::Token::Token
Token(int index, float scaleFactor)
Definition
ZdcInjPulserAmpMap.h:35
ZdcInjPulserAmpMap::Token::isValid
bool isValid() const
Definition
ZdcInjPulserAmpMap.h:48
ZdcInjPulserAmpMap::Token::value
int value() const
Definition
ZdcInjPulserAmpMap.h:32
ZdcInjPulserAmpMap::Token::ZdcInjPulserAmpMap
friend class ZdcInjPulserAmpMap
Definition
ZdcInjPulserAmpMap.h:41
ZdcInjPulserAmpMap::Token::scaleFactor
float scaleFactor() const
Definition
ZdcInjPulserAmpMap.h:33
ZdcInjPulserAmpMap::Token::m_scaleFactor
float m_scaleFactor
Definition
ZdcInjPulserAmpMap.h:30
ZdcInjPulserAmpMap::Token::m_index
int m_index
Definition
ZdcInjPulserAmpMap.h:29
ZdcInjPulserAmpMap
Definition
ZdcInjPulserAmpMap.h:25
ZdcInjPulserAmpMap::m_validJSon
bool m_validJSon
Definition
ZdcInjPulserAmpMap.h:68
ZdcInjPulserAmpMap::m_stepsConfigs
std::map< std::string, StepsDescr > m_stepsConfigs
Definition
ZdcInjPulserAmpMap.h:76
ZdcInjPulserAmpMap::json
nlohmann::json json
Definition
ZdcInjPulserAmpMap.h:51
ZdcInjPulserAmpMap::m_activeConfigs
std::vector< const StepsDescr * > m_activeConfigs
Definition
ZdcInjPulserAmpMap.h:80
ZdcInjPulserAmpMap::ZdcInjPulserAmpMap
ZdcInjPulserAmpMap()
Definition
ZdcInjPulserAmpMap.cxx:19
ZdcInjPulserAmpMap::parseJsonFile
bool parseJsonFile(std::ifstream &ifs)
Definition
ZdcInjPulserAmpMap.cxx:46
ZdcInjPulserAmpMap::m_filePath
std::string m_filePath
Definition
ZdcInjPulserAmpMap.h:67
ZdcInjPulserAmpMap::m_lock
std::mutex m_lock
Definition
ZdcInjPulserAmpMap.h:62
ZdcInjPulserAmpMap::getContext
std::pair< unsigned int, StepsVector > getContext(const Token &token) const
Definition
ZdcInjPulserAmpMap.h:88
ZdcInjPulserAmpMap::StepsDescr
std::pair< unsigned int, StepsVector > StepsDescr
Definition
ZdcInjPulserAmpMap.h:56
ZdcInjPulserAmpMap::getPulserAmplitude
float getPulserAmplitude(const Token &token, unsigned int lumiBlock) const
Definition
ZdcInjPulserAmpMap.h:141
ZdcInjPulserAmpMap::RunRangeDescr
std::tuple< unsigned int, unsigned int, std::string, float > RunRangeDescr
Definition
ZdcInjPulserAmpMap.h:58
ZdcInjPulserAmpMap::getFilePath
const std::string & getFilePath() const
Definition
ZdcInjPulserAmpMap.h:113
ZdcInjPulserAmpMap::getCycleNumber
int getCycleNumber(const Token &token, unsigned int lumiBlock) const
Definition
ZdcInjPulserAmpMap.h:131
ZdcInjPulserAmpMap::readPulserSteps
void readPulserSteps(StepsDescr &steps, const json &stepsJson)
Definition
ZdcInjPulserAmpMap.cxx:107
ZdcInjPulserAmpMap::getInstance
static const ZdcInjPulserAmpMap * getInstance()
Definition
ZdcInjPulserAmpMap.cxx:11
ZdcInjPulserAmpMap::StepsVector
std::vector< float > StepsVector
Definition
ZdcInjPulserAmpMap.h:55
ZdcInjPulserAmpMap::m_runRangeDescrs
std::vector< RunRangeDescr > m_runRangeDescrs
Definition
ZdcInjPulserAmpMap.h:72
ZdcInjPulserAmpMap::lookupRun
Token lookupRun(unsigned int runNumber, bool allowDefault=false)
Definition
ZdcInjPulserAmpMap.cxx:142
ZdcInjPulserAmpMap::getFirstLumiBlock
unsigned int getFirstLumiBlock(const Token &token) const
Definition
ZdcInjPulserAmpMap.h:119
ZdcInjPulserAmpMap::fillVVector
void fillVVector(StepsVector &stepVec, const nlohmann::json &entry)
Definition
ZdcInjPulserAmpMap.cxx:129
ZdcInjPulserAmpMap::getNumSteps
unsigned int getNumSteps(const Token &token) const
Definition
ZdcInjPulserAmpMap.h:124
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition
AsgMessaging.h:40
map
STL class.
index
Definition
index.py:1
Generated on
for ATLAS Offline Software by
1.17.0