Skip to content

[EMCAL-610, EMCAL-659, EMCAL-661] EMCAL digit to raw converter stand alone application#4045

Merged
shahor02 merged 5 commits intoAliceO2Group:devfrom
mfasDa:EMCAL-610
Aug 21, 2020
Merged

[EMCAL-610, EMCAL-659, EMCAL-661] EMCAL digit to raw converter stand alone application#4045
shahor02 merged 5 commits intoAliceO2Group:devfrom
mfasDa:EMCAL-610

Conversation

@mfasDa
Copy link
Copy Markdown
Collaborator

@mfasDa mfasDa commented Jul 27, 2020

  • Change output handling in RawWriter from RawPageHandler to RawFileWriter and make use of its methods to create timeframes and superpages
  • Add stand alone application which reads the digit file, passes the digit and trigger branch to the RawWriter and launches the raw encoding.

@mfasDa mfasDa changed the title [EMCAL-610] Output raw stream based on RawFileWriter [EMCAL-610, EMCAL-659] Output raw stream based on RawFileWriter Jul 27, 2020
@mfasDa
Copy link
Copy Markdown
Collaborator Author

mfasDa commented Jul 27, 2020

Pull request will be extended by a stand-alone application converting digit files to raw data (separate ticket ID).

@mfasDa mfasDa changed the title [EMCAL-610, EMCAL-659] Output raw stream based on RawFileWriter [EMCAL-610, EMCAL-659, EMCAL-661] EMCAL digit to raw converter stand alone application Jul 27, 2020
@mfasDa
Copy link
Copy Markdown
Collaborator Author

mfasDa commented Aug 3, 2020

@shahor02 @sawenzel The first IR should be the same for the digitizer and for the raw writer, how do we propagate it in the best way.

Currently for EMCAL the digits vector contains all digits in the timeframe, separated by triggers using a second vector with a range reference marking the digits belonging to the same readout window (trigger). This is done in order to implement the handling of pileup in the EMCAL. Live/Dead times are handled there as well. In the digitizer we use the collision context to get the IR, set the detector live for the first trigger, accumulate digits from collisions within the 1.5 ms readout window digitised using the EMCAL time response, and set the detector busy afterwards. Therefore even though for the moment the first collision opens the EMCAL readout window we cannot blindly use the first IR in the timeframe as in the future it might not be the first collision.

@shahor02
Copy link
Copy Markdown
Collaborator

shahor02 commented Aug 3, 2020

Hi @mfasDa

I have not really understood the question. The 1st IR of digitization can be anything, it is where the collision happened (currently the sampling starts for orbit/bc = 1/0, can be overridden by --firstOrbit, --firstBC options to digitizer), the 1st IR of raw data is the start of the 1st TF, i.e. detectors data packaging (defined by the configurable param

int nHBFPerTF = 1 + 0xff; // number of orbits per BC
uint16_t bcFirst = 0; ///< BC of 1st TF
uint32_t orbitFirst = 0; ///< orbit of 1st TF
). For consistence, the 1st TF 1st IR must be <= first collision IR.

Cheers,
Ruben

@mfasDa
Copy link
Copy Markdown
Collaborator Author

mfasDa commented Aug 3, 2020

@shahor02 The problem is that our readout window with 1.5 mus >> bunch spacing with 25 ns. Therefore in the digitization in order to simulate pileup we integrate over as many collisions as we can fit into the readout window (-600 ns due to delays in the cable). Therefore we decided to store the digits not per event - which would be anyhow questionable with pileup - but per timeframe, splitting the digits vector in ranges belonging to the same readout window. Therefore we assume in the digitization that all collisions we loop over belong to the same timeframe, and we push the digits vector once per timeframe. Doing this, we must have the same timing definition in the digitizer and the raw writer. We could simply mark the first IR but it might be that EMCAL will not trigger at the first IR and therefore set a wrong IR as first IR - which should be common for all detectors. Otherwise I would be curious how other detectors do it - in particular the continuous detectors must integrate in the digitization over many events and are busy at the end of timeframe, no?

@shahor02
Copy link
Copy Markdown
Collaborator

shahor02 commented Aug 3, 2020

@mfasDa: all detectors store their data in this way, ITS readout window can be as large as 20 \mus, it does not matter. On the digitization level we don't have TF definition at all, but every digit is associated with well defined BC (when the trigger or strobe started). It is irrelevant what other (later) BCs will contribute to this digit, at digit->raw conversion it goes to the TF which its opening BC belongs to.

@mfasDa
Copy link
Copy Markdown
Collaborator Author

mfasDa commented Aug 3, 2020

@shahor02 OK, for us all the digits in the same open readout window have the same IR, the one of the trigger which opened the readout window, and the raw writer makes use of it. Shall we rather push digits in readout windows?

@shahor02
Copy link
Copy Markdown
Collaborator

shahor02 commented Aug 3, 2020 via email

Copy link
Copy Markdown
Collaborator

@shahor02 shahor02 left a comment

Choose a reason for hiding this comment

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

Hi @mfasDa

Please see a comment below on some needed functionalities of the converter. Apart from these minor details, is this PR ready to be tested/merged?

Comment on lines 40 to 50
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you please add the following options:

  1. possibility to produce 1 raw file per link (i.e. FEEID), this is preferred mode for replay using readout.exe. See how it is done e.g. for ITS:

    add_option("file-for,f", bpo::value<std::string>()->default_value("layer"), "single file per: all,layer,cru,link");

  2. parsing configKeyValues options, i.e.

    add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");

o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());

This is necessary for e.g. generation of raw data with custom number of HBFs per TF.

Also, all detectors generate in the output directory a configuration file which can be provided to RawFileReader, this can be done by a simple call:

m2r.getWriter().writeConfFile(MAP::getName(), "RAWDATA", o2::utils::concat_string(outDir, '/', MAP::getName(), "raw.cfg"));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

All requests are added to the RawCreator + RawWriter is adapted.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@mfasDa concerning the carryOverMethod: does the original data you provide to writer->addData(..) already contain the trailer (placeholder) which need to be finalized in carryOverMethod or you want to build it on the fly add and to every page payload, regardless if it the data need splitting or not?
What we discussed yesterday is to call carryOverMethod also for the last chunk if there was at least 1 splitting, but given this will be wrong if your data comes w/o trailer.
In the latter case, I would simply add an option (you will need to activate it for EMCal) to always call this method, even if splitting is not needed at all.
But if your original data contain a trailer, then it is more tricky, since it will need to be modified in the original data which is supposed to be const...

Additional point: the trailer string supplied by the method must be a multiple of 16B CRU word.
Is this is a case for the RCU trailer your create?
Also, if your original data do not contain a trailer (so it is added on top of the maxSize):
can the trailer size exceed one 16B word? In this case, if the maxSize estimated by the writer is 16B (minimal possible value), then you will get a negative actualSize.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@shahor02 Currently the trailer is added at the end of the payload, containing the full payload size which is the number of 32bit ALTRO words in the payload sent to addData. In the hardware the trailer (size typically 9 32 bit ADC words) is added to every page and it contains the number of 10 bit words per page, so in the decoding I have to add the payload size from all the trailers belonging to the same page in order to know how the exact amount of words. In the simulation the trailers must be handled in the same way.

In the carryOverMethod implementation used now I read the trailer from the end-of-payload and replace the payload size with the payload size of the page, in the same way as it is done for ITSMFT. (This answers the first question with yes) This is rather trivial as the number of 8bit words just needs to be divided by 4. However the last trailer must be adapted as well and this I can only do once I know the size of the payload in the last page.

Concerning maxSize: I was under the impression this is the size of the page? The trailer would always be smaller. Did I misunderstand something?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @mfasDa
The maxSize is the number of bytes remaining in the current open page to reach 8KB limit (or the super-page to reach is limit, by default 1MB). So, ultimately, the maxSize can be just 16B. But if your data already contains the fixed-size trailer, this is not a problem. Since you are starting a new page for every trigger, I don't think you will have a situation of only 16B remaining on the 8KB page, it could happen if you add a new payload to a partially filled page. And in case of super-page filling there is a protection to not create a new page in the same super-page if less than 128B left (from which 64 will be taken by the RDH), so, you should be safe.

Basically, for the EMCAL I will need the writer will need to call carryOverMethod for the very last chunk (where no splitting is actually needed) and instead of adding the supplied trailer after writing the payload (as it would do if there is a real splitting) it should overwrite the last carryOverTrailer.size() bytes, is this correct?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@mfasDa please check if #4179 is what you want. You will need to enable the carry-over call for the last chunk by RawFileWriter::setApplyCarryOverToLastPage(true); and detect such a call as the modified test shows: https://github.com/AliceO2Group/AliceO2/blob/863c3435580f5fbe1bc34870f4a40a31f45aea82/Detectors/Raw/test/testRawReaderWriter.cxx#L166-L170

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi @shahor02, yes, the conclusion is correct. The carryOverMethod currently sets the payload size to the trailer whenever it is called. So since the end of data contains the trailer either it has to be overwritten by the RawFileWriter or our custom carryOverMethod. In the second case I would not add a trailer but modify it myself (probably overall easier). In this case I would need to know that we are on the last page.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@mfasDa as far as I can see, your carryOverMethod sets the returned actual size to maxSize - trailer.size, this is ok except when you are on the last chunk: in this case the you should return the original maxSize as an actual payload to write and supply the modified trailer string. The writer will overtwrite last trailer.size() of the payload last chunk by this modified trailer. You cannot modify in the carry-over method the original data: it is const gsl::span, just provide an updated trailer to override the one in the payload.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OK, so I only need to know that I am on the last page to include the trailer size in the from the actual size. I was thinking to take this from the payload size but in principle the page could be 8 kB. Anything that tells me how much data is still to come? I.e. the gsl::span contains the full data or the data starting from the page?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The const gsl::span<char> data refers to the full original payload you provided to addData, const char* ptr
is start of data yet to write (can be anything between data.begin() and data.end()) and the int maxSize is the max number of bytes the writer can write (starting from the ptr) to currently open 8kb page.
You can detect that you are on the last page by

int bytesLeft = data.size() - (ptr - &data[0]);
bool lastPage = bytesLeft <= maxSize;

Copy link
Copy Markdown
Collaborator

@shahor02 shahor02 left a comment

Choose a reason for hiding this comment

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

@mfasDa : you should also set (e.g. in the init) writer->setApplyCarryOverToLastPage(true) to trigger the callback at the last page.

mfasDa added 4 commits August 20, 2020 18:03
- Replace usage of RawOutputPageHandler with
  RawFileWriter for output streaming
- Initialize RawFileWriter using a single output file and a
  linear link assignment for C-RORC/Link ID untill final
  link assignment on production FLPs is fixed
- Convert input handing from std::vectors to gsl::span
…conversion

Stand alone application reading digits file and processing
digits to raw conversion for each timeframe entry in the
digits tree. Open points:
- First IR need to be specified for methods in RawFileWriter
- Raw writer settings to come from the CCDB
…h raw page

CarryOverMethod cuts the payload in size - size of the RCU
trailer and adds the RCU trailer from the last page, in which
the payload size is adapted to the size in the page.
- Add option to split to file per full detector, subdector or crorc+link
- Change rawfile to output location in order to support multiple raw files
- Add parising of the configuration file in order to configure tf handling
- Add writing of the output config
- Remove obsolete classes
@mfasDa
Copy link
Copy Markdown
Collaborator Author

mfasDa commented Aug 20, 2020

@shahor02 I intended to wait until #4179 is merged and then add the line in order to avoid conflicts. No I see it is merged so I will add this immediately.

…he last RCU trailer

Specify also using carryOverMethod for the last page
@shahor02
Copy link
Copy Markdown
Collaborator

@mfasDa is this ready to be merged?

@mfasDa
Copy link
Copy Markdown
Collaborator Author

mfasDa commented Aug 21, 2020

@shahor02 Yes, please squash-merge!

@shahor02 shahor02 merged commit da63125 into AliceO2Group:dev Aug 21, 2020
@mfasDa mfasDa deleted the EMCAL-610 branch August 21, 2020 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants