Project
Loading...
Searching...
No Matches
ElectronicsDelay.cxx
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
16
18
19#include <algorithm>
20#include <fstream>
21#include <string>
22
23namespace o2
24{
25namespace mid
26{
27
28std::ostream& operator<<(std::ostream& os, const ElectronicsDelay& delay)
29{
30 os << "calibToFET: " << delay.calibToFET << "\n";
31 os << "localToBC: " << delay.localToBC << "\n";
32 os << "localToReg: " << delay.localToReg << "\n";
33 return os;
34}
35
37{
38 ElectronicsDelay electronicsDelay;
39 std::ifstream inFile(filename);
40 if (inFile.is_open()) {
41 std::string line;
42 while (std::getline(inFile, line)) {
43 line.erase(std::remove_if(line.begin(), line.end(), [](unsigned char x) { return std::isspace(x); }), line.end());
44 auto pos = line.find(":");
45 if (pos != std::string::npos) {
46 std::string key = line.substr(0, pos);
47 int16_t val = std::atoi(line.substr(pos + 1).c_str());
48 if (key == "calibToFET") {
49 electronicsDelay.calibToFET = val;
50 } else if (key == "localToBC") {
51 electronicsDelay.localToBC = val;
52 } else if (key == "localToReg") {
53 electronicsDelay.localToReg = val;
54 }
55 }
56 }
57 } else {
58 std::cout << "Error: cannot open file " << filename << std::endl;
59 }
60 return electronicsDelay;
61}
62
63void applyElectronicsDelay(uint32_t& orbit, uint16_t& bc, int16_t delay, uint16_t maxBunches)
64{
65 int16_t val = static_cast<int16_t>(bc) + delay;
66 int16_t resetPeriod = static_cast<int16_t>(maxBunches);
67 if (val < 0) {
68 // If corrected clock is smaller than 0 it means that the local clock was reset
69 // This event therefore belongs to the previous orbit.
70 // We therefore add the value of the last BC (+1 to account for the reset)
71 // and we decrease the orbit by 1.
72 --orbit;
73 val += resetPeriod;
74 } else if (val >= resetPeriod) {
75 // If the corrected clock is larger than the maximum clock (corresponding to the reset)
76 // it means that this event belongs to the next orbit
77 ++orbit;
78 val -= resetPeriod;
79 }
80 // The previous line ensure that 0<val<maxBunches, so we can safely convert the int in unit16_t
81 bc = static_cast<uint16_t>(val);
82}
83
84} // namespace mid
85} // namespace o2
Delay parameters for MID electronics.
uint64_t orbit
Definition RawEventData.h:6
uint64_t bc
Definition RawEventData.h:5
uint16_t pos
Definition RawData.h:3
StringRef key
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLfloat * val
Definition glcorearb.h:1582
std::ostream & operator<<(std::ostream &os, const Cluster &data)
Definition Cluster.cxx:27
void applyElectronicsDelay(uint32_t &orbit, uint16_t &bc, int16_t delay, uint16_t maxBunches=constants::lhc::LHCMaxBunches)
ElectronicsDelay readElectronicsDelay(const char *filename)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
int16_t localToReg
Delay between regional board and local board answers.
int16_t calibToFET
Delay between FET and calibration event.
int16_t localToBC
Delay between collision BC and local clock.