File indexing completed on 2025-08-06 08:18:39
0001 #include "SpinDBContent.h"
0002
0003 #include <boost/format.hpp>
0004
0005 #include <iostream>
0006
0007 const int SpinDBContent::NCROSS = 120;
0008 const int SpinDBContent::ERROR_VALUE = -999;
0009
0010
0011
0012 void SpinDBContent::Initialize()
0013 {
0014 runnum = ERROR_VALUE;
0015 qa_level = ERROR_VALUE;
0016 fillnum = ERROR_VALUE;
0017 badrun = ERROR_VALUE;
0018 cross_shift = ERROR_VALUE;
0019
0020 for (int icross = 0; icross < NCROSS; icross++)
0021 {
0022 bpol[icross] = (float) ERROR_VALUE;
0023 bpolerr[icross] = (float) ERROR_VALUE;
0024 bpolsys[icross] = (float) ERROR_VALUE;
0025 ypol[icross] = (float) ERROR_VALUE;
0026 ypolerr[icross] = (float) ERROR_VALUE;
0027 ypolsys[icross] = (float) ERROR_VALUE;
0028 bpat[icross] = ERROR_VALUE;
0029 ypat[icross] = ERROR_VALUE;
0030 scaler_mbd_vtxcut[icross] = (long long) ERROR_VALUE;
0031 scaler_mbd_nocut[icross] = (long long) ERROR_VALUE;
0032 scaler_zdc_nocut[icross] = (long long) ERROR_VALUE;
0033 bad_bunch[icross] = ERROR_VALUE;
0034 }
0035
0036 cross_angle = (float) ERROR_VALUE;
0037 cross_angle_std = (float) ERROR_VALUE;
0038 cross_angle_min = (float) ERROR_VALUE;
0039 cross_angle_max = (float) ERROR_VALUE;
0040
0041 asym_bf = (float) ERROR_VALUE;
0042 asym_bb = (float) ERROR_VALUE;
0043 asym_yf = (float) ERROR_VALUE;
0044 asym_yb = (float) ERROR_VALUE;
0045 asymerr_bf = (float) ERROR_VALUE;
0046 asymerr_bb = (float) ERROR_VALUE;
0047 asymerr_yf = (float) ERROR_VALUE;
0048 asymerr_yb = (float) ERROR_VALUE;
0049 phase_bf = (float) ERROR_VALUE;
0050 phase_bb = (float) ERROR_VALUE;
0051 phase_yf = (float) ERROR_VALUE;
0052 phase_yb = (float) ERROR_VALUE;
0053 phaseerr_bf = (float) ERROR_VALUE;
0054 phaseerr_bb = (float) ERROR_VALUE;
0055 phaseerr_yf = (float) ERROR_VALUE;
0056 phaseerr_yb = (float) ERROR_VALUE;
0057
0058
0059
0060 }
0061
0062
0063
0064 int SpinDBContent::CheckBunchNumber(int bunch)
0065 {
0066 if (bunch < 0 || bunch >= NCROSS)
0067 {
0068 std::cout << (boost::format("Error : bunch number (%d) is out of range (0-119).") % bunch).str();
0069 return (ERROR_VALUE);
0070 }
0071
0072 return (1);
0073 }
0074
0075
0076
0077 void SpinDBContent::Print() const
0078 {
0079 std::cout << (boost::format("Run number = %d\n") % runnum).str();
0080 std::cout << (boost::format("QA Level = %d\n") % qa_level).str();
0081 std::cout << (boost::format("Fill number = %d\n") % fillnum).str();
0082 std::cout << (boost::format("Bad run QA = %d\n") % badrun).str();
0083 std::cout << (boost::format("Crossing shift = %d\n") % cross_shift).str();
0084
0085 for (int i = 0; i < NCROSS; i++)
0086 {
0087 std::cout << (boost::format("%3d : %12lld %12lld %12lld : %3d %3d : %d") % i % scaler_mbd_vtxcut[i] % scaler_mbd_nocut[i] % scaler_zdc_nocut[i] % bpat[i] % ypat[i] % bad_bunch[i]).str();
0088
0089 std::cout << (boost::format(" : %6.3f +- %6.3f +- %6.3f %6.3f +- %6.3f +- %6.3f\n") % bpol[i] % bpolerr[i] % bpolsys[i] % ypol[i] % ypolerr[i] % ypolsys[i]).str();
0090 }
0091
0092 return;
0093 }
0094
0095
0096
0097 int SpinDBContent::SetPolarizationBlue(int bunch, float value, float error)
0098 {
0099 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0100 {
0101 return (ERROR_VALUE);
0102 }
0103 bpol[bunch] = value;
0104 bpolerr[bunch] = error;
0105 return (1);
0106 }
0107
0108
0109
0110 int SpinDBContent::SetPolarizationBlue(int bunch, float value, float error, float syserr)
0111 {
0112 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0113 {
0114 return (ERROR_VALUE);
0115 }
0116 bpol[bunch] = value;
0117 bpolerr[bunch] = error;
0118 bpolsys[bunch] = syserr;
0119 return (1);
0120 }
0121
0122
0123
0124 int SpinDBContent::SetPolarizationYellow(int bunch, float value, float error)
0125 {
0126 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0127 {
0128 return (ERROR_VALUE);
0129 }
0130 ypol[bunch] = value;
0131 ypolerr[bunch] = error;
0132 return (1);
0133 }
0134
0135
0136 int SpinDBContent::SetPolarizationYellow(int bunch, float value, float error, float syserr)
0137 {
0138 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0139 {
0140 return (ERROR_VALUE);
0141 }
0142 ypol[bunch] = value;
0143 ypolerr[bunch] = error;
0144 ypolsys[bunch] = syserr;
0145 return (1);
0146 }
0147
0148
0149 int SpinDBContent::SetSpinPatternBlue(int bunch, int value)
0150 {
0151 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0152 {
0153 return (ERROR_VALUE);
0154 }
0155 bpat[bunch] = value;
0156 return (1);
0157 }
0158
0159
0160
0161 int SpinDBContent::SetSpinPatternYellow(int bunch, int value)
0162 {
0163 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0164 {
0165 return (ERROR_VALUE);
0166 }
0167 ypat[bunch] = value;
0168 return (1);
0169 }
0170
0171
0172
0173 int SpinDBContent::SetScalerMbdVertexCut(int bunch, long long value)
0174 {
0175 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0176 {
0177 return (ERROR_VALUE);
0178 }
0179 scaler_mbd_vtxcut[bunch] = value;
0180 return (1);
0181 }
0182
0183
0184
0185 int SpinDBContent::SetScalerMbdNoCut(int bunch, long long value)
0186 {
0187 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0188 {
0189 return (ERROR_VALUE);
0190 }
0191 scaler_mbd_nocut[bunch] = value;
0192 return (1);
0193 }
0194
0195
0196
0197 int SpinDBContent::SetScalerZdcNoCut(int bunch, long long value)
0198 {
0199 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0200 {
0201 return (ERROR_VALUE);
0202 }
0203 scaler_zdc_nocut[bunch] = value;
0204 return (1);
0205 }
0206
0207
0208
0209 int SpinDBContent::SetScaler(int channel, int bunch, long long value)
0210 {
0211 switch (channel)
0212 {
0213 case 0:
0214 return SetScalerMbdVertexCut(bunch, value);
0215 case 1:
0216 return SetScalerMbdNoCut(bunch, value);
0217 case 2:
0218 return SetScalerZdcNoCut(bunch, value);
0219 default:
0220 break;
0221 }
0222 return ERROR_VALUE;
0223 }
0224
0225
0226
0227 int SpinDBContent::SetBadBunchFlag(int bunch, int value)
0228 {
0229 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0230 {
0231 return (ERROR_VALUE);
0232 }
0233 bad_bunch[bunch] = value;
0234 return (1);
0235 }
0236
0237
0238
0239 void SpinDBContent::SetAsymBlueForward(float value, float error)
0240 {
0241 asym_bf = value;
0242 asymerr_bf = error;
0243 return;
0244 }
0245
0246
0247
0248 void SpinDBContent::SetAsymBlueBackward(float value, float error)
0249 {
0250 asym_bb = value;
0251 asymerr_bb = error;
0252 return;
0253 }
0254
0255
0256
0257 void SpinDBContent::SetAsymYellowForward(float value, float error)
0258 {
0259 asym_yf = value;
0260 asymerr_yf = error;
0261 return;
0262 }
0263
0264
0265
0266 void SpinDBContent::SetAsymYellowBackward(float value, float error)
0267 {
0268 asym_yb = value;
0269 asymerr_yb = error;
0270 return;
0271 }
0272
0273
0274
0275
0276 void SpinDBContent::SetPhaseBlueForward(float value, float error)
0277 {
0278 phase_bf = value;
0279 phaseerr_bf = error;
0280 return;
0281 }
0282
0283
0284
0285 void SpinDBContent::SetPhaseBlueBackward(float value, float error)
0286 {
0287 phase_bb = value;
0288 phaseerr_bb = error;
0289 return;
0290 }
0291
0292
0293
0294 void SpinDBContent::SetPhaseYellowForward(float value, float error)
0295 {
0296 phase_yf = value;
0297 phaseerr_yf = error;
0298 return;
0299 }
0300
0301
0302
0303 void SpinDBContent::SetPhaseYellowBackward(float value, float error)
0304 {
0305 phase_yb = value;
0306 phaseerr_yb = error;
0307 return;
0308 }
0309
0310
0311
0312 int SpinDBContent::GetPolarizationBlue(int bunch, float &value, float &error)
0313 {
0314 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0315 {
0316 return (ERROR_VALUE);
0317 }
0318 value = bpol[bunch];
0319 error = bpolerr[bunch];
0320 return (1);
0321 }
0322
0323
0324
0325 int SpinDBContent::GetPolarizationBlue(int bunch, float &value, float &error, float &syserr)
0326 {
0327 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0328 {
0329 return (ERROR_VALUE);
0330 }
0331 value = bpol[bunch];
0332 error = bpolerr[bunch];
0333 syserr = bpolsys[bunch];
0334 return (1);
0335 }
0336
0337
0338
0339 int SpinDBContent::GetPolarizationBlue(int bunch, double &value, double &error)
0340 {
0341 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0342 {
0343 return (ERROR_VALUE);
0344 }
0345 value = (double) bpol[bunch];
0346 error = (double) bpolerr[bunch];
0347 return (1);
0348 }
0349
0350
0351
0352 int SpinDBContent::GetPolarizationBlue(int bunch, double &value, double &error, double &syserr)
0353 {
0354 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0355 {
0356 return (ERROR_VALUE);
0357 }
0358 value = (double) bpol[bunch];
0359 error = (double) bpolerr[bunch];
0360 syserr = (double) bpolsys[bunch];
0361 return (1);
0362 }
0363
0364
0365
0366 int SpinDBContent::GetPolarizationYellow(int bunch, float &value, float &error)
0367 {
0368 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0369 {
0370 return (ERROR_VALUE);
0371 }
0372 value = ypol[bunch];
0373 error = ypolerr[bunch];
0374 return (1);
0375 }
0376
0377
0378
0379 int SpinDBContent::GetPolarizationYellow(int bunch, float &value, float &error, float &syserr)
0380 {
0381 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0382 {
0383 return (ERROR_VALUE);
0384 }
0385 value = ypol[bunch];
0386 error = ypolerr[bunch];
0387 syserr = ypolsys[bunch];
0388 return (1);
0389 }
0390
0391
0392
0393 int SpinDBContent::GetPolarizationYellow(int bunch, double &value, double &error)
0394 {
0395 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0396 {
0397 return (ERROR_VALUE);
0398 }
0399 value = (double) ypol[bunch];
0400 error = (double) ypolerr[bunch];
0401 return (1);
0402 }
0403
0404
0405
0406 int SpinDBContent::GetPolarizationYellow(int bunch, double &value, double &error, double &syserr)
0407 {
0408 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0409 {
0410 return (ERROR_VALUE);
0411 }
0412 value = (double) ypol[bunch];
0413 error = (double) ypolerr[bunch];
0414 syserr = (double) ypolsys[bunch];
0415 return (1);
0416 }
0417
0418
0419
0420 int SpinDBContent::GetSpinPatternBlue(int bunch)
0421 {
0422 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0423 {
0424 return (ERROR_VALUE);
0425 }
0426 return (bpat[bunch]);
0427 }
0428
0429
0430
0431 int SpinDBContent::GetSpinPatternYellow(int bunch)
0432 {
0433 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0434 {
0435 return (ERROR_VALUE);
0436 }
0437 return (ypat[bunch]);
0438 }
0439
0440
0441
0442 long long SpinDBContent::GetScalerMbdVertexCut(int bunch)
0443 {
0444 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0445 {
0446 return (ERROR_VALUE);
0447 }
0448 return (scaler_mbd_vtxcut[bunch]);
0449 }
0450
0451
0452
0453 long long SpinDBContent::GetScalerMbdNoCut(int bunch)
0454 {
0455 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0456 {
0457 return (ERROR_VALUE);
0458 }
0459 return (scaler_mbd_nocut[bunch]);
0460 }
0461
0462
0463
0464 long long SpinDBContent::GetScalerZdcNoCut(int bunch)
0465 {
0466 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0467 {
0468 return (ERROR_VALUE);
0469 }
0470 return (scaler_zdc_nocut[bunch]);
0471 }
0472
0473
0474
0475 long long SpinDBContent::GetScaler(int channel, int bunch)
0476 {
0477 switch (channel)
0478 {
0479 case 0:
0480 return GetScalerMbdVertexCut(bunch);
0481 case 1:
0482 return GetScalerMbdNoCut(bunch);
0483 case 2:
0484 return GetScalerZdcNoCut(bunch);
0485 default:
0486 break;
0487 }
0488 return ERROR_VALUE;
0489 }
0490
0491
0492
0493 int SpinDBContent::GetBadBunchFlag(int bunch)
0494 {
0495 if (CheckBunchNumber(bunch) == ERROR_VALUE)
0496 {
0497 return (ERROR_VALUE);
0498 }
0499 return (bad_bunch[bunch]);
0500 }
0501
0502
0503
0504 void SpinDBContent::GetAsymBlueForward(float &value, float &error)
0505 {
0506 value = asym_bf;
0507 error = asymerr_bf;
0508 return;
0509 }
0510
0511
0512
0513 void SpinDBContent::GetAsymBlueBackward(float &value, float &error)
0514 {
0515 value = asym_bb;
0516 error = asymerr_bb;
0517 return;
0518 }
0519
0520
0521
0522 void SpinDBContent::GetAsymYellowForward(float &value, float &error)
0523 {
0524 value = asym_yf;
0525 error = asymerr_yf;
0526 return;
0527 }
0528
0529
0530
0531 void SpinDBContent::GetAsymYellowBackward(float &value, float &error)
0532 {
0533 value = asym_yb;
0534 error = asymerr_yb;
0535 return;
0536 }
0537
0538
0539
0540 void SpinDBContent::GetPhaseBlueForward(float &value, float &error)
0541 {
0542 value = phase_bf;
0543 error = phaseerr_bf;
0544 return;
0545 }
0546
0547
0548
0549 void SpinDBContent::GetPhaseBlueBackward(float &value, float &error)
0550 {
0551 value = phase_bb;
0552 error = phaseerr_bb;
0553 return;
0554 }
0555
0556
0557
0558 void SpinDBContent::GetPhaseYellowForward(float &value, float &error)
0559 {
0560 value = phase_yf;
0561 error = phaseerr_yf;
0562 return;
0563 }
0564
0565
0566
0567 void SpinDBContent::GetPhaseYellowBackward(float &value, float &error)
0568 {
0569 value = phase_yb;
0570 error = phaseerr_yb;
0571 return;
0572 }
0573
0574