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
19 changes: 17 additions & 2 deletions Detectors/TRD/calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,30 @@ o2_add_library(TRDCalibration
SOURCES src/TrackBasedCalib.cxx
src/CalibratorVdExB.cxx
src/KrClusterFinder.cxx
src/DCSProcessor.cxx
PUBLIC_LINK_LIBRARIES O2::TRDBase
O2::DataFormatsTRD
O2::DataFormatsGlobalTracking
O2::DetectorsBase
O2::DetectorsCalibration
O2::MathUtils
O2::GPUTracking)
O2::GPUTracking
O2::DetectorsDCS)

o2_target_root_dictionary(TRDCalibration
HEADERS include/TRDCalibration/TrackBasedCalib.h
include/TRDCalibration/CalibratorVdExB.h
include/TRDCalibration/KrClusterFinder.h)
include/TRDCalibration/KrClusterFinder.h
include/TRDCalibration/DCSProcessor.h)

o2_add_executable(trd-dcs-sim-workflow
COMPONENT_NAME calibration
SOURCES workflow/trd-dcs-sim-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::DCStestWorkflow)

o2_add_executable(trd-dcs-workflow
COMPONENT_NAME calibration
SOURCES workflow/trd-dcs-data-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::Framework
O2::TRDCalibration
O2::DetectorsDCS)
106 changes: 106 additions & 0 deletions Detectors/TRD/calibration/include/TRDCalibration/DCSProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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.

#ifndef DETECTOR_TRDDCSPROCESSOR_H_
#define DETECTOR_TRDDCSPROCESSOR_H_

#include "Framework/Logger.h"
#include "DetectorsDCS/DataPointCompositeObject.h"
#include "DetectorsDCS/DataPointIdentifier.h"
#include "DetectorsDCS/DataPointValue.h"
#include "DetectorsDCS/DeliveryType.h"
#include "CCDB/CcdbObjectInfo.h"
#include "CommonUtils/MemFileHelper.h"
#include "CCDB/CcdbApi.h"
#include <Rtypes.h>
#include <unordered_map>
#include <string>
#include <gsl/gsl>

/// @brief Class to process TRD DCS data points

namespace o2
{
namespace trd
{

using DPID = o2::dcs::DataPointIdentifier;
using DPVAL = o2::dcs::DataPointValue;
using DPCOM = o2::dcs::DataPointCompositeObject;

struct TRDDCSMinMaxMeanInfo {
float minValue{0.f}; // min value seen by the TRD DCS processor
float maxValue{0.f}; // max value seen by the TRD DCS processor
float meanValue{0.f}; // mean value seen by the TRD DCS processor
int nPoints{0}; // number of values seen by the TRD DCS processor

void print() const;
void addPoint(float value);

ClassDefNV(TRDDCSMinMaxMeanInfo, 1);
};

class DCSProcessor
{

public:
using TFType = uint64_t;
using CcdbObjectInfo = o2::ccdb::CcdbObjectInfo;

DCSProcessor() = default;
~DCSProcessor() = default;

void init(const std::vector<DPID>& pids);

int process(const gsl::span<const DPCOM> dps);
int processDP(const DPCOM& dpcom);
int processFlags(uint64_t flag, const char* pid);

void updateDPsCCDB();

const CcdbObjectInfo& getccdbDPsInfo() const { return mCcdbDPsInfo; }
CcdbObjectInfo& getccdbDPsInfo() { return mCcdbDPsInfo; }
const std::unordered_map<DPID, TRDDCSMinMaxMeanInfo>& getTRDDPsInfo() const { return mTRDDCS; }

template <typename T>
void prepareCCDBobjectInfo(T& obj, CcdbObjectInfo& info, const std::string& path, TFType tf,
const std::map<std::string, std::string>& md);

void setStartValidity(TFType tf) { mStartValidity = tf; }
void useVerboseMode() { mVerbose = true; }

void clearDPsinfo()
{
mDpsDoublesmap.clear();
mTRDDCS.clear();
}

private:
std::unordered_map<DPID, TRDDCSMinMaxMeanInfo> mTRDDCS; // this is the object that will go to the CCDB
std::unordered_map<DPID, bool> mPids; // contains all PIDs for the processor, the bool
// will be true if the DP was processed at least once
std::unordered_map<DPID, std::vector<DPCOM>> mDpsDoublesmap; // this is the map that will hold the DPs for the
// double type

CcdbObjectInfo mCcdbDPsInfo;
TFType mStartTF; // TF index for processing of first processed TF, used to store CCDB object
TFType mStartValidity = 0; // TF index for processing, used to store CCDB object
bool mStartTFset = false;

bool mVerbose = false;

ClassDefNV(DCSProcessor, 0);
};

} // namespace trd
} // namespace o2

#endif
17 changes: 17 additions & 0 deletions Detectors/TRD/calibration/macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.

if(BUILD_TESTING)
o2_add_test_root_macro(checkNoisyMCMs.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsTRD
O2::CCDB
LABELS trd)
endif()

o2_add_test_root_macro(makeTRDCCDBEntryForDCS.C
PUBLIC_LINK_LIBRARIES O2::DetectorsDCS
O2::CCDB
LABELS trd)

o2_add_test_root_macro(readTRDDCSentries.C
PUBLIC_LINK_LIBRARIES O2::DetectorsDCS
O2::CCDB
LABELS trd)

install(
FILES makeTRDCCDBEntryForDCS.C
readTRDDCSentries.C
DESTINATION share/macro/)
56 changes: 56 additions & 0 deletions Detectors/TRD/calibration/macros/makeTRDCCDBEntryForDCS.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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.

#include <vector>
#include <string>
#include "TFile.h"
#include "CCDB/CcdbApi.h"
#include "DetectorsDCS/AliasExpander.h"
#include "DetectorsDCS/DeliveryType.h"
#include "DetectorsDCS/DataPointIdentifier.h"

#include <unordered_map>
#include <chrono>

using DPID = o2::dcs::DataPointIdentifier;

int makeTRDCCDBEntryForDCS(const std::string url = "http://localhost:8080")
{

// macro to populate CCDB for TRD with the configuration for DCS
std::unordered_map<DPID, std::string> dpid2DataDesc;
std::vector<std::string> aliasesFloat;
aliasesFloat.insert(aliasesFloat.end(), {"trd_gasCO2", "trd_gasH2O", "trd_gasO2"});
aliasesFloat.insert(aliasesFloat.end(), {"trd_gaschromatographCO2", "trd_gaschromatographN2", "trd_gaschromatographXe"});
// aliasesFloat.insert(aliasesFloat.end(), {"trd_hvAnodeImon[00..539]", "trd_hvAnodeUmon[00..539]", "trd_hvDriftImon[00..539]", "trd_hvDriftImon[00..539]"});
// std::vector<std::string> aliasesInt = {"trd_fedChamberStatus[00..539]", "trd_runNo", "trd_runType"};
std::vector<std::string> aliasesInt = {"trd_runNo", "trd_runType"};
std::vector<std::string> expAliasesFloat = o2::dcs::expandAliases(aliasesFloat);
std::vector<std::string> expAliasesInt = o2::dcs::expandAliases(aliasesInt);

DPID dpidTmp;
for (size_t i = 0; i < expAliasesFloat.size(); ++i) {
DPID::FILL(dpidTmp, expAliasesFloat[i], o2::dcs::DeliveryType::DPVAL_DOUBLE);
dpid2DataDesc[dpidTmp] = "TRDDATAPOINTS";
}
for (size_t i = 0; i < expAliasesInt.size(); ++i) {
DPID::FILL(dpidTmp, expAliasesInt[i], o2::dcs::DeliveryType::DPVAL_INT);
dpid2DataDesc[dpidTmp] = "TRDDATAPOINTS";
}

o2::ccdb::CcdbApi api;
api.init(url);
std::map<std::string, std::string> md;
long ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
api.storeAsTFileAny(&dpid2DataDesc, "TRD/Config/DCSDPconfig", md, ts);

return 0;
}
68 changes: 68 additions & 0 deletions Detectors/TRD/calibration/macros/readTRDDCSentries.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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.

// macro to read the TOF DCS information from CCDB
// default ts is very big: Saturday, November 20, 2286 5:46:39 PM

#if !defined(__CLING__) || defined(__ROOTCLING__)
#include "CCDB/CcdbApi.h"
#include "DetectorsDCS/DataPointIdentifier.h"

#include <string>
#include <unordered_map>
#include <chrono>
#include <bitset>
#endif

void readTRDDCSentries(long ts = 9999999999000, const char* ccdb = "http://localhost:8080")
{

o2::ccdb::CcdbApi api;
api.init(ccdb); // or http://ccdb-test.cern.ch:8080
std::map<std::string, std::string> metadata;
if (ts == 9999999999000) {
ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

std::unordered_map<o2::dcs::DataPointIdentifier, std::string>* map = api.retrieveFromTFileAny<std::unordered_map<o2::dcs::DataPointIdentifier, std::string>>("TRD/Config/DCSDPconfig", metadata, ts);
for (auto& i : *map) {
std::cout << "id = " << i.first << std::endl;
std::cout << "string= " << i.second << std::endl;
}
/*
std::unordered_map<o2::dcs::DataPointIdentifier, o2::tof::TOFDCSinfo>* m = api.retrieveFromTFileAny<std::unordered_map<o2::dcs::DataPointIdentifier, o2::tof::TOFDCSinfo>>("TOF/DCSDPs", metadata, ts);
std::cout << "size of map = " << m->size() << std::endl;

for (auto& i : *m) {
std::cout << "id = " << i.first << std::endl;
i.second.print();
}

std::bitset<o2::tof::Geo::NCHANNELS>* feac = api.retrieveFromTFileAny<std::bitset<o2::tof::Geo::NCHANNELS>>("TOF/LVStatus", metadata, ts);
//std::cout << "LV info (FEAC): " << feac->to_string() << std::endl;
std::cout << "LV info (FEAC): number of channels that are ON = " << feac->count() << std::endl;
for (int ich = 0; ich < o2::tof::Geo::NCHANNELS; ++ich) {
if (feac->test(ich) != 0) {
std::cout << "LV for channel " << ich << " is ON" << std::endl;
}
}

std::bitset<o2::tof::Geo::NCHANNELS>* hv = api.retrieveFromTFileAny<std::bitset<o2::tof::Geo::NCHANNELS>>("TOF/HVStatus", metadata, ts);
//std::cout << "HV info : " << hv->to_string() << std::endl;
std::cout << "HV info : number of channels that are ON = " << hv->count() << std::endl;
for (int ich = 0; ich < o2::tof::Geo::NCHANNELS; ++ich) {
if (hv->test(ich) != 0) {
std::cout << "HV for channel " << ich << " is ON" << std::endl;
}
}
*/
return;
}
Loading