13 #include "TTimeStamp.h"
51 inline std::istream&
operator>>(std::istream& in, TTimeStamp&
object)
66 is.str(
replace(buffer,
'-',
' '));
68 if (is >> year >> month >>
day) {
77 is.str(
replace(buffer,
':',
' '));
79 if (is >> hour >> min >> sec) {
81 object = TTimeStamp(year, month,
day, hour, min, sec);
89 in.setstate(ios::failbit);
102 inline std::ostream&
operator>>(std::ostream& out,
const TTimeStamp&
object)
104 return out <<
object.AsString();
114 int main(
int argc,
char **argv)
135 JParser<> zap(
"Example program to plot quality data from data base or input file.");
141 zap[
'f'] =
make_field(inputFile,
"Optional input file instead of database.") =
"";
142 zap[
'o'] =
make_field(
outputFile,
"ROOT file with histograms and n-tuple or ASCII file with QA/QC data.") =
"monitor.root";
143 zap[
'D'] =
make_field(detid,
"detector identifier");
144 zap[
'S'] =
make_field(source,
"GIT versions") =
getGITTags(TRegexp(
"v[0-9]*\\.[0-9]*\\.[0-9]*$"), JGITTags_t::key_type(
"2019-04-12"));
146 zap[
'T'] =
make_field(Tmin_s,
"minimal run duration [s]") = 60;
151 catch(
const exception &error) {
152 FATAL(error.what() << endl);
163 const int ID = getDetector<int >(detid);
164 detid = getDetector<string>(detid);
168 NOTICE(
"Extracting run information from database... " << flush);
172 for (
JRuns parameters; rs >> parameters; ) {
174 parameters.DETID =
ID;
176 if (UTC(parameters.getRunStartTime())) {
177 runs.insert(parameters);
186 FATAL(
"No runs for detector " << detid << endl);
189 NOTICE(
"Run range " << runs.begin()->RUN <<
' ' << runs.rbegin()->RUN << endl);
191 if (inputFile ==
"") {
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);
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) {
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 if (UTC(TTimeStamp(quality.
UTCMin_s, 0)) &&
235 UTC(TTimeStamp(quality.
UTCMax_s, 0))) {
236 buffer.insert(quality);
250 if (UTC(TTimeStamp(quality.UTCMin_s, 0)) &&
251 UTC(TTimeStamp(quality.UTCMax_s, 0))) {
252 buffer.insert(quality);
259 catch(
const exception& error) {
260 FATAL(error.what() << endl);
270 X.push_back(runs. begin()->getRunStartTime());
273 X.push_back(quality->UTCMin_s);
274 X.push_back(quality->UTCMax_s);
277 X.push_back(runs.rbegin()->getRunStartTime());
279 sort(X.begin(), X.end());
286 bool operator()(
const double x1,
const double x2)
288 return x2 - x1 <=
xmin;
294 X.erase(unique(X.begin(), X.end(), Xmin(Tmin_s)), X.end());
296 TH1D h0(
"livetime_s", NULL, X.size() - 1, X.data());
297 TH1D h1(
"QAQC", NULL, X.size() - 1, X.data());
306 << setw(8) << i->RUN <<
' '
307 << TTimeStamp((time_t) i->UNIXSTARTTIME/1000).AsString(
"c") <<
' ';
309 if (quality != buffer.end())
310 cout <<
"[" << TTimeStamp((time_t) quality->UTCMin_s).AsString(
"c") <<
"," << TTimeStamp((time_t) quality->UTCMax_s).AsString(
"c") <<
"]";
312 cout <<
"missing QA/QC data";
317 h1.Fill(i->getRunStartTime() + Tmin_s, (quality != buffer.end() ? 1.0 : -1.0));
325 const double x = 0.5 * (quality->UTCMin_s + quality->UTCMax_s);
327 h0.Fill(
x, 100.0 * quality->livetime_s / (quality->UTCMax_s - quality->UTCMin_s));
329 H1[
"JDAQEvent"] -> Fill(
x, quality->JDAQEvent);
330 H1[
"JTrigger3DShower"] -> Fill(
x, quality->JTrigger3DShower);
331 H1[
"JTrigger3DMuon"] -> Fill(
x, quality->JTrigger3DMuon);
332 H1[
"JTriggerMXShower"] -> Fill(
x, quality->JTriggerMXShower);
334 if (quality->livetime_s > 0.0) {
335 R1[
"JDAQEvent"] -> Fill(
x, quality->JDAQEvent / quality->livetime_s);
336 R1[
"JTrigger3DShower"] -> Fill(
x, quality->JTrigger3DShower / quality->livetime_s);
337 R1[
"JTrigger3DMuon"] -> Fill(
x, quality->JTrigger3DMuon / quality->livetime_s);
338 R1[
"JTriggerMXShower"] -> Fill(
x, quality->JTriggerMXShower / quality->livetime_s);
343 Double_t W[2] = { 0.0 };
345 W[0] = *X.rbegin() - *X.begin();
348 W[1] += quality->livetime_s;
351 NOTICE(
"Average data taking efficiency " <<
FIXED(5,1) << 100.0*W[1]/W[0] <<
" %." << endl);
354 for (TH1* p : { &h0, &h1 }) {
355 p->GetXaxis()->SetTimeDisplay(1);
364 for (Int_t i = 1; i <= p->second->GetXaxis()->GetNbins(); ++i) {
365 p->second->SetBinContent(i, (W += p->second->GetBinContent(i)));
368 p->second->GetXaxis()->SetTimeDisplay(1);
369 p->second->GetXaxis()->SetTimeFormat(
TIMESTAMP);
370 p->second->Sumw2(
false);
375 p->second->GetXaxis()->SetTimeDisplay(1);
376 p->second->GetXaxis()->SetTimeFormat(
TIMESTAMP);
377 p->second->Sumw2(
false);
382 out << h0 << h1 << H1 <<
R1;
395 out.setf(ios::fixed);
std::istream & operator>>(std::istream &in, TTimeStamp &object)
Read time stamp from input stream.
int main(int argc, char **argv)
Specifications of file name extensions.
Dynamic ROOT object management.
General purpose messaging.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
TString replace(const TString &target, const TRegexp ®exp, const T &replacement)
Replace regular expression in input by given replacement.
Auxiliary class to define a range between two values.
Print objects in ASCII format using ROOT dictionary.
Auxiliary class for specifying selection of database data.
JSelector & add(const JSelector &selection)
Add selection.
Object reading from ASCII file.
Object(s) writing to ASCII file.
virtual void close()
Close file.
Utility class to parse command line options.
ResultSet & getResultSet(const std::string &query)
Get result set.
std::vector< JServer > getServernames()
Get list of names of available database servers.
std::vector< std::string > getGITTags(const TRegexp ®exp, const JGITTags_t::key_type &date)
Get selection of GIT tags.
std::string getFilenameExtension(const std::string &file_name)
Get file name extension, i.e. part after last JEEP::FILENAME_SEPARATOR if any.
static const char *const TIMESTAMP
Time stamp of earliest UTC time.
T & getInstance(const T &object)
Get static instance from temporary object.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< event_type > data_type
static const char *const ASCII_FILE_FORMAT
file name extension ASCII format
static const char *const ROOT_FILE_FORMAT
file name extension ROOT format
std::map< int, range_type > map_type
std::istream & operator>>(std::istream &in, std::vector< int > &object)
Read std::vector<int> from input.
Auxiliary data structure for floating point format specification.
Type definition of range.
Auxiliary data structure for data quality.
double UTCMin_s
minimal UTC time (from "runs" table)
void put(const std::string &key, const std::string &value)
Put value at given key.
double UTCMax_s
maximal UTC time (from "runs" table)
std::string GIT
GIT version used to write QA/QC data.
int detector
detector identifier
Wrapper class for server name.
Template definition for getting table specific selector.