Swarm-NG  1.1
log.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2010 by Mario Juric and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
25 #pragma once
26 
27 #include "../common.hpp"
28 
29 #include "gpulog/gpulog.h"
30 #include "gpulog/lprintf.h"
31 
32 #include "../types/ensemble.hpp"
33 
34 #include "types.hpp"
35 
36 namespace swarm {
191 namespace log {
192 
193 // Make sure these stay synced with src/swarm/query.cpp
195 static const int EVT_SNAPSHOT = 1;
196  // Common physical events
198 static const int EVT_EJECTION = 2;
200 static const int EVT_ENCOUNTER = 3;
202 static const int EVT_COLLISION = 4;
204 static const int EVT_COLLISION_CENTRAL = 5;
205  // Common types of observations
207 static const int EVT_RV_OBS = 11;
209 static const int EVT_ASTROM_OBS = 12;
211 static const int EVT_TIMING_OBS = 13;
213 static const int EVT_DIRECT_IMAGE_OBS = 14;
215 static const int EVT_TRANSIT = 15;
217 static const int EVT_OCCULTATION = 16;
219 static const int EVT_MUTUAL_EVENT = 17;
220  // let query and writers know which codes are to be used for events
222 static const int EVT_FIRST_OBS_CODE = EVT_RV_OBS;
225 
226  // save at least 8 bits for future use
227  //static const int EVT_USER_1 = 256; //! marks user defined event
228  //static const int EVT_USER_2 = 257; //! marks user defined event
229  //static const int EVT_USER_3 = 258; //! marks user defined event
230 
231 #if 0
232  // Helper class for expected data size
233  // But do we really need these at compile time?
234  template<int N>
235  struct event_data_size
236  {
237  int num_ints() { return -1; }
238  int num_doubles() { return -1; }
239  };
240 
241  template<> struct event_data_size<EVT_RV_OBS>
242  { int num_ints() { return 1; } int num_doubles() { return 1; } };
243  template<> struct event_data_size<EVT_ASTROM_OBS>
244  { int num_ints() { return 1; } int num_doubles() { return 2; } };
245  template<> struct event_data_size<EVT_TIMING_OBS>
246  { int num_ints() { return 1; } int num_doubles() { return 1; } };
247  template<> struct event_data_size<EVT_DIRECT_IMAGE_OBS>
248  { int num_ints() { return 1; } int num_doubles() { return 2; } };
249  template<> struct event_data_size<EVT_TRANSIT>
250  { int num_ints() { return 1; } int num_doubles() { return 2; } };
251  template<> struct event_data_size<EVT_OCCULTATION>
252  { int num_ints() { return 1; } int num_doubles() { return 2; } };
253  template<> struct event_data_size<EVT_MUTUAL_EVENT>
254  { int num_ints() { return 2; } int num_doubles() { return 2; } };
255 #endif
256 
258  int num_ints_for_event(const int code);
260  int num_doubles_for_event(const int code);
261 
262 template<typename L, typename T1>
263 GENERIC PTR_T(SCALAR(T1)) event(L &l, const int recid, const double T, const int sys, const T1 &v1){
264  return l.write(recid, T, sys, v1);
265 }
266 
267 template<typename L, typename T1, typename T2>
268 GENERIC PTR_T(SCALAR(T2)) event(L &l, const int recid, const double T, const int sys, const T1 &v1, const T2 &v2)
269  {
270  return l.write(recid, T, sys, v1, v2);
271  }
272 
273 template<typename L, typename T1, typename T2, typename T3>
274 GENERIC PTR_T(SCALAR(T3)) event(L &l, const int recid, const double T, const int sys, const T1 &v1, const T2 &v2, const T3 &v3)
275  {
276  return l.write(recid, T, sys, v1, v2, v3);
277  }
278 
279 template<typename L, typename T1, typename T2, typename T3, typename T4>
280 GENERIC PTR_T(SCALAR(T4)) event(L &l, const int recid, const double T, const int sys, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
281  {
282  return l.write(recid, T, sys, v1, v2, v3, v4);
283  }
284 
285 template<typename L, typename T1, typename T2, typename T3, typename T4, typename T5>
286 GENERIC PTR_T(SCALAR(T5)) event(L &l, const int recid, const double T, const int sys, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5)
287  {
288  return l.write(recid, T, sys, v1, v2, v3, v4, v5);
289  }
290 
291 template<typename L, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
292 GENERIC PTR_T(SCALAR(T6)) event(L &l, const int recid, const double T, const int sys, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6)
293  {
294  return l.write(recid, T, sys, v1, v2, v3, v4, v5, v6);
295  }
296 
297 template<typename L, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
298 GENERIC PTR_T(SCALAR(T7)) event(L &l, const int recid, const double T, const int sys, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7)
299  {
300  return l.write(recid, T, sys, v1, v2, v3, v4, v5, v6, v7);
301  }
302 
303 template<typename L, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
304 GENERIC PTR_T(SCALAR(T8)) event(L &l, const int recid, const double T, const int sys, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7, const T8 &v8)
305  {
306  return l.write(recid, T, sys, v1, v2, v3, v4, v5, v6, v7, v8);
307  }
308 
309 
313 template<typename L>
314 GENERIC void system(L &l, ensemble::SystemRefConst sys)
315 {
316  body *bodies = swarm::log::event(l, EVT_SNAPSHOT, sys.time(), sys.id()
317  , sys.state() , sys.nbod(), gpulog::array<body>(sys.nbod()));
318 
319  if(bodies != NULL) // buffer overflow hasn't happened
320  {
321  for(int bod=0; bod < sys.nbod(); bod++)
322  {
323  bodies[bod].set(bod,sys[bod]);
324  }
325  }
326 }
327 
331 template<typename L>
332 GENERIC void system(L &l, const ensemble &ens, const int sys) { system(l,ens[sys]); }
333 
337 template<typename L>
338 GENERIC void ensemble(L &l, const swarm::ensemble &ens)
339 {
340  for(int sys = 0; sys < ens.nsys(); sys++)
341  system(l, ens[sys]);
342 }
343 
347 template<typename L>
349 {
350  for(int sys = 0; sys < ens.nsys(); sys++)
351  {
352  if(ens[sys].is_enabled())
353  system(l, ens[sys]);
354  }
355 }
356 
357 
358 } }