|
| 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