Project
Loading...
Searching...
No Matches
MCGenProperties.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef ALICEO2_SIMDATA_MCGENPROPERTIES_H_
13#define ALICEO2_SIMDATA_MCGENPROPERTIES_H_
14
15namespace o2
16{
17namespace mcgenstatus
18{
19
20// Value to check MCGenStatusEncoding::isEncoded against to decide whether or not the stored value is encoded or basically only the HepMC status code
21// as it used to be
22constexpr unsigned int isEncodedValue{5};
23
24// internal structure to allow convenient manipulation of properties as bits on an int to (dis)entangle HepMC and specific generator status codes
28 // To be backward-compatible, only set transport to 1 if hepmc status is 1
29 MCGenStatusEncoding(int hepmcIn, int genIn) : isEncoded(isEncodedValue), hepmc(hepmcIn), gen(genIn), reserved(0) {}
31 struct {
32 int hepmc : 9; // HepMC status code
33 int gen : 10; // specific generator status code
34 int reserved : 10; // reserved bits for future usage
35 unsigned int isEncoded : 3; // special bits to check whether or not the fullEncoding is a combination of HepMC and gen status codes
36 };
37};
38
39inline bool isEncoded(MCGenStatusEncoding statusCode)
40{
41 return (statusCode.isEncoded == isEncodedValue);
42}
43
44inline bool isEncoded(int statusCode)
45{
46 return isEncoded(MCGenStatusEncoding(statusCode));
47}
48
50{
51 if (!isEncoded(enc)) {
52 // in this case simply set hepmc code to what was given
53 return enc.fullEncoding;
54 }
55 return enc.hepmc;
56}
57
59{
60 if (!isEncoded(enc)) {
61 // in this case simply set hepmc code to what was given
62 return enc.fullEncoding;
63 }
64 return enc.gen;
65}
66
67inline int getHepMCStatusCode(int encoded)
68{
70}
71
72inline int getGenStatusCode(int encoded)
73{
75}
76
77} // namespace mcgenstatus
78
79namespace mcgenid
80{
81
82// Define some common properties that can be set for Generators
84{
85 public:
86 typedef const char* Property;
87 static constexpr Property GENERATORID{"generator_id"};
88 static constexpr Property GENERATORDESCRIPTION{"generator_description"};
89 static constexpr Property SUBGENERATORID{"subgenerator_id"};
90 static constexpr Property SUBGENERATORDESCRIPTIONMAP{"subgenerator_description_map"};
91};
92
93// internal structure to allow encoding of generator IDs and map different numbers to a single short
96 MCGenIdEncoding(int enc) : fullEncoding(enc) {}
99 struct {
100 unsigned short generatorId : 7; // an additional identifier for a generator which can be set by the user
101 unsigned short sourceId : 4; // ID used in embedding scenarios
102 unsigned short subGeneratorId : 5; // sub generator ID in case a generator implements some additional logic
103 };
104};
105
106inline short getEncodedGenId(int generatorId, int sourceId, int subGeneratorId = -1)
107{
108
109 return MCGenIdEncoding(generatorId, sourceId, subGeneratorId + 1).fullEncoding;
110}
111
112inline int getGeneratorId(short encoded)
113{
114
115 return static_cast<int>(MCGenIdEncoding(encoded).generatorId);
116}
117
118inline int getSourceId(short encoded)
119{
120 return static_cast<int>(MCGenIdEncoding(encoded).sourceId);
121}
122
123inline int getSubGeneratorId(short encoded)
124{
125 return static_cast<int>(MCGenIdEncoding(encoded).subGeneratorId) - 1;
126}
127
128} // namespace mcgenid
129
130} // namespace o2
131
132#endif
static constexpr Property GENERATORID
static constexpr Property SUBGENERATORID
static constexpr Property GENERATORDESCRIPTION
static constexpr Property SUBGENERATORDESCRIPTIONMAP
int getSourceId(short encoded)
int getGeneratorId(short encoded)
short getEncodedGenId(int generatorId, int sourceId, int subGeneratorId=-1)
int getSubGeneratorId(short encoded)
int getGenStatusCode(MCGenStatusEncoding enc)
int getHepMCStatusCode(MCGenStatusEncoding enc)
constexpr unsigned int isEncodedValue
bool isEncoded(MCGenStatusEncoding statusCode)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
MCGenIdEncoding(int generatorId, int sourceId, int subGeneratorId)
MCGenStatusEncoding(int hepmcIn, int genIn)