290 const string myname =
"DataPrepModule::produce: ";
296 unsigned long triggerPerTick = 25;
299 bool skipAllEvents =
false;
300 bool skipEventsWithCorruptDataDropped =
false;
305 int itimrem = beginTime.
timeLow();
307 if ( itim == 0 && itimrem != 0 ) {
314 cout << myname <<
"Run " << evt.
run();
316 cout <<
", event " << evt.
event();
322 TTimeStamp rtim(itim, itimrem);
323 string stim =
string(rtim.AsString(
"s")) +
" UTC";
324 cout << myname <<
"Real data event time: " << itim <<
" (" << stim <<
")" <<
endl;
330 cout << myname <<
"Event time high, low: " << beginTime.
timeHigh() <<
", " << beginTime.
timeLow() <<
endl;
336 using TimeVector = std::vector<raw::RDTimeStamp>;
337 const TimeVector* ptims =
nullptr;
340 auto htims = evt.
getHandle<TimeVector>(itag1);
343 if ( ptims->size() != 1 ) {
344 cout << myname <<
"WARNING: Unexpected timing clocks size: " << ptims->size() <<
endl;
345 for (
unsigned int itim=0; itim<ptims->size() && itim<50; ++itim ) {
346 cout << myname <<
" " << ptims->at(itim).GetTimeStamp() <<
endl;
350 if ( logInfo ) cout << myname <<
"Timing clock: " << tim.
GetTimeStamp() <<
endl;
354 if (
m_LogLevel >= 2 ) cout << myname <<
"Trigger flag: " << trigFlag <<
" (";
355 bool isBeam = trigFlag == 0xc;
356 bool isCrt = trigFlag == 13;
357 bool isFake = trigFlag >= 0x8 && trigFlag <= 0xb;
359 if ( isBeam ) cout <<
"Beam";
360 else if ( isCrt ) cout <<
"CRT";
361 else if ( isFake ) cout <<
"Fake";
362 else cout <<
"Unexpected";
368 cout << myname <<
"WARNING: Event timing clocks product not found." <<
endl;
376 using StatVector = std::vector<raw::RDStatus>;
377 using DigitVector = std::vector<raw::RawDigit>;
378 std::unique_ptr<TimeVector> ptimsFromTool;
379 std::unique_ptr<StatVector> pstatsFromTool;
380 std::unique_ptr<DigitVector> pdigitsFromTool;
381 if ( useDecoderTool ) {
382 if ( useDecoderTool ) {
383 ptimsFromTool.reset(
new TimeVector);
384 pstatsFromTool.reset(
new StatVector);
385 pdigitsFromTool.reset(
new DigitVector);
387 std::vector<int> apas = {-1};
388 if ( logInfo ) cout << myname <<
"Fetching digits and clocks with decoder tool." <<
endl;
390 retrieveDataForSpecifiedAPAs(evt, *pdigitsFromTool.get(), *ptimsFromTool.get(),
391 *pstatsFromTool.get(), apas);
393 cout << myname <<
"WARNING: Decoder tool returned " << decodeStat <<
endl;
396 cout << myname <<
" Digit count from tool: " << pdigitsFromTool->size() <<
endl;
397 cout << myname <<
" Stats count from tool: " << pstatsFromTool->size() <<
endl;
398 cout << myname <<
" Clock count from tool: " << ptimsFromTool->size() <<
endl;
403 vector<AdcLongIndex> channelClocks;
404 vector<ULong64_t> tzeroClockCandidates;
405 float trigTickOffset = -500.5;
406 if ( ptimsFromTool ) {
407 using ClockCounter = std::map<ULong64_t, AdcIndex>;
408 ClockCounter clockCounts;
409 ULong64_t chClock = 0;
410 long chClockDiff = 0;
411 float tickdiff = 0.0;
413 chClock = chts.GetTimeStamp();
414 channelClocks.push_back(chClock);
415 chClockDiff = chClock > timingClock ? (chClock - timingClock)
416 : -(timingClock - chClock);
417 bool nearTrigger = fabs(tickdiff - trigTickOffset) < 1.0;
418 tickdiff = chClockDiff/triggerPerTick;
419 if ( clockCounts.find(chClock) == clockCounts.end() ) {
420 clockCounts[chClock] = 1;
421 if ( nearTrigger ) tzeroClockCandidates.push_back(chClock);
423 ++clockCounts[chClock];
425 if ( ! nearTrigger ) {
427 cout << myname <<
"WARNING: Channel timing difference: " << chClockDiff
428 <<
" (" << tickdiff <<
" ticks)." <<
endl;
432 if ( clockCounts.size() > 1 ) {
434 cout << myname <<
"WARNING: Channel clocks are not consistent." <<
endl;
435 cout << myname <<
"WARNING: Clock ticks count" <<
endl;
437 for ( ClockCounter::value_type iclk : clockCounts ) {
438 ULong64_t chClock = iclk.first;
440 long chClockDiff = chClock > timingClock ? (chClock - timingClock)
441 : -(timingClock - chClock);
442 float tickdiff = chClockDiff/triggerPerTick;
444 cout << myname <<
"WARNING:" <<
setw(10) << chClockDiff <<
setw(10) << tickdiff
449 if ( logInfo ) cout << myname <<
"Channel counts are consistent with an offset of " 450 << tickdiff <<
" ticks." <<
endl;
453 if ( logInfo ) cout << myname <<
"Channel clocks not checked for data retrieval from stroe." <<
endl;
457 const std::vector<raw::RDStatus>* pstats =
nullptr;
458 if ( useDecoderTool ) {
459 pstats = pstatsFromTool.get();
462 auto hstats = evt.
getHandle<std::vector<raw::RDStatus>>(itag2);
467 cout << myname <<
"WARNING: Raw data status product not found." <<
endl;
474 bool skipEvent = skipAllEvents;
475 if ( pstats !=
nullptr ) {
476 if ( pstats->size() != 1 ) {
477 cout << myname <<
"WARNING: Unexpected raw data status size: " << pstats->size() <<
endl;
479 const RDStatus rdstat = pstats->at(0);
481 cout << myname <<
"Raw data status: " << rdstat.
GetStatWord();
494 std::vector< art::Ptr<beam::ProtoDUNEBeamEvent> > beaminfo;
496 if ( pdbeamHandle ) {
498 if ( beaminfo.size() == 0 ) {
499 cout << myname <<
"WARNING: Beam event vector is empty." <<
endl;
501 if ( beaminfo.size() > 1 ) {
502 cout << myname <<
"WARNING: Beam event vector has size " << beaminfo.size() <<
endl;
504 AdcIndex beamTrigFlag = beaminfo[0]->GetTimingTrigger();
505 if ( beamTrigFlag != trigFlag ) {
506 if ( logInfo ) cout << myname <<
"Beam event and timing trigger flags differ: " << beamTrigFlag <<
" != " << trigFlag <<
endl;
507 }
else if ( beamTrigFlag != 12 ) {
508 if ( logInfo ) cout << myname <<
"Beam event trigger is not beam: it is " << beamTrigFlag <<
endl;
511 }
else if ( beaminfo[0]->GetTOFChan() == -1 ) {
512 if ( logInfo ) cout << myname <<
"Beam event index does not indicate match." <<
endl;
514 int beamChan = beaminfo[0]->GetTOFChan();
515 beamTof = beaminfo[0]->GetTOF();
516 if ( logInfo ) cout << myname <<
"Beam event TOF[" << beamChan <<
"]: " << beamTof <<
endl;
520 if ( logInfo ) cout << myname <<
"Beam event data product not found: " <<
m_BeamEventLabel <<
endl;
525 const DigitVector* pdigits =
nullptr;
527 if ( useDecoderTool ) {
528 pdigits = pdigitsFromTool.get();
531 hdigits = evt.
getHandle<DigitVector>(itag3);
535 cout << myname <<
"# digits read: " << pdigits->size() <<
endl;
537 if ( pdigits->size() == 0 )
mf::LogWarning(
"DataPrepModule") <<
"Input digit container is empty";
540 std::unique_ptr<std::vector<recob::Wire>> pwires(
new std::vector<recob::Wire>);
541 pwires->reserve(pdigits->size());
550 if ( logInfo ) cout << myname <<
"Skipping event with " << srdstat <<
endl;
568 unsigned int nkeep = 0;
569 unsigned int nskip = 0;
570 unsigned int ndigi = pdigits->size();
574 pevt->subRun = evt.
subRun();
577 pevt->timerem = itimrem;
578 pevt->triggerClock = timingClock;
579 pevt->trigger = trigFlag;
581 for (
unsigned int idig=0; idig<ndigi; ++idig ) {
594 if ( fulldatamap.find(chan) != fulldatamap.end() ) {
595 cout << myname <<
"WARNING: Skipping duplicate channel " << chan <<
"." <<
endl;
612 fembChannel = ichOn % 128;
627 if ( channelClocks.size() > idig ) acd.
channelClock = channelClocks[idig];
636 unsigned int nproc = 0;
637 vector<AdcChannelDataMap> datamaps;
642 if ( ptm ==
nullptr ) {
643 errmsg =
"Tool manager not found.";
646 if ( pcrt ==
nullptr ) errmsg =
"Unable to find IndexRangeTool with name channelRanges.";
648 if ( pcrt ==
nullptr ) {
649 cout << myname <<
"ERROR: IndexRangeTool not found: channelRanges" <<
endl;
654 datamaps.emplace_back();
657 if ( fulldatamap.find(icha) != fulldatamap.end() ) {
658 datamap.emplace(icha,
move(fulldatamap[icha]));
663 cout << myname <<
"WARNING: Channel range not found: " << crn <<
endl;
669 mf::LogError(
"DataPrepModule") <<
"Channel group service not found." <<
endl;
673 for (
unsigned int igrp=0; igrp<ngrp; ++igrp ) {
674 datamaps.emplace_back();
677 if ( fulldatamap.find(chan) != fulldatamap.end() ) {
678 datamap.emplace(chan,
move(fulldatamap[chan]));
684 datamaps.emplace_back(
move(fulldatamap));
685 nproc = datamaps.front().size();
688 cout << myname <<
" # input digits: " << ndigi <<
endl;
689 cout << myname <<
" # channels selected: " << nkeep <<
endl;
690 cout << myname <<
" # channels skipped: " << nskip <<
endl;
691 cout << myname <<
" # channels to be processed: " << nproc <<
endl;
703 if ( bstat ) cout << myname <<
"WARNING: Event initialization failed." <<
endl;
708 Index nacd = datamap.size();
711 if ( logInfo ) cout << myname <<
"Skipping empty data map." <<
endl;
718 cout << myname <<
"Preparing " << nacd <<
" channel" << (nacd == 1 ?
"" :
"s") <<
"." << endl;
721 if ( rstat != 0 )
mf::LogWarning(
"DataPrepModule") <<
"Data preparation service returned error " << rstat;
725 for (
const AdcChannelDataMap::value_type& iacd : datamap ) {
735 <<
"Can't associate wire " << iwir <<
" with raw digit " << idig;
741 datamap.erase(datamap.begin(), datamap.end());
746 if ( estat ) cout << myname <<
"WARNING: Event finalization failed." <<
endl;
748 if ( logInfo ) cout << myname <<
"Created wire count: " << pwires->size() <<
endl;
749 if ( pwires->size() == 0 )
mf::LogWarning(
"DataPrepModule") <<
"No wires made for this event.";
758 if ( useDecoderTool ) {
766 vector<Wire>* pintWires = pintStates->
wires[sname];
767 if ( pintWires ==
nullptr ) {
768 cout << myname <<
"WARNING: Wires not found for state " << sname <<
"." <<
endl;
772 cout << myname <<
"Recording intermediate state " << sname <<
" with " 773 << pintWires->size() <<
" channels." <<
endl;
776 for (
const Wire& wire : *pintWires ) {
777 cout << myname <<
" Channel " << wire.Channel() <<
" has " 778 << wire.SignalROI().n_ranges() <<
" ROI and " 779 << wire.SignalROI().count() <<
"/" << wire.SignalROI().size()
780 <<
" ticks." <<
endl;
783 std::unique_ptr<std::vector<recob::Wire>> pintWiresWrapped(pintWires);
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
constexpr std::uint32_t timeLow() const
NameVector m_ChannelRanges
EventNumber_t event() const
uint16_t GetFlags() const
Collection of charge vs time digitized from a single readout channel.
virtual Index size() const =0
AdcChannelVector m_SkipChannels
const AdcIndex AdcChannelStatusNoisy
static std::string toString(art::Timestamp tart)
Handle< PROD > getHandle(SelectorBase const &) const
virtual bool IsNoisy(raw::ChannelID_t channel) const =0
Returns whether the specified channel is noisy in the current run.
constexpr std::uint32_t timeHigh() const
ChannelID_t Channel() const
DAQ channel this raw data was read from.
ChannelGroupService::Name Name
std::vector< std::string > m_IntermediateStates
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::shared_ptr< const EventInfo > EventInfoPtr
const raw::RawDigit * digit
virtual int prepare(detinfo::DetectorClocksData const &clockData, AdcChannelDataMap &prepdigs, std::vector< recob::Wire > *pwires=nullptr, WiredAdcChannelDataMap *pwiredData=nullptr) const =0
bool GetCorruptDataDroppedFlag() const
void setChannelInfo(ChannelInfoPtr pchi)
virtual const ChannelVector & channels(Index igrp) const =0
std::string m_DigitProducer
AdcChannelVector m_KeepFembs
void setEventInfo(EventInfoPtr pevi)
SubRunNumber_t subRun() const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
AdcChannel m_KeepChannelBegin
ULong64_t GetTimeStamp() const
RawDigitPrepService * m_pRawDigitPrepService
Q_EXPORT QTSManip setw(int w)
std::map< Name, WireContainer * > wires
std::unique_ptr< PDSPTPCDataInterfaceParent > m_pDecoderTool
AdcChannel m_KeepChannelEnd
virtual int beginEvent(const DuneEventInfo &) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
unsigned long AdcLongIndex
Name m_WireName
Second field in full label for the output wire container.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
const AdcIndex AdcChannelStatusGood
virtual int endEvent(const DuneEventInfo &) const
AdcLongIndex channelClock
bool GetCorruptDataKeptFlag() const
Class holding the regions of interest of signal from a channel.
std::unique_ptr< IndexMapTool > m_onlineChannelMapTool
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
const AdcIndex AdcChannelStatusBad
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
ChannelGroupService * m_pChannelGroupService
unsigned int GetStatWord() const
std::string to_string(ModuleType const mt)
std::string m_BeamEventLabel
QTextStream & endl(QTextStream &s)
const lariov::ChannelStatusProvider * m_pChannelStatusProvider