14 #include "art/Framework/Art/artapp.h"
15 #include "artdaq-core/Data/Fragment.hh"
16 #include "artdaq/Application/CommandableFragmentGenerator.hh"
17 #include "artdaq/Application/makeCommandableFragmentGenerator.hh"
18 #include "artdaq/DAQrate/EventStore.hh"
19 #include "artdaq-core/Core/SimpleMemoryReader.hh"
20 #include "artdaq-core/Utilities/SimpleLookupPolicy.hh"
21 #include "cetlib/container_algorithms.h"
22 #include "cetlib/filepath_maker.h"
23 #include "fhiclcpp/ParameterSet.h"
24 #include "fhiclcpp/make_ParameterSet.h"
26 #include <boost/program_options.hpp>
34 using namespace fhicl;
35 namespace bpo = boost::program_options;
38 int main(
int argc,
char* argv[])
try
44 std::cout <<
"****************************************" << std::endl;
45 std::cout <<
"*** \"demo_driver\" has been deprecated (15-Dec-2016)." << std::endl;
46 std::cout <<
"*** Please use the \"artdaqDriver\" application that is available from" << std::endl
47 <<
"*** the artdaq software package instead of \"demo_driver\"." << std::endl;
55 std::ostringstream descstr;
56 descstr << argv[0] <<
" <-c <config-file>> <other-options>";
58 bpo::options_description desc = descstr.str();
61 (
"config,c", bpo::value<std::string>(),
"Configuration file.")
62 (
"help,h",
"produce help message");
64 bpo::variables_map vm;
68 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
71 catch (bpo::error
const& e)
73 std::cerr <<
"Exception from command line processing in " << argv[0]
74 <<
": " << e.what() <<
"\n";
80 std::cout << desc << std::endl;
83 if (!vm.count(
"config"))
85 std::cerr <<
"Exception from command line processing in " << argv[0]
86 <<
": no configuration file given.\n"
87 <<
"For usage and an options list, please do '"
88 << argv[0] <<
" --help"
97 ParameterSet complete_pset;
99 if (getenv(
"FHICL_FILE_PATH") ==
nullptr)
102 <<
"INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
103 setenv(
"FHICL_FILE_PATH",
".", 0);
108 make_ParameterSet(vm[
"config"].as<std::string>(), lookup_policy, complete_pset);
110 ParameterSet fragment_receiver_pset = complete_pset.get<ParameterSet>(
"fragment_receiver");
111 ParameterSet event_builder_pset = complete_pset.get<ParameterSet>(
"event_builder");
116 std::unique_ptr<artdaq::CommandableFragmentGenerator>
const
117 gen(artdaq::makeCommandableFragmentGenerator(fragment_receiver_pset.get<std::string>(
"generator"),
118 fragment_receiver_pset));
124 bool const want_artapp = event_builder_pset.get<
bool>(
"use_art",
false);
126 std::ostringstream os;
129 os << event_builder_pset.get<
int>(
"events_expected_in_SimpleMemoryReader");
131 std::string oss = os.str();
133 const char* args[2]{
"SimpleMemoryReader",
const_cast<char *
>(oss.c_str())};
135 int es_argc(want_artapp ? argc : 2);
136 char** es_argv(want_artapp ? argv : const_cast<char**>(args));
138 artdaq::EventStore::ART_CMDLINE_FCN*
141 artdaq::EventStore store(event_builder_pset, event_builder_pset.get<
size_t>(
"expected_fragments_per_event"),
142 complete_pset.get<artdaq::EventStore::run_id_t>(
"run_number"),
147 int events_to_generate = complete_pset.get<
int>(
"events_to_generate", 0);
151 uint64_t timeout = 45;
152 uint64_t timestamp = std::numeric_limits<uint64_t>::max();
154 gen.get()->StartCmd(complete_pset.get<artdaq::EventStore::run_id_t>(
"run_number"), timeout, timestamp);
158 while (events_to_generate >= 0 && gen->getNext(frags))
160 for (
auto& val : frags)
162 std::cout <<
"Fragment: Seq ID: " << val->sequenceID() <<
", Frag ID: " << val->fragmentID() <<
", total size in bytes: " << val->size() *
sizeof(
artdaq::RawDataType) << std::endl;
164 if (val->sequenceID() != previous_sequence_id)
167 previous_sequence_id = val->sequenceID();
169 if (events_to_generate != 0 && event_count > events_to_generate)
170 gen.get()->StopCmd(timeout, timestamp);
172 store.insert(std::move(val));
176 if (events_to_generate != 0 && event_count >= events_to_generate)
177 gen.get()->StopCmd(timeout, timestamp);
180 int readerReturnValue;
181 bool endSucceeded =
false;
182 int attemptsToEnd = 1;
183 endSucceeded = store.endOfData(readerReturnValue);
184 while (! endSucceeded && attemptsToEnd < 3)
187 endSucceeded = store.endOfData(readerReturnValue);
191 std::cerr <<
"Failed to shut down the reader and the event store "
192 <<
"because the endOfData marker could not be pushed "
193 <<
"onto the queue." << std::endl;
195 return readerReturnValue;
198 catch (std::string& x)
200 std::cerr <<
"Exception (type string) caught in driver: " << x <<
"\n";
204 catch (
char const* m)
206 std::cerr <<
"Exception (type char const*) caught in driver: " << std::endl;
213 std::cerr <<
"[the value was a null pointer, so no message is available]";
detail::RawFragmentHeader::RawDataType RawDataType
std::list< FragmentPtr > FragmentPtrs
int SimpleMemoryReaderApp(int argc, char **argv)
detail::RawFragmentHeader::sequence_id_t sequence_id_t