88// granted to it by virtue of its status as an Intergovernmental Organization
99// or submit itself to any jurisdiction.
1010
11- #include < vector>
1211#include < iostream>
12+ #include < vector>
13+ #include < type_traits>
14+ #include < gsl/span>
1315
1416#include " FairLogger.h"
1517
1618#include " Framework/ControlService.h"
1719#include " Framework/DataRefUtils.h"
1820#include " DataFormatsEMCAL/EMCALBlockHeader.h"
21+ #include " DataFormatsEMCAL/Cell.h"
1922#include " DataFormatsEMCAL/Digit.h"
23+ #include " DataFormatsEMCAL/TriggerRecord.h"
2024#include " EMCALWorkflow/DigitsPrinterSpec.h"
2125
2226using namespace o2 ::emcal::reco_workflow;
2327
24- void DigitsPrinterSpec::init (framework::InitContext& ctx)
28+ template <class InputType >
29+ void DigitsPrinterSpec<InputType>::init(o2::framework::InitContext& ctx)
2530{
2631}
2732
28- void DigitsPrinterSpec::run (framework::ProcessingContext& pc)
33+ template <class InputType >
34+ void DigitsPrinterSpec<InputType>::run(framework::ProcessingContext& pc)
2935{
3036 // Get the EMCAL block header and check whether it contains digits
3137 LOG (DEBUG ) << " [EMCALDigitsPrinter - process] called" ;
32- auto dataref = pc.inputs ().get (" digits" );
38+ std::string objectbranch;
39+ if constexpr (std::is_same<InputType, o2::emcal::Digit>::value)
40+ objectbranch = " digits" ;
41+ else if constexpr (std::is_same<InputType, o2::emcal::Cell>::value)
42+ objectbranch = " cells" ;
43+ else {
44+ LOG (ERROR ) << " Unsupported input type ... " ;
45+ return ;
46+ }
47+ auto dataref = pc.inputs ().get (objectbranch);
3348 auto const * emcheader = o2::framework::DataRefUtils::getHeader<o2::emcal::EMCALBlockHeader*>(dataref);
3449 if (!emcheader->mHasPayload ) {
3550 LOG (DEBUG ) << " [EMCALDigitsPrinter - process] No more digits" << std::endl;
3651 pc.services ().get <o2::framework::ControlService>().readyToQuit (framework::QuitRequest::Me);
3752 return ;
3853 }
3954
40- auto digits = pc.inputs ().get <std::vector<o2::emcal::Digit>>(" digits" );
41- std::cout << " [EMCALDigitsPrinter - process] receiveed " << digits.size () << " digits ..." << std::endl;
42- if (digits.size ()) {
43- for (const auto & d : digits) {
44- std::cout << " [EMCALDigitsPrinter - process] Channel: " << d.getTower () << std::endl;
45- std::cout << " [EMCALDigitsPrinter - process] Energy: " << d.getEnergy () << std::endl;
46- // std::cout << d << std::endl;
55+ auto objects = pc.inputs ().get <gsl::span<InputType>>(objectbranch);
56+ auto triggerrecords = pc.inputs ().get <gsl::span<o2::emcal::TriggerRecord>>(" triggerrecord" );
57+ std::cout << " [EMCALDigitsPrinter - process] receiveed " << objects.size () << " digits from " << triggerrecords.size () << " triggers ..." << std::endl;
58+ if (triggerrecords.size ()) {
59+ for (const auto & trg : triggerrecords) {
60+ if (!trg.getNumberOfObjects ()) {
61+ std::cout << " [EMCALDigitsPrinter - process] Trigger does not contain " << objectbranch << " , skipping ..." << std::endl;
62+ continue ;
63+ }
64+ std::cout << " [EMCALDigitsPrinter - process] Trigger has " << trg.getNumberOfObjects () << " " << objectbranch << " ..." << std::endl;
65+ gsl::span<const InputType> objectsTrigger (objects.data () + trg.getFirstEntry (), trg.getNumberOfObjects ());
66+ for (const auto & d : objectsTrigger) {
67+ std::cout << " [EMCALDigitsPrinter - process] Channel: " << d.getTower () << std::endl;
68+ std::cout << " [EMCALDigitsPrinter - process] Energy: " << d.getEnergy () << std::endl;
69+ // std::cout << d << std::endl;
70+ }
4771 }
4872 }
4973}
5074
51- o2::framework::DataProcessorSpec o2::emcal::reco_workflow::getEmcalDigitsPrinterSpec ()
75+ o2::framework::DataProcessorSpec o2::emcal::reco_workflow::getEmcalDigitsPrinterSpec (std::string inputtype )
5276{
53-
54- return o2::framework::DataProcessorSpec{" EMCALDigitsPrinter" ,
55- {{" digits" , o2::header::gDataOriginEMC , " DIGITS" , 0 , o2::framework::Lifetime::Timeframe}},
56- {},
57- o2::framework::adaptFromTask<o2::emcal::reco_workflow::DigitsPrinterSpec>()};
77+ if (inputtype == " digits" ) {
78+ return o2::framework::DataProcessorSpec{" EMCALDigitsPrinter" ,
79+ {{" digits" , o2::header::gDataOriginEMC , " DIGITS" , 0 , o2::framework::Lifetime::Timeframe},
80+ {" triggerrecord" , o2::header::gDataOriginEMC , " DIGITSTRGR" , 0 , o2::framework::Lifetime::Timeframe}},
81+ {},
82+ o2::framework::adaptFromTask<o2::emcal::reco_workflow::DigitsPrinterSpec<o2::emcal::Digit>>()};
83+ } else if (inputtype == " cells" ) {
84+ return o2::framework::DataProcessorSpec{" EMCALDigitsPrinter" ,
85+ {{" cells" , o2::header::gDataOriginEMC , " CELLS" , 0 , o2::framework::Lifetime::Timeframe},
86+ {" triggerrecord" , o2::header::gDataOriginEMC , " CELLSTRGR" , 0 , o2::framework::Lifetime::Timeframe}},
87+ {},
88+ o2::framework::adaptFromTask<o2::emcal::reco_workflow::DigitsPrinterSpec<o2::emcal::Cell>>()};
89+ }
90+ throw std::runtime_error (" Input type not supported" );
5891}
92+
93+ // template class o2::emcal::reco_workflow::DigitsPrinterSpec<o2::emcal::Digit>;
94+ // template class o2::emcal::reco_workflow::DigitsPrinterSpec<o2::emcal::Cell>;
0 commit comments