Project
Loading...
Searching...
No Matches
ctp-ccdb-orbit.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
12// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
13// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
14// All rights not expressly granted are reserved.
15//
16// This software is distributed under the terms of the GNU General Public
17// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
18//
19// In applying this license CERN does not waive the privileges and immunities
20// granted to it by virtue of its status as an Intergovernmental Organization
21// or submit itself to any jurisdiction.
22
23// example to run:
24//
25#include <boost/program_options.hpp>
26#include <filesystem>
27#include <TFile.h>
28#include <TStopwatch.h>
31#include <iostream>
32#include <vector>
33#include <string>
34namespace bpo = boost::program_options;
35//
36// get object from ccdb
37// auto & cc = o2::ccdb::BasicCCDNManager::instance();
38// auto pp = ccdbMgr.getSpecific<std::vector<long>>("CTP/Calib/OrbitResetTest")
39// std::cout << (*pp)[0] << std::endl;
40int main(int argc, char** argv)
41{
42 const std::string testCCDB = "http://ccdb-test.cern.ch:8080";
43 const std::string prodCCDB = "http://o2-ccdb.internal";
44 bpo::variables_map vm;
45 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
46 " Write orbit staff to ccdb\n");
47 bpo::options_description opt_hidden("");
48 bpo::options_description opt_all;
49 bpo::positional_options_description opt_pos;
50 try {
51 auto add_option = opt_general.add_options();
52 add_option("help,h", "Print this help message");
53 add_option("output-file,o", bpo::value<std::string>()->default_value("none"), "output file name, none - file not created");
54 add_option("output-dir,d", bpo::value<std::string>()->default_value("./"), "output dir");
55 add_option("ccdb", bpo::value<std::string>()->default_value("test"), "choose databse: test- test ccdb; prod - production ccdb; else ccdb parameter");
56 add_option("action,a", bpo::value<std::string>()->default_value(""), "sox - first orbit otherwise orbit reset");
57 add_option("run-number,r", bpo::value<int64_t>()->default_value(123), "run number");
58 add_option("testReset,t", bpo::value<bool>()->default_value(0), "0 = CTP/Calib/OrbitReset; 1 = CTP/Calib/OrbitResetTest");
59 add_option("sox-orbit,x", bpo::value<int64_t>()->default_value(0), "SOX orbit");
60 add_option("timestamp,s", bpo::value<uint64_t>()->default_value(0), "timestamp of SOX/orbit reading; if 0 timestamp is calulated inside this code");
61
62 //
63 opt_all.add(opt_general).add(opt_hidden);
64 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
65 if (vm.count("help")) {
66 std::cout << opt_general << std::endl;
67 exit(0);
68 }
69 bpo::notify(vm);
70 } catch (bpo::error& e) {
71 std::cerr << "ERROR: " << e.what() << std::endl
72 << std::endl;
73 std::cerr << opt_general << std::endl;
74 exit(1);
75 } catch (std::exception& e) {
76 std::cerr << e.what() << ", application will now exit" << std::endl;
77 exit(2);
78 }
79 int ret = 0;
80 std::string action = vm["action"].as<std::string>();
81 std::vector<int64_t> vect;
82 std::string ccdbPath;
83 long tt = vm["timestamp"].as<uint64_t>();
84 if (tt == 0) {
85 auto now = std::chrono::system_clock::now();
86 tt = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
87 }
88 vect.push_back(tt);
89 if (action == "sox") {
90 // write to CTP/Calib/FirstRunOrbit
91 std::cout << "===> FirsRunOrbit" << std::endl;
92 vect.push_back(vm["run-number"].as<int64_t>());
93 vect.push_back(vm["sox-orbit"].as<int64_t>());
94 ccdbPath = "CTP/Calib/FirstRunOrbit";
95 } else {
96 // write to CTP/Calib/OrbitReset
97 std::cout << "===> ResetOrbit" << std::endl;
98 ccdbPath = "CTP/Calib/OrbitReset";
99 if (vm["testReset"].as<bool>()) {
100 ccdbPath += "Test";
101 }
102 }
103 //
104 std::string ccdbAddress;
105 if (vm["ccdb"].as<std::string>() == "prod") {
106 ccdbAddress = prodCCDB;
107 } else if (vm["ccdb"].as<std::string>() == "test") {
108 ccdbAddress = testCCDB;
109 } else {
110 ccdbAddress = vm["ccdb"].as<std::string>();
111 }
112 std::cout << " Writing to db:" << ccdbAddress << std::endl;
113 if (ccdbAddress != "none") {
114 // auto& ccdbMgr = o2::ccdb::BasicCCDBManager::instance();
116 api.init(ccdbAddress.c_str());
117 std::map<std::string, std::string> metadata;
118 long tmin = tt / 1000;
119 long tmax = tmin + 381928219;
120 if (action == "sox") {
121 int64_t runnum = vm["run-number"].as<int64_t>();
122 metadata["runNumber"] = std::to_string(runnum);
123 std::cout << "Storing:" << ccdbPath << " " << metadata["runNumber"] << " tmin:" << tmin << " tmax:" << tmax << " ts:" << tt << std::endl;
124 ret = api.storeAsTFileAny(&(vect), ccdbPath, metadata, tmin, tmax);
125 } else {
126 std::cout << "Storing:" << ccdbPath << " tmin:" << tmin << " tmax:" << tmax << " ts:" << tt << std::endl;
127 std::string filename = "orbitReset.root";
128 auto classname = "std::vector<int64_t>";
129 metadata["adjustableEOV"] = "true";
130 ret = api.storeAsTFileAny(&(vect), ccdbPath, metadata, tmin, tmax);
131 o2::ccdb::CcdbObjectInfo oi(ccdbPath, classname, filename, metadata, tmin, tmax);
132 adjustOverriddenEOV(api, oi);
133 }
134 }
135 //
136 if (vm["output-file"].as<std::string>() != "none") {
137 std::string file = vm["output-dir"].as<std::string>() + vm["output-file"].as<std::string>();
138 TFile* f = TFile::Open(file.c_str(), "RECREATE");
139 if (f == nullptr) {
140 std::cout << "Error: File" << file << " could not be open for writing !!!" << std::endl;
141 ret++;
142 } else {
143 std::cout << "File" << file << " being writen." << std::endl;
144 f->WriteObject(&vect, "ccdb_object");
145 f->Close();
146 }
147 } else {
148 std::cout << "No file created" << std::endl;
149 }
150 return ret;
151}
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
std::string ccdbPath(const std::string badChannelType)
int storeAsTFileAny(const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const
Definition CcdbApi.h:163
void init(std::string const &hosts)
Definition CcdbApi.cxx:240
GLdouble f
Definition glcorearb.h:310
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
#define main