1 #include "artdaq/ArtModules/detail/RawEventQueueReader.hh"
3 #include "art/Framework/Core/FileBlock.h"
5 #include "art/Framework/IO/Sources/SourceHelper.h"
6 #include "art/Framework/Principal/Event.h"
7 #include "art/Framework/Principal/EventPrincipal.h"
8 #include "art/Framework/Principal/Handle.h"
9 #include "art/Framework/Principal/RunPrincipal.h"
10 #include "art/Framework/Principal/SubRunPrincipal.h"
12 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
13 #include "art/Persistency/Provenance/MasterProductRegistry.h"
14 #include "art/Persistency/Provenance/ProductMetaData.h"
15 #include "canvas/Persistency/Provenance/EventID.h"
16 #include "canvas/Persistency/Provenance/FileFormatVersion.h"
17 #include "canvas/Persistency/Provenance/ModuleDescription.h"
18 #include "canvas/Persistency/Provenance/Parentage.h"
19 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
20 #include "canvas/Persistency/Provenance/RunID.h"
21 #include "canvas/Persistency/Provenance/SubRunID.h"
22 #include "canvas/Persistency/Provenance/Timestamp.h"
23 #include "canvas/Utilities/Exception.h"
24 #include "canvas/Utilities/GetPassID.h"
25 #include "art/Version/GetReleaseVersion.h"
26 #include "artdaq-core/Core/GlobalQueue.hh"
27 #include "artdaq-core/Data/Fragment.hh"
28 #include "fhiclcpp/make_ParameterSet.h"
30 #define BOOST_TEST_MODULE ( raw_event_queue_reader_t )
31 #include <boost/test/auto_unit_test.hpp>
51 typedef std::map<std::string, art::BranchKey>
BKmap_t;
65 art::ProcessConfiguration*
67 std::string
const& processName,
68 fhicl::ParameterSet
const& moduleParams,
69 std::string
const& release = art::getReleaseVersion(),
70 std::string
const& pass = art::getPassID());
79 std::unique_ptr<art::BranchDescription>
81 std::string
const& processName,
82 std::string
const& productInstanceName = std::string());
96 , processConfigurations_()
112 #if ART_HEX_VERSION >= 0x20703
120 art::ProcessConfiguration*
123 std::string
const& processName,
124 fhicl::ParameterSet
const& moduleParams,
125 std::string
const& release,
126 std::string
const& pass)
128 fhicl::ParameterSet processParams;
129 processParams.put(processName, moduleParams);
130 processParams.put<std::string>(
"process_name",
134 std::make_unique<art::ProcessConfiguration>(processName, processParams.id(), release, pass));
135 return emplace_pair.first->second.get();
138 std::unique_ptr<art::BranchDescription>
141 std::string
const& processName,
142 std::string
const& productInstanceName)
144 std::string moduleLabel = processName +
"dummyMod";
145 std::string moduleClass(
"DummyModule");
146 fhicl::ParameterSet modParams;
147 modParams.put<std::string>(
"module_type", moduleClass);
148 modParams.put<std::string>(
"module_label", moduleLabel);
149 art::ProcessConfiguration* process =
151 art::ModuleDescription mod(modParams.id(),
155 art::TypeID dummyType(
typeid(
int));
156 art::BranchDescription* result =
157 new art::BranchDescription(
158 #
if ART_HEX_VERSION >= 0x20703
160 art::TypeLabel(dummyType,
161 productInstanceName),
163 art::TypeLabel(art::InEvent,
165 productInstanceName),
170 branchKeys_.insert(std::make_pair(tag, art::BranchKey(*result)));
171 return std::unique_ptr<art::BranchDescription>(result);
184 static bool once(
true);
188 art::ModuleDescription md(fhicl::ParameterSet().
id(),
191 *
gf().processConfigurations_[
"daq"]);
194 helper().registerProducts(
gf().productRegistry_, md);
216 static art::ProductRegistryHelper s_helper;
226 static std::unique_ptr<art::SourceHelper>
228 if (!s_source_helper)
230 fhicl::ParameterSet sourceParams;
231 std::string moduleType{
"DummySource" };
232 std::string moduleLabel{
"daq" };
233 sourceParams.put<std::string>(
"module_type", moduleType);
234 sourceParams.put<std::string>(
"module_label", moduleLabel);
238 art::ModuleDescription md(sourceParams.id(),
242 s_source_helper = std::make_unique<art::SourceHelper>(md);
244 return *s_source_helper;
253 fhicl::ParameterSet pset;
258 gf().productRegistry_);
259 static bool reader_initialized =
false;
260 if (!reader_initialized)
263 helper().reconstitutes<artdaq::Fragments, art::InEvent>(
"daq",
"ABCDEF");
264 reader_initialized =
true;
282 std::unique_ptr<art::RunPrincipal>&& run,
283 std::unique_ptr<art::SubRunPrincipal>&& subrun,
284 art::EventID
const& eventid)
286 BOOST_REQUIRE(run || subrun ==
nullptr);
287 std::shared_ptr<artdaq::RawEvent> event(
new artdaq::RawEvent(eventid.run(), eventid.subRun(), eventid.event()));
288 std::vector<artdaq::Fragment::value_type> fakeData{ 1, 2, 3, 4 };
290 tmpFrag(artdaq::Fragment::dataFrag(eventid.event(),
294 tmpFrag->setUserType(1);
295 event->insertFragment(std::move(tmpFrag));
296 event->markComplete();
297 artdaq::getGlobalQueue().enqNowait(event);
298 art::EventPrincipal* newevent =
nullptr;
299 art::SubRunPrincipal* newsubrun =
nullptr;
300 art::RunPrincipal* newrun =
nullptr;
301 bool rc = reader.
readNext(run.get(), subrun.get(), newrun, newsubrun, newevent);
303 if (run.get() && run->run() == eventid.run())
305 BOOST_CHECK(newrun ==
nullptr);
310 BOOST_CHECK(newrun->id() == eventid.runID());
312 if (!newrun && subrun.get() && subrun->subRun() == eventid.subRun())
314 BOOST_CHECK(newsubrun ==
nullptr);
318 BOOST_CHECK(newsubrun);
319 BOOST_CHECK(newsubrun->id() == eventid.subRunID());
321 BOOST_CHECK(newevent);
322 BOOST_CHECK(newevent->id() == eventid);
323 art::Event e(*newevent, art::ModuleDescription());
324 art::Handle<std::vector<artdaq::Fragment>> h;
325 e.getByLabel(
"daq",
"ABCDEF", h);
326 BOOST_CHECK(h.isValid());
327 BOOST_CHECK(h->size() == 1);
328 BOOST_CHECK(std::equal(fakeData.begin(),
330 h->front().dataBegin()));
339 art::EventID eventid(2112, 1, 3);
342 std::unique_ptr<art::RunPrincipal>(source_helper().makeRunPrincipal(eventid.run(), now)),
343 std::unique_ptr<art::SubRunPrincipal>(source_helper().makeSubRunPrincipal(eventid.run(), eventid.subRun(), now)),
349 art::EventID eventid(2112, 1, 3);
359 art::EventID eventid(2112, 1, 3);
362 std::unique_ptr<art::RunPrincipal>(source_helper().makeRunPrincipal(eventid.run(), now)),
363 std::unique_ptr<art::SubRunPrincipal>(source_helper().makeSubRunPrincipal(eventid.run(), 0, now)),
369 art::EventID eventid(2112, 1, 3);
372 std::unique_ptr<art::RunPrincipal>(source_helper().makeRunPrincipal(eventid.run() - 1, now)),
373 std::unique_ptr<art::SubRunPrincipal>(source_helper().makeSubRunPrincipal(eventid.run() - 1,
384 std::string
const fakeFileName(
"no such file exists");
385 art::FileBlock* pFile =
nullptr;
386 reader().readFile(fakeFileName, pFile);
388 BOOST_CHECK(pFile->fileFormatVersion() == art::FileFormatVersion(1,
"RawEvent2011"));
389 BOOST_CHECK(pFile->tree() ==
nullptr);
391 BOOST_CHECK(!pFile->fastClonable());
395 art::RunID runid(2112);
396 art::SubRunID subrunid(2112, 1);
397 art::EventID eventid(2112, 1, 3);
399 std::unique_ptr<art::RunPrincipal> run(source_helper().makeRunPrincipal(runid.run(), now));
400 std::unique_ptr<art::SubRunPrincipal> subrun(source_helper().makeSubRunPrincipal(runid.run(), subrunid.subRun(), now));
401 std::unique_ptr<art::EventPrincipal> event(source_helper().makeEventPrincipal(runid.run(),
405 artdaq::getGlobalQueue().enqNowait(std::shared_ptr<artdaq::RawEvent>(
nullptr));
406 art::EventPrincipal* newevent =
nullptr;
407 art::SubRunPrincipal* newsubrun =
nullptr;
408 art::RunPrincipal* newrun =
nullptr;
409 bool rc = reader().readNext(run.get(), subrun.get(), newrun, newsubrun, newevent);
411 BOOST_CHECK(newrun ==
nullptr);
412 BOOST_CHECK(newsubrun ==
nullptr);
413 BOOST_CHECK(newevent ==
nullptr);
416 BOOST_AUTO_TEST_SUITE_END()
bool readNext(art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
Dequeue a RawEvent and declare its Fragment contents to art, creating Run, SubRun, and EventPrincipal objects as necessary.
std::map< std::string, std::unique_ptr< art::ProcessConfiguration > > processConfigurations_
Configurations.
art::ProductRegistryHelper & helper()
Get an art::ProductRegistryHelper, creating a static instance if necessary.
void finalize()
Finalizes the ProductRegistry.
The RawEventQueueReader is a class which implements the methods needed by art::Source.
art::MasterProductRegistry productRegistry_
MasterProductRegistry instance.
void basic_test(artdaq::detail::RawEventQueueReader &reader, std::unique_ptr< art::RunPrincipal > &&run, std::unique_ptr< art::SubRunPrincipal > &&subrun, art::EventID const &eventid)
Run a basic checkout of the RawEventQueueReader.
art::ProcessConfiguration * fake_single_module_process(std::string const &tag, std::string const &processName, fhicl::ParameterSet const &moduleParams, std::string const &release=art::getReleaseVersion(), std::string const &pass=art::getPassID())
Create the ProcessConfiguration for a single module art process.
std::unique_ptr< art::BranchDescription > fake_single_process_branch(std::string const &tag, std::string const &processName, std::string const &productInstanceName=std::string())
Create a BranchDescription for a process.
MasterProductRegistry Test Fixture.
RawEventQueueReader Test Fixture.
REQRTestFixture()
REQRTestFixture Constructor.
std::map< std::string, art::BranchKey > BKmap_t
BKmap_t associates a string with a art::BranchKey.
MPRGlobalTestFixture()
MPRGlobalTestFixture Constructor.
art::SourceHelper & source_helper()
Get an art::SourceHelper object, creating a static instance if necessary.
std::map< Fragment::type_t, std::string > fragment_type_map_
The Fragment type names that this RawEventQueueReader knows about.
artdaq::detail::RawEventQueueReader & reader()
Get an artdaq::detail::RawEventQueueReader object, creating a static instance if necessary.
MPRGlobalTestFixture & gf()
Get a MPRGlobalTestFixture, creating a static instance if necessary.
BKmap_t branchKeys_
Keys in this test fixture.