Skip to content

Commit

Permalink
finalize multi-frame treatement in tof chain
Browse files Browse the repository at this point in the history
  • Loading branch information
noferini committed Feb 26, 2020
1 parent 903fb0b commit 467618d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Detectors/TOF/simulation/src/Digitizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ int Digitizer::process(const std::vector<HitType>* hits, std::vector<Digit>* dig
} // close loop readout window
} // close if continuous

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

for (auto& hit : *hits) {
//TODO: put readout window counting/selection
Expand Down
21 changes: 14 additions & 7 deletions Detectors/TOF/workflow/src/TOFDigitWriterSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ template <typename T>
TBranch* getOrMakeBranch(TTree& tree, std::string brname, T* ptr)
{
if (auto br = tree.GetBranch(brname.c_str())) {
br->SetAddress(static_cast<void*>(&ptr));
printf("Re-use output branch %s\n",brname.c_str());
br->SetAddress(static_cast<void*>(ptr));
return br;
}
// otherwise make it
printf("Create output branch %s\n",brname.c_str());
return tree.Branch(brname.c_str(), ptr);
}

Expand All @@ -54,9 +56,13 @@ DataProcessorSpec getTOFDigitWriterSpec(bool useMC)
auto outputfile = std::make_shared<TFile>(filename.c_str(), "RECREATE");
auto outputtree = std::make_shared<TTree>(treename.c_str(), treename.c_str());

int *nCalls = new int;
*nCalls = 0;

// the callback to be set as hook at stop of processing for the framework
auto finishWriting = [outputfile, outputtree]() {
outputtree->SetEntries(1);
auto finishWriting = [outputfile, outputtree, nCalls]() {
printf("finish writing with %d entries in the tree\n",*nCalls);
outputtree->SetEntries(*nCalls);
outputtree->Write();
outputfile->Close();
};
Expand All @@ -66,15 +72,16 @@ DataProcessorSpec getTOFDigitWriterSpec(bool useMC)
// using by-copy capture of the worker instance shared pointer
// the shared pointer makes sure to clean up the instance when the processing
// function gets out of scope
auto processingFct = [outputfile, outputtree, useMC](ProcessingContext& pc) {
auto processingFct = [outputfile, outputtree, useMC, nCalls](ProcessingContext& pc) {
static bool finished = false;
if (finished) {
// avoid being executed again when marked as finished;
return;
}

(*nCalls)++;
// retrieve the digits from the input
auto indata = pc.inputs().get<std::vector<o2::tof::Digit>*>("tofdigits");
LOG(INFO) << "Call " << *nCalls;
LOG(INFO) << "RECEIVED DIGITS SIZE " << indata->size();
auto row = pc.inputs().get<std::vector<o2::tof::ReadoutWindowData>*>("readoutwin");
LOG(INFO) << "RECEIVED READOUT WINDOWS " << row->size();
Expand All @@ -100,8 +107,8 @@ DataProcessorSpec getTOFDigitWriterSpec(bool useMC)
labelbr->Fill();
}

finished = true;
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
// finished = true;
// pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
};

// return the actual processing function as a lambda function using variables
Expand Down
60 changes: 31 additions & 29 deletions Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -144,34 +144,35 @@ DataProcessorSpec getTOFDigitizerSpec(int channel, bool useCCDB)
// call actual digitization procedure
labels->clear();
digits->clear();
if (digitizer->process(&hits, digits.get())) {
// Post Data
if (digitizer->isContinuous()) {
digits->clear();
labels->clear();
digitizer->flushOutputContainer(*digits.get());
}

std::vector<Digit>* digitsVector = digitizer->getDigitPerTimeFrame();
std::vector<ReadoutWindowData>* readoutwindow = digitizer->getReadoutWindowData();
std::vector<o2::dataformats::MCTruthContainer<o2::MCCompLabel>>* mcLabVecOfVec = digitizer->getMCTruthPerTimeFrame();

LOG(INFO) << "Post " << digitsVector->size() << " digits in " << readoutwindow->size() << " RO windows";

// here we have all digits and we can send them to consumer (aka snapshot it onto output)
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIGITS", 0, Lifetime::Timeframe}, *digitsVector);
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIGITSMCTR", 0, Lifetime::Timeframe}, *mcLabVecOfVec);
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "READOUTWINDOW", 0, Lifetime::Timeframe}, *readoutwindow);
LOG(INFO) << "TOF: Sending ROMode= " << roMode << " to GRPUpdater";
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "ROMode", 0, Lifetime::Timeframe}, roMode);

// go to new TF
digitizer->newTF();

digitizer->setEventTime(timesview[collID].timeNS);

digitizer->process(&hits, digits.get());
}
digitizer->process(&hits, digits.get());
// if (digitizer->process(&hits, digits.get())) {
// // Post Data
// if (digitizer->isContinuous()) {
// digits->clear();
// labels->clear();
// digitizer->flushOutputContainer(*digits.get());
// }

// std::vector<Digit>* digitsVector = digitizer->getDigitPerTimeFrame();
// std::vector<ReadoutWindowData>* readoutwindow = digitizer->getReadoutWindowData();
// std::vector<o2::dataformats::MCTruthContainer<o2::MCCompLabel>>* mcLabVecOfVec = digitizer->getMCTruthPerTimeFrame();

// LOG(INFO) << "Post " << digitsVector->size() << " digits in " << readoutwindow->size() << " RO windows";

// // here we have all digits and we can send them to consumer (aka snapshot it onto output)
// pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIGITS", 0, Lifetime::Timeframe}, *digitsVector);
// pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIGITSMCTR", 0, Lifetime::Timeframe}, *mcLabVecOfVec);
// pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "READOUTWINDOW", 0, Lifetime::Timeframe}, *readoutwindow);
// LOG(INFO) << "TOF: Sending ROMode= " << roMode << " to GRPUpdater";
// pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "ROMode", 0, Lifetime::Timeframe}, roMode);

// // go to new TF
// digitizer->newTF();

// digitizer->setEventTime(timesview[collID].timeNS);

// digitizer->process(&hits, digits.get());
// }
// copy digits into accumulator
//std::copy(digits->begin(), digits->end(), std::back_inserter(*digitsAccum.get()));
//labelAccum.mergeAtBack(*labels);
Expand Down Expand Up @@ -201,7 +202,8 @@ DataProcessorSpec getTOFDigitizerSpec(int channel, bool useCCDB)
LOG(INFO) << "Digitization took " << timer.CpuTime() << "s";

// we should be only called once; tell DPL that this process is ready to exit
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
pc.services().get<ControlService>().endOfStream();
//pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);

finished = true;
};
Expand Down

0 comments on commit 467618d

Please sign in to comment.