ATLAS Offline Software
Loading...
Searching...
No Matches
ZdcInjPulserAmpMap Class Reference

#include <ZdcInjPulserAmpMap.h>

Inheritance diagram for ZdcInjPulserAmpMap:
Collaboration diagram for ZdcInjPulserAmpMap:

Classes

class  Token

Public Types

using json = nlohmann::json

Public Member Functions

 ZdcInjPulserAmpMap ()
const std::string & getFilePath () const
Token lookupRun (unsigned int runNumber, bool allowDefault=false)
unsigned int getFirstLumiBlock (const Token &token) const
unsigned int getNumSteps (const Token &token) const
int getCycleNumber (const Token &token, unsigned int lumiBlock) const
float getPulserAmplitude (const Token &token, unsigned int lumiBlock) const
void setLevel (MSG::Level lvl)
 Change the current logging level.
Functions providing the same interface as AthMessaging
bool msgLvl (const MSG::Level lvl) const
 Test the output level of the object.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.

Static Public Member Functions

static const ZdcInjPulserAmpMapgetInstance ()

Private Types

using StepsVector = std::vector<float>
using StepsDescr = std::pair<unsigned int, StepsVector>
using RunRangeDescr = std::tuple<unsigned int, unsigned int, std::string, float>

Private Member Functions

bool parseJsonFile (std::ifstream &ifs)
void readPulserSteps (StepsDescr &steps, const json &stepsJson)
void fillVVector (StepsVector &stepVec, const nlohmann::json &entry)
std::pair< unsigned int, StepsVectorgetContext (const Token &token) const
void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

std::mutex m_lock
std::string m_filePath
bool m_validJSon {false}
std::vector< RunRangeDescrm_runRangeDescrs
std::map< std::string, StepsDescrm_stepsConfigs
std::vector< const StepsDescr * > m_activeConfigs
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels)
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging)

Detailed Description

Definition at line 24 of file ZdcInjPulserAmpMap.h.

Member Typedef Documentation

◆ json

using ZdcInjPulserAmpMap::json = nlohmann::json

Definition at line 51 of file ZdcInjPulserAmpMap.h.

◆ RunRangeDescr

using ZdcInjPulserAmpMap::RunRangeDescr = std::tuple<unsigned int, unsigned int, std::string, float>
private

Definition at line 58 of file ZdcInjPulserAmpMap.h.

◆ StepsDescr

using ZdcInjPulserAmpMap::StepsDescr = std::pair<unsigned int, StepsVector>
private

Definition at line 56 of file ZdcInjPulserAmpMap.h.

◆ StepsVector

using ZdcInjPulserAmpMap::StepsVector = std::vector<float>
private

Definition at line 55 of file ZdcInjPulserAmpMap.h.

Constructor & Destructor Documentation

◆ ZdcInjPulserAmpMap()

ZdcInjPulserAmpMap::ZdcInjPulserAmpMap ( )

Definition at line 19 of file ZdcInjPulserAmpMap.cxx.

19 : asg::AsgMessaging("ZdcInjPulserAmpMap")
20{
21 msg().setLevel(MSG::INFO);
22
23 // std::string filePath = PathResolverFindCalibFile("ZdcConditions/ZDC_InjectPulseSteps.json"); // change back file name after other changes get merged + ready for T0 reprocessing
24 std::string filePath = PathResolverFindCalibFile("ZdcConditions/INJpulser_combined_2024.json");
25
26 if (!filePath.empty())
27 {
28 ATH_MSG_INFO( "ZdcInjPulserAmpMap::found ZDC JSON at " << filePath );
29 }
30 else
31 {
32 ATH_MSG_WARNING( "ZdcInjPulserAmpMap constructor, JSON file not found in search path, trying local file" ) ;
33 filePath = "./ZDC_InjectPulseSteps.json";
34 }
35
36
37 std::ifstream ifs(filePath);
38 if (!ifs.is_open()) {
39 ATH_MSG_FATAL("ZdcInjPulserAmpMap constructor, JSON file cannot be opened!" ) ;
40 }
41
42 m_filePath = std::move(filePath);
43 if (parseJsonFile(ifs)) m_validJSon = true;;
44}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
bool parseJsonFile(std::ifstream &ifs)
MsgStream & msg() const
The standard message stream.
str filePath
Definition hancool.py:27

Member Function Documentation

◆ fillVVector()

void ZdcInjPulserAmpMap::fillVVector ( StepsVector & stepVec,
const nlohmann::json & entry )
private

Definition at line 129 of file ZdcInjPulserAmpMap.cxx.

130{
131 unsigned int nStep = entry.at("nStep");
132 float vStart = entry.at("vStart");
133 float vStep = entry.at("vStep");
134
135 float voltage = vStart;
136 for (size_t step = 0; step < nStep; step++) {
137 stepVec.push_back(voltage);
138 voltage += vStep;
139 }
140}

◆ getContext()

std::pair< unsigned int, StepsVector > ZdcInjPulserAmpMap::getContext ( const Token & token) const
inlineprivate

Definition at line 88 of file ZdcInjPulserAmpMap.h.

89 {
90 if (!m_validJSon) {
91 throw std::runtime_error("Invalid Injected Pulser configuration");
92 }
93 if (!token.isValid() || size_t(token.value()) >= m_activeConfigs.size()) {
94 throw std::runtime_error("Invalid Injected Pulser configuration");
95 }
96
97 unsigned int index = token.value();
98 const StepsDescr& stepsConfig = *(m_activeConfigs[index]);
99
100 unsigned int firstLB = stepsConfig.first;
101 const StepsVector& steps = stepsConfig.second;
102
103 return std::make_pair(firstLB, steps);
104 }
std::vector< const StepsDescr * > m_activeConfigs
std::pair< unsigned int, StepsVector > StepsDescr
std::vector< float > StepsVector
str index
Definition DeMoScan.py:362

◆ getCycleNumber()

int ZdcInjPulserAmpMap::getCycleNumber ( const Token & token,
unsigned int lumiBlock ) const
inline

Definition at line 130 of file ZdcInjPulserAmpMap.h.

131 {
132 auto [firstLB, map] = getContext(token);
133
134 if (lumiBlock < firstLB) return -1;
135 return std::floor(float(lumiBlock - firstLB)/map.size());
136 }
std::pair< unsigned int, StepsVector > getContext(const Token &token) const

◆ getFilePath()

const std::string & ZdcInjPulserAmpMap::getFilePath ( ) const
inline

Definition at line 112 of file ZdcInjPulserAmpMap.h.

112{return m_filePath;}

◆ getFirstLumiBlock()

unsigned int ZdcInjPulserAmpMap::getFirstLumiBlock ( const Token & token) const
inline

Definition at line 118 of file ZdcInjPulserAmpMap.h.

118 {
119 auto result = getContext(token);
120 return result.first;
121 }

◆ getInstance()

const ZdcInjPulserAmpMap * ZdcInjPulserAmpMap::getInstance ( )
static

Definition at line 11 of file ZdcInjPulserAmpMap.cxx.

12{
13 static const ZdcInjPulserAmpMap pulser_map;
14 return &pulser_map;
15}

◆ getNumSteps()

unsigned int ZdcInjPulserAmpMap::getNumSteps ( const Token & token) const
inline

Definition at line 123 of file ZdcInjPulserAmpMap.h.

123 {
124 auto result = getContext(token);
125 return result.second.size();
126 }

◆ getPulserAmplitude()

float ZdcInjPulserAmpMap::getPulserAmplitude ( const Token & token,
unsigned int lumiBlock ) const
inline

Definition at line 140 of file ZdcInjPulserAmpMap.h.

141 {
142 auto [firstLB, map] = getContext(token);
143
144 // We do a cyclic lookup of the pulser amplitude (in volts) starting from the first LB
145 //
146 if (lumiBlock < firstLB) return -1000.;
147 unsigned int vecIndex = (lumiBlock - firstLB) % map.size();
148 return map.at(vecIndex) * token.scaleFactor();
149 }
setTeId lumiBlock

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ lookupRun()

ZdcInjPulserAmpMap::Token ZdcInjPulserAmpMap::lookupRun ( unsigned int runNumber,
bool allowDefault = false )

Definition at line 142 of file ZdcInjPulserAmpMap.cxx.

143{
144 std::string configName = (allowDefault ? "Default" : "_none_");
145 float scaleFactor = 1;
146
147 for ( auto rangeDescr : m_runRangeDescrs) {
148 if (runNumber >= std::get<0>(rangeDescr) && runNumber < std::get<1>(rangeDescr)) {
149 configName = std::get<2>(rangeDescr);
150 scaleFactor = std::get<3>(rangeDescr);
151
152 ATH_MSG_INFO( "ZdcInjPulserAmpMap::lookupRun(): found config name " << configName << " for run number "
153 << runNumber);
154 }
155 }
156
157 if (configName == "Default") {
158 ATH_MSG_WARNING("ZdcInjPulserAmpMap::lookupRun(): no valid configuration found for run number " << runNumber
159 << ". Using Default configuration.");
160 }
161
162 if (configName == "_none_") {
163 ATH_MSG_ERROR("ZdcInjPulserAmpMap::lookupRun(): no valid configuration found for run number " << runNumber
164 << "; Default configuration is NOT allowed. Will return an invalid (empty) token.");
165 }
166
167 // Find the corresponding configuration -- we hope
168 //
169 auto findIter = m_stepsConfigs.find(configName);
170 if (findIter == m_stepsConfigs.end()) return Token(); // config name doesn't match to any step configuration: return an invalid token
171
172 // Now we make a new active configuration -- the only thing that needs to be thread-protected
173 //
174 const std::lock_guard<std::mutex> lock(m_lock);
175
176 // Put a new entry in the active configuration vector
177 //
178 int newIndex = m_activeConfigs.size();
179 m_activeConfigs.push_back(&findIter->second);
180
181 ATH_MSG_DEBUG( "ZdcInjPulserAmpMap::lookupRun(): creating token for run number " << runNumber
182 << " with index " << newIndex << ", and scaleFactor " << scaleFactor);
183
184 return Token(newIndex, scaleFactor);
185}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
std::map< std::string, StepsDescr > m_stepsConfigs
std::vector< RunRangeDescr > m_runRangeDescrs

◆ msg() [1/2]

MsgStream & asg::AsgMessaging::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 49 of file AsgMessaging.cxx.

49 {
50#ifndef XAOD_STANDALONE
51 return ::AthMessaging::msg();
52#else // not XAOD_STANDALONE
53 return m_msg;
54#endif // not XAOD_STANDALONE
55 }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 57 of file AsgMessaging.cxx.

57 {
58#ifndef XAOD_STANDALONE
59 return ::AthMessaging::msg( lvl );
60#else // not XAOD_STANDALONE
61 m_msg << lvl;
62 return m_msg;
63#endif // not XAOD_STANDALONE
64 }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 41 of file AsgMessaging.cxx.

41 {
42#ifndef XAOD_STANDALONE
43 return ::AthMessaging::msgLvl( lvl );
44#else // not XAOD_STANDALONE
45 return m_msg.msgLevel( lvl );
46#endif // not XAOD_STANDALONE
47 }

◆ parseJsonFile()

bool ZdcInjPulserAmpMap::parseJsonFile ( std::ifstream & ifs)
private

Definition at line 46 of file ZdcInjPulserAmpMap.cxx.

47{
48 try {
49 nlohmann::json j = nlohmann::json::parse(ifs);
50
51 // Check for the existence of the run range section of the json file
52 //
53 auto rangeIter = j.find("RunRanges");
54 if (rangeIter == j.end()) return false;
55
56 //
57 // We loop over all the defined run ranges and save
58 //
59 for (json range : *rangeIter) {
60 unsigned int first = range.at("First");
61 unsigned int last = range.at("Last");
62 std::string name = range.at("StepsConfig");
63 float scale = range.at("ScaleFactor");
64
65 m_runRangeDescrs.push_back(std::make_tuple(first, last, name, scale));
66
67 ATH_MSG_DEBUG( "ZdcInjPulserAmpMap::found run range: first, last = " << first << ", " << last
68 << ", config name = " << name << ", scale factor = " << scale );
69 }
70
71 auto stepConfigIter = j.find("StepConfigurations");
72 if (stepConfigIter == j.end()) return false;
73
74 // Now loop over the configurations and save
75 //
76 for (json::iterator configIt = stepConfigIter->begin(); configIt != stepConfigIter->end(); ++configIt) {
77 std::string confName = configIt.key();
78
79 // First we make a spot in the map
80 //
81 auto [insertIter, insertResult] = m_stepsConfigs.insert(std::make_pair(confName, StepsDescr()));
82 if (!insertResult) return false;
83
84 // And now we fill it
85 //
86 json steps = configIt.value();
87 if (!steps.is_array()) {
88 return false;
89 }
90
91 // Unpack the elements of the step confg array
92 //
93 StepsDescr& stepsDesc = insertIter->second;
94 readPulserSteps(stepsDesc, steps);
95
96 ATH_MSG_DEBUG( "ZdcInjPulserAmpMap::found steps configuration with name " << confName << ", starting LB = "
97 << stepsDesc.first << ", number of LBs = " << stepsDesc.second.size());
98 }
99 }
100 catch (...) {
101 return false;
102 }
103
104 return true;
105}
void readPulserSteps(StepsDescr &steps, const json &stepsJson)
bool first
Definition DeMoScan.py:534

◆ readPulserSteps()

void ZdcInjPulserAmpMap::readPulserSteps ( StepsDescr & steps,
const json & stepsJson )
private

Definition at line 107 of file ZdcInjPulserAmpMap.cxx.

108{
109 // Loop over all entries in the json array
110 //
111 for (unsigned int index = 0; index < stepsJson.size(); index++) {
112 const json& elem = stepsJson[index];
113
114 // Get the starting LB entry in the json if it exists
115 //
116 if (index ==0 && elem.size() == 1) {
117 if (elem.find("startLB") != elem.end()) {
118 steps.first = elem["startLB"];
119 }
120 }
121 else {
122 // Fill out the pulser amplitudes for this step
123 //
124 fillVVector(steps.second, elem);
125 }
126 }
127}
void fillVVector(StepsVector &stepVec, const nlohmann::json &entry)

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_activeConfigs

std::vector<const StepsDescr*> ZdcInjPulserAmpMap::m_activeConfigs
private

Definition at line 80 of file ZdcInjPulserAmpMap.h.

◆ m_filePath

std::string ZdcInjPulserAmpMap::m_filePath
private

Definition at line 67 of file ZdcInjPulserAmpMap.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lock

std::mutex ZdcInjPulserAmpMap::m_lock
private

Definition at line 62 of file ZdcInjPulserAmpMap.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_runRangeDescrs

std::vector<RunRangeDescr> ZdcInjPulserAmpMap::m_runRangeDescrs
private

Definition at line 72 of file ZdcInjPulserAmpMap.h.

◆ m_stepsConfigs

std::map<std::string, StepsDescr> ZdcInjPulserAmpMap::m_stepsConfigs
private

Definition at line 76 of file ZdcInjPulserAmpMap.h.

◆ m_validJSon

bool ZdcInjPulserAmpMap::m_validJSon {false}
private

Definition at line 68 of file ZdcInjPulserAmpMap.h.

68{false};

The documentation for this class was generated from the following files: