114 typedef JRange<int> JRange_t;
124 JRange<TTimeStamp> UTC;
130 JParser<> zap(
"Example program to plot quality data from data base.");
137 zap[
'D'] =
make_field(detid,
"detector identifier");
138 zap[
'R'] =
make_field(runs,
"run range") = JRange_t(1, JRange_t::getMaximum());
139 zap[
'S'] =
make_field(source,
"GIT versions") =
getGITTags(TRegexp(
"v[0-9]*\\.[0-9]*\\.[0-9]*$"), JGITTags_t::key_type(
"2019-04-12"));
140 zap[
'U'] =
make_field(UTC,
"UTC time range" ) = JRange<TTimeStamp>();
141 zap[
'T'] =
make_field(Tmin_s,
"minimal run duration [s]") = 60;
146 catch(
const exception &error) {
147 FATAL(error.what() << endl);
162 ID = to_value<int>(detid);
170 NOTICE(
"Extracting run information from database... " << flush);
172 ResultSet& rs =
getResultSet(getTable<JRuns>(), getSelector<JRuns>(ID));
176 parameters.DETID =
ID;
178 if (UTC(parameters.getRunStartTime())) {
179 data.push_back(parameters);
187 catch(
const exception& error) {}
202 JSelector selector = getSelector<JRunSummaryNumbers>(detid, runs.getLowerLimit(), runs.getUpperLimit());
204 selector.add(&JRunSummaryNumbers::SOURCE_NAME, *git);
208 NOTICE(
"Extracting run summmary information with source " << *git <<
" from database... " << flush);
210 ResultSet& rs =
getResultSet(getTable<JRunSummaryNumbers>(), selector);
212 for (JRunSummaryNumbers parameters; rs >>
parameters; ) {
213 zmap[parameters.RUN].insert(make_pair(parameters.PARAMETER_NAME, parameters.DATA_VALUE));
220 catch(
const exception& error) {
NOTICE(endl); }
222 for (map_type::const_iterator run = zmap.begin(); run != zmap.end(); ++run) {
227 quality.detector =
ID;
228 quality.run = run->first;
230 for (data_type::const_iterator p = run->second.begin(); p != run->second.end(); ++p) {
231 quality.put(p->first, p->second);
234 qaqc.insert(JRun_t(ID, quality.run));
236 if (UTC(TTimeStamp(quality.UTCMin_s, 0)) &&
237 UTC(TTimeStamp(quality.UTCMax_s, 0))) {
241 if (p == buffer.end() || p->run != quality.run) {
242 buffer.insert(p, quality);
248 catch(
const exception& error) {
249 FATAL(error.what() << endl);
252 if (buffer.empty()) {
253 FATAL(
"No valid QA/QC data for detector " << detid << endl);
262 X.push_back(quality->UTCMin_s);
263 X.push_back(quality->UTCMax_s);
266 sort(
X.begin(),
X.end());
273 bool operator()(
const double x1,
const double x2)
275 return x2 - x1 <= xmin;
281 X.push_back(data.rbegin()->getRunStartTime());
283 X.erase(unique(
X.begin(),
X.end(), Xmin(Tmin_s)),
X.end());
285 TH1D h0(
"livetime_s", NULL,
X.size() - 1,
X.data());
286 TH1D
h1(
"QAQC", NULL,
X.size() - 1,
X.data());
290 const JRun_t run(i->DETID,i->RUN);
295 << setw(8) << i->RUN <<
' '
296 << TTimeStamp((time_t) i->UNIXSTARTTIME/1000).AsString(
"c") <<
' ';
300 if (quality != buffer.end() && quality->run == i->RUN) {
301 cout <<
"[" << TTimeStamp((time_t) quality->UTCMin_s).AsString(
"c") <<
"," << TTimeStamp((time_t) quality->UTCMax_s).AsString(
"c") <<
"]";
303 cout << (
qaqc.count(run) == 0 ?
"missing" :
"invalid") <<
" QA/QC data";
311 if (! binary_search(buffer.begin(), buffer.end(), run)) {
312 W = (
qaqc.count(run) == 0 ? -1.0 : 0.0);
315 h1.Fill(i->getRunStartTime() + Tmin_s, W);
318 JManager<string, TH1D>
H1(
new TH1D(
"H[%]", NULL,
X.size() - 1,
X.data()));
319 JManager<string, TH1D>
R1(
new TH1D(
"R[%]", NULL,
X.size() - 1,
X.data()));
323 const double x = 0.5 * (quality->UTCMin_s + quality->UTCMax_s);
325 h0.Fill(x, 100.0 * quality->livetime_s / (quality->UTCMax_s - quality->UTCMin_s));
327 H1[
"JDAQEvent"] -> Fill(x, quality->JDAQEvent);
328 H1[
"JTrigger3DShower"] -> Fill(x, quality->JTrigger3DShower);
329 H1[
"JTrigger3DMuon"] -> Fill(x, quality->JTrigger3DMuon);
330 H1[
"JTriggerMXShower"] -> Fill(x, quality->JTriggerMXShower);
332 if (quality->livetime_s > 0.0) {
333 R1[
"JDAQEvent"] -> Fill(x, quality->JDAQEvent / quality->livetime_s);
334 R1[
"JTrigger3DShower"] -> Fill(x, quality->JTrigger3DShower / quality->livetime_s);
335 R1[
"JTrigger3DMuon"] -> Fill(x, quality->JTrigger3DMuon / quality->livetime_s);
336 R1[
"JTriggerMXShower"] -> Fill(x, quality->JTriggerMXShower / quality->livetime_s);
341 Double_t W[2] = { 0.0 };
343 W[0] = *
X.rbegin() - *
X.begin();
346 W[1] += quality->livetime_s;
349 NOTICE(
"Average data taking efficiency " <<
FIXED(5,1) << 100.0*W[1]/W[0] <<
" %." << endl);
352 for (TH1* p : { &h0, &
h1 }) {
353 p->GetXaxis()->SetTimeDisplay(1);
358 for (JManager<string, TH1D>::iterator p =
H1.begin(); p !=
H1.end(); ++p) {
362 for (Int_t i = 1; i <= p->second->GetXaxis()->GetNbins(); ++i) {
363 p->second->SetBinContent(i, (W += p->second->GetBinContent(i)));
366 p->second->GetXaxis()->SetTimeDisplay(1);
367 p->second->GetXaxis()->SetTimeFormat(
TIMESTAMP);
368 p->second->Sumw2(
false);
371 for (JManager<string, TH1D>::iterator p =
R1.begin(); p !=
R1.end(); ++p) {
373 p->second->GetXaxis()->SetTimeDisplay(1);
374 p->second->GetXaxis()->SetTimeFormat(
TIMESTAMP);
375 p->second->Sumw2(
false);
380 out << h0 <<
h1 <<
H1 <<
R1;
Utility class to parse command line options.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
then for HISTOGRAM in h0 h1
Auxiliary data structure for floating point format specification.
std::vector< std::string > getGITTags(const TRegexp ®exp, const JGITTags_t::key_type &date)
Get selection of GIT tags.
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
then break fi done getCenter read X Y Z let X
bool is_integer(const std::string &buffer)
Check if string is an integer.
ResultSet & getResultSet(const std::string &query)
Get result set.
std::vector< JServer > getServernames()
Get list of names of available database servers.
static const char *const TIMESTAMP
Time stamp of earliest UTC time.
int qaqc
QA/QC file descriptor.