|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// \file eventSelectionTester.cxx |
| 13 | +/// \brief unified, self-configuring event selection task |
| 14 | +/// \author ALICE |
| 15 | + |
| 16 | +//=============================================================== |
| 17 | +// |
| 18 | +// Unified, self-configuring event selection task |
| 19 | +// |
| 20 | +//=============================================================== |
| 21 | + |
| 22 | +#include "Common/Core/MetadataHelper.h" |
| 23 | +#include "Common/DataModel/EventSelection.h" |
| 24 | +#include "Common/Tools/EventSelectionModule.h" |
| 25 | +#include "Common/Tools/timestampModule.h" |
| 26 | + |
| 27 | +#include <CCDB/BasicCCDBManager.h> |
| 28 | +#include <Framework/AnalysisDataModel.h> |
| 29 | +#include <Framework/AnalysisHelpers.h> |
| 30 | +#include <Framework/AnalysisTask.h> |
| 31 | +#include <Framework/Configurable.h> |
| 32 | +#include <Framework/DataTypes.h> |
| 33 | +#include <Framework/HistogramRegistry.h> |
| 34 | +#include <Framework/InitContext.h> |
| 35 | +#include <Framework/OutputObjHeader.h> |
| 36 | +#include <Framework/runDataProcessing.h> |
| 37 | + |
| 38 | +#include <cstdint> |
| 39 | +#include <stdexcept> |
| 40 | +#include <string> |
| 41 | +#include <vector> |
| 42 | + |
| 43 | +using namespace o2; |
| 44 | +using namespace o2::framework; |
| 45 | + |
| 46 | +o2::common::core::MetadataHelper metadataInfo; // Metadata helper |
| 47 | + |
| 48 | +using BCsWithRun2InfosAndMatches = soa::Join<aod::BCs, aod::Run2BCInfos, aod::Run2MatchedToBCSparse>; |
| 49 | +using BCsWithRun3Matchings = soa::Join<aod::BCs, aod::Run3MatchedToBCSparse>; |
| 50 | +using FullTracks = soa::Join<aod::Tracks, aod::TracksExtra>; |
| 51 | +using FullTracksIU = soa::Join<aod::TracksIU, aod::TracksExtra>; |
| 52 | + |
| 53 | +struct eventselectionRun2 { |
| 54 | + o2::common::timestamp::timestampConfigurables timestampConfigurables; |
| 55 | + o2::common::timestamp::TimestampModule timestampMod; |
| 56 | + |
| 57 | + o2::common::eventselection::bcselConfigurables bcselOpts; |
| 58 | + o2::common::eventselection::BcSelectionModule bcselmodule; |
| 59 | + |
| 60 | + o2::common::eventselection::evselConfigurables evselOpts; |
| 61 | + o2::common::eventselection::EventSelectionModule evselmodule; |
| 62 | + |
| 63 | + Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task |
| 64 | + Produces<aod::BcSels> bcsel; |
| 65 | + Produces<aod::EvSels> evsel; |
| 66 | + |
| 67 | + // for slicing |
| 68 | + SliceCache cache; |
| 69 | + |
| 70 | + // CCDB boilerplate declarations |
| 71 | + o2::framework::Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; |
| 72 | + Service<o2::ccdb::BasicCCDBManager> ccdb; |
| 73 | + |
| 74 | + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; |
| 75 | + |
| 76 | + // buffering intermediate results for passing |
| 77 | + std::vector<uint64_t> timestamps; |
| 78 | + std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer; |
| 79 | + |
| 80 | + // auxiliary |
| 81 | + Partition<FullTracks> tracklets = (aod::track::trackType == static_cast<uint8_t>(o2::aod::track::TrackTypeEnum::Run2Tracklet)); |
| 82 | + Preslice<FullTracks> perCollision = aod::track::collisionId; |
| 83 | + |
| 84 | + void init(o2::framework::InitContext& context) |
| 85 | + { |
| 86 | + // CCDB boilerplate init |
| 87 | + ccdb->setCaching(true); |
| 88 | + ccdb->setLocalObjectValidityChecking(); |
| 89 | + ccdb->setURL(ccdburl.value); |
| 90 | + |
| 91 | + // task-specific |
| 92 | + timestampMod.init(timestampConfigurables, metadataInfo); |
| 93 | + bcselmodule.init(context, bcselOpts, histos, metadataInfo); |
| 94 | + evselmodule.init(context, evselOpts, histos, metadataInfo); |
| 95 | + } |
| 96 | + |
| 97 | + void process(BCsWithRun2InfosAndMatches const& bcs, |
| 98 | + aod::Collisions const& collisions, |
| 99 | + aod::Zdcs const&, |
| 100 | + aod::FV0As const&, |
| 101 | + aod::FV0Cs const&, |
| 102 | + aod::FT0s const&, |
| 103 | + aod::FDDs const&, |
| 104 | + FullTracks const&) |
| 105 | + { |
| 106 | + timestampMod.process(bcs, ccdb, timestamps, timestampTable); |
| 107 | + bcselmodule.processRun2(ccdb, bcs, timestamps, bcselsbuffer, bcsel); |
| 108 | + evselmodule.processRun2(ccdb, histos, collisions, tracklets, cache, timestamps, bcselsbuffer, evsel); |
| 109 | + } |
| 110 | +}; |
| 111 | + |
| 112 | +struct eventselectionRun3 { |
| 113 | + o2::common::timestamp::timestampConfigurables timestampConfigurables; |
| 114 | + o2::common::timestamp::TimestampModule timestampMod; |
| 115 | + |
| 116 | + o2::common::eventselection::bcselConfigurables bcselOpts; |
| 117 | + o2::common::eventselection::BcSelectionModule bcselmodule; |
| 118 | + |
| 119 | + o2::common::eventselection::evselConfigurables evselOpts; |
| 120 | + o2::common::eventselection::EventSelectionModule evselmodule; |
| 121 | + |
| 122 | + o2::common::eventselection::lumiConfigurables lumiOpts; |
| 123 | + o2::common::eventselection::LumiModule lumimodule; |
| 124 | + |
| 125 | + Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task |
| 126 | + Produces<aod::BcSels> bcsel; |
| 127 | + Produces<aod::EvSels> evsel; |
| 128 | + |
| 129 | + // for slicing |
| 130 | + SliceCache cache; |
| 131 | + |
| 132 | + // CCDB boilerplate declarations |
| 133 | + o2::framework::Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; |
| 134 | + Service<o2::ccdb::BasicCCDBManager> ccdb; |
| 135 | + |
| 136 | + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; |
| 137 | + |
| 138 | + // the best: have readable cursors |
| 139 | + // this: a stopgap solution to avoid spawning yet another device |
| 140 | + std::vector<uint64_t> timestamps; |
| 141 | + std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer; |
| 142 | + |
| 143 | + // auxiliary |
| 144 | + Partition<FullTracksIU> pvTracks = ((aod::track::flags & static_cast<uint32_t>(o2::aod::track::PVContributor)) == static_cast<uint32_t>(o2::aod::track::PVContributor)); |
| 145 | + Preslice<FullTracksIU> perCollisionIU = aod::track::collisionId; |
| 146 | + |
| 147 | + void init(o2::framework::InitContext& context) |
| 148 | + { |
| 149 | + // CCDB boilerplate init |
| 150 | + ccdb->setCaching(true); |
| 151 | + ccdb->setLocalObjectValidityChecking(); |
| 152 | + ccdb->setURL(ccdburl.value); |
| 153 | + |
| 154 | + // task-specific |
| 155 | + timestampMod.init(timestampConfigurables, metadataInfo); |
| 156 | + bcselmodule.init(context, bcselOpts, histos, metadataInfo); |
| 157 | + evselmodule.init(context, evselOpts, histos, metadataInfo); |
| 158 | + lumimodule.init(context, lumiOpts, histos); |
| 159 | + } |
| 160 | + |
| 161 | + void process(aod::Collisions const& collisions, |
| 162 | + BCsWithRun3Matchings const& bcs, |
| 163 | + aod::Zdcs const&, |
| 164 | + aod::FV0As const&, |
| 165 | + aod::FT0s const& ft0s, // to resolve iterator |
| 166 | + aod::FDDs const&, |
| 167 | + FullTracksIU const&) |
| 168 | + { |
| 169 | + timestampMod.process(bcs, ccdb, timestamps, timestampTable); |
| 170 | + bcselmodule.processRun3(ccdb, histos, bcs, timestamps, bcselsbuffer, bcsel); |
| 171 | + evselmodule.processRun3(ccdb, histos, bcs, collisions, pvTracks, ft0s, cache, timestamps, bcselsbuffer, evsel); |
| 172 | + lumimodule.process(ccdb, histos, bcs, timestamps, bcselsbuffer); |
| 173 | + } |
| 174 | +}; |
| 175 | + |
| 176 | +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
| 177 | +{ |
| 178 | + // Parse the metadata for later too |
| 179 | + metadataInfo.initMetadata(cfgc); |
| 180 | + |
| 181 | + LOGF(info, "Event selection with forced Run 2 mode engaging in unchecked mode."); |
| 182 | + LOGF(info, "To be improved once metadata enabling in defineDataProcessing is worked out."); |
| 183 | + |
| 184 | + // force Run 2 mode |
| 185 | + return WorkflowSpec{adaptAnalysisTask<eventselectionRun2>(cfgc)}; |
| 186 | +} |
0 commit comments