12 #include "eformat/Version.h"
13 #include "eformat/HeaderMarker.h"
14 #include "eformat/DetectorMask.h"
15 #include "oh/OHRootProvider.h"
16 #include "rc/RunParamsNamed.h"
18 #include "TEfficiency.h"
19 #include "TProfile2D.h"
47 void copyAttributes(TH1* prof,
const TEfficiency*
eff) {
50 const auto*
tot{
eff->GetTotalHistogram()};
53 TString xlabel{
tot->GetXaxis()->GetTitle()};
54 TString ylabel{
tot->GetYaxis()->GetTitle()};
55 TString zlabel{
tot->GetZaxis()->GetTitle()};
56 if (xlabel) prof->GetXaxis()->SetTitle(xlabel);
57 if (ylabel) prof->GetYaxis()->SetTitle(ylabel);
58 if (zlabel) prof->GetZaxis()->SetTitle(zlabel);
60 Int_t nbinsx = prof->GetNbinsX();
61 Int_t nbinsy = prof->GetNbinsY();
64 if (
tot->GetXaxis()->GetLabels() !=
nullptr) {
65 for (
int ibinx = 1; ibinx <= nbinsx; ++ibinx)
66 prof->GetXaxis()->SetBinLabel(ibinx,
tot->GetXaxis()->GetBinLabel(ibinx));
68 if (
tot->GetYaxis()->GetLabels() !=
nullptr) {
69 for (
int ibiny = 1; ibiny <= nbinsy; ++ibiny)
70 prof->GetYaxis()->SetBinLabel(ibiny,
tot->GetYaxis()->GetBinLabel(ibiny));
74 eff->TAttLine::Copy(*prof);
75 eff->TAttFill::Copy(*prof);
76 eff->TAttMarker::Copy(*prof);
80 std::unique_ptr<const TProfile> create1DProfile(
const TEfficiency*
eff) {
81 const auto*
tot{
eff->GetTotalHistogram()};
82 const auto* pass{
eff->GetPassedHistogram()};
83 std::unique_ptr<TProfile> prof;
84 const auto* xaxis{
tot->GetXaxis()};
85 if (xaxis->IsVariableBinSize()) {
86 prof = std::make_unique<TProfile>(
"eff_histo",
eff->GetTitle(),
87 xaxis->GetNbins(), xaxis->GetXbins()->GetArray());
89 prof = std::make_unique<TProfile>(
"eff_histo",
eff->GetTitle(),
90 xaxis->GetNbins(), xaxis->GetXmin(), xaxis->GetXmax());
92 prof->SetDirectory(0);
94 for (Int_t ibin = 0; ibin <
tot->GetNbinsX()+2; ++ibin) {
95 auto center{
tot->GetBinCenter(ibin)};
96 prof->Fill(center, 1, pass->GetBinContent(ibin));
97 prof->Fill(center, 0,
tot->GetBinContent(ibin)-pass->GetBinContent(ibin));
98 prof->SetBinEntries(ibin,
tot->GetBinContent(ibin));
100 copyAttributes(prof.get(),
eff);
105 std::unique_ptr<const TProfile2D> create2DProfile(
const TEfficiency*
eff) {
106 const auto*
tot{
eff->GetTotalHistogram()};
107 const auto* pass{
eff->GetPassedHistogram()};
108 std::unique_ptr<TProfile2D> prof;
109 Int_t nbinsx{
tot->GetNbinsX()};
110 Int_t nbinsy{
tot->GetNbinsY()};
111 const auto* xaxis{
tot->GetXaxis()};
112 const auto* yaxis{
tot->GetYaxis()};
114 if (xaxis->IsVariableBinSize() && yaxis->IsVariableBinSize() ) {
115 prof = std::make_unique<TProfile2D>(
"eff_histo",
116 eff->GetTitle(), nbinsx, xaxis->GetXbins()->GetArray(),
117 nbinsy, yaxis->GetXbins()->GetArray());
118 }
else if (xaxis->IsVariableBinSize() && ! yaxis->IsVariableBinSize() ) {
119 prof = std::make_unique<TProfile2D>(
"eff_histo",
120 eff->GetTitle(), nbinsx, xaxis->GetXbins()->GetArray(),
121 nbinsy, yaxis->GetXmin(), yaxis->GetXmax());
122 }
else if (!xaxis->IsVariableBinSize() && yaxis->IsVariableBinSize() ) {
123 prof = std::make_unique<TProfile2D>(
"eff_histo",
124 eff->GetTitle(), nbinsx, xaxis->GetXmin(), xaxis->GetXmax(),
125 nbinsy, yaxis->GetXbins()->GetArray());
127 prof = std::make_unique<TProfile2D>(
"eff_histo",
128 eff->GetTitle(), nbinsx, xaxis->GetXmin(), xaxis->GetXmax(),
129 nbinsy, yaxis->GetXmin(), yaxis->GetXmax());
131 prof->SetDirectory(0);
133 for (Int_t ibinx = 0; ibinx <
tot->GetNbinsX()+2; ++ibinx) {
134 auto centerx{
tot->GetXaxis()->GetBinCenter(ibinx)};
135 for (Int_t ibiny = 0; ibiny <
tot->GetNbinsY()+2; ++ibiny) {
136 auto centery{
tot->GetYaxis()->GetBinCenter(ibiny)};
137 prof->Fill(centerx, centery, 1, pass->GetBinContent(ibinx, ibiny));
138 prof->Fill(centerx, centery, 0,
139 tot->GetBinContent(ibinx, ibiny)-pass->GetBinContent(ibinx, ibiny));
140 prof->SetBinEntries(prof->GetBin(ibinx, ibiny),
141 tot->GetBinContent(ibinx, ibiny));
145 copyAttributes(prof.get(),
eff);
153 base_class(
name,svcloc),
154 m_inputMetaDataStore(
"StoreGateSvc/InputMetaDataStore",
name ),
155 m_sgSvc(
"StoreGateSvc",
name),
156 m_robProvider(
"ROBDataProviderSvc",
name),
157 m_histSvc(
"THistSvc",
name)
173 return StatusCode::FAILURE;
178 return StatusCode::FAILURE;
210 signal(SIGTERM, handle_terminate);
219 return StatusCode::SUCCESS;
226 if(!IPCCore::isInitialised()) {
227 char*
argv[2] = { 0 };
245 std::unique_ptr<emon::SamplingAddress>
address;
255 emon::Origin l1_origin = emon::origin::AFTER_VETO;
262 l1_logic = emon::logic::IGNORE;
266 l1_origin = emon::origin::BEFORE_PRESCALE;
268 l1_origin = emon::origin::AFTER_PRESCALE;
270 l1_origin = emon::origin::AFTER_VETO;
280 stream_logic = emon::logic::IGNORE;
293 ATH_MSG_ERROR(
"Cannot read L1Menu to map L1 item names to IDs. The property " <<
m_l1names.name() <<
" will be ignored!");
295 for (
const std::string& l1name :
m_l1names) {
297 const unsigned int id = l1Menu->
item(l1name).
ctpId();
298 ATH_MSG_DEBUG(
"Item " << l1name <<
" mapped to CTP ID " <<
id);
299 l1bits.push_back(
static_cast<unsigned short>(
id));
308 typedef emon::MaskedValue<unsigned char> L1TriggerType;
310 emon::SmartBitValue l1pattern(l1bits, l1_logic, l1_origin);
315 emon::SelectionCriteria criteria(l1triggerType,
316 std::move(l1pattern),
317 std::move(streamTags),
337 <<
" Reason: " << ex.what());
346 ATH_MSG_WARNING(
"previousEvent not implemented for ByteStreamEmonInputSvc");
357 if (
st)
delete []
st;
361 while(
m_re ==
nullptr) {
382 }
catch(emon::NoMoreEvents& ex) {
399 if (buf[0] == eformat::FULL_EVENT) {
402 m_re = std::make_unique<RawEvent>(buf);
409 std::stringstream
ss;
421 m_robProvider->setEventStatus(Gaudi::Hive::currentContext(), 0);
425 ATH_MSG_ERROR(
"nextEvent: Got invalid fragment of unknown type: 0x"
426 << std::hex << buf[0] << std::dec);
443 if (ioc.isSuccess()) {
456 if (iocaux.isSuccess()) {
468 if (rec_sg != StatusCode::SUCCESS) {
469 ATH_MSG_ERROR(
"Fail to record BS DataHeader in StoreGate. Skipping events?! " << rec_sg);
501 unsigned int missed_publications = 0;
503 missed_publications++;
508 ATH_MSG_WARNING(
" check_publish: missed " << missed_publications <<
" publications to OH");
523 if(!
part.isValid())
return;
542 m_provider->publish(*
h, name_tag.first, name_tag.second);
545 for(
const std::string&
name :
m_histSvc->getEfficiencies()) {
555 TEfficiency *
h =
nullptr;
558 std::unique_ptr<const TH1>
p;
559 if (
h->GetDimension() == 1) {
560 p = create1DProfile(
h);
561 }
else if (
h->GetDimension() == 2) {
562 p = create2DProfile(
h);
566 m_provider->publish(*
p, name_tag.first, name_tag.second);
571 }
catch (daq::oh::Exception& ex) {
582 RunParamsNamed runParams(
p,
"RunParams.RunParams");
584 runParams.checkout();
586 eformat::helper::DetectorMask
mask(runParams.det_mask);
588 auto metadatacont = std::make_unique<ByteStreamMetadataContainer>();
589 metadatacont->push_back(std::make_unique<ByteStreamMetadata>(
590 runParams.run_number,
593 runParams.recording_enabled,
594 runParams.trigger_type,
595 mask.serialize().second,
597 runParams.beam_energy,
600 runParams.T0_project_tag,
602 std::vector<std::string>()
628 for(
const std::string&
name :
m_histSvc->getEfficiencies()) {
629 TEfficiency *
h =
nullptr;
631 std::unique_ptr<TH1> pass{
h->GetCopyPassedHisto()};
633 h->SetPassedHistogram(*pass.get(),
"");
634 std::unique_ptr<TH1>
tot{
h->GetCopyTotalHisto()};
636 h->SetTotalHistogram(*
tot.get(),
"");
641 return StatusCode::SUCCESS;
660 return StatusCode::SUCCESS;