13 #include "TTimeStamp.h"
46 inline std::istream&
operator>>(std::istream&
in, TTimeStamp&
object)
61 is.str(
replace(buffer,
'-',
' '));
63 if (is >> year >> month >> day) {
72 is.str(
replace(buffer,
':',
' '));
74 if (is >> hour >> min >> sec) {
76 object = TTimeStamp(year, month, day, hour, min, sec);
84 in.setstate(ios::failbit);
97 inline std::ostream&
operator>>(std::ostream& out,
const TTimeStamp&
object)
99 return out <<
object.AsString();
109 int main(
int argc,
char **argv)
114 typedef JRange<int> JRange_t;
123 JRange<TTimeStamp> UTC;
129 JParser<> zap(
"Example program to plot quality data from data base.");
135 zap[
'D'] =
make_field(detid,
"detector identifier");
136 zap[
'R'] =
make_field(runs,
"run range") = JRange_t(1, JRange_t::getMaximum());
137 zap[
'S'] =
make_field(source,
"GIT versions") =
getGITTags(TRegexp(
"v.*\\..*\\..*"), JGITTags_t::key_type(
"2019-04-12"));
138 zap[
'U'] =
make_field(UTC,
"UTC time range" ) = JRange<TTimeStamp>();
139 zap[
'T'] =
make_field(Tmin_s,
"minimal run duration [s]") = 60;
144 catch(
const exception &error) {
145 FATAL(error.what() << endl);
160 ID = to_value<int>(detid);
168 ResultSet& rs =
getResultSet(getTable<JRuns>(), getSelector<JRuns>(ID));
172 parameters.DETID =
ID;
174 if (UTC(parameters.getRunStartTime())) {
175 data.push_back(parameters);
181 catch(
const exception& error) {}
196 JSelector selector = getSelector<JRunSummaryNumbers>(detid, runs.getLowerLimit(), runs.getUpperLimit());
198 selector.add(&JRunSummaryNumbers::SOURCE_NAME, *i);
202 ResultSet& rs =
getResultSet(getTable<JRunSummaryNumbers>(), selector);
205 zmap[parameters.RUN].insert(make_pair(parameters.PARAMETER_NAME, parameters.DATA_VALUE));
210 catch(
const exception& error) {}
212 for (map_type::const_iterator run = zmap.begin(); run != zmap.end(); ++run) {
217 quality.detector =
ID;
218 quality.run = run->first;
220 for (data_type::const_iterator p = run->second.begin(); p != run->second.end(); ++p) {
221 quality.put(p->first, p->second);
224 qaqc.insert(JRun_t(ID, quality.run));
226 if (UTC(TTimeStamp(quality.UTCMin_s, 0)) &&
227 UTC(TTimeStamp(quality.UTCMax_s, 0))) {
231 if (p == buffer.end() || p->run != quality.run) {
232 buffer.insert(p, quality);
238 catch(
const exception& error) {
239 FATAL(error.what() << endl);
242 if (buffer.empty()) {
243 FATAL(
"No valid QA/QC data for detector " << detid << endl);
252 X.push_back(quality->UTCMin_s);
253 X.push_back(quality->UTCMax_s);
256 sort(
X.begin(),
X.end());
263 bool operator()(
const double x1,
const double x2)
265 return x2 - x1 <= xmin;
271 X.push_back(data.rbegin()->getRunStartTime());
273 X.erase(unique(
X.begin(),
X.end(), Xmin(Tmin_s)),
X.end());
275 TH1D h0(
"livetime_s", NULL,
X.size() - 1,
X.data());
276 TH1D
h1(
"QAQC", NULL,
X.size() - 1,
X.data());
280 const JRun_t run(i->DETID,i->RUN);
285 << setw(8) << i->RUN <<
' '
286 << TTimeStamp((time_t) i->UNIXSTARTTIME/1000).AsString(
"c") <<
' ';
290 if (quality != buffer.end() && quality->run == i->RUN) {
291 cout <<
"[" << TTimeStamp((time_t) quality->UTCMin_s).AsString(
"c") <<
"," << TTimeStamp((time_t) quality->UTCMax_s).AsString(
"c") <<
"]";
293 cout << (
qaqc.count(run) == 0 ?
"missing" :
"invalid") <<
" QA/QC data";
301 if (! binary_search(buffer.begin(), buffer.end(), run)) {
302 W = (
qaqc.count(run) == 0 ? -1.0 : 0.0);
305 h1.Fill(i->getRunStartTime() + Tmin_s, W);
308 JManager<string, TH1D>
H1(
new TH1D(
"%", NULL,
X.size() - 1,
X.data()));
312 const double x = 0.5 * (quality->UTCMin_s + quality->UTCMax_s);
314 h0.Fill(x, 100.0 * quality->livetime_s / (quality->UTCMax_s - quality->UTCMin_s));
316 H1[
"JDAQEvent"] -> Fill(x, quality->JDAQEvent);
317 H1[
"JTrigger3DShower"] -> Fill(x, quality->JTrigger3DShower);
318 H1[
"JTrigger3DMuon"] -> Fill(x, quality->JTrigger3DMuon);
319 H1[
"JTriggerMXShower"] -> Fill(x, quality->JTriggerMXShower);
323 Double_t W[2] = { 0.0 };
325 W[0] = *
X.rbegin() - *
X.begin();
328 W[1] += quality->livetime_s;
331 NOTICE(
"Average data taking efficiency " <<
FIXED(5,1) << 100.0*W[1]/W[0] <<
" %." << endl);
334 for (TH1* p : { &h0, &
h1 }) {
335 p->GetXaxis()->SetTimeDisplay(1);
340 for (JManager<string, TH1D>::iterator p = H1.begin(); p != H1.end(); ++p) {
344 for (Int_t i = 1; i <= p->second->GetXaxis()->GetNbins(); ++i) {
345 p->second->SetBinContent(i, (W += p->second->GetBinContent(i)));
348 p->second->GetXaxis()->SetTimeDisplay(1);
349 p->second->GetXaxis()->SetTimeFormat(
TIMESTAMP);
350 p->second->Sumw2(
false);
355 out << h0 <<
h1 <<
H1;
Utility class to parse command line options.
int main(int argc, char *argv[])
TString replace(const TString &target, const TRegexp ®exp, const T &replacement)
Replace regular expression in input by given replacement.
std::vector< std::string > getGITTags(const TRegexp regexp, const JGITTags_t::key_type date)
Get selection of GIT tags.
Print objects in ASCII format using ROOT dictionary.
*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
Dynamic ROOT object management.
Auxiliary data structure for floating point format specification.
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.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
General purpose messaging.
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
ResultSet & getResultSet(const std::string &query)
Get result set.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
static const char *const TIMESTAMP
Time stamp of earliest UTC time.
int qaqc
QA/QC file descriptor.