Skip to content

Conversation

@PetrilloAtWork
Copy link
Member

@PetrilloAtWork PetrilloAtWork commented Mar 20, 2024

This pull request includes two parts:

  1. an extension of the channel mapping service to provide additional PMT information on PMT pair and adder signals and their path through the hardware; this also includes an utility to extract that mapping information in a format convenient for higher level usage.
  2. a trigger decoder able to process and extract all the additional information carried by the adder triggers, including which trigger logic caused the acquisition (majority, adders or both) and the trigger primitive bits that were active at the time of the trigger.

These changes need to be supported by a new channel mapping database with the additional information; with the existing database, the code will still work but won't unpack the trigger primitive bits correctly (close to it, but still no).

This PR depends (and effectively includes) PR #709. The release manager can opt to merge this one directly if it is convenient.

Dependency on icarus_data needs to be bumped to v09_84_01, which @SFBayLaser has tagged and deployed on March 20, 2024.

Once this pull request is merged into a release, ICARUS trigger decoding will be complete.

Testing

This branch was tested with a data file from run 9435 with the new database version, and on a data file from run 11790 (featuring a mixed majority + adder trigger) with the current database and with the new (not released) one.

Reviewers

  • @jzettle current maintainer of the trigger decoder: please concentrate in particular on the decoder tool
  • @SFBayLaser current database release manager (although he'll never admit that)

While this PR is, to my knowledge, non-breaking, it's based on the code breaking #709. Unfortunately that also means that all the code in that PR also appears here, making the review harder.
The new code is expected to correctly process data from the whole ICARUS dataset with no special configuration needs (besides the standard channel mapping service ones).

Note to the release manager

(and to the reviewers if they care)

In order to make the review easier, I have rebased this PR on #709, which this one depends on, instead of its real target develop.
So please once this PR is approved, rebase it back to develop before merging (it does make no sense to merge it to feature/gp_trigDecoderDB branch, as the PR is configured now).

Digitizer label is already present; LVDS and adder connector information
is going to be added to the databases soon.
It can't still be used with `lar::providerFrom` because it's movable.
This is a new feature that allows callers to know if the content provided
by the service has changed from the last check or not.
It will be used by a coming trigger decoder.
PMT pair bits are assigned to their proper position via a mapping informed
by the PMT channel mapping database (which requires an update).
In case the information is not available (old database), an option can be
activated to allow for a legacy hard-coded fallback. Note that this legacy
mapping is known to be incorrect for Run2.
The use of the database is enabled by default.
A utility to map LVDS bits and PMT channels is also provided (and used
by the decoder).
Adder bits are not yet mapped in this way.
An updated database is necessary. If an older one is used,
a legacy map will be used (which is known not to be completely correct).
It has been found that the FPGS logic assigning a trigger to adder or
majority logic may, in case the decision is "both", miss one bit,
hence returning a value 3 or 5 instead of the canonical 7.
Although this has not been observed in the triggering cryostat information,
I am relaxing the decoding logic so that in those cases the trigger
is assigned to both cryostats.
That can be majority (PMT pair) trigger, adder trigger or both.
This information is stored independently for each cryostat
(in case both cryostats are reported as triggering).
@PetrilloAtWork PetrilloAtWork added the enhancement New feature or request label Mar 20, 2024
@PetrilloAtWork PetrilloAtWork changed the base branch from develop to feature/gp_trigDecoderDB March 20, 2024 01:18
@SFBayLaser SFBayLaser changed the base branch from feature/gp_trigDecoderDB to develop March 20, 2024 17:46
@SFBayLaser
Copy link
Contributor

rebased back to develop branch since PR #709 was merged to develop

Copy link
Contributor

@jzettle jzettle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the best I could. I left a few comments sprinkled about but they are mostly questions for my own understanding of how this will work moving forward.

/// Encodes the `connectorWord` LVDS bits from the specified `cryostat`
/// and `connector` into the format required by `sbn::ExtraTriggerInfo`.
static std::uint64_t encodeLVDSbits
static std::uint64_t encodeLVDSbitsLegacy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the idea of "Legacy" here? Is that needed to preserve the ability to decode previous data? How would one know which to use and how is it decided?

Copy link
Member Author

@PetrilloAtWork PetrilloAtWork Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should clarify that this legacy is about how to interpret the bits from the 64-bit trigger words. "Legacy" is how we interpreted them (or should have interpreted them) before database-based mapping was introduced with this PR. This legacy is not related to the format or version of the input packet, and it does not affect anything commonly used for analysis, including the trigger counts for PoT accounting, or the types of triggers.

It is a fallback for the decoding of those trigger words in case the channel mapping database is not available.
I thought of preserving a bit of the functionality in a possible context where database access is problematic (note however that by default AllowDefaultLVDSmap is false, and the channel mapping service is required).
The "legacy" mapping of the LVDS is "almost right" in the sense that typically the bit is close to where it should be, but it may be not exactly there.

The other case where legacy mapping kicks in is when the database lacks the proper information. Effectively this is a non-issue, since @mvicenzi has updated all run periods with the data needed for the PMT pair mapping, and while the adders information is present only for Run3, but so are the adder bits, so before then there is nothing to decode.

[*] A bit is associated to a defined location according to the prescription in sbn::ExtraTriggerInfo, which says the most upstream PMT end in the most significant bits. This prescription is not fully... prescriptive though: consider for example that the first two bits include PMT channels #0 and #1 respectively, and these two PMT have the same z coordinate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The choice of whether the legacy mapping is used or not is automatic -- the only direct control the user has is whether to ever allow it to kick in (AllowDefaultLVDSmap: true) or not (the default).
If allowed, the legacy kicks in if the mapping database is not available (which will be a fatal issue for other decoders, I think). For example, one could think that in the online monitor environment database access is preferably avoided.
Users should not want the legacy mapping for any reason if there is choice.



std::uint64_t TriggerDecoderV3::encodeLVDSbits
std::uint64_t TriggerDecoderV3::encodeLVDSbitsLegacy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the legacy needed for? Is this needed to decode previous data? How do we know which one we need to use and how is it set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged into the answer above.

Copy link
Contributor

@jzettle jzettle Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought I lost the original review comment and didn't realize it preserved it. I only meant to ask that question once...

std::uint64_t connector01word, std::uint64_t connector23word
) const {

if (!fPMTpairMap) { // use legacy approach
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the functional difference between the legacy approach and the normal one? Does the input string change somehow or are you extracting the information in the same way if you have this map or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also merged in the answer above.
In short: for the purpose of the trigger 64-bit words, the input string is still and always the same.

icarus::TriggerConfiguration const* fTriggerConfiguration = nullptr;

/// Map of LVDS bits.
std::optional<icarus::trigger::PMTpairBitMap> fPMTpairMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something pulled from an updated version of one of our databases?

Copy link
Member Author

@PetrilloAtWork PetrilloAtWork Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that utility is initialised with PMT mapping informartion from standard IICARUSChannelMap service, which together with the database itself was complemented with new information.
You can notice in the code that the constructor of this object requires a reference to the channel mapping service.

std::string const triggerLogicKey = "MJ_Adder Source " + Side;
int const triggerLogicCode = data.hasItem(triggerLogicKey)
? data.getItem(triggerLogicKey).getNumber<int>(0): 0;
sbn::bits::triggerLogicMask triggerLogicMask;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure I understand the additions: There is a new word (or two) in the trigger data packet string than before based on the adders (this one and another)? However, because nothing is being operated on in the online, this does not affect the data fragment creation and just necessitates updating the decoder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. Since there may be two triggers in the two cryostats at the same time, there are two new words, one per cryostat (MJ_Adder Source EAST and MJ_Adder Source WEST). If I remember the fragment creation code correctly, it will split the trigger string in words and read the one it is interested in: we can add freely as long as the required words are still present and not renamed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is partly true, it does this if we want it to. Otherwise the entire string as it is sent is preserved and sent along with the information in the event. The decoder then presumably has utilities to extract the information from either there directly or the different functions within the fragment.

The new SQLite database is available from `icarus_data` `v09_84_01`.
PostgreSQL database is not updated yet.
@PetrilloAtWork
Copy link
Member Author

The additional commit is enabling by default the new database, which is now distributed with icarus_data v09_84_01.

Copy link
Contributor

@SFBayLaser SFBayLaser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it looks like all questions, issues are dealt with and so will move to merge for patch release

@SFBayLaser SFBayLaser merged commit e4adca5 into SBNSoftware:develop Mar 21, 2024
@PetrilloAtWork PetrilloAtWork deleted the feature/gp_adderDecoder branch May 8, 2024 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants