Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions DataFormats/Detectors/ITSMFT/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ o2_add_library(DataFormatsITSMFT
src/ClusterPattern.cxx
src/ClusterTopology.cxx
src/TopologyDictionary.cxx
src/TimeDeadMap.cxx
src/CTF.cxx
PUBLIC_LINK_LIBRARIES O2::ITSMFTBase
O2::ReconstructionDataFormats
Microsoft.GSL::GSL)

o2_target_root_dictionary(DataFormatsITSMFT
HEADERS include/DataFormatsITSMFT/ROFRecord.h
include/DataFormatsITSMFT/Digit.h
include/DataFormatsITSMFT/GBTCalibData.h
include/DataFormatsITSMFT/NoiseMap.h
include/DataFormatsITSMFT/TimeDeadMap.h
include/DataFormatsITSMFT/Digit.h
include/DataFormatsITSMFT/GBTCalibData.h
include/DataFormatsITSMFT/NoiseMap.h
include/DataFormatsITSMFT/TimeDeadMap.h
include/DataFormatsITSMFT/Cluster.h
include/DataFormatsITSMFT/CompCluster.h
include/DataFormatsITSMFT/ClusterPattern.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#define ALICEO2_ITSMFT_TIMEDEADMAP_H

#include "Rtypes.h"
#include "DetectorsCommonDataFormats/DetID.h"
#include <iostream>
#include <vector>
#include <map>

Expand All @@ -26,6 +24,8 @@ namespace o2
namespace itsmft
{

class NoiseMap;

class TimeDeadMap
{
public:
Expand Down Expand Up @@ -56,96 +56,17 @@ class TimeDeadMap
mStaticDeadMap.clear();
}

void decodeMap(o2::itsmft::NoiseMap& noisemap)
{ // for static part only
if (mMAP_VERSION == "3") {
LOG(error) << "Trying to decode static part of deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing.";
return;
}
for (int iel = 0; iel < mStaticDeadMap.size(); iel++) {
uint16_t w = mStaticDeadMap[iel];
noisemap.maskFullChip(w & 0x7FFF);
if (w & 0x8000) {
for (int w2 = (w & 0x7FFF) + 1; w2 < mStaticDeadMap.at(iel + 1); w2++) {
noisemap.maskFullChip(w2);
}
}
}
}

void decodeMap(unsigned long orbit, o2::itsmft::NoiseMap& noisemap, bool includeStaticMap = true, long orbitGapAllowed = 330000)
{ // for time-dependent and (optionally) static part. Use orbitGapAllowed = -1 to ignore check on orbit difference

if (mMAP_VERSION != "3" && mMAP_VERSION != "4") {
LOG(error) << "Trying to decode time-dependent deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing.";
return;
}

if (mEvolvingDeadMap.empty()) {
LOG(warning) << "Time-dependent dead map is empty. Doing nothing.";
return;
}

std::vector<uint16_t> closestVec;
long dT = getMapAtOrbit(orbit, closestVec);

if (orbitGapAllowed >= 0 && std::abs(dT) > orbitGapAllowed) {
LOG(warning) << "Requested orbit " << orbit << ", found " << orbit - dT << ". Orbit gap is too high, skipping time-dependent map.";
closestVec.clear();
}

// add static part if requested. something may be masked twice
if (includeStaticMap && mMAP_VERSION != "3") {
closestVec.insert(closestVec.end(), mStaticDeadMap.begin(), mStaticDeadMap.end());
}

// vector encoding: if 1<<15 = 0x8000 is set, the word encodes the first element of a range, with mask (1<<15)-1 = 0x7FFF. The last element of the range is the next in the vector.

for (int iel = 0; iel < closestVec.size(); iel++) {
uint16_t w = closestVec.at(iel);
noisemap.maskFullChip(w & 0x7FFF);
if (w & 0x8000) {
for (int w2 = (w & 0x7FFF) + 1; w2 < closestVec.at(iel + 1); w2++) {
noisemap.maskFullChip(w2);
}
}
}
};

void decodeMap(NoiseMap& noisemap) const;
void decodeMap(unsigned long orbit, o2::itsmft::NoiseMap& noisemap, bool includeStaticMap = true, long orbitGapAllowed = 330000) const;
std::string getMapVersion() const { return mMAP_VERSION; };

unsigned long getEvolvingMapSize() const { return mEvolvingDeadMap.size(); };

std::vector<unsigned long> getEvolvingMapKeys()
{
std::vector<unsigned long> keys;
std::transform(mEvolvingDeadMap.begin(), mEvolvingDeadMap.end(), std::back_inserter(keys),
[](const auto& O) { return O.first; });
return keys;
}

void getStaticMap(std::vector<uint16_t>& mmap) { mmap = mStaticDeadMap; };

long getMapAtOrbit(unsigned long orbit, std::vector<uint16_t>& mmap)
{ // fills mmap and returns requested_orbit - found_orbit. Found orbit is the highest key lower or equal to the requested one
if (mEvolvingDeadMap.empty()) {
LOG(warning) << "Requested orbit " << orbit << "from an empty time-dependent map. Doing nothing";
return (long)orbit;
}
auto closest = mEvolvingDeadMap.upper_bound(orbit);
if (closest != mEvolvingDeadMap.begin()) {
--closest;
mmap = closest->second;
return (long)orbit - closest->first;
} else {
mmap = mEvolvingDeadMap.begin()->second;
return (long)(orbit)-mEvolvingDeadMap.begin()->first;
}
}

std::vector<unsigned long> getEvolvingMapKeys() const;
void getStaticMap(std::vector<uint16_t>& mmap) const { mmap = mStaticDeadMap; };
long getMapAtOrbit(unsigned long orbit, std::vector<uint16_t>& mmap) const;
void setMapVersion(std::string version) { mMAP_VERSION = version; };

bool isDefault() { return mIsDefaultObject; };
bool isDefault() const { return mIsDefaultObject; };
void setAsDefault(bool isdef = true) { mIsDefaultObject = isdef; };

private:
Expand Down
100 changes: 100 additions & 0 deletions DataFormats/Detectors/ITSMFT/common/src/TimeDeadMap.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file TimeDeadMap.cxx
/// \brief Implementation of the time-dependent map

#include "DataFormatsITSMFT/TimeDeadMap.h"
#include "DataFormatsITSMFT/NoiseMap.h"
#include "Framework/Logger.h"

using namespace o2::itsmft;

void TimeDeadMap::decodeMap(o2::itsmft::NoiseMap& noisemap) const
{ // for static part only
if (mMAP_VERSION == "3") {
LOG(error) << "Trying to decode static part of deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing.";
return;
}
for (int iel = 0; iel < mStaticDeadMap.size(); iel++) {
uint16_t w = mStaticDeadMap[iel];
noisemap.maskFullChip(w & 0x7FFF);
if (w & 0x8000) {
for (int w2 = (w & 0x7FFF) + 1; w2 < mStaticDeadMap.at(iel + 1); w2++) {
noisemap.maskFullChip(w2);
}
}
}
}

void TimeDeadMap::decodeMap(unsigned long orbit, o2::itsmft::NoiseMap& noisemap, bool includeStaticMap, long orbitGapAllowed) const
{ // for time-dependent and (optionally) static part. Use orbitGapAllowed = -1 to ignore check on orbit difference

if (mMAP_VERSION != "3" && mMAP_VERSION != "4") {
LOG(error) << "Trying to decode time-dependent deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing.";
return;
}

if (mEvolvingDeadMap.empty()) {
LOG(warning) << "Time-dependent dead map is empty. Doing nothing.";
return;
}

std::vector<uint16_t> closestVec;
long dT = getMapAtOrbit(orbit, closestVec);

if (orbitGapAllowed >= 0 && std::abs(dT) > orbitGapAllowed) {
LOG(warning) << "Requested orbit " << orbit << ", found " << orbit - dT << ". Orbit gap is too high, skipping time-dependent map.";
closestVec.clear();
}

// add static part if requested. something may be masked twice
if (includeStaticMap && mMAP_VERSION != "3") {
closestVec.insert(closestVec.end(), mStaticDeadMap.begin(), mStaticDeadMap.end());
}

// vector encoding: if 1<<15 = 0x8000 is set, the word encodes the first element of a range, with mask (1<<15)-1 = 0x7FFF. The last element of the range is the next in the vector.

for (int iel = 0; iel < closestVec.size(); iel++) {
uint16_t w = closestVec.at(iel);
noisemap.maskFullChip(w & 0x7FFF);
if (w & 0x8000) {
for (int w2 = (w & 0x7FFF) + 1; w2 < closestVec.at(iel + 1); w2++) {
noisemap.maskFullChip(w2);
}
}
}
}

std::vector<unsigned long> TimeDeadMap::getEvolvingMapKeys() const
{
std::vector<unsigned long> keys;
std::transform(mEvolvingDeadMap.begin(), mEvolvingDeadMap.end(), std::back_inserter(keys),
[](const auto& O) { return O.first; });
return keys;
}

long TimeDeadMap::getMapAtOrbit(unsigned long orbit, std::vector<uint16_t>& mmap) const
{ // fills mmap and returns requested_orbit - found_orbit. Found orbit is the highest key lower or equal to the requested one
if (mEvolvingDeadMap.empty()) {
LOG(warning) << "Requested orbit " << orbit << "from an empty time-dependent map. Doing nothing";
return (long)orbit;
}
auto closest = mEvolvingDeadMap.upper_bound(orbit);
if (closest != mEvolvingDeadMap.begin()) {
--closest;
mmap = closest->second;
return (long)orbit - closest->first;
} else {
mmap = mEvolvingDeadMap.begin()->second;
return (long)(orbit)-mEvolvingDeadMap.begin()->first;
}
}