1010// or submit itself to any jurisdiction.
1111
1212#include < memory>
13- #include < vector>
14- #include < string>
15- #include < algorithm>
16- #include " fmt/format.h"
1713
1814#include " Framework/Task.h"
19- #include " Framework/ControlService.h"
20- #include " Framework/ConfigParamRegistry.h"
15+ #include " Framework/InputRecordWalker.h"
2116#include " Framework/Logger.h"
2217#include " Framework/DataProcessorSpec.h"
23- #include " Framework/WorkflowSpec.h"
24-
25- #include " DataFormatsTPC/TPCSectorHeader.h"
2618#include " Headers/DataHeader.h"
27- #include " CCDB/CcdbApi.h"
28- #include " DetectorsCalibration/Utils.h"
19+ #include " DataFormatsTPC/TPCSectorHeader.h"
2920
30- #include " TPCBase/RDHUtils.h"
31- #include " TPCBase/Mapper.h"
3221#include " TPCReconstruction/KrBoxClusterFinder.h"
3322#include " TPCReconstruction/KrCluster.h"
34- #include " TPCReconstruction/RawReaderCRU.h"
35- #include " TPCWorkflow/CalibProcessingHelper.h"
3623#include " TPCWorkflow/KryptonClustererSpec.h"
3724
3825using namespace o2 ::framework;
26+ using namespace o2 ::header;
3927using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType;
4028
4129namespace o2
@@ -46,132 +34,69 @@ namespace tpc
4634class KrBoxClusterFinderDevice : public o2 ::framework::Task
4735{
4836 public:
49- KrBoxClusterFinderDevice (int lane, const std::vector< int >& sectors ) : mClusters ( 36 ), mLane {lane}, mSectors (sectors), mClusterFinder {std::make_unique<KrBoxClusterFinder>()} {}
37+ KrBoxClusterFinderDevice () : mClusterFinder {std::make_unique<KrBoxClusterFinder>()} {}
5038
5139 void init (o2::framework::InitContext& ic) final
5240 {
53- // set up ADC value filling
54- mRawReader .createReader (" " );
55-
56- mRawReader .setLinkZSCallback ([this ](int cru, int rowInSector, int padInRow, int timeBin, float adcValue) -> bool {
57- const int sector = cru / 10 ;
58- if ((mLastSector > -1 ) && (sector != mLastSector )) {
59- LOGP (debug, " analysing sector {} ({})" , mLastSector , sector);
60- mClusterFinder ->findLocalMaxima (true );
61- LOGP (info, " found {} clusters in sector {}" , mClusterFinder ->getClusters ().size (), mLastSector );
62- std::swap (mClusters [mLastSector ], mClusterFinder ->getClusters ());
63- mClusterFinder ->resetADCMap ();
64- mClusterFinder ->resetClusters ();
65- }
66-
67- mClusterFinder ->fillADCValue (cru, rowInSector, padInRow, timeBin, adcValue);
68-
69- mLastSector = sector;
70- return true ;
71- });
72-
73- mMaxEvents = static_cast <uint32_t >(ic.options ().get <int >(" max-events" ));
74- mForceQuit = ic.options ().get <bool >(" force-quit" );
41+ mClusterFinder ->init ();
7542 }
7643
7744 void run (o2::framework::ProcessingContext& pc) final
7845 {
79- // in case the maximum number of events was reached don't do further processing
80- if (mReadyToQuit ) {
81- return ;
82- }
46+ for (auto const & inputRef : InputRecordWalker (pc.inputs ())) {
47+ auto const * sectorHeader = DataRefUtils::getHeader<TPCSectorHeader*>(inputRef);
48+ if (sectorHeader == nullptr ) {
49+ LOGP (error, " sector header missing on header stack for input on " , inputRef.spec ->binding );
50+ continue ;
51+ }
8352
84- std::for_each (mClusters .begin (), mClusters .end (), [](auto & cl) { cl.clear (); });
53+ const int sector = sectorHeader->sector ();
54+ auto inDigits = pc.inputs ().get <gsl::span<o2::tpc::Digit>>(inputRef);
8555
86- auto & reader = mRawReader .getReaders ()[0 ];
87- mActiveSectors = calib_processing_helper::processRawData (pc.inputs (), reader, false , mSectors );
56+ mClusterFinder ->loopOverSector (inDigits, sector);
8857
89- // analyse the final sector
90- if (mLastSector > -1 ) {
91- LOGP (debug, " analysing sector {}" , mLastSector );
92- mClusterFinder ->findLocalMaxima (true );
93- if (mClusterFinder ->getClusters ().size ()) {
94- LOGP (info, " found {} clusters in sector {}" , mClusterFinder ->getClusters ().size (), mLastSector );
95- std::swap (mClusters [mLastSector ], mClusterFinder ->getClusters ());
96- }
97- }
98- mClusterFinder ->resetADCMap ();
99- mClusterFinder ->resetClusters ();
58+ snapshotClusters (pc.outputs (), mClusterFinder ->getClusters (), sector);
10059
101- ++mProcessedTFs ;
102- LOGP (info, " Number of processed time frames: {} ({})" , mProcessedTFs , mMaxEvents );
103-
104- snapshotClusters (pc.outputs ());
105-
106- // TODO: is this still needed?
107- if (mMaxEvents && (mProcessedTFs >= mMaxEvents )) {
108- LOGP (info, " Maximm number of time frames reached ({}), no more processing will be done" , mMaxEvents );
109- mReadyToQuit = true ;
110- if (mForceQuit ) {
111- pc.services ().get <ControlService>().endOfStream ();
112- pc.services ().get <ControlService>().readyToQuit (QuitRequest::All);
113- } else {
114- pc.services ().get <ControlService>().readyToQuit (QuitRequest::Me);
115- }
116- }
117- }
60+ LOGP (info, " processed sector {} with {} digits and {} reconstructed clusters" , sector, inDigits.size (), mClusterFinder ->getClusters ().size ());
11861
119- void endOfStream (o2::framework::EndOfStreamContext& ec) final
120- {
121- LOGP (info, " endOfStream" );
122- if (mActiveSectors ) {
123- snapshotClusters (ec.outputs ());
62+ mClusterFinder ->resetClusters ();
12463 }
125- ec.services ().get <ControlService>().readyToQuit (QuitRequest::Me);
64+
65+ ++mProcessedTFs ;
66+ LOGP (info, " Number of processed time frames: {}" , mProcessedTFs );
12667 }
12768
12869 private:
129- std::vector<std::vector<KrCluster>> mClusters ;
13070 std::unique_ptr<KrBoxClusterFinder> mClusterFinder ;
131- int mLastSector {-1 };
132- rawreader::RawReaderCRUManager mRawReader ;
133- int mLane {0 }; // /< lane number of processor
134- std::vector<int > mSectors {}; // /< sectors to process in this instance
135- uint32_t mMaxEvents {0 };
13671 uint32_t mProcessedTFs {0 };
137- bool mReadyToQuit {false };
138- bool mCalibDumped {false };
139- bool mForceQuit {false };
140- uint64_t mActiveSectors {0 }; // /< bit mask of active sectors
14172
14273 // ____________________________________________________________________________
143- void snapshotClusters (DataAllocator& output)
74+ void snapshotClusters (DataAllocator& output, const std::vector<o2::tpc::KrCluster>& clusters, int sector )
14475 {
145- for (const int sector : mSectors ) {
146- o2::tpc::TPCSectorHeader header{sector};
147- header.activeSectors = mActiveSectors ;
148- // digit for now are transported per sector, not per lane
149- output.snapshot (Output{" TPC" , " KRCLUSTERS" , static_cast <SubSpecificationType>(sector), Lifetime::Timeframe, header},
150- mClusters [sector]);
151- }
152- mActiveSectors = 0 ;
76+ o2::tpc::TPCSectorHeader header{sector};
77+ header.activeSectors = (0x1 << sector);
78+ output.snapshot (Output{gDataOriginTPC , " KRCLUSTERS" , static_cast <SubSpecificationType>(sector), Lifetime::Timeframe, header}, clusters);
15379 }
15480};
15581
156- o2::framework::DataProcessorSpec getKryptonClustererSpec (const std::string inputSpec, int ilane, std::vector< int > const & sectors )
82+ o2::framework::DataProcessorSpec getKryptonClustererSpec ()
15783{
15884 using device = o2::tpc::KrBoxClusterFinderDevice;
15985
86+ std::vector<InputSpec> inputs{
87+ InputSpec{" digits" , gDataOriginTPC , " DIGITS" , 0 , Lifetime::Timeframe},
88+ };
89+
16090 std::vector<OutputSpec> outputs;
161- for (auto isector : sectors) {
162- outputs.emplace_back (" TPC" , " KRCLUSTERS" , static_cast <SubSpecificationType>(isector), Lifetime::Timeframe);
163- }
91+ outputs.emplace_back (gDataOriginTPC , " KRCLUSTERS" , 0 , Lifetime::Timeframe);
16492
16593 return DataProcessorSpec{
166- fmt::format ( " tpc-krypton-clusterer-{} " , ilane) ,
167- select (inputSpec. data ()) ,
94+ " tpc-krypton-clusterer" ,
95+ inputs ,
16896 outputs,
169- AlgorithmSpec{adaptFromTask<device>(ilane, sectors)},
170- Options{
171- {" max-events" , VariantType::Int, 0 , {" maximum number of events to process" }},
172- {" force-quit" , VariantType::Bool, false , {" force quit after max-events have been reached" }},
173- } // end Options
174- }; // end DataProcessorSpec
97+ AlgorithmSpec{adaptFromTask<device>()},
98+ Options{} // end Options
99+ }; // end DataProcessorSpec
175100}
176101} // namespace tpc
177102} // namespace o2
0 commit comments