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,79 @@ 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+ LOG (info) << " init: " << ic.options ().hasOption (" ignore-irframes" ) << " " << ic.options ().get <bool >(" ignore-irframes" );
74+ if (ic.options ().hasOption (" ignore-irframes" ) && !ic.options ().get <bool >(" ignore-irframes" )) {
75+ mUseIRFrames = true ;
76+ }
6977 connectTree (filename);
7078}
7179
7280void DigitReader::run (ProcessingContext& pc)
7381{
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);
82+ gsl::span<const o2::dataformats::IRFrame> irFrames{};
83+ // LOG(info) << "Using IRs:" << mUseIRFrames;
84+ if (mUseIRFrames ) {
85+ irFrames = pc.inputs ().get <gsl::span<o2::dataformats::IRFrame>>(" driverInfo" );
86+ }
87+ auto ent = mTree ->GetReadEntry ();
88+ if (!mUseIRFrames ) {
89+ ent++;
90+ assert (ent < mTree ->GetEntries ()); // this should not happen
91+ mTree ->GetEntry (ent);
92+ LOG (info) << " DigitReader pushes " << mDigits .size () << " digits at entry " << ent;
93+ pc.outputs ().snapshot (Output{" CTP" , " DIGITS" , 0 }, mDigits );
94+ pc.outputs ().snapshot (Output{" CTP" , " LUMI" , 0 }, mLumi );
95+ if (mTree ->GetReadEntry () + 1 >= mTree ->GetEntries ()) {
96+ pc.services ().get <ControlService>().endOfStream ();
97+ pc.services ().get <ControlService>().readyToQuit (QuitRequest::Me);
98+ }
99+ } else {
100+ std::vector<o2::ctp::CTPDigit> digitSel;
101+ if (irFrames.size ()) { // we assume the IRFrames are in the increasing order
102+ if (ent < 0 ) {
103+ ent++;
104+ }
105+ o2::utils::IRFrameSelector irfSel;
106+ long biasInBC = 0 ; // depends if digits are already aligned
107+ irfSel.setSelectedIRFrames (irFrames, 0 , 0 , -biasInBC, true );
108+ const auto irMin = irfSel.getIRFrames ().front ().getMin (); // use processed IRframes for rough comparisons (possible shift!)
109+ const auto irMax = irfSel.getIRFrames ().back ().getMax ();
110+ LOGP (info, " Selecting IRFrame {}-{}" , irMin.asString (), irMax.asString ());
111+ while (ent < mTree ->GetEntries ()) {
112+ if ( ent > mTree ->GetReadEntry ()){
113+ mTree ->GetEntry (ent);
114+ }
115+ if ( mDigits .front ().intRecord <= irMax && mDigits .back ().intRecord >= irMin) { // THere is overlap
116+ for (int i = 0 ; i < (int )mDigits .size (); i++) {
117+ const auto & dig = mDigits [i];
118+ // if(irfSel.check(dig.intRecord)) { // adding selected digit
119+ if (dig.intRecord >= irMin && dig.intRecord <= irMax) {
120+ digitSel.push_back (dig);
121+ LOG (info) << " adding:" << dig.intRecord << " ent:" << ent;
122+ }
123+ }
124+ }
125+ if (mDigits .back ().intRecord < irMax) { // need to check the next entry
126+ ent++;
127+ continue ;
128+ }
129+ break ; // push collected data
130+ }
131+ }
132+ pc.outputs ().snapshot (Output{" CTP" , " DIGITS" , 0 }, digitSel);
133+ pc.outputs ().snapshot (Output{" CTP" , " LUMI" , 0 }, mLumi ); // add full lumi for this TF
134+ if (!irFrames.size () || irFrames.back ().isLast ()) {
135+ pc.services ().get <ControlService>().endOfStream ();
136+ pc.services ().get <ControlService>().readyToQuit (QuitRequest::Me);
137+ }
84138 }
85139}
86140
0 commit comments