Skip to content

Commit df8ed9b

Browse files
MagField object added
clang-format
1 parent a7f27a7 commit df8ed9b

9 files changed

Lines changed: 187 additions & 1 deletion

File tree

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
5252
// Filename of general run parameters from ECS (GRPECS)
5353
static std::string getGRPECSFileName(const std::string_view prefix = STANDARDSIMPREFIX);
5454

55+
// Filename of general run parameters fof B field (GRPMagField)
56+
static std::string getGRPMagFieldFileName(const std::string_view prefix = STANDARDSIMPREFIX);
57+
5558
// Filename to store kinematics + TrackRefs
5659
static std::string getMCKinematicsFileName(const std::string_view prefix = STANDARDSIMPREFIX)
5760
{
@@ -123,6 +126,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
123126
static constexpr std::string_view DIGITS_STRING = "Digits"; // hardcoded
124127
static constexpr std::string_view GRP_STRING = "grp"; // hardcoded
125128
static constexpr std::string_view GRPECS_STRING = "grpecs"; // hardcoded
129+
static constexpr std::string_view GRPMAGFIELD_STRING = "grpMagField"; // hardcoded
126130
static constexpr std::string_view KINE_STRING = "Kine"; // hardcoded
127131
static constexpr std::string_view MCHEADER_STRING = "MCHeader"; // hardcoded
128132
static constexpr std::string_view GEOM_FILE_STRING = "geometry";
@@ -139,6 +143,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
139143
// these are configurable paths for some commonly used files
140144
std::string mDirGRP = "none"; // directory for GRP file ("none" == "")
141145
std::string mDirGRPECS = "none"; // directory for GRPECS file ("none" == "")
146+
std::string mDirGRPMagField = "none"; // directory for GRPMagField file ("none" == "")
142147
std::string mDirGeom = "none"; // directory for geometry file
143148
std::string mDirMatLUT = "none"; // directory for material LUT
144149
std::string mDirCollContext = "none"; // directory for collision context

DataFormats/Detectors/Common/src/NameConf.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ std::string NameConf::getGRPECSFileName(const std::string_view prefix)
6161
return buildFileName(prefix, "_", STANDARDSIMPREFIX, GRPECS_STRING, ROOT_EXT_STRING, Instance().mDirGRPECS);
6262
}
6363

64+
// Filename to store general run parameters from ECS (GRPECS)
65+
std::string NameConf::getGRPMagFieldFileName(const std::string_view prefix)
66+
{
67+
return buildFileName(prefix, "_", STANDARDSIMPREFIX, GRPMAGFIELD_STRING, ROOT_EXT_STRING, Instance().mDirGRPMagField);
68+
}
69+
6470
// Filename to store simulation cuts/process summary
6571
std::string NameConf::getCutProcFileName(std::string_view prefix)
6672
{

DataFormats/Parameters/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ o2_add_library(DataFormatsParameters
1313
SOURCES src/GRPObject.cxx
1414
src/LHCIFData.cxx
1515
src/GRPECSObject.cxx
16+
src/GRPMagField.cxx
1617
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants
1718
O2::CommonTypes
1819
O2::DetectorsCommonDataFormats)
@@ -21,6 +22,7 @@ o2_target_root_dictionary(DataFormatsParameters
2122
HEADERS include/DataFormatsParameters/GRPObject.h
2223
include/DataFormatsParameters/LHCIFData.h
2324
include/DataFormatsParameters/GRPECSObject.h
25+
include/DataFormatsParameters/GRPMagField.h
2426
LINKDEF src/ParametersDataLinkDef.h)
2527

2628

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
12+
/// \file GRPMagField.h
13+
/// \brief Header of the General Run Parameters object for B field values
14+
/// \author ruben.shahoyan@cern.ch
15+
16+
#ifndef ALICEO2_DATA_GRPMAGFIELDOBJECT_H_
17+
#define ALICEO2_DATA_GRPMAGFIELDOBJECT_H_
18+
19+
#include <Rtypes.h>
20+
#include <cstdint>
21+
#include "CommonTypes/Units.h"
22+
23+
namespace o2
24+
{
25+
namespace parameters
26+
{
27+
/*
28+
* Collects parameters describing the run that are related to the B field only.
29+
*/
30+
31+
class GRPMagField
32+
{
33+
public:
34+
GRPMagField() = default;
35+
~GRPMagField() = default;
36+
37+
/// getters/setters for magnets currents
38+
o2::units::Current_t getL3Current() const { return mL3Current; }
39+
o2::units::Current_t getDipoleCurrent() const { return mDipoleCurrent; }
40+
bool getFieldUniformity() const { return mUniformField; }
41+
void setL3Current(o2::units::Current_t v) { mL3Current = v; }
42+
void setDipoleCurrent(o2::units::Current_t v) { mDipoleCurrent = v; }
43+
void setFieldUniformity(bool v) { mUniformField = v; }
44+
45+
/// print itself
46+
void print() const { printf("magnet currents (A) L3 = %.3f, Dipole = %.f; uniformity = %s\n", getL3Current(), getDipoleCurrent(), mUniformField ? "true" : "false"); }
47+
48+
static GRPMagField* loadFrom(const std::string& grpMagFieldFileName = "", const std::string& grpMagFieldName = "GRPMAGFIELD");
49+
50+
private:
51+
o2::units::Current_t mL3Current = 0.f; ///< signed current in L3
52+
o2::units::Current_t mDipoleCurrent = 0.f; ///< signed current in Dipole
53+
bool mUniformField = false; ///< uniformity of magnetic field
54+
55+
ClassDefNV(GRPMagField, 1);
56+
};
57+
58+
} // namespace parameters
59+
} // namespace o2
60+
61+
#endif

DataFormats/Parameters/src/GRPECSObject.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// or submit itself to any jurisdiction.
1111

1212
/// \file GRPECSObject.cxx
13-
/// \brief Implementation of General Run Parameters object
13+
/// \brief Implementation of General Run Parameters object from ECS
1414
/// \author ruben.shahoyan@cern.ch
1515

1616
#include <FairLogger.h>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
12+
/// \file GRPMagField.cxx
13+
/// \brief Implementation of General Run Parameters object for MagField
14+
/// \author ruben.shahoyan@cern.ch
15+
16+
#include <FairLogger.h>
17+
#include "DataFormatsParameters/GRPMagField.h"
18+
#include "DetectorsCommonDataFormats/NameConf.h"
19+
20+
using namespace o2::parameters;
21+
22+
//_______________________________________________
23+
GRPMagField* GRPMagField::loadFrom(const std::string& grpMagFieldFileName, const std::string& grpMagFieldName)
24+
{
25+
// load object from file
26+
auto fname = o2::base::NameConf::getGRPMagFieldFileName(grpMagFieldFileName);
27+
TFile flGRPMagField(fname.c_str());
28+
if (flGRPMagField.IsZombie()) {
29+
LOG(ERROR) << "Failed to open " << fname;
30+
throw std::runtime_error("Failed to open GRP Mag Field file");
31+
}
32+
auto grpMagField = reinterpret_cast<o2::parameters::GRPMagField*>(
33+
flGRPMagField.GetObjectChecked(grpMagFieldName.data(), o2::parameters::GRPMagField::Class()));
34+
if (!grpMagField) {
35+
LOG(ERROR) << "Did not find GRP Mag Field object named " << grpMagFieldName;
36+
throw std::runtime_error("Failed to load GRP Mag Field object");
37+
}
38+
return grpMagField;
39+
}

DataFormats/Parameters/src/ParametersDataLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
#pragma link C++ class o2::parameters::LHCIFData + ;
2828
#pragma link C++ class std::pair < long, std::string> + ;
2929
#pragma link C++ class o2::parameters::GRPECSObject + ;
30+
#pragma link C++ class o2::parameters::GRPMagField + ;
3031

3132
#endif

macro/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ install(FILES CheckDigits_mft.C
5555
UploadDummyAlignment.C
5656
CreateCTPOrbitResetObject.C
5757
CreateGRPECSObject.C
58+
CreateGRPMagFieldObject.C
5859
DESTINATION share/macro/)
5960

6061
# FIXME: a lot of macros that are here should really be elsewhere. Those which
@@ -351,6 +352,18 @@ o2_add_test_root_macro(CreateGRPECSObject.C
351352
O2::DetectorsCommonDataFormats
352353
O2::CCDB)
353354

355+
o2_add_test_root_macro(CreateGRPMagFieldObject.C
356+
PUBLIC_LINK_LIBRARIES O2::DataFormatsParameters
357+
O2::CommonTypes
358+
O2::CCDB)
359+
360+
o2_add_test_root_macro(UploadMatBudLUT.C
361+
PUBLIC_LINK_LIBRARIES O2::DetectorsCommonDataFormats
362+
O2::CCDB
363+
O2::DataFormatsParameters
364+
O2::DetectorsBase
365+
O2::CommonUtils)
366+
354367
#
355368
# NOTE: commented out until unit testing reenabled FIXME : re-enable or delete ?
356369
#

macro/CreateGRPMagFieldObject.C

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
12+
#if !defined(__CLING__) || defined(__ROOTCLING__)
13+
14+
#include <ctime>
15+
#include <chrono>
16+
#include "DataFormatsParameters/GRPMagField.h"
17+
#include "CCDB/CcdbApi.h"
18+
#include "CommonTypes/Units.h"
19+
20+
#endif
21+
22+
using timePoint = std::time_t;
23+
using CcdbApi = o2::ccdb::CcdbApi;
24+
using GRPMagField = o2::parameters::GRPMagField;
25+
using current = o2::units::Current_t;
26+
27+
// Simple macro to exemplify how to fill a GRPMagField object (GRP object containing the information on the magnetic field)
28+
29+
// e.g.
30+
/*
31+
.L CreateGRPMagFieldObject.C+
32+
float l3 = 30000 // Ampere
33+
float dipole = 6000 // Ampere
34+
std::time_t tStart = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count()
35+
std::time_t tEnd = (tStart + 60 * 60 * 24 * 365) * 1000; // 1 year validity, just an example
36+
bool isUniform = true
37+
int runNb = 123456
38+
CreateGRPMagFieldObject(l3, dipole, tStart, runNb, tEnd, isUniform)
39+
*/
40+
41+
void CreateGRPMagFieldObject(current l3, current dipole, timePoint start, int run, timePoint end = -1, bool isUniform = true, std::string ccdbPath = "http://ccdb-test.cern.ch:8080")
42+
{
43+
44+
GRPMagField grp;
45+
grp.setL3Current(l3);
46+
grp.setDipoleCurrent(dipole);
47+
grp.setFieldUniformity(isUniform);
48+
49+
CcdbApi api;
50+
api.init(ccdbPath);
51+
std::map<std::string, std::string> metadata;
52+
metadata["responsible"] = "DCS";
53+
metadata["run_number"] = std::to_string(run);
54+
//long ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
55+
if (end < 0) {
56+
end = (start + 60 * 60 * 10) * 1000; // start + 10h, in ms
57+
}
58+
api.storeAsTFileAny(&grp, "GLO/Config/GRPMagField", metadata, start * 1000, end); // making it 1-year valid to be sure we have something
59+
}

0 commit comments

Comments
 (0)