Project
Loading...
Searching...
No Matches
BunchFilling.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
13
14#ifndef ALICEO2_BUNCHFILLING_H
15#define ALICEO2_BUNCHFILLING_H
16
18#include <Rtypes.h>
19#include <bitset>
20#include <string>
21#include <array>
22
23namespace o2
24{
26{
27 public:
28 using Pattern = std::bitset<o2::constants::lhc::LHCMaxBunches>;
29
30 BunchFilling() = default;
31 BunchFilling(const std::string& beamA, const std::string& beamC);
32 BunchFilling(const std::string& interactingBC);
33
34 // this is a pattern creator similar to Run1/2 AliTriggerBCMask
35 // The string has the following syntax:
36 // "25L 25(2H2LH 3(23HL))"
37 // - H/h -> 1 L/l -> 0
38 // - spaces, new lines are white characters
39 static Pattern createPattern(const std::string& p);
40
41 // create pattern string from filled bucket
42 static std::string buckets2PatternString(const std::vector<int>& buckets, int ibeam);
43
44 // get interacting bunches pattern (B)
45 const auto& getBCPattern() const { return mPattern; }
46
47 // get pattern or clockwise (0, A) and anticlockwise (1, C) beams at P2
48 const auto& getBeamPattern(int beam) const { return mBeamAC[beam]; }
49
50 // get pattern of interacting BCs (-1) or beams filled BCs at P2 (0,1)
51 const auto& getPattern(int dir = -1) const { return dir < 0 ? getBCPattern() : getBeamPattern(dir); }
52
53 // create pattern from filled bucket
54 void buckets2BeamPattern(const std::vector<int>& buckets, int ibeam);
55
56 // get number of interacting bunches (-1) and number of filled bunches for clockwise (0, A) and anticlockwise (1, C) beams
57 int getNBunches(int dir = -1) const { return dir < 0 ? mPattern.count() : mBeamAC[dir].count(); }
58
59 // test interacting bunch
60 bool testInteractingBC(int bcID) const { return mPattern[bcID]; }
61
62 // test bean bunch
63 bool testBeamBunch(int bcID, int dir) const { return mBeamAC[dir][bcID]; }
64
65 // test interacting (-1) or clockwise (0, A) and anticlockwise (1, C) beams bunch
66 bool testBC(int bcID, int dir = -1) const { return dir < 0 ? testInteractingBC(bcID) : testBeamBunch(bcID, dir); }
67
68 // BC setters, dir=-1 is for interacting bunches pattern, 0, 1 for clockwise (C) and anticlockwise (A) beams
69 void setBC(int bcID, bool active = true, int dir = -1);
70 void setBCTrain(int nBC, int bcSpacing, int firstBC, int dir = -1);
71 void setBCTrains(int nTrains, int trainSpacingInBC, int nBC, int bcSpacing, int firstBC, int dir = -1);
72
73 // new format for setting bunches pattern, see createPattern comments
74 void setBCFilling(const std::string& patt, int dir = -1);
75
77
78 int getFirstFilledBC(int dir = -1) const;
79 int getLastFilledBC(int dir = -1) const;
80
81 // print pattern of bunches, dir=0,1: for C,A beams, dir=-1: for interacting BCs, otherwise: all
82 void print(int dir = -2, bool filledOnly = true, int bcPerLine = 20) const;
83
84 // get vector with filled BCs
85 std::vector<int> getFilledBCs(int dir = -1) const;
86
87 // set BC filling a la TPC TDR, 12 50ns trains of 48 BCs
88 // but instead of uniform train spacing we add 96empty BCs after each train
90 {
91 // setBCTrains(12, 96, 48, 2, 0); // obsolete way of setting the trains
92 setBCFilling("12(48(HL) 96L)", 0);
93 setBCFilling("12(48(HL) 96L)", 1);
95 }
96
97 // merge this bunch filling with other
98 void mergeWith(o2::BunchFilling const& other);
99
100 static BunchFilling* loadFrom(const std::string& fileName, const std::string& objName = "");
101
102 private:
103 static bool parsePattern(const unsigned char*& input, Pattern& patt, int& ibit, int& level);
104
105 Pattern mPattern{}; // Pattern of interacting BCs at P2
106 std::array<Pattern, o2::constants::lhc::NBeamDirections> mBeamAC{}; // pattern of 2 beam bunches at P2, 0 for A, 1 for C beam
107
108 ClassDefNV(BunchFilling, 2);
109};
110} // namespace o2
111
112namespace framework
113{
114template <typename T>
115struct is_messageable;
116template <>
117struct is_messageable<o2::BunchFilling> : std::true_type {
118};
119
120} // namespace framework
121
122#endif
void print() const
Header to collect LHC related constants.
const auto & getPattern(int dir=-1) const
void mergeWith(o2::BunchFilling const &other)
std::bitset< o2::constants::lhc::LHCMaxBunches > Pattern
void setBCTrains(int nTrains, int trainSpacingInBC, int nBC, int bcSpacing, int firstBC, int dir=-1)
static std::string buckets2PatternString(const std::vector< int > &buckets, int ibeam)
bool testBeamBunch(int bcID, int dir) const
void setBCTrain(int nBC, int bcSpacing, int firstBC, int dir=-1)
std::vector< int > getFilledBCs(int dir=-1) const
bool testInteractingBC(int bcID) const
int getNBunches(int dir=-1) const
int getLastFilledBC(int dir=-1) const
void setBC(int bcID, bool active=true, int dir=-1)
bool testBC(int bcID, int dir=-1) const
int getFirstFilledBC(int dir=-1) const
void setBCFilling(const std::string &patt, int dir=-1)
BunchFilling()=default
void setInteractingBCsFromBeams()
const auto & getBCPattern() const
void buckets2BeamPattern(const std::vector< int > &buckets, int ibeam)
const auto & getBeamPattern(int beam) const
static BunchFilling * loadFrom(const std::string &fileName, const std::string &objName="")
static Pattern createPattern(const std::string &p)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
VectorOfTObjectPtrs other