00001 #ifndef __N3AnaBase__ana_event_h
00002 #define __N3AnaBase__ana_event_h 1
00003
00004 #include <stdexcept>
00005 #include <iostream>
00006 #include <sstream>
00007 #include <fstream>
00008 #include <string>
00009 #include <vector>
00010 #include <list>
00011 #include <map>
00012
00013 extern "C"
00014 {
00015 #include <time.h>
00016 }
00017
00018 #include <boost/cstdint.hpp>
00019
00020 #include <boost/serialization/list.hpp>
00021 #include <boost/serialization/map.hpp>
00022 #include <boost/serialization/string.hpp>
00023 #include <boost/serialization/nvp.hpp>
00024 #include <boost/serialization/access.hpp>
00025 #include <boost/serialization/version.hpp>
00026
00027 #include <datatools/event/event_id.h>
00028 #include <datatools/utils/properties.h>
00029 #include <datatools/utils/i_tree_dump.h>
00030 #include <datatools/utils/i_clear.h>
00031 #include <datatools/utils/i_propinit.h>
00032 #include <datatools/serialization/safe_serial.h>
00033 #include <datatools/serialization/i_serializable.h>
00034
00035 #include <N3GeomDef/N3GeigerGeom.h>
00036
00037 #include <N3AnaBase/event/sim_event_utils.h>
00038 #include <N3AnaBase/event/event_utils.h>
00039 #include <N3AnaBase/event/scin_hit.h>
00040 #include <N3AnaBase/event/gg_hit.h>
00041 #include <N3AnaBase/event/tracking.h>
00042 #include <N3AnaBase/event/gamma_tracking.h>
00043 #include <N3AnaBase/event/tof_col.h>
00044
00046
00047 namespace nemo3 {
00050
00066
00067 class ana_event :
00068 public datatools::utils::i_tree_dumpable,
00069 public datatools::utils::i_clear,
00070 public datatools::serialization::i_serializable
00071 {
00072
00073 public:
00074
00076 class i_measurement : public datatools::utils::i_propinit
00077 {
00078 public:
00080 virtual void do_measurement (ana_event &) = 0;
00082 ana_event & operator () (ana_event &);
00083
00084 };
00085
00087 class i_predicate : public datatools::utils::i_propinit
00088 {
00089 public:
00091 virtual bool do_test (ana_event &) = 0;
00093 bool operator () (ana_event &);
00094
00095 };
00096
00098 class timestamp
00099 {
00100 public:
00101 static const char IO_FORMAT_SEP = '_';
00102 static int32_t convert_to_sec_epoch (int date_, int time_);
00103 static int32_t extract_millisec (int time_);
00104
00105 public:
00106 int32_t __date;
00107 int32_t __time;
00108 uint32_t __sec_epoch;
00109 int32_t __millisec;
00111 public:
00112
00113 timestamp ();
00115 timestamp (int date_, int time_);
00117 void set (int date_, int time_);
00119 int32_t get_date () const;
00120 int32_t get_time () const;
00121 int32_t get_sec_epoch () const;
00122 int32_t get_millisec () const;
00124 int32_t get_year () const;
00125 int32_t get_month () const;
00126 int32_t get_day () const;
00127 int32_t get_hours () const;
00128 int32_t get_minutes () const;
00129 int32_t get_seconds () const;
00130 int32_t get_milliseconds () const
00131 {
00132 return get_millisec ();
00133 }
00134
00135 bool is_valid () const;
00137 void clear ();
00139 std::string to_string () const;
00141 void from_string (const std::string &);
00143 friend std::ostream & operator<< (std::ostream &, const timestamp &);
00145 friend std::istream & operator>> (std::istream &, timestamp &);
00147 private:
00148
00150 friend class boost::serialization::access;
00158 template<class Archive>
00159 void serialize (Archive & ar_ ,
00160 const unsigned int version_)
00161 {
00162 ar_ & boost::serialization::make_nvp ("date", __date);
00163 ar_ & boost::serialization::make_nvp ("time", __time);
00164 ar_ & boost::serialization::make_nvp ("sec_epoch", __sec_epoch);
00165 ar_ & boost::serialization::make_nvp ("millisec", __millisec);
00166 }
00167 };
00168
00169
00170 public:
00172 typedef std::list<sim_vertex> sim_vertex_col;
00174 typedef std::list<sim_particle> sim_particle_col;
00176 typedef std::list<scin_hit> scin_hit_col;
00178 typedef std::list<gg_hit> gg_hit_col;
00180 typedef std::map<std::string, tracking> tracking_col;
00181
00182 public:
00184 bool is_calib_ok () {return __calib_is_ok;}
00186 void set_calib_ok () {__calib_is_ok = true;}
00187
00189 void revert_pm_time ();
00190
00191 bool is_debug () const;
00192
00193 void set_debug (bool);
00194
00195
00196 void set_selected (bool);
00198 bool is_selected () const;
00199
00200 bool is_simulated () const;
00201
00202 void set_simulated (bool);
00203
00204 const datatools::event::event_id & get_id () const;
00206 const datatools::event::event_id & get_id_ro () const
00207 {
00208 return get_id ();
00209 }
00210
00211 int get_run_number () const
00212 {
00213 return get_id ().get_run_number ();
00214 }
00215
00216 int get_event_number () const
00217 {
00218 return get_id ().get_event_number ();
00219 }
00221 datatools::event::event_id & get_id ();
00223 datatools::event::event_id & get_id_rw ()
00224 {
00225 return get_id ();
00226 }
00228 void set_id (const datatools::event::event_id &);
00230 const datatools::utils::properties & properties () const;
00232 const datatools::utils::properties & get_properties_ro () const
00233 {
00234 return properties ();
00235 }
00237 const datatools::utils::properties & get_properties_const () const
00238 {
00239 return properties ();
00240 }
00242 datatools::utils::properties & properties ();
00244 datatools::utils::properties & get_properties_rw ()
00245 {
00246 return properties ();
00247 }
00249 const timestamp & get_timestamp () const;
00251 const timestamp & get_timestamp_ro () const
00252 {
00253 return get_timestamp ();
00254 }
00256 void set_timestamp (const timestamp &);
00258 int get_year () const
00259 {
00260 return __timestamp.get_year ();
00261 }
00263 int get_month () const
00264 {
00265 return __timestamp.get_month ();
00266 }
00268 int get_day () const
00269 {
00270 return __timestamp.get_day ();
00271 }
00273 int get_hours () const
00274 {
00275 return __timestamp.get_hours ();
00276 }
00278 int get_minutes () const
00279 {
00280 return __timestamp.get_minutes ();
00281 }
00283 int get_seconds () const
00284 {
00285 return __timestamp.get_seconds ();
00286 }
00288 int get_milliseconds () const
00289 {
00290 return __timestamp.get_milliseconds ();
00291 }
00293 int get_sec_epoch () const
00294 {
00295 return __timestamp.get_sec_epoch ();
00296 }
00298 void clear_scin_hits ();
00300 void clear_gg_hits ();
00302 void clear_trackings ();
00304 void clear_sim_data ();
00306 void set_sim_data (const sim_primary_event &);
00308 const sim_primary_event & get_sim_data () const;
00310 const sim_primary_event & get_sim_data_ro () const
00311 {
00312 return get_sim_data ();
00313 }
00315 sim_primary_event & get_sim_data ();
00317 sim_primary_event & get_sim_data_rw ()
00318 {
00319 return get_sim_data ();
00320 }
00322 scin_hit_col & scin_hits ();
00324 gg_hit_col & gg_hits ();
00326 const gg_hit_col & gg_hits () const;
00328 int get_number_of_gg_hits () const
00329 {
00330 return gg_hits ().size ();
00331 }
00333 tracking_col & trackings ();
00335 const scin_hit_col & scin_hits () const;
00337 int get_number_of_scin_hits () const
00338 {
00339 return scin_hits ().size ();
00340 }
00342 const gg_hit & get_gg_hit (int i_) const;
00344 gg_hit & gg (int i_);
00346 const scin_hit & get_scin_hit (int i_) const;
00348 scin_hit & scin (int i_);
00350 const tracking_col & trackings () const;
00352 void set_default_tracking (const std::string & name_);
00354 bool has_default_tracking () const;
00355
00357 bool has_tracking () const;
00358
00361 bool has_tracking_with_name (const std::string & name_) const;
00363 const tracking & get_tracking (const std::string & name_) const;
00365 const tracking & get_tracking_const (const std::string & name_) const
00366 {
00367 return get_tracking (name_);
00368 }
00370 const tracking & get_tracking_ro (const std::string & name_) const
00371 {
00372 return get_tracking (name_);
00373 }
00375 void add_tracking (const std::string & name_,
00376 const tracking & tracking_,
00377 bool default_ = true);
00378
00379 tracking & get_tracking (const std::string & name_);
00381 tracking & get_tracking_rw (const std::string & name_)
00382 {
00383 return get_tracking (name_);
00384 }
00386 const tracking & get_default_tracking () const;
00388 const tracking & get_default_tracking_const () const
00389 {
00390 return get_default_tracking ();
00391 }
00393 const tracking & get_default_tracking_ro () const
00394 {
00395 return get_default_tracking ();
00396 }
00398 tracking & get_default_tracking ();
00400 tracking & get_default_tracking_rw ()
00401 {
00402 return get_default_tracking ( );
00403 }
00405 gamma_tracking & get_gamma_tracking () {return __gamma_tracks;}
00407 gamma_tracking copy_gamma_tracking () const {return __gamma_tracks;}
00409 const tof_col& get_tof_col () const {return __tof_col;};
00411 tof_col& get_tof_col_no_const () {return __tof_col;};
00412 public:
00414 void measure (i_measurement & measurement_);
00415
00416 public:
00417
00419 ana_event ();
00420
00422 ana_event (const datatools::event::event_id & id_,
00423 bool simulated_ = false);
00425 virtual ~ana_event ();
00426
00427 private:
00428 bool __debug;
00429 bool __selected;
00430 bool __calib_is_ok;
00431 datatools::event::event_id __id;
00432 bool __simulated;
00433 timestamp __timestamp;
00434 datatools::utils::properties __properties;
00435 sim_primary_event __sim_data;
00436 scin_hit_col __scin_hits;
00437 gg_hit_col __gg_hits;
00438 tracking_col __trackings;
00439 std::string __default_tracking_name;
00440 gamma_tracking __gamma_tracks;
00441 tof_col __tof_col;
00442
00443 public:
00444
00446
00447 virtual void clear ();
00448
00450 virtual void tree_dump (std::ostream & out_ = std::clog,
00451 const std::string & title_ = "",
00452 const std::string & indent_ = "",
00453 bool inherit_ = false) const;
00454
00456 void dump () const
00457 {
00458 tree_dump (std::clog, "ana_event");
00459 }
00461 static const std::string SERIAL_TAG;
00462
00464 virtual const std::string & get_serial_tag () const;
00465
00466 private:
00468 friend class boost::serialization::access;
00470 template<class Archive>
00471 void serialize (Archive & ar_,
00472 const unsigned int version_)
00473 {
00474
00475 ar_ & boost::serialization::make_nvp ("id", __id);
00476 ar_ & boost::serialization::make_nvp ("simulated", __simulated);
00477 ar_ & boost::serialization::make_nvp ("timestamp", __timestamp);
00478 ar_ & boost::serialization::make_nvp ("properties", __properties);
00479 ar_ & boost::serialization::make_nvp ("sim_data", __sim_data);
00480 ar_ & boost::serialization::make_nvp ("scin_hits", __scin_hits);
00481 ar_ & boost::serialization::make_nvp ("gg_hits", __gg_hits);
00482 ar_ & boost::serialization::make_nvp ("trackings", __trackings);
00483 ar_ & boost::serialization::make_nvp ("default_tracking_name",
00484 __default_tracking_name);
00485
00486 if(version_ > 0)
00487 {
00488 ar_ & boost::serialization::make_nvp ("gamma_track", __gamma_tracks);
00489
00490 if (version_ > 1)
00491 {
00492 ar_ & boost::serialization::make_nvp ("tof_col",__tof_col);
00493 if (version_ > 2)
00494 {
00495 ar_ & boost::serialization::make_nvp ("calib_is_ok",__calib_is_ok);
00496 }
00497 }
00498 }
00499 }
00500
00501 public:
00502
00503 typedef datatools::serialization::safe_serial<ana_event> safe_serial;
00504
00505 };
00506
00508 class ana_event_has_id
00509 : public std::unary_function<ana_event, bool>
00510 {
00511 datatools::event::event_id __id;
00512 public:
00513
00514 explicit ana_event_has_id (const datatools::event::event_id & id_)
00515 {
00516 __id = id_;
00517 }
00518
00519 bool operator () (const ana_event & event_) const
00520 {
00521 return (__id == event_.get_id ());
00522 }
00523 };
00524
00525 }
00526
00528 BOOST_CLASS_VERSION(nemo3::ana_event, 3)
00529 #endif // __N3AnaBase__ana_event_h
00530
00531