1717#include " DataFormatsCTP/LumiInfo.h"
1818#include " Headers/DataHeader.h"
1919#include " DetectorsCommonDataFormats/DetID.h"
20+ #include " SimulationDataFormat/MCCompLabel.h"
21+ #include " SimulationDataFormat/ConstMCTruthContainer.h"
2022#include " CommonUtils/NameConf.h"
23+ #include " CommonUtils/IRFrameSelector.h"
2124#include " Framework/DataProcessorSpec.h"
2225#include " Framework/Task.h"
2326#include " Framework/ControlService.h"
@@ -50,6 +53,7 @@ class DigitReader : public Task
5053 std::unique_ptr<TTree> mTree ;
5154
5255 bool mUseMC = false ; // use MC truth
56+ bool mUseIRFrames = false ; // selected IRFrames mode
5357 std::string mDigTreeName = " o2sim" ;
5458 std::string mDigitBranchName = " CTPDigits" ;
5559 std::string mLumiBranchName = " CTPLumi" ;
@@ -58,29 +62,78 @@ class DigitReader : public Task
5862DigitReader::DigitReader (bool useMC)
5963{
6064 if (useMC) {
61- LOG (info) << " CTP does not support MC truth at the moment " ;
65+ LOG (info) << " CTP : truth = data as CTP inputs are already digital " ;
6266 }
6367}
6468
6569void DigitReader::init (InitContext& ic)
6670{
6771 auto filename = o2::utils::Str::concat_string (o2::utils::Str::rectifyDirectory (ic.options ().get <std::string>(" input-dir" )),
6872 ic.options ().get <std::string>(" ctp-digit-infile" ));
73+ if (ic.options ().hasOption (" ignore-irframes" ) && !ic.options ().get <bool >(" ignore-irframes" )) {
74+ mUseIRFrames = true ;
75+ }
6976 connectTree (filename);
7077}
7178
7279void DigitReader::run (ProcessingContext& pc)
7380{
74- auto ent = mTree ->GetReadEntry () + 1 ;
75- assert (ent < mTree ->GetEntries ()); // this should not happen
76-
77- mTree ->GetEntry (ent);
78- LOG (info) << " DigitReader pushes " << mDigits .size () << " digits at entry " << ent;
79- pc.outputs ().snapshot (Output{" CTP" , " DIGITS" , 0 }, mDigits );
80- pc.outputs ().snapshot (Output{" CTP" , " LUMI" , 0 }, mLumi );
81- if (mTree ->GetReadEntry () + 1 >= mTree ->GetEntries ()) {
82- pc.services ().get <ControlService>().endOfStream ();
83- pc.services ().get <ControlService>().readyToQuit (QuitRequest::Me);
81+ gsl::span<const o2::dataformats::IRFrame> irFrames{};
82+ // LOG(info) << "Using IRs:" << mUseIRFrames;
83+ if (mUseIRFrames ) {
84+ irFrames = pc.inputs ().get <gsl::span<o2::dataformats::IRFrame>>(" driverInfo" );
85+ }
86+ auto ent = mTree ->GetReadEntry ();
87+ if (!mUseIRFrames ) {
88+ ent++;
89+ assert (ent < mTree ->GetEntries ()); // this should not happen
90+ mTree ->GetEntry (ent);
91+ LOG (info) << " DigitReader pushes " << mDigits .size () << " digits at entry " << ent;
92+ pc.outputs ().snapshot (Output{" CTP" , " DIGITS" , 0 }, mDigits );
93+ pc.outputs ().snapshot (Output{" CTP" , " LUMI" , 0 }, mLumi );
94+ if (mTree ->GetReadEntry () + 1 >= mTree ->GetEntries ()) {
95+ pc.services ().get <ControlService>().endOfStream ();
96+ pc.services ().get <ControlService>().readyToQuit (QuitRequest::Me);
97+ }
98+ } else {
99+ std::vector<o2::ctp::CTPDigit> digitSel;
100+ if (irFrames.size ()) { // we assume the IRFrames are in the increasing order
101+ if (ent < 0 ) {
102+ ent++;
103+ }
104+ o2::utils::IRFrameSelector irfSel;
105+ // MC digits are already aligned
106+ irfSel.setSelectedIRFrames (irFrames, 0 , 0 , 0 , true );
107+ const auto irMin = irfSel.getIRFrames ().front ().getMin (); // use processed IRframes for rough comparisons (possible shift!)
108+ const auto irMax = irfSel.getIRFrames ().back ().getMax ();
109+ LOGP (info, " Selecting IRFrame {}-{}" , irMin.asString (), irMax.asString ());
110+ while (ent < mTree ->GetEntries ()) {
111+ if (ent > mTree ->GetReadEntry ()) {
112+ mTree ->GetEntry (ent);
113+ }
114+ if (mDigits .front ().intRecord <= irMax && mDigits .back ().intRecord >= irMin) { // THere is overlap
115+ for (int i = 0 ; i < (int )mDigits .size (); i++) {
116+ const auto & dig = mDigits [i];
117+ // if(irfSel.check(dig.intRecord)) { // adding selected digit
118+ if (dig.intRecord >= irMin && dig.intRecord <= irMax) {
119+ digitSel.push_back (dig);
120+ LOG (info) << " adding:" << dig.intRecord << " ent:" << ent;
121+ }
122+ }
123+ }
124+ if (mDigits .back ().intRecord < irMax) { // need to check the next entry
125+ ent++;
126+ continue ;
127+ }
128+ break ; // push collected data
129+ }
130+ }
131+ pc.outputs ().snapshot (Output{" CTP" , " DIGITS" , 0 }, digitSel);
132+ pc.outputs ().snapshot (Output{" CTP" , " LUMI" , 0 }, mLumi ); // add full lumi for this TF
133+ if (!irFrames.size () || irFrames.back ().isLast ()) {
134+ pc.services ().get <ControlService>().endOfStream ();
135+ pc.services ().get <ControlService>().readyToQuit (QuitRequest::Me);
136+ }
84137 }
85138}
86139
0 commit comments