Skip to content

Commit

Permalink
Create FairTypes.h
Browse files Browse the repository at this point in the history
Created `namespace FairRoot`
with `struct EntryID {size_t fId;}`.

Should replace PR #1405.
  • Loading branch information
karabowi committed Jun 19, 2023
1 parent 9717b2e commit 914afe8
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fairroot/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ endif()

fair_change_extensions_if_exists(.cxx .h FILES "${sources}" OUTVAR headers)

list(APPEND headers
steer/FairTypes.h
)

add_library(${target} SHARED ${sources} ${headers})
fairroot_library_settings(${target})

Expand Down
106 changes: 106 additions & 0 deletions fairroot/base/steer/FairTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/********************************************************************************
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/*
* FairTypes.h
*
* Created on: May 16, 2023
* Author: R.Karabowicz
*/

#ifndef FAIR_TYPES_H_
#define FAIR_TYPES_H_

#include <iostream>
#include <limits>

/**
* \brief Main namespace for FairRoot classes / types
*
* All new public classes and types of FairRoot will be in this namespace.
* Note: Nost classes are still in no namespace.
*/
namespace FairRoot {
/**
* \brief Ordinal identification number of entry in IO stream
*
* Data stored in ROOT trees are gropued into entries,
* essentially equivalent to HEP events
*/
struct EntryID
{
using underlying_type = size_t;

static const EntryID None;

EntryID(underlying_type value)
: fId(value)
{}

EntryID() = default;

operator underlying_type() const { return fId; }

friend auto operator<<(std::ostream& os, EntryID id) -> std::ostream&
{
if (id == None) {
return os << "<No Entry>";
}
return os << static_cast<underlying_type>(id);
}

auto operator++()
{
if (fId != None) {
++fId;
}
return *this;
}
auto operator++(int)
{
auto temp = *this;
if (fId != None) {
++fId;
}
return temp;
}

auto operator--()
{
if (fId != None) {
--fId;
}
return *this;
}
auto operator--(int)
{
auto temp = *this;
if (fId != None) {
--fId;
}
return temp;
}
auto operator+=(const EntryID& rhs)
{
fId += rhs.fId;
return *this;
}
auto operator-=(const EntryID& rhs)
{
fId -= rhs.fId;
return *this;
}

private:
underlying_type fId{std::numeric_limits<underlying_type>::max()};
};

/// \sa https://stackoverflow.com/questions/29432283/c-static-constexpr-field-with-incomplete-type/50295183#50295183
inline constexpr const EntryID EntryID::None{};
} // namespace FairRoot

#endif // FAIR_TYPES_H_

0 comments on commit 914afe8

Please sign in to comment.