1414// / @file TPCCalibPedestalSpec.h
1515// / @brief TPC Pedestal calibration processor
1616
17- #include " DetectorsCalibration/Utils.h"
17+ #include < vector>
18+ #include < string>
19+ #include < chrono>
20+
1821#include " Framework/Task.h"
19- #include " Framework/ConfigParamRegistry.h"
2022#include " Framework/ControlService.h"
21- #include " Framework/WorkflowSpec.h"
22-
2323#include " Framework/Logger.h"
24+ #include " Framework/ConfigParamRegistry.h"
25+
2426#include " Headers/DataHeader.h"
25- #include " Framework/ConfigParamSpec.h"
26- #include " Framework/CompletionPolicy.h"
27- #include " Framework/CompletionPolicyHelpers.h"
27+ #include " CCDB/CcdbApi.h"
2828#include " DetectorsCalibration/Utils.h"
29- #include " DPLUtils/RawParser.h"
30- #include " Headers/DataHeader.h"
31- #include " CommonUtils/ConfigurableParam.h"
29+
30+ #include " TPCBase/CDBInterface.h"
3231#include " TPCCalibration/CalibPedestal.h"
3332#include " TPCReconstruction/RawReaderCRU.h"
34- #include < vector>
35- #include < string>
36- #include " DetectorsRaw/RDHUtils.h"
37- #include " TPCBase/RDHUtils.h"
38- #include " TPCBase/CDBInterface.h"
39- #include " CCDB/CcdbApi.h"
33+ #include " TPCWorkflow/CalibProcessingHelper.h"
4034
4135using namespace o2 ::framework;
4236using namespace o2 ::tpc;
43- using RDHUtils = o2::raw::RDHUtils;
4437using clbUtils = o2::calibration::Utils;
4538
4639namespace o2
@@ -51,6 +44,8 @@ namespace calibration
5144class TPCCalibPedestalDevice : public o2 ::framework::Task
5245{
5346 public:
47+ TPCCalibPedestalDevice (bool skipCalib) : mSkipCalib (skipCalib) {}
48+
5449 void init (o2::framework::InitContext& ic) final
5550 {
5651 // set up ADC value filling
@@ -78,81 +73,8 @@ class TPCCalibPedestalDevice : public o2::framework::Task
7873 return ;
7974 }
8075
81- std::vector<InputSpec> filter = {{" check" , ConcreteDataTypeMatcher{o2::header::gDataOriginTPC , " RAWDATA" }, Lifetime::Timeframe}};
82-
83- for (auto const & ref : InputRecordWalker (pc.inputs (), filter)) {
84- const auto * dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
85-
86- // ---| extract hardware information to do the processing |---
87- const auto subSpecification = dh->subSpecification ;
88- rdh_utils::FEEIDType feeID = (rdh_utils::FEEIDType)dh->subSpecification ;
89- rdh_utils::FEEIDType cruID, linkID, endPoint;
90-
91- if (mUseOldSubspec ) {
92- // ---| old definition by Gvozden |---
93- cruID = (rdh_utils::FEEIDType)(subSpecification >> 16 );
94- linkID = (rdh_utils::FEEIDType)((subSpecification + (subSpecification >> 8 )) & 0xFF ) - 1 ;
95- endPoint = (rdh_utils::FEEIDType)((subSpecification >> 8 ) & 0xFF ) > 0 ;
96- } else {
97- // ---| new definition by David |---
98- rdh_utils::getMapping (feeID, cruID, endPoint, linkID);
99- }
100-
101- const auto globalLinkID = linkID + endPoint * 12 ;
102-
103- // ---| update hardware information in the reader |---
104- auto & reader = mRawReader .getReaders ()[0 ];
105- reader->forceCRU (cruID);
106- reader->setLink (globalLinkID);
107-
108- LOGP (info, " Specifier: {}/{}/{}" , dh->dataOrigin .as <std::string>(), dh->dataDescription .as <std::string>(), subSpecification);
109- LOGP (info, " Payload size: {}" , dh->payloadSize );
110- LOGP (info, " CRU: {}; linkID: {}; endPoint: {}; globalLinkID: {}" , cruID, linkID, endPoint, globalLinkID);
111-
112- // TODO: exception handling needed?
113- const gsl::span<const char > raw = pc.inputs ().get <gsl::span<char >>(ref);
114- o2::framework::RawParser parser (raw.data (), raw.size ());
115-
116- // TODO: it would be better to have external event handling and then moving the event processing functionality to CalibRawBase and RawReader to not repeat it in other places
117- rawreader::ADCRawData rawData;
118- rawreader::GBTFrame gFrame ;
119-
120- for (auto it = parser.begin (), end = parser.end (); it != end; ++it) {
121- // debugging stuff
122- /*
123- auto* rdhPtr = it.get_if<o2::header::RAWDataHeader>();
124- if (!rdhPtr) {
125- break;
126- }
127- const auto& rdh = *rdhPtr;
128- auto feeID = RDHUtils::getFEEID(rdh);
129- rdh_utils::FEEIDType cru, link, endPoint;
130- rdh_utils::getMapping(feeID, cru, endPoint, link);
131- LOGP(info, "feeID: {} -- CRU: {}; linkID: {}; endPoint: {}", feeID, cru, link, endPoint);
132- */
133-
134- const auto size = it.size ();
135- auto data = it.data ();
136- // LOGP(info, "Data size: {}", size);
137-
138- int iFrame = 0 ;
139- for (int i = 0 ; i < size; i += 16 ) {
140- gFrame .setFrameNumber (iFrame);
141- gFrame .setPacketNumber (iFrame / 508 );
142- gFrame .readFromMemory (gsl::span<const o2::byte>(data + i, 16 ));
143-
144- // extract the half words from the 4 32-bit words
145- gFrame .getFrameHalfWords ();
146-
147- gFrame .getAdcValues (rawData);
148- gFrame .updateSyncCheck (false );
149-
150- ++iFrame;
151- }
152- }
153-
154- reader->runADCDataCallback (rawData);
155- }
76+ auto & reader = mRawReader .getReaders ()[0 ];
77+ calib_processing_helper::processRawData (pc.inputs (), reader, mUseOldSubspec );
15678
15779 mCalibPedestal .incrementNEvents ();
15880 LOGP (info, " Number of processed events: {} ({})" , mCalibPedestal .getNumberOfProcessedEvents (), mMaxEvents );
@@ -174,7 +96,9 @@ class TPCCalibPedestalDevice : public o2::framework::Task
17496 {
17597 LOGP (info, " endOfStream" );
17698 dumpCalibData ();
177- sendOutput (ec.outputs ());
99+ if (!mSkipCalib ) {
100+ sendOutput (ec.outputs ());
101+ }
178102 ec.services ().get <ControlService>().readyToQuit (QuitRequest::Me);
179103 }
180104
@@ -187,12 +111,16 @@ class TPCCalibPedestalDevice : public o2::framework::Task
187111 bool mUseOldSubspec {false };
188112 bool mForceQuit {false };
189113 bool mDirectFileDump {false };
114+ bool mSkipCalib {false };
190115
191116 // ____________________________________________________________________________
192117 void sendOutput (DataAllocator& output)
193118 {
194119 CDBStorage::MetaData_t md;
195- long timeStart = 0 ;
120+
121+ // perhaps should be changed to time of the run
122+ const auto now = std::chrono::system_clock::now ();
123+ long timeStart = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch ()).count ();
196124 long timeEnd = 99999999999999 ;
197125
198126 std::array<const CalDet<float >*, 2 > data = {&mCalibPedestal .getPedestal (), &mCalibPedestal .getNoise ()};
@@ -233,19 +161,21 @@ class TPCCalibPedestalDevice : public o2::framework::Task
233161namespace framework
234162{
235163
236- DataProcessorSpec getTPCCalibPedestalSpec (const std::string inputSpec)
164+ DataProcessorSpec getTPCCalibPedestalSpec (const std::string inputSpec, bool skipCalib )
237165{
238166 using device = o2::calibration::TPCCalibPedestalDevice;
239167
240168 std::vector<OutputSpec> outputs;
241- outputs.emplace_back (ConcreteDataTypeMatcher{clbUtils::gDataOriginCLB , clbUtils::gDataDescriptionCLBPayload });
242- outputs.emplace_back (ConcreteDataTypeMatcher{clbUtils::gDataOriginCLB , clbUtils::gDataDescriptionCLBInfo });
169+ if (!skipCalib) {
170+ outputs.emplace_back (ConcreteDataTypeMatcher{clbUtils::gDataOriginCLB , clbUtils::gDataDescriptionCLBPayload });
171+ outputs.emplace_back (ConcreteDataTypeMatcher{clbUtils::gDataOriginCLB , clbUtils::gDataDescriptionCLBInfo });
172+ }
243173
244174 return DataProcessorSpec{
245175 " calib-tpc-pedestal" ,
246176 select (inputSpec.data ()),
247177 outputs,
248- AlgorithmSpec{adaptFromTask<device>()},
178+ AlgorithmSpec{adaptFromTask<device>(skipCalib )},
249179 Options{
250180 {" max-events" , VariantType::Int, 100 , {" maximum number of events to process" }},
251181 {" use-old-subspec" , VariantType::Bool, false , {" use old subsecifiation definition" }},
0 commit comments