2 #include "artdaq/DAQdata/Globals.hh"
3 #include "artdaq/ArtModules/detail/RawEventQueueReader.hh"
5 #include "art/Framework/IO/Sources/put_product_in_principal.h"
6 #include "canvas/Persistency/Provenance/FileFormatVersion.h"
7 #include "canvas/Utilities/Exception.h"
8 #include "artdaq-core/Data/Fragment.hh"
14 art::ProductRegistryHelper& help,
15 art::SourceHelper
const& pm) :
17 , incoming_events(getGlobalQueue())
18 , waiting_time(ps.get<double>(
"waiting_time", 86400.0))
19 , resume_after_timeout(ps.get<bool>(
"resume_after_timeout", true))
20 , pretend_module_name(ps.get<std::string>(
"raw_data_label",
"daq"))
21 , unidentified_instance_name(
"unidentified")
22 , shutdownMsgReceived(false)
23 , outputFileCloseNeeded(false)
24 , fragment_type_map_(Fragment::MakeSystemTypeMap())
40 fb =
new art::FileBlock(art::FileFormatVersion(1,
"RawEvent2011"),
"nothing");
44 art::SubRunPrincipal*
const & inSR,
45 art::RunPrincipal*& outR,
46 art::SubRunPrincipal*& outSR,
47 art::EventPrincipal*& outE)
53 if (readNext_calls_++ == 0)
55 incoming_events.setReaderIsReady();
56 TRACE(50,
"RawEventQueueReader::readNext after incoming_events.setReaderIsReady()");
62 RawEvent_ptr popped_event;
68 bool keep_looping =
true;
69 bool got_event =
false;
73 got_event = incoming_events.deqTimedWait(popped_event, waiting_time);
76 TLOG_INFO(
"RawEventQueueReader")
77 <<
"InputFailure: Reading timed out in RawEventQueueReader::readNext()" << TLOG_ENDL;
78 keep_looping = resume_after_timeout;
86 if (!got_event || !popped_event)
88 TLOG_DEBUG(
"RawEventQueueReader") <<
"Received shutdown message, returning false" << TLOG_ENDL;
89 shutdownMsgReceived =
true;
96 art::Timestamp currentTime = time(0);
99 if (inR == 0 || inR->run() != popped_event->runID())
101 outR = pmaker.makeRunPrincipal(popped_event->runID(),
105 if (popped_event->numFragments() == 1)
107 if (popped_event->releaseProduct(Fragment::EndOfRunFragmentType)->size() == 1)
109 art::EventID
const evid(art::EventID::flushEvent());
110 outR = pmaker.makeRunPrincipal(evid.runID(), currentTime);
111 outSR = pmaker.makeSubRunPrincipal(evid.subRunID(), currentTime);
112 outE = pmaker.makeEventPrincipal(evid, currentTime);
115 else if (popped_event->releaseProduct(Fragment::EndOfSubrunFragmentType)->size() == 1)
118 if (inR == 0 || inR->run() != popped_event->runID())
120 outSR = pmaker.makeSubRunPrincipal(popped_event->runID(),
121 popped_event->subrunID(),
123 #ifdef ARTDAQ_ART_EVENTID_HAS_EXPLICIT_RUNID
124 art::EventID
const evid(art::EventID::flushEvent(outR->id(), outSR->id()));
126 art::EventID
const evid(art::EventID::flushEvent(outSR->id()));
128 outE = pmaker.makeEventPrincipal(evid, currentTime);
136 if (inSR != 0 && !inSR->id().isFlush() && inSR->subRun() == popped_event->subrunID())
138 art::EventID
const evid(art::EventID::flushEvent(inR->id()));
139 outSR = pmaker.makeSubRunPrincipal(evid.subRunID(), currentTime);
140 outE = pmaker.makeEventPrincipal(evid, currentTime);
147 outSR = pmaker.makeSubRunPrincipal(popped_event->runID(),
148 popped_event->subrunID(),
150 #ifdef ARTDAQ_ART_EVENTID_HAS_EXPLICIT_RUNID
151 art::EventID
const evid(art::EventID::flushEvent(inR->id(), outSR->id()));
153 art::EventID
const evid(art::EventID::flushEvent(outSR->id()));
155 outE = pmaker.makeEventPrincipal(evid, currentTime);
167 art::SubRunID subrun_check(popped_event->runID(), popped_event->subrunID());
168 if (inSR == 0 || subrun_check != inSR->id())
170 outSR = pmaker.makeSubRunPrincipal(popped_event->runID(),
171 popped_event->subrunID(),
174 outE = pmaker.makeEventPrincipal(popped_event->runID(),
175 popped_event->subrunID(),
176 popped_event->sequenceID(),
179 std::vector<Fragment::type_t> type_list;
180 popped_event->fragmentTypes(type_list);
182 std::map<Fragment::type_t, std::string>::const_iterator iter_end =
183 fragment_type_map_.end();
184 for (
size_t idx = 0; idx < type_list.size(); ++idx)
186 std::map<Fragment::type_t, std::string>::const_iterator iter =
187 fragment_type_map_.find(type_list[idx]);
188 if (iter != iter_end)
190 put_product_in_principal(popped_event->releaseProduct(type_list[idx]),
197 put_product_in_principal(popped_event->releaseProduct(type_list[idx]),
200 unidentified_instance_name);
201 TLOG_WARNING(
"RawEventQueueReader")
202 <<
"UnknownFragmentType: The product instance name mapping for fragment type \""
203 << ((int)type_list[idx]) <<
"\" is not known. Fragments of this "
204 <<
"type will be stored in the event with an instance name of \""
205 << unidentified_instance_name <<
"\"." << TLOG_ENDL;
std::string pretend_module_name
The module name to store data under.
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.
RawEventQueueReader(RawEventQueueReader const &)=delete
Copy Constructor is deleted.
std::string unidentified_instance_name
The name to use for unknown Fragment types.
void readFile(std::string const &, art::FileBlock *&fb)
Emulate opening a file.
void closeCurrentFile()
Emulate closing a file. No-Op.
std::map< Fragment::type_t, std::string > fragment_type_map_
The Fragment type names that this RawEventQueueReader knows about.