Project
Loading...
Searching...
No Matches
ctp-bk-write.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>
32#include "BookkeepingApi/BkpClientFactory.h"
33#include "BookkeepingApi/BkpClient.h"
34#include <iostream>
35#include <fstream>
36#include <vector>
37#include <string>
38namespace bpo = boost::program_options;
39//
40// Test in the lab
41// o2-ctp-bk-write -r 37 -s 1 -c 1 --ccdb='http://acsl-ccdb.cern.ch:8083' -b 'acsl-aliecs.cern.ch:4001' -t 1753185071753
42//
43int main(int argc, char** argv)
44{
45 const std::string testCCDB = "http://ccdb-test.cern.ch:8080";
46 // std::string prodCCDB = "http://o2-ccdb.internal";
47 const std::string aliceCCDB = "http://alice-ccdb.cern.ch";
48 bpo::variables_map vm;
49 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
50 " Write ctp config or scalers to BK\n");
51 bpo::options_description opt_hidden("");
52 bpo::options_description opt_all;
53 bpo::positional_options_description opt_pos;
54 try {
55 auto add_option = opt_general.add_options();
56 add_option("help,h", "Print this help message");
57 add_option("input-file,f", bpo::value<std::string>()->default_value("none"), "input file name, none - do not read file");
58 add_option("bkhost,b", bpo::value<std::string>()->default_value("none"), "bk web address");
59 add_option("ccdb", bpo::value<std::string>()->default_value("alice"), "choose databse: test- test ccdb; prod - production ccdb; alice - alice ccdb; else ccdb parameter");
60 add_option("run-number,r", bpo::value<uint32_t>()->default_value(0), "run number");
61 add_option("timestamp,t", bpo::value<uint64_t>()->default_value(0), "timestamp; if 0 timestamp is calulated inside this code");
62 add_option("cfg,c", bpo::value<bool>()->default_value(0), "Do cfg");
63 add_option("scalers,s", bpo::value<bool>()->default_value(0), "Do scalers");
64 //
65 opt_all.add(opt_general).add(opt_hidden);
66 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
67 if (vm.count("help")) {
68 std::cout << opt_general << std::endl;
69 exit(0);
70 }
71 bpo::notify(vm);
72 } catch (bpo::error& e) {
73 std::cerr << "ERROR: " << e.what() << std::endl
74 << std::endl;
75 std::cerr << opt_general << std::endl;
76 exit(1);
77 } catch (std::exception& e) {
78 std::cerr << e.what() << ", application will now exit" << std::endl;
79 exit(2);
80 }
81 uint64_t timestamp = vm["timestamp"].as<uint64_t>();
82 //
83 int ret = 0;
84 std::vector<std::string> runs;
85 int32_t run = vm["run-number"].as<uint32_t>();
86 std::cout << "run:" << run << std::endl;
87 if (run) {
88 std::cout << "pushing" << std::endl;
89 runs.push_back(std::to_string(run));
90 }
91 // read input file
92 std::string filename = vm["input-file"].as<std::string>();
93 if (filename != "none") {
94 std::ifstream file(filename);
95 if (!file.is_open()) {
96 LOG(fatal) << "Cannot open file:" << filename << std::endl;
97 } else {
98 std::string line;
99 while (std::getline(file, line)) {
100 std::cout << line << "\n";
101 std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
102 // int run = std::stoi(tokens[0]);
103 runs.push_back(tokens[0]);
104 }
105 }
106 }
107 bool cfg = vm["cfg"].as<bool>();
108 bool scalers = vm["scalers"].as<bool>();
109 std::cout << "Doing: cfg:" << cfg << " scal:" << scalers << std::endl;
110 if (cfg || scalers) {
111 std::string bkhost = vm["bkhost"].as<std::string>();
112 std::unique_ptr<o2::bkp::api::BkpClient> mBKClient = o2::bkp::api::BkpClientFactory::create(bkhost);
113 // get from ccdb
114 std::string ccdbAddress;
115 if (vm["ccdb"].as<std::string>() == "prod") {
116 // ccdbAddress = prodCCDB;
117 } else if (vm["ccdb"].as<std::string>() == "test") {
118 ccdbAddress = testCCDB;
119 } else if (vm["ccdb"].as<std::string>() == "alice") {
120 ccdbAddress = aliceCCDB;
121 } else {
122 ccdbAddress = vm["ccdb"].as<std::string>();
123 }
125 std::cout << "CCDB: " << vm["ccdb"].as<std::string>() << " " << ccdbAddress << std::endl;
126 std::map<std::string, std::string> metadata;
127 for (auto const& run : runs) {
128 metadata["runNumber"] = run;
129 bool ok;
130 int runNumber = std::stoi(run);
131 auto ctpcfg = o2::ctp::ctpCCDBManager::getConfigFromCCDB(timestamp, run, ok);
132
133 if (cfg) {
134 std::string ctpcfgstr = ctpcfg.getConfigString();
135 try {
136 mBKClient->run()->setRawCtpTriggerConfiguration(runNumber, ctpcfgstr);
137 } catch (std::runtime_error& error) {
138 std::cerr << "An error occurred: " << error.what() << std::endl;
139 // return 1;
140 }
141 LOG(info) << "Run BK:" << run << " CFG:" << cfg;
142 }
143 if (scalers) {
144 auto ctpcnts = o2::ctp::ctpCCDBManager::getScalersFromCCDB(timestamp, run, "CTP/Calib/Scalers", ok);
145 ctpcnts.convertRawToO2();
146 std::vector<uint32_t> clsinds = ctpcnts.getClassIndexes();
147 long ts = ctpcnts.getTimeLimit().second;
148 int i = 0;
149 for (auto const& ind : clsinds) {
150 std::array<uint64_t, 7> cntsbk = ctpcnts.getIntegralForClass(i);
151 std::string clsname = ctpcfg.getClassNameFromHWIndex(cntsbk[0]);
152 try {
153 mBKClient->ctpTriggerCounters()->createOrUpdateForRun(runNumber, clsname, ts, cntsbk[1], cntsbk[2], cntsbk[3], cntsbk[4], cntsbk[5], cntsbk[6]);
154 std::cout << runNumber << " clsname: " << cntsbk[0] << " " << clsname << " t:" << ts << " cnts:" << cntsbk[1] << " " << cntsbk[2] << " " << cntsbk[3] << " " << cntsbk[4] << " " << cntsbk[5] << " " << cntsbk[6] << std::endl;
155 ;
156
157 } catch (std::runtime_error& error) {
158 std::cerr << "An error occurred: " << error.what() << std::endl;
159 // return 1;
160 }
161 LOG(debug) << "Run BK scalers ok";
162 i++;
163 }
164 }
165 }
166 // add to bk
167 }
168 std::cout << "o2-ctp-bk-write done" << std::endl;
169 return ret;
170}
std::ostringstream debug
int32_t i
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
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 runs
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
char error[CURL_ERROR_SIZE]
CTPRunScalers getScalersFromCCDB(long timestamp, std::string run, bool &ok)
static void setCCDBHost(std::string host)
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool &ok)
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
static std::vector< std::string > tokenize(const std::string &src, char delim, bool trimToken=true, bool skipEmpty=true)
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"