File indexing completed on 2025-01-18 10:17:36
0001
0002
0003
0004 #pragma once
0005 #include <JANA/Utils/JEventLevel.h>
0006 #include <vector>
0007
0008 class JEventKey {
0009 struct Entry { JEventLevel level,
0010 uint64_t absolute_number,
0011 uint64_t relative_number,
0012 uint64_t user_number }
0013
0014
0015 std::vector<Entry> m_entries;
0016 int64_t m_run_number = -1;
0017
0018
0019
0020
0021 public:
0022
0023 JEventKey() {
0024 m_entries.push_back({JEventLevel::None, 0, 0, 0});
0025 }
0026
0027 Configure(JEventLevel level, uint64_t absolute_number) {
0028 m_entries.clear();
0029 m_entries.push_back({level, absolute_number, absolute_number, absolute_number});
0030 }
0031
0032 AddParent(const JEventKey& parent_key, uint64_t relative_number) {
0033 if (m_entries.size() > 1) {
0034 throw JException("Event already has a parent");
0035 }
0036 for (const auto& entry : parent_key.m_entries) {
0037 m_entries.push_back(entry);
0038
0039
0040 }
0041 m_entries[0].relative_number = relative_number;
0042 if (m_run_number == -1) {
0043 m_run_number = parent_key.m_run_number;
0044 }
0045 }
0046
0047 const std::vector<Entry>& GetEntries() const {
0048 return m_entries;
0049 }
0050
0051 void SetUserEventNumber(uint64_t user_number) {
0052
0053 if (m_entries.size() == 0) throw JException("")
0054 m_entries.back().user_number = user_number;
0055 }
0056
0057 void SetRunNumber(int64_t run_number) {
0058 m_run_number = run_number;
0059 }
0060
0061 std::string toString() {
0062 std::ostringstream ss;
0063 ss << *this;
0064 return ss.str();
0065 }
0066
0067 JEventLevel GetLevel() {
0068 return m_entries[0].level;
0069 }
0070
0071 uint64_t GetAbsoluteEventNumber() {
0072 return m_entries[0].absolute_number;
0073 }
0074
0075 uint64_t GetRelativeEventNumber() {
0076 return m_entries[0].relative_number;
0077 }
0078
0079 uint64_t GetUserEventNumber() {
0080 return m_entries[0].user_number;
0081 }
0082 }
0083
0084 inline std::ostream& operator<<(std::ostream& in, const JEventKey& key) {
0085
0086 in << key.GetLevel() << " ";
0087 auto s = m_entries.size();
0088 for (size_t i=m_entries.size(); i>0; --i) {
0089 in << m_entries[s-i-1].relative_number << ".";
0090 }
0091 in << key.GetRelativeEventNumber();
0092 if (key.GetRelativeEventNumber() != key.GetAbsoluteEventNumber()) {
0093 in << "(absolute #" << key.GetAbsoluteEventNumber();
0094
0095 }
0096 if (key.GetUserEventNumber() != key.GetAbsoluteEventNumber()) {
0097 in << ", user #" << key.GetUserNumber();
0098 }
0099 in << ")";
0100 return in;
0101 }