ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
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. More...
 

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. More...
 

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. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

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_DEBUG( "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 
43  if (parseJsonFile(ifs)) m_validJSon = true;;
44 }

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  }

◆ 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  }

◆ 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  }

◆ 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  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ 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_DEBUG( "ZdcInjPulserAmpMap::lookupRun(): found config name " << configName << " for run number "
153  << runNumber);
154  }
155  }
156 
157 
158  // Find the corresponding configuration -- we hope
159  //
160  auto findIter = m_stepsConfigs.find(configName);
161  if (findIter == m_stepsConfigs.end()) return Token();
162 
163  // Now we make a new active configuration -- the only thing that needs to be thread-protected
164  //
165  const std::lock_guard<std::mutex> lock(m_lock);
166 
167  // Put a new entry in the active configuration vector
168  //
169  int newIndex = m_activeConfigs.size();
170  m_activeConfigs.push_back(&findIter->second);
171 
172  ATH_MSG_DEBUG( "ZdcInjPulserAmpMap::lookupRun(): creating token for run number " << runNumber
173  << " with index " << newIndex << ", and scaleFactor " << scaleFactor);
174 
175  return Token(newIndex, scaleFactor);
176 }

◆ 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
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
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 {
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 }

◆ 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 }

◆ 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.

◆ 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.

◆ 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.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ZdcInjPulserAmpMap::StepsVector
std::vector< float > StepsVector
Definition: ZdcInjPulserAmpMap.h:55
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
ZdcInjPulserAmpMap::parseJsonFile
bool parseJsonFile(std::ifstream &ifs)
Definition: ZdcInjPulserAmpMap.cxx:46
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
get_generator_info.result
result
Definition: get_generator_info.py:21
json
nlohmann::json json
Definition: HistogramDef.cxx:9
index
Definition: index.py:1
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
ZdcInjPulserAmpMap::getContext
std::pair< unsigned int, StepsVector > getContext(const Token &token) const
Definition: ZdcInjPulserAmpMap.h:88
ZdcInjPulserAmpMap::m_validJSon
bool m_validJSon
Definition: ZdcInjPulserAmpMap.h:68
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
ZdcInjPulserAmpMap::m_activeConfigs
std::vector< const StepsDescr * > m_activeConfigs
Definition: ZdcInjPulserAmpMap.h:80
ZdcInjPulserAmpMap::m_filePath
std::string m_filePath
Definition: ZdcInjPulserAmpMap.h:67
ZdcInjPulserAmpMap::fillVVector
void fillVVector(StepsVector &stepVec, const nlohmann::json &entry)
Definition: ZdcInjPulserAmpMap.cxx:129
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
ZdcInjPulserAmpMap::readPulserSteps
void readPulserSteps(StepsDescr &steps, const json &stepsJson)
Definition: ZdcInjPulserAmpMap.cxx:107
ZdcInjPulserAmpMap::m_runRangeDescrs
std::vector< RunRangeDescr > m_runRangeDescrs
Definition: ZdcInjPulserAmpMap.h:72
beamspotman.steps
int steps
Definition: beamspotman.py:505
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
hancool.filePath
string filePath
Definition: hancool.py:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
DeMoScan.index
string index
Definition: DeMoScan.py:364
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
DeMoScan.first
bool first
Definition: DeMoScan.py:536
ZdcInjPulserAmpMap::m_lock
std::mutex m_lock
Definition: ZdcInjPulserAmpMap.h:62
LArCellBinning.step
step
Definition: LArCellBinning.py:158
ZdcInjPulserAmpMap::m_stepsConfigs
std::map< std::string, StepsDescr > m_stepsConfigs
Definition: ZdcInjPulserAmpMap.h:76
ZdcInjPulserAmpMap
Definition: ZdcInjPulserAmpMap.h:25
ZdcInjPulserAmpMap::StepsDescr
std::pair< unsigned int, StepsVector > StepsDescr
Definition: ZdcInjPulserAmpMap.h:56
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7