15#include <framework/database/DBImportObjPtr.h>
16#include <framework/database/DBObjPtr.h>
17#include <framework/database/DBStore.h>
18#include <framework/datastore/StoreObjPtr.h>
19#include <framework/datastore/DataStore.h>
20#include <framework/dataobjects/EventMetaData.h>
21#include <framework/logging/LogSystem.h>
22#include <trg/cdc/dbobjects/CDCTriggerDeadch.h>
42bool get_wire_mgr(
int mask_sl[],
int mask_layer[],
int mask_ch[],
int mgr)
44 int mgr_sl = mgr / 1000;
45 int mgr_i = (mgr - mgr_sl * 1000) / 10;
58 for (
int i = 0; i < 32; i++) {
60 mask_ch[i] = mgr_i * 32 + i;
62 if (mgr_u == 1) mask_layer[i] += 3;
63 if (mgr_sl == 0) mask_layer[i] += 2;
65 for (
int i = 0; i < 32; i++) {
66 mask_sl[i + 32] = mgr_sl;
67 mask_ch[i + 32] = mgr_i * 32 + i;
68 mask_layer[i + 32] = 1;
69 if (mgr_u == 1) mask_layer[i + 32] += 3;
70 if (mgr_sl == 0) mask_layer[i + 32] += 2;
72 for (
int i = 0; i < 32; i++) {
73 mask_sl[i + 64] = mgr_sl;
74 mask_ch[i + 64] = mgr_i * 32 + i;
75 mask_layer[i + 64] = 2;
76 if (mgr_u == 1) mask_layer[i + 64] += 3;
77 if (mgr_sl == 0) mask_layer[i + 64] += 2;
82static std::string trim(
const std::string& s)
85 while (b < s.size() && std::isspace(
static_cast<unsigned char>(s[b]))) b++;
87 while (e > b && std::isspace(
static_cast<unsigned char>(s[e - 1]))) e--;
88 return s.substr(b, e - b);
91static std::vector<int> parseIntList(
const std::string& line)
94 size_t lb = line.find(
'[');
95 size_t rb = line.find(
']');
96 if (lb == std::string::npos || rb == std::string::npos || rb <= lb)
return out;
97 std::string inner = line.substr(lb + 1, rb - lb - 1);
98 std::stringstream ss(inner);
100 while (std::getline(ss, tok,
',')) {
102 if (!tok.empty()) out.push_back(std::stoi(tok));
107static bool loadConfigs(
const std::string& path, std::vector<DeadchConfig>& configs)
109 std::ifstream ifs(path);
111 std::cerr <<
"Cannot open config file: " << path << std::endl;
116 bool inConfigs =
false;
118 bool haveCurrent =
false;
120 while (std::getline(ifs, line)) {
122 if (line.find(
"\"configs\"") != std::string::npos) {
126 if (!inConfigs)
continue;
128 if (line.find(
'}') != std::string::npos && haveCurrent) {
129 configs.push_back(current);
133 if (line.find(
"\"run\"") != std::string::npos) {
134 std::vector<int> run = parseIntList(line);
135 if (run.size() != 4) {
136 std::cerr <<
"Bad run array (need 4 values): " << line << std::endl;
139 for (
int i = 0; i < 4; i++) current.run[i] = run[i];
142 if (line.find(
"\"mgr\"") != std::string::npos) {
143 current.mgr = parseIntList(line);
147 if (haveCurrent) configs.push_back(current);
149 if (configs.empty()) {
150 std::cerr <<
"No configs found in " << path << std::endl;
156void setdeadchFromConfigs(
const std::vector<DeadchConfig>& configs)
158 const static int MAX_N_LAYERS = 8;
159 const int N_config = configs.size();
161 auto badch_map =
new bool[N_config][9][8][384];
162 for (
int i = 0; i < N_config; i++) {
163 for (
unsigned int j = 0; j < c_nSuperLayers; j++) {
164 for (
unsigned int k = 0; k < MAX_N_LAYERS; k++) {
165 for (
unsigned int l = 0; l < c_maxNDriftCells; l++) {
166 badch_map[i][j][k][l] =
true;
173 for (
int i = 0; i < N_config; i++) {
174 for (
unsigned int j = 8; j < 9; j++) {
175 for (
unsigned int k = 4; k < 5; k++) {
176 for (
unsigned int l = 0; l < c_maxNDriftCells; l++) {
177 badch_map[i][j][k][l] =
false;
185 for (
int i = 0; i < N_config; i++) {
186 for (
unsigned int j = 0; j < configs[i].mgr.size(); j++) {
190 get_wire_mgr(mgr_sl, mgr_layer, mgr_ch, configs[i].mgr[j]);
191 for (
int k = 0; k < 96; k++) {
192 badch_map[i][mgr_sl[k]][mgr_layer[k]][mgr_ch[k]] =
false;
202 for (
int i = 0; i < N_config; i++) {
203 const int* r = configs[i].run;
204 std::cout <<
"import config " << i <<
" iov=(" << r[0] <<
"," << r[1]
205 <<
"," << r[2] <<
"," << r[3] <<
") n_mgr=" << configs[i].mgr.size() << std::endl;
207 for (
unsigned int j = 0; j < c_nSuperLayers; j++) {
208 for (
unsigned int k = 0; k < MAX_N_LAYERS; k++) {
209 for (
unsigned int l = 0; l < c_maxNDriftCells; l++) {
210 db_dead->setdeadch(j, k, l, badch_map[i][j][k][l]);
216 }
else if (ONLINE == 1) {
217 for (
int i = 0; i < 1; i++) {
219 for (
unsigned int j = 0; j < c_nSuperLayers; j++) {
220 for (
unsigned int k = 0; k < MAX_N_LAYERS; k++) {
221 for (
unsigned int l = 0; l < c_maxNDriftCells; l++) {
222 db_dead->setdeadch(j, k, l, badch_map[i][j][k][l]);
233int main(
int argc,
char* argv[])
235 std::string configPath =
"cdcdead_config.json";
236 if (argc >= 2) configPath = argv[1];
238 std::vector<DeadchConfig> configs;
239 if (!loadConfigs(configPath, configs))
return 1;
241 std::cout <<
"Loaded " << configs.size() <<
" config(s) from " << configPath << std::endl;
242 setdeadchFromConfigs(configs);
243 std::cout <<
"Done. localdb written in current working directory." << std::endl;
bool import(const IntervalOfValidity &iov)
Import the object to database.
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
A class that describes the interval of experiments/runs for which an object in the database is valid.
Abstract base class for different kinds of events.