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"
21 #include "GaudiKernel/ITHistSvc.h"
49 void copyAttributes(
TH1* prof,
const TEfficiency*
eff) {
52 const auto*
tot{
eff->GetTotalHistogram()};
55 TString xlabel{
tot->GetXaxis()->GetTitle()};
56 TString ylabel{
tot->GetYaxis()->GetTitle()};
57 TString zlabel{
tot->GetZaxis()->GetTitle()};
58 if (xlabel) prof->GetXaxis()->SetTitle(xlabel);
59 if (ylabel) prof->GetYaxis()->SetTitle(ylabel);
60 if (zlabel) prof->GetZaxis()->SetTitle(zlabel);
62 Int_t nbinsx = prof->GetNbinsX();
63 Int_t nbinsy = prof->GetNbinsY();
66 if (
tot->GetXaxis()->GetLabels() !=
nullptr) {
67 for (
int ibinx = 1; ibinx <= nbinsx; ++ibinx)
68 prof->GetXaxis()->SetBinLabel(ibinx,
tot->GetXaxis()->GetBinLabel(ibinx));
70 if (
tot->GetYaxis()->GetLabels() !=
nullptr) {
71 for (
int ibiny = 1; ibiny <= nbinsy; ++ibiny)
72 prof->GetYaxis()->SetBinLabel(ibiny,
tot->GetYaxis()->GetBinLabel(ibiny));
76 eff->TAttLine::Copy(*prof);
77 eff->TAttFill::Copy(*prof);
78 eff->TAttMarker::Copy(*prof);
82 std::unique_ptr<const TProfile> create1DProfile(
const TEfficiency*
eff) {
83 const auto*
tot{
eff->GetTotalHistogram()};
84 const auto* pass{
eff->GetPassedHistogram()};
85 std::unique_ptr<TProfile> prof;
86 const auto* xaxis{
tot->GetXaxis()};
87 if (xaxis->IsVariableBinSize()) {
88 prof = std::make_unique<TProfile>(
"eff_histo",
eff->GetTitle(),
89 xaxis->GetNbins(), xaxis->GetXbins()->GetArray());
91 prof = std::make_unique<TProfile>(
"eff_histo",
eff->GetTitle(),
92 xaxis->GetNbins(), xaxis->GetXmin(), xaxis->GetXmax());
94 prof->SetDirectory(0);
96 for (Int_t ibin = 0; ibin <
tot->GetNbinsX()+2; ++ibin) {
97 auto center{
tot->GetBinCenter(ibin)};
98 prof->
Fill(center, 1, pass->GetBinContent(ibin));
99 prof->
Fill(center, 0,
tot->GetBinContent(ibin)-pass->GetBinContent(ibin));
100 prof->SetBinEntries(ibin,
tot->GetBinContent(ibin));
102 copyAttributes(prof.get(),
eff);
107 std::unique_ptr<const TProfile2D> create2DProfile(
const TEfficiency*
eff) {
108 const auto*
tot{
eff->GetTotalHistogram()};
109 const auto* pass{
eff->GetPassedHistogram()};
110 std::unique_ptr<TProfile2D> prof;
111 Int_t nbinsx{
tot->GetNbinsX()};
112 Int_t nbinsy{
tot->GetNbinsY()};
113 const auto* xaxis{
tot->GetXaxis()};
114 const auto* yaxis{
tot->GetYaxis()};
116 if (xaxis->IsVariableBinSize() && yaxis->IsVariableBinSize() ) {
117 prof = std::make_unique<TProfile2D>(
"eff_histo",
118 eff->GetTitle(), nbinsx, xaxis->GetXbins()->GetArray(),
119 nbinsy, yaxis->GetXbins()->GetArray());
120 }
else if (xaxis->IsVariableBinSize() && ! yaxis->IsVariableBinSize() ) {
121 prof = std::make_unique<TProfile2D>(
"eff_histo",
122 eff->GetTitle(), nbinsx, xaxis->GetXbins()->GetArray(),
123 nbinsy, yaxis->GetXmin(), yaxis->GetXmax());
124 }
else if (!xaxis->IsVariableBinSize() && yaxis->IsVariableBinSize() ) {
125 prof = std::make_unique<TProfile2D>(
"eff_histo",
126 eff->GetTitle(), nbinsx, xaxis->GetXmin(), xaxis->GetXmax(),
127 nbinsy, yaxis->GetXbins()->GetArray());
129 prof = std::make_unique<TProfile2D>(
"eff_histo",
130 eff->GetTitle(), nbinsx, xaxis->GetXmin(), xaxis->GetXmax(),
131 nbinsy, yaxis->GetXmin(), yaxis->GetXmax());
133 prof->SetDirectory(0);
135 for (Int_t ibinx = 0; ibinx <
tot->GetNbinsX()+2; ++ibinx) {
136 auto centerx{
tot->GetXaxis()->GetBinCenter(ibinx)};
137 for (Int_t ibiny = 0; ibiny <
tot->GetNbinsY()+2; ++ibiny) {
138 auto centery{
tot->GetYaxis()->GetBinCenter(ibiny)};
139 prof->
Fill(centerx, centery, 1, pass->GetBinContent(ibinx, ibiny));
140 prof->
Fill(centerx, centery, 0,
141 tot->GetBinContent(ibinx, ibiny)-pass->GetBinContent(ibinx, ibiny));
142 prof->SetBinEntries(prof->GetBin(ibinx, ibiny),
143 tot->GetBinContent(ibinx, ibiny));
147 copyAttributes(prof.get(),
eff);
156 m_inputMetaDataStore(
"StoreGateSvc/InputMetaDataStore",
name ),
157 m_sgSvc(
"StoreGateSvc",
name),
158 m_robProvider(
"ROBDataProviderSvc",
name)
165 setProperty(
"State",
"Init").ignore();
176 return StatusCode::FAILURE;
181 return StatusCode::FAILURE;
186 if (service(
"THistSvc",
m_histSvc,
true).isFailure()) {
213 signal(SIGTERM, handle_terminate);
222 return StatusCode::SUCCESS;
227 setProperty(
"State",
"Init").ignore();
229 if(!IPCCore::isInitialised()) {
230 char*
argv[2] = { 0 };
248 std::unique_ptr<emon::SamplingAddress>
address;
258 emon::Origin l1_origin = emon::origin::AFTER_VETO;
265 l1_logic = emon::logic::IGNORE;
269 l1_origin = emon::origin::BEFORE_PRESCALE;
271 l1_origin = emon::origin::AFTER_PRESCALE;
273 l1_origin = emon::origin::AFTER_VETO;
283 stream_logic = emon::logic::IGNORE;
296 ATH_MSG_ERROR(
"Cannot read L1Menu to map L1 item names to IDs. The property " <<
m_l1names.name() <<
" will be ignored!");
298 for (
const std::string& l1name :
m_l1names) {
300 const unsigned int id = l1Menu->
item(l1name).
ctpId();
301 ATH_MSG_DEBUG(
"Item " << l1name <<
" mapped to CTP ID " <<
id);
302 l1bits.push_back(
static_cast<unsigned short>(
id));
311 typedef emon::MaskedValue<unsigned char> L1TriggerType;
313 emon::SmartBitValue l1pattern(l1bits, l1_logic, l1_origin);
318 emon::SelectionCriteria criteria(l1triggerType,
336 setProperty(
"State",
"Connected").ignore();
340 <<
" Reason: " << ex.what());
349 ATH_MSG_WARNING(
"previousEvent not implemented for ByteStreamEmonInputSvc");
360 if (st)
delete [] st;
364 while(
m_re ==
nullptr) {
385 }
catch(emon::NoMoreEvents& ex) {
396 setProperty(
"State",
"Processing").ignore();
402 if (buf[0] == eformat::FULL_EVENT) {
405 m_re = std::make_unique<RawEvent>(buf);
412 std::stringstream
ss;
428 ATH_MSG_ERROR(
"nextEvent: Got invalid fragment of unknown type: 0x"
429 << std::hex << buf[0] << std::dec);
445 if (ioc.isSuccess()) {
457 if (iocaux.isSuccess()) {
469 if (rec_sg != StatusCode::SUCCESS) {
470 ATH_MSG_ERROR(
"Fail to record BS DataHeader in StoreGate. Skipping events?! " << rec_sg);
502 unsigned int missed_publications = 0;
504 missed_publications++;
509 ATH_MSG_WARNING(
" check_publish: missed " << missed_publications <<
" publications to OH");
524 if(!
part.isValid())
return;
543 m_provider->publish(*
h, name_tag.first, name_tag.second);
546 for(
const std::string&
name :
m_histSvc->getEfficiencies()) {
556 TEfficiency *
h =
nullptr;
559 std::unique_ptr<const TH1>
p;
560 if (
h->GetDimension() == 1) {
561 p = create1DProfile(
h);
562 }
else if (
h->GetDimension() == 2) {
563 p = create2DProfile(
h);
567 m_provider->publish(*
p, name_tag.first, name_tag.second);
572 }
catch (daq::oh::Exception& ex) {
583 RunParamsNamed runParams(
p,
"RunParams.RunParams");
585 runParams.checkout();
587 eformat::helper::DetectorMask
mask(runParams.det_mask);
589 auto metadatacont = std::make_unique<ByteStreamMetadataContainer>();
590 metadatacont->push_back(std::make_unique<ByteStreamMetadata>(
591 runParams.run_number,
594 runParams.recording_enabled,
595 runParams.trigger_type,
596 mask.serialize().second,
598 runParams.beam_energy,
601 runParams.T0_project_tag,
603 std::vector<std::string>()
629 for(
const std::string&
name :
m_histSvc->getEfficiencies()) {
630 TEfficiency *
h =
nullptr;
632 std::unique_ptr<TH1> pass{
h->GetCopyPassedHisto()};
634 h->SetPassedHistogram(*pass.get(),
"");
635 std::unique_ptr<TH1>
tot{
h->GetCopyTotalHisto()};
637 h->SetTotalHistogram(*
tot.get(),
"");
642 return StatusCode::SUCCESS;
650 setProperty(
"State",
"Reconnect").ignore();
657 setProperty(
"State",
"Shutdown").ignore();
661 return StatusCode::SUCCESS;