CMS 3D CMS Logo

RunInfoPayloadInspectoHelper.h
Go to the documentation of this file.
1 #ifndef CONDCORE_RUNINFOPLUGINS_RUNINFOPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_RUNINFOPLUGINS_RUNINFOPAYLOADINSPECTORHELPER_H
3 
4 #include <vector>
5 #include <string>
6 #include <ctime>
7 #include "TH1.h"
8 #include "TH2.h"
9 #include "TStyle.h"
10 #include "TPaveText.h"
11 #include "TStyle.h"
13 
14 // for the FED intervals
16 
17 #define MK_P(a, b) std::make_pair(a, b)
18 
19 namespace RunInfoPI {
20 
21  enum state { k_fake = 0, k_valid = 1, k_invalid = 2 };
22 
23  // values are taken from https://github.com/cms-sw/cmssw/blob/master/MagneticField/GeomBuilder/plugins/VolumeBasedMagneticFieldESProducerFromDB.cc#L74-L75
24  constexpr std::array<int, 7> nominalCurrents{{-1, 0, 9558, 14416, 16819, 18268, 19262}};
25  constexpr std::array<float, 7> nominalFields{{3.8, 0., 2., 3., 3.5, 3.8, 4.}};
26 
27  // all parameter than can be displayed
28  enum parameters {
29  m_run, // int
30  m_start_time_ll, // long long;
31  m_stop_time_ll, // long long
32  m_start_current, // float
33  m_stop_current, // float
34  m_avg_current, // float
35  m_max_current, // float
36  m_min_current, // float
38  m_fedIN, // unsigned int
39  m_BField, // float
41  };
42 
43  /************************************************/
44  inline float theBField(const float current) {
45  // logic is taken from https://github.com/cms-sw/cmssw/blob/master/MagneticField/GeomBuilder/plugins/VolumeBasedMagneticFieldESProducerFromDB.cc#L156
46 
47  int i = 0;
48  for (; i < (int)nominalFields.size() - 1; i++) {
49  if (2 * current < nominalCurrents[i] + nominalCurrents[i + 1]) {
50  return nominalFields[i];
51  }
52  }
53  return nominalFields[i];
54  }
55 
56  /************************************************/
57  inline float runDuration(const std::shared_ptr<RunInfo>& payload) {
58  // calculation of the run duration in seconds
59  time_t start_time = payload->m_start_time_ll;
60  ctime(&start_time);
61  time_t end_time = payload->m_stop_time_ll;
62  ctime(&end_time);
63  return difftime(end_time, start_time) / 1.0e+6;
64  }
65 
66  /************************************************/
67  inline std::string runStartTime(const std::shared_ptr<RunInfo>& payload) {
68  const time_t start_time = payload->m_start_time_ll / 1.0e+6;
69  return std::asctime(std::gmtime(&start_time));
70  }
71 
72  /************************************************/
73  inline std::string runEndTime(const std::shared_ptr<RunInfo>& payload) {
74  const time_t end_time = payload->m_stop_time_ll / 1.0e+6;
75  return std::asctime(std::gmtime(&end_time));
76  }
77 
78  /************************************************/
80  switch (parameter) {
81  case m_run:
82  return "run number";
83  case m_start_time_ll:
84  return "start time";
85  case m_stop_time_ll:
86  return "stop time";
87  case m_start_current:
88  return "start current [A]";
89  case m_stop_current:
90  return "stop current [A]";
91  case m_avg_current:
92  return "average current [A]";
93  case m_max_current:
94  return "max current [A]";
95  case m_min_current:
96  return "min current [A]";
98  return "run duration [s]";
99  case m_fedIN:
100  return "n. FEDs";
101  case m_BField:
102  return "B-field intensity [T]";
103  default:
104  return "should never be here";
105  }
106  }
107 
108  /************************************************/
109  inline void reportSummaryMapPalette(TH2* obj) {
110  static int pcol[20];
111 
112  float rgb[20][3];
113 
114  for (int i = 0; i < 20; i++) {
115  if (i < 17) {
116  rgb[i][0] = 0.80 + 0.01 * i;
117  rgb[i][1] = 0.00 + 0.03 * i;
118  rgb[i][2] = 0.00;
119  } else if (i < 19) {
120  rgb[i][0] = 0.80 + 0.01 * i;
121  rgb[i][1] = 0.00 + 0.03 * i + 0.15 + 0.10 * (i - 17);
122  rgb[i][2] = 0.00;
123  } else if (i == 19) {
124  rgb[i][0] = 0.00;
125  rgb[i][1] = 0.80;
126  rgb[i][2] = 0.00;
127  }
128  pcol[i] = TColor::GetColor(rgb[i][0], rgb[i][1], rgb[i][2]);
129  }
130 
131  gStyle->SetPalette(20, pcol);
132 
133  if (obj) {
134  obj->SetMinimum(-1.e-15);
135  obj->SetMaximum(+1.0);
136  obj->SetOption("colz");
137  }
138  }
139 
140  // FED bounds
141  enum DET {
157  };
158 
159  using FEDMAP_T = std::map<RunInfoPI::DET, std::pair<int, int> >;
160 
162  static RunInfoPI::FEDMAP_T fb;
169  fb.insert(MK_P(TOTEMRP_T,
179  return fb;
180  }
181 }; // namespace RunInfoPI
182 #endif
void reportSummaryMapPalette(TH2 *obj)
float runDuration(const std::shared_ptr< RunInfo > &payload)
std::string runEndTime(const std::shared_ptr< RunInfo > &payload)
std::map< RunInfoPI::DET, std::pair< int, int > > FEDMAP_T
std::string getStringFromTypeEnum(const parameters &parameter)
Definition: HCAL.py:1
constexpr std::array< float, 7 > nominalFields
float theBField(const float current)
constexpr std::array< int, 7 > nominalCurrents
std::string runStartTime(const std::shared_ptr< RunInfo > &payload)
def rgb(r, g, b, maximum=1.)
Definition: svgfig.py:40
#define MK_P(a, b)