Project
Loading...
Searching...
No Matches
SyncPatternMonitor.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
15#ifndef ALICEO2_TPC_SYNCPATTERNMONITOR_H_
16#define ALICEO2_TPC_SYNCPATTERNMONITOR_H_
17
18#include <fairlogger/Logger.h>
19#include <iosfwd>
20#include <iomanip>
21#include <array>
22
23namespace o2
24{
25namespace tpc
26{
27
30
32{
33 public:
36
38 SyncPatternMonitor(int sampa, int lowHigh);
39
42
45
47 void reset();
48
55 short addSequence(const short hw0, const short hw1, const short hw2, const short hw3);
56
59 short getPosition() { return mPatternFound ? mHwWithPattern : -1; };
60
63 short getPatternA() const { return PATTERN_A; };
64
67 short getPatternB() const { return PATTERN_B; };
68
69 // Return first position to look for in whole pattern
71 short getSyncStart() const { return SYNC_START; };
72
73 private:
74 const static short SYNC_START = 2;
75 const static short PATTERN_A = 0x15;
76 const static short PATTERN_B = 0x0A;
77 static constexpr std::array<short, 32> SYNC_PATTERN{{PATTERN_A, PATTERN_A, PATTERN_B, PATTERN_B, PATTERN_A, PATTERN_A, PATTERN_B, PATTERN_B,
78 PATTERN_A, PATTERN_A, PATTERN_B, PATTERN_B, PATTERN_A, PATTERN_A, PATTERN_B, PATTERN_B,
79 PATTERN_A, PATTERN_A, PATTERN_A, PATTERN_A, PATTERN_B, PATTERN_B, PATTERN_B, PATTERN_B,
80 PATTERN_A, PATTERN_A, PATTERN_A, PATTERN_A, PATTERN_B, PATTERN_B, PATTERN_B, PATTERN_B}};
81
82 void patternFound(const short hw);
83
84 void checkWord(const short hw, const short pos);
85
86 bool mPatternFound;
87 short mPosition;
88 short mHwWithPattern;
89 int mSampa;
90 int mLowHigh;
91 unsigned mCheckedWords;
92};
93
94inline short SyncPatternMonitor::addSequence(const short hw0, const short hw1, const short hw2, const short hw3)
95{
96 checkWord(hw0, 1);
97 checkWord(hw1, 2);
98 checkWord(hw2, 3);
99 checkWord(hw3, 0);
100 return mPatternFound; //getPosition();
101};
102
103inline void SyncPatternMonitor::checkWord(const short hw, const short pos)
104{
105 ++mCheckedWords;
106 if (hw == SYNC_PATTERN[mPosition]) {
107 ++mPosition;
108 } else if (!(mPosition == SYNC_START + 2 && hw == SYNC_PATTERN[mPosition - 1])) {
109 mPosition = SYNC_START;
110 }
111 // Don't reset mPosition at the beginning to avoid missing of start of sync pattern in cases like
112 //
113 //
114 // ... A A A B B ...
115 //
116 // ^ ^ ^
117 // random A _| | |_ would trigger reset
118 // |
119 // real start
120
121 if (mPosition == 32) {
122 patternFound(pos);
123 }
124};
125
126inline void SyncPatternMonitor::patternFound(const short hw)
127{
128 LOG(debug) << "SAMPA " << mSampa << " (" << ((mLowHigh == 0) ? " low" : "high") << "): "
129 << "SYNC found at Position " << hw << " in checked half word #" << mCheckedWords;
130 if (mPatternFound) {
131 LOG(warning) << "SAMPA " << mSampa << " (" << ((mLowHigh == 0) ? " low" : "high") << "): "
132 << "SYNC was already found";
133 }
134 mPatternFound = true;
135 mPosition = SYNC_START;
136 mHwWithPattern = hw;
137};
138
139} // namespace tpc
140} // namespace o2
141#endif
uint16_t pos
Definition RawData.h:3
std::ostringstream debug
Class to monitor the data stream and detect synchronization patterns.
short addSequence(const short hw0, const short hw1, const short hw2, const short hw3)
SyncPatternMonitor(const SyncPatternMonitor &other)
Copy Constructor.
SyncPatternMonitor()
Default Constructor.
~SyncPatternMonitor()=default
Destructor.
void reset()
Reset function to clear history.
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
VectorOfTObjectPtrs other
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"