11 #include <type_traits>
83 for (
size_t i = 0; i <
ns; ++i) {
85 thread worker([
this, katoomba]() {
92 unique_lock<mutex> lock(
in);
94 cv.wait(lock, [
this]() {
return stop || !input.empty(); });
96 if (
stop && input.empty()) {
100 data.swap(input.front());
105 const auto result = fremantle(data.begin(), data.end());
107 if (
result.chi2 /
result.ndf <= fremantle.parameters.chi2perNDF) {
110 unique_lock<mutex> lock(out);
114 if (JFremantle::output != NULL) {
131 workers.emplace_back(move(worker));
144 unique_lock<mutex> lock(
in);
151 for (
auto& worker : workers) {
167 unique_lock<mutex> lock(
in);
179 void enqueue(data_type& data)
184 unique_lock<mutex> lock(
in);
187 throw runtime_error(
"The thread pool has been stopped.");
190 input.emplace(move(data));
202 queue <data_type> input;
205 condition_variable cv;
221 int main(
int argc,
char **argv)
237 transmitters_container transmitters;
238 hydrophones_container hydrophones;
241 disable_container disable;
248 JParser<> zap(
"Application to fit position calibration model to acoustic data.");
250 zap[
'f'] =
make_field(inputFile,
"output of JAcousticEventBuilder[.sh]");
252 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
260 zap[
'u'] =
make_field(unify,
"unify weighing of pings");
262 zap[
'N'] =
make_field(jobs,
"number of parallel jobs") = 1;
263 zap[
'D'] =
make_field(Tmax_s,
"deadtime [s]") = 100.0e-3;
268 catch(
const exception &error) {
269 FATAL(error.what() << endl);
272 ROOT::EnableThreadSafety();
274 const int sleep_us = 100;
288 for (JDetector::const_iterator i =
detector.begin(); i !=
detector.end(); ++i) {
289 receivers[i->getID()] = i->getLocation();
292 for (tripods_container::const_iterator i =
tripods.begin(); i !=
tripods.end(); ++i) {
293 emitters[i->getID()] =
JEmitter(i->getID(),
294 i->getUTMPosition() -
detector.getUTMPosition());
297 for (transmitters_container::const_iterator i = transmitters.begin(); i != transmitters.end(); ++i) {
299 emitters[i->getID()] =
JEmitter(i->getID(),
302 catch(
const exception&) {
317 if (inputFile.size() > 1
u) {
321 for (
const string& file_name : inputFile) {
329 if (JFremantle::oid ==
"")
330 JFremantle::oid = evt->
getOID();
331 else if (JFremantle::oid != evt->
getOID())
332 FATAL(
"Invalid detector identifier " << evt->
getOID() <<
" != " << JFremantle::oid << endl);
335 zmap[evt->begin()->getToE()] = file_name;
344 inputFile.push_back(i->second);
364 JFremantle fremantle(katoomba, jobs);
366 typedef deque<JEvent> buffer_type;
368 for (buffer_type zbuf; inputFile.hasNext(); ) {
370 STATUS(inputFile.getFilename() <<
'\r');
DEBUG(endl);
374 for (
const string file_name = inputFile.getFilename(); inputFile.hasNext() && file_name == inputFile.getFilename(); ) {
376 const JEvent* evt = inputFile.next();
378 if (emitters.has(evt->
getID())) {
379 zbuf.push_back(*evt);
383 sort(zbuf.begin(), zbuf.end());
385 for (buffer_type::iterator p = zbuf.begin(), q; p != zbuf.end(); p = q) {
387 for (q = p; ++q != zbuf.end() && q->begin()->getToE() <= p->rbegin()->getToE() +
parameters.Tmax_s; ) {}
389 if (q == zbuf.end()) {
391 if (inputFile.hasNext()) {
393 zbuf.erase(zbuf.begin(), p);
405 for (buffer_type::const_iterator i = p; i != q; ++i) {
406 numberOfPings[i->getID()] += 1;
409 int minimum_number_of_pings = numeric_limits<int>::max();
412 minimum_number_of_pings = min(minimum_number_of_pings, i->second);
418 for (buffer_type::iterator evt = p; evt != q; ++evt) {
424 const JEmitter& emitter = emitters[evt->getID()];
425 const double weight = (unify ? (double) minimum_number_of_pings / (
double) numberOfPings[evt->getID()] : 1.0);
427 for (JEvent::const_iterator i = evt->begin(); i != __end; ++i) {
432 if (receivers.has(i->getID()) && geometry.
hasLocation(receivers[i->getID()]) && i->getQ() >=
parameters.Qmin * (unit(
parameters.Qmin) ? i->getW() : 1.0)) {
434 data.push_back(
JHit(emitter,
436 receivers[i->getID()],
441 buffer.insert(evt->getID());
449 while (fremantle.backlog() > jobs) {
450 this_thread::sleep_for(chrono::microseconds(sleep_us));
453 fremantle.enqueue(data);
460 catch(
const exception& error) {
461 FATAL(
"main " << error.what());
Worker class for complete fit procedure of acoustic model.
Utility class to parse command line options.
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
static JDetectorMechanics getMechanics
Function object to get string mechanics.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
General purpose class for hash map of unique elements.
ROOT TTree parameter settings.
Recording of objects on file according a format that follows from the file name extension.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
Data structure for detector geometry and calibration.
Data structure for hydrophone.
size_t getNumberOfEmitters(T __begin, T __end)
Get number of emitters.
then usage $script[port]< option > nPossible stop
Scanning of objects from a single file according a format that follows from the extension of each fil...
Auxiliary class for defining the range of iterations of objects.
static const JSoundVelocity getSoundVelocity(1541.0,-17.0e-3,-2000.0)
Function object for velocity of sound.
Data structure for transmitter.
Auxiliary wrapper for I/O of container with optional comment (see JComment).
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
const std::string & getOID() const
Get detector identifier.
JPosition3D getPosition(const Vec &pos)
Get position.
General purpose messaging.
Implementation for depth dependend velocity of sound.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxiliary class to define a range between two values.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
Acoustic transmission identifier.
Fit function of acoustic model.
bool hasLocation(const JLocation &location) const
Check if this detector has given location.
Template interface of object output for single data type.
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
do set_variable DETECTOR_TXT $WORKDIR detector
int getID() const
Get emitter identifier.
Data structure for tripod.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Acoustic transmission identifier.
Auxiliary data structure for floating point format specification.
Auxiliary data structure to convert model to super event.
Template definition of fit function of acoustic model.
#define DEBUG(A)
Message macros.
Data structure for optical module.