Skip to content

Commit

Permalink
Merge pull request #1 from noferini/rdev-compressor-devel
Browse files Browse the repository at this point in the history
add tof compressed decoding task
  • Loading branch information
preghenella authored Feb 25, 2020
2 parents 7745398 + f209350 commit 4c94343
Show file tree
Hide file tree
Showing 14 changed files with 390 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include "GlobalTrackingWorkflow/TrackTPCITSReaderSpec.h"
#include "TOFWorkflow/DigitReaderSpec.h"
#include "TOFWorkflow/TOFDigitWriterSpec.h"
#include "TOFWorkflow/RawReaderSpec.h"
#include "TOFWorkflow/ClusterReaderSpec.h"
#include "TOFWorkflow/TOFClusterizerSpec.h"
#include "TOFWorkflow/TOFClusterWriterSpec.h"
#include "TOFWorkflow/TOFMatchedWriterSpec.h"
#include "TOFWorkflow/TOFCalibWriterSpec.h"
#include "TOFWorkflow/TOFRawWriterSpec.h"
#include "TOFWorkflow/CompressedDecodingTask.h"
#include "Framework/WorkflowSpec.h"
#include "Framework/ConfigParamSpec.h"
#include "TOFWorkflow/RecoWorkflowSpec.h"
Expand Down Expand Up @@ -52,6 +52,7 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
workflowOptions.push_back(ConfigParamSpec{"tof-lanes", o2::framework::VariantType::Int, 1, {"number of parallel lanes up to the matcher, TBI"}});
workflowOptions.push_back(ConfigParamSpec{"use-ccdb", o2::framework::VariantType::Bool, false, {"enable access to ccdb tof calibration objects"}});
workflowOptions.push_back(ConfigParamSpec{"use-fit", o2::framework::VariantType::Bool, false, {"enable access to fit info for calibration"}});
workflowOptions.push_back(ConfigParamSpec{"input-desc", o2::framework::VariantType::String, "CRAWDATA", {"Input specs description string"}});
}

#include "Framework/runDataProcessing.h" // the main driver
Expand Down Expand Up @@ -110,6 +111,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
if (outputType.rfind("raw") < outputType.size())
writeraw = 1;

bool dgtinput = 0;
if (inputType == "digits") {
dgtinput = 1;
}
bool clusterinput = 0;
if (inputType == "clusters") {
clusterinput = 1;
Expand All @@ -135,7 +140,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
if (clusterinput) {
LOG(INFO) << "Insert TOF Cluster Reader";
specs.emplace_back(o2::tof::getClusterReaderSpec(useMC));
} else if (!rawinput) {
} else if (dgtinput) {
// TOF clusterizer
LOG(INFO) << "Insert TOF Digit reader from file";
specs.emplace_back(o2::tof::getDigitReaderSpec(useMC));
Expand All @@ -144,9 +149,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
LOG(INFO) << "Insert TOF Raw writer";
specs.emplace_back(o2::tof::getTOFRawWriterSpec());
}
} else {
LOG(INFO) << "Insert TOF Raw Reader";
specs.emplace_back(o2::tof::getRawReaderSpec());
} else if (rawinput) {
LOG(INFO) << "Insert TOF Compressed Raw Decoder";
auto inputDesc = cfgc.options().get<std::string>("input-desc");
specs.emplace_back(o2::tof::getCompressedDecodingSpec(inputDesc));
useMC = 0;

if (writedigit) {
Expand Down
2 changes: 1 addition & 1 deletion Detectors/TOF/base/include/TOFBase/Strip.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Strip

/// Empties the point container
/// @param option unused
void clear();
void clear() { mDigits.clear(); }

/// Change the chip index
/// @param index New chip index
Expand Down
5 changes: 4 additions & 1 deletion Detectors/TOF/base/include/TOFBase/WindowFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ class WindowFiller

void initObj();

void reset();

Int_t getCurrentReadoutWindow() const { return mReadoutWindowCurrent; }
void setCurrentReadoutWindow(Double_t value) { mReadoutWindowCurrent = value; }
void setEventTime(double value) { mEventTime = value; }
void setEventTime(double value) { mEventTime = value - mTF * o2::constants::lhc::LHCOrbitNS * 256; }

std::vector<Digit>* getDigitPerTimeFrame() { return &mDigitsPerTimeFrame; }
std::vector<ReadoutWindowData>* getReadoutWindowData() { return &mReadoutWindowData; }
Expand All @@ -45,6 +47,7 @@ class WindowFiller

protected:
// info TOF timewindow
Int_t mTF = 0;
Int_t mReadoutWindowCurrent = 0;
Int_t mFirstOrbit = 0;
Int_t mFirstBunch = 0;
Expand Down
22 changes: 22 additions & 0 deletions Detectors/TOF/base/src/WindowFiller.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ void WindowFiller::initObj()
}
}
//______________________________________________________________________
void WindowFiller::reset()
{
mIcurrentReadoutWindow = 0;
mReadoutWindowCurrent = 0;

for (Int_t i = 0; i < MAXWINDOWS; i++) {
for (Int_t j = 0; j < Geo::NSTRIPS; j++) {
mStrips[i][j].clear();
}
}
mFutureDigits.clear();

mStripsCurrent = &(mStrips[0]);
mStripsNext[0] = &(mStrips[1]);

mDigitsPerTimeFrame.clear();
mReadoutWindowData.clear();

mFirstOrbit = 0;
mFirstBunch = 0;
}
//______________________________________________________________________
void WindowFiller::fillDigitsInStrip(std::vector<Strip>* strips, int channel, int tdc, int tot, int nbc, UInt_t istrip, Int_t triggerorbit, Int_t triggerbunch)
{
(*strips)[istrip].addDigit(channel, tdc, tot * Geo::NTOTBIN_PER_NS, nbc, 0, triggerorbit, triggerbunch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Decoder : public WindowFiller

bool decode();
void readTRM(int icru, int icrate, int orbit, int bunchid);
void InsertDigit(int icrate, int itrm, int itdc, int ichain, int channel, int orbit, int bunchid, int time_ext, int tdc, int tot);
void FillWindows();
void clear();

bool close();
void setVerbose(bool val) { mVerbose = val; };
Expand Down
39 changes: 37 additions & 2 deletions Detectors/TOF/reconstruction/src/Decoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ bool Decoder::close()
return false;
}

void Decoder::clear()
{
reset();
}

void Decoder::InsertDigit(int icrate, int itrm, int itdc, int ichain, int channel, int orbit, int bunchid, int time_ext, int tdc, int tot)
{
std::array<int, 6> digitInfo;

fromRawHit2Digit(icrate, itrm, itdc, ichain, channel, orbit, bunchid, time_ext + tdc, tot, digitInfo);

mHitDecoded++;

int isnext = digitInfo[3] * Geo::BC_IN_WINDOW_INV;

if (isnext >= MAXWINDOWS) { // accumulate all digits which are not in the first windows

insertDigitInFuture(digitInfo[0], digitInfo[1], digitInfo[2], digitInfo[3], 0, digitInfo[4], digitInfo[5]);
} else {
std::vector<Strip>* cstrip = mStripsCurrent; // first window
if (isnext)
cstrip = mStripsNext[isnext - 1]; // next window

UInt_t istrip = digitInfo[0] / Geo::NPADS;

// add digit
fillDigitsInStrip(cstrip, digitInfo[0], digitInfo[1], digitInfo[2], digitInfo[3], istrip);
}
}

void Decoder::readTRM(int icru, int icrate, int orbit, int bunchid)
{

Expand Down Expand Up @@ -272,11 +302,16 @@ bool Decoder::decode() // return a vector of digits in a TOF readout window

// since digits are not yet divided in tof readout window we need to do it
// flushOutputContainer does the job
FillWindows();

return false;
}

void Decoder::FillWindows()
{
std::vector<Digit> digTemp;
flushOutputContainer(digTemp);
printf("hit decoded = %d (digits not filled = %lu)\n", mHitDecoded, mFutureDigits.size());

return false;
}

void Decoder::printCrateInfo(int icru) const
Expand Down
4 changes: 3 additions & 1 deletion Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class Digitizer : public WindowFiller

void init();

void process(const std::vector<HitType>* hits, std::vector<Digit>* digits);
void newTF();

int process(const std::vector<HitType>* hits, std::vector<Digit>* digits);

void setCalibApi(CalibApi* calibApi) { mCalibApi = calibApi; }

Expand Down
26 changes: 22 additions & 4 deletions Detectors/TOF/simulation/src/Digitizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ void Digitizer::init()

//______________________________________________________________________

void Digitizer::process(const std::vector<HitType>* hits, std::vector<Digit>* digits)
int Digitizer::process(const std::vector<HitType>* hits, std::vector<Digit>* digits)
{
// hits array of TOF hits for a given simulated event
// digits passed from external to be filled, in continuous readout mode we will push it on mDigitsPerTimeFrame vector of vectors of digits

// printf("process event time = %f with %ld hits\n",mEventTime,hits->size());

Int_t readoutwindow = Int_t((mEventTime - Geo::BC_TIME * (Geo::OVERLAP_IN_BC + 2)) * Geo::READOUTWINDOW_INV); // event time shifted by 2 BC as safe margin before to change current readout window to account for decalibration

if (mContinuous && readoutwindow > mReadoutWindowCurrent) { // if we are moving in future readout windows flush previous ones (only for continuous readout mode)
Expand All @@ -98,6 +100,9 @@ void Digitizer::process(const std::vector<HitType>* hits, std::vector<Digit>* di
} // close loop readout window
} // close if continuous

if (mReadoutWindowCurrent >= 256 * Geo::NWINDOW_IN_ORBIT) // new TF
return 1;

for (auto& hit : *hits) {
//TODO: put readout window counting/selection

Expand All @@ -108,6 +113,8 @@ void Digitizer::process(const std::vector<HitType>* hits, std::vector<Digit>* di
digits->clear();
fillOutputContainer(*digits);
}

return 0;
}

//______________________________________________________________________
Expand Down Expand Up @@ -306,7 +313,7 @@ void Digitizer::addDigit(Int_t channel, UInt_t istrip, Double_t time, Float_t x,

if (isnext < 0) {
LOG(ERROR) << "error: isnext =" << isnext << "(current window = " << mReadoutWindowCurrent << ")"
<< "\n";
<< " nbc = " << nbc << " -- event time = " << mEventTime << " -- TF = " << mTF << "\n";

return;
}
Expand Down Expand Up @@ -335,7 +342,7 @@ void Digitizer::addDigit(Int_t channel, UInt_t istrip, Double_t time, Float_t x,
iscurrent = false;
}

// printf("add TOF digit c=%i n=%i\n",iscurrent,isnext);
//printf("add TOF digit c=%i n=%i\n",iscurrent,isnext);

std::vector<Strip>* strips;
o2::dataformats::MCTruthContainer<o2::tof::MCLabel>* mcTruthContainer;
Expand Down Expand Up @@ -490,7 +497,16 @@ Float_t Digitizer::getEffZ(Float_t z)

//______________________________________________________________________
Float_t Digitizer::getFractionOfCharge(Float_t x, Float_t z) { return 1; }
//______________________________________________________________________
void Digitizer::newTF()
{
reset();

mMCTruthOutputContainerPerTimeFrame.clear();

mTF++;
printf("New TF = %d\n", mTF);
}
//______________________________________________________________________
void Digitizer::initParameters()
{
Expand Down Expand Up @@ -783,10 +799,12 @@ void Digitizer::fillOutputContainer(std::vector<Digit>& digits)
// filling the digit container doing a loop on all strips
for (auto& strip : *mStripsCurrent) {
strip.fillOutputContainer(digits);
if (strip.getNumberOfDigits())
printf("strip size = %d - digit size = %d\n", strip.getNumberOfDigits(), digits.size());
}

if (mContinuous) {
// printf("%i) # TOF digits = %lu (%p)\n", mIcurrentReadoutWindow, digits.size(), mStripsCurrent);
//printf("%i) # TOF digits = %lu (%p)\n", mIcurrentReadoutWindow, digits.size(), mStripsCurrent);
int first = mDigitsPerTimeFrame.size();
int ne = digits.size();
ReadoutWindowData info(first, ne);
Expand Down
2 changes: 1 addition & 1 deletion Detectors/TOF/workflow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

o2_add_library(TOFWorkflowUtils
SOURCES src/DigitReaderSpec.cxx
src/RawReaderSpec.cxx
src/ClusterReaderSpec.cxx
src/TOFClusterizerSpec.cxx
src/TOFClusterWriterSpec.cxx
src/TOFDigitWriterSpec.cxx
src/TOFRawWriterSpec.cxx
src/CompressedDecodingTask.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2::TOFBase O2::DataFormatsTOF
O2::TOFReconstruction)

Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// @file RawReaderSpec.h
/// @file CompressedDecodingTask.h
/// @author Francesco Noferini
/// @since 2020-02-25
/// @brief TOF compressed data decoding task

#ifndef O2_TOF_RAWREADER
#define O2_TOF_RAWREADER
#ifndef O2_TOF_COMPRESSEDDECODINGTASK
#define O2_TOF_COMPRESSEDDECODINGTASK

#include "TFile.h"

#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include "Framework/DataProcessorSpec.h"
#include <fstream>
#include "TOFReconstruction/Decoder.h"
#include "TOFBase/Digit.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"

using namespace o2::framework;

Expand All @@ -29,25 +29,30 @@ namespace o2
namespace tof
{

class RawReader : public Task
class CompressedDecodingTask : public Task
{
public:
RawReader() = default;
~RawReader() override = default;
CompressedDecodingTask() = default;
~CompressedDecodingTask() override = default;
void init(InitContext& ic) final;
void run(ProcessingContext& pc) final;

void postData(ProcessingContext& pc);

private:
int mState = 0;
std::string mFilename;
bool mStatus = false;
o2::tof::compressed::Decoder mDecoder;
std::vector<std::vector<o2::tof::Digit>> mDigits;
int mNTF = 0;
int mNCrateOpenTF = 0;
int mNCrateCloseTF = 0;
bool mHasToBePosted = false;
int mInitOrbit = 0;
};

/// create a processor spec
/// read simulated TOF raws from a root file
framework::DataProcessorSpec getRawReaderSpec();
framework::DataProcessorSpec getCompressedDecodingSpec(std::string inputDesc);

} // namespace tof
} // namespace o2

#endif /* O2_TOF_RAWREADER */
#endif /* O2_TOF_COMPRESSEDDECODINGTASK */
Loading

0 comments on commit 4c94343

Please sign in to comment.