00001
00002
00003
00004 #ifndef EPOS_EntriesAllocation
00005 #define EPOS_EntriesAllocation 99900
00006 #endif // EPOS_EntriesAllocation
00007
00008
00009 #ifndef HEPMC_EPOS_COMMON_H
00010 #define HEPMC_EPOS_COMMON_H
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #include <ctype.h>
00066
00067 const unsigned int epos_bytes_allocation =
00068 sizeof(long int) * ( 2 + 6 * EPOS_EntriesAllocation )
00069 + sizeof(double) * ( 9 * EPOS_EntriesAllocation );
00070
00071
00072 #ifdef _WIN32 // Platform: Windows MS Visual C++
00073 struct HEPCOM_DEF{
00074 char data[epos_bytes_allocation];
00075 };
00076 extern "C" HEPCOM_DEF HEPCOM;
00077 #define hepcom HEPCOM
00078
00079 #else
00080 extern "C" {
00081 extern struct {
00082 char data[epos_bytes_allocation];
00083 } hepcom_;
00084 }
00085 #define hepcom hepcom_
00086
00087 #endif // Platform
00088
00089 #endif // HEPMC_EPOS_COMMON_H
00090
00091
00092 #ifndef HEPMC_EPOS_WRAPPER_H
00093 #define HEPMC_EPOS_WRAPPER_H
00094
00096
00097
00098
00099
00100
00101
00102
00103
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 #include <iostream>
00121 #include <cstdio>
00122
00123 namespace EPOS {
00124
00126
00131 class EPOS_Wrapper {
00132 public:
00133
00135 static void print_hepcom( std::ostream& ostr = std::cout );
00137 static void print_hepcom_particle( int index,
00138 std::ostream& ostr = std::cout );
00140 static void zero_everything();
00141
00143
00145 static int event_number();
00146 static int number_entries();
00147 static int status( int index );
00148 static int id( int index );
00149 static int first_parent( int index );
00150 static int last_parent( int index );
00151 static int number_parents( int index );
00152 static int first_child( int index );
00153 static int last_child( int index );
00154 static int number_children( int index );
00155 static double px( int index );
00156 static double py( int index );
00157 static double pz( int index );
00158 static double e( int index );
00159 static double m( int index );
00160 static double x( int index );
00161 static double y( int index );
00162 static double z( int index );
00163 static double t( int index );
00164
00166
00168
00170 static void set_event_number( int evtno );
00172 static void set_number_entries( int noentries );
00174 static void set_status( int index, int status );
00176 static void set_id( int index, int id );
00178 static void set_parents( int index, int firstparent, int lastparent );
00180 static void set_children( int index, int firstchild, int lastchild );
00182 static void set_momentum( int index, double px, double py,
00183 double pz, double e );
00185 static void set_mass( int index, double mass );
00187 static void set_position( int index, double x, double y, double z,
00188 double t );
00190
00192 static unsigned int sizeof_int();
00193 static unsigned int sizeof_real();
00194 static int max_number_entries();
00195 static void set_sizeof_int(unsigned int);
00196 static void set_sizeof_real(unsigned int);
00197 static void set_max_number_entries(unsigned int);
00198
00199 protected:
00201 static double byte_num_to_double( unsigned int );
00203 static int byte_num_to_int( unsigned int );
00205 static void write_byte_num( double, unsigned int );
00207 static void write_byte_num( int, unsigned int );
00209 static void print_legend( std::ostream& ostr = std::cout );
00210
00211 private:
00212 static unsigned int s_sizeof_int;
00213 static unsigned int s_sizeof_real;
00214 static unsigned int s_max_number_entries;
00215
00216 };
00217
00219
00221 inline unsigned int EPOS_Wrapper::sizeof_int(){ return s_sizeof_int; }
00222
00223 inline unsigned int EPOS_Wrapper::sizeof_real(){ return s_sizeof_real; }
00224
00225 inline int EPOS_Wrapper::max_number_entries()
00226 { return (int)s_max_number_entries; }
00227
00228 inline void EPOS_Wrapper::set_sizeof_int( unsigned int size )
00229 {
00230 if ( size != sizeof(short int) && size != sizeof(long int) && size != sizeof(int) ) {
00231 std::cerr << "HepMC is not able to handle integers "
00232 << " of size other than 2 or 4."
00233 << " You requested: " << size << std::endl;
00234 }
00235 s_sizeof_int = size;
00236 }
00237
00238 inline void EPOS_Wrapper::set_sizeof_real( unsigned int size ) {
00239 if ( size != sizeof(float) && size != sizeof(double) ) {
00240 std::cerr << "HepMC is not able to handle floating point numbers"
00241 << " of size other than 4 or 8."
00242 << " You requested: " << size << std::endl;
00243 }
00244 s_sizeof_real = size;
00245 }
00246
00247 inline void EPOS_Wrapper::set_max_number_entries( unsigned int size ) {
00248 s_max_number_entries = size;
00249 }
00250
00251 inline double EPOS_Wrapper::byte_num_to_double( unsigned int b ) {
00252 if ( b >= epos_bytes_allocation ) std::cerr
00253 << "EPOS_Wrapper: requested hepcom data exceeds allocation"
00254 << std::endl;
00255 if ( s_sizeof_real == sizeof(float) ) {
00256 float* myfloat = (float*)&hepcom.data[b];
00257 return (double)(*myfloat);
00258 } else if ( s_sizeof_real == sizeof(double) ) {
00259 double* mydouble = (double*)&hepcom.data[b];
00260 return (*mydouble);
00261 } else {
00262 std::cerr
00263 << "EPOS_Wrapper: illegal floating point number length."
00264 << s_sizeof_real << std::endl;
00265 }
00266 return 0;
00267 }
00268
00269 inline int EPOS_Wrapper::byte_num_to_int( unsigned int b ) {
00270 if ( b >= epos_bytes_allocation ) std::cerr
00271 << "EPOS_Wrapper: requested hepcom data exceeds allocation"
00272 << std::endl;
00273 if ( s_sizeof_int == sizeof(short int) ) {
00274 short int* myshortint = (short int*)&hepcom.data[b];
00275 return (int)(*myshortint);
00276 } else if ( s_sizeof_int == sizeof(long int) ) {
00277 long int* mylongint = (long int*)&hepcom.data[b];
00278 return (*mylongint);
00279
00280 } else if ( s_sizeof_int == sizeof(int) ) {
00281 int* myint = (int*)&hepcom.data[b];
00282 return (*myint);
00283 } else {
00284 std::cerr
00285 << "EPOS_Wrapper: illegal integer number length."
00286 << s_sizeof_int << std::endl;
00287 }
00288 return 0;
00289 }
00290
00291 inline void EPOS_Wrapper::write_byte_num( double in, unsigned int b ) {
00292 if ( b >= epos_bytes_allocation ) std::cerr
00293 << "EPOS_Wrapper: requested hepcom data exceeds allocation"
00294 << std::endl;
00295 if ( s_sizeof_real == sizeof(float) ) {
00296 float* myfloat = (float*)&hepcom.data[b];
00297 (*myfloat) = (float)in;
00298 } else if ( s_sizeof_real == sizeof(double) ) {
00299 double* mydouble = (double*)&hepcom.data[b];
00300 (*mydouble) = (double)in;
00301 } else {
00302 std::cerr
00303 << "EPOS_Wrapper: illegal floating point number length."
00304 << s_sizeof_real << std::endl;
00305 }
00306 }
00307
00308 inline void EPOS_Wrapper::write_byte_num( int in, unsigned int b ) {
00309 if ( b >= epos_bytes_allocation ) std::cerr
00310 << "EPOS_Wrapper: requested hepcom data exceeds allocation"
00311 << std::endl;
00312 if ( s_sizeof_int == sizeof(short int) ) {
00313 short int* myshortint = (short int*)&hepcom.data[b];
00314 (*myshortint) = (short int)in;
00315 } else if ( s_sizeof_int == sizeof(long int) ) {
00316 long int* mylongint = (long int*)&hepcom.data[b];
00317 (*mylongint) = (int)in;
00318
00319 } else if ( s_sizeof_int == sizeof(int) ) {
00320 int* myint = (int*)&hepcom.data[b];
00321 (*myint) = (int)in;
00322 } else {
00323 std::cerr
00324 << "EPOS_Wrapper: illegal integer number length."
00325 << s_sizeof_int << std::endl;
00326 }
00327 }
00328
00330
00332
00333 inline int EPOS_Wrapper::event_number()
00334 { return byte_num_to_int(0); }
00335
00336 inline int EPOS_Wrapper::number_entries()
00337 {
00338 int nhep = byte_num_to_int( 1*sizeof_int() );
00339 return ( nhep <= max_number_entries() ?
00340 nhep : max_number_entries() );
00341 }
00342
00343 inline int EPOS_Wrapper::status( int index )
00344 { return byte_num_to_int( (2+index-1) * sizeof_int() ); }
00345
00346 inline int EPOS_Wrapper::id( int index )
00347 {
00348 return byte_num_to_int( (2+max_number_entries()+index-1)
00349 * sizeof_int() );
00350 }
00351
00352 inline int EPOS_Wrapper::first_parent( int index )
00353 {
00354 int parent = byte_num_to_int( (2+2*max_number_entries()+2*(index-1))
00355 * sizeof_int() );
00356 return ( parent > 0 && parent <= number_entries() ) ?
00357 parent : 0;
00358 }
00359
00360 inline int EPOS_Wrapper::last_parent( int index )
00361 {
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 int firstparent = first_parent(index);
00372 int parent = byte_num_to_int( (2+2*max_number_entries()+2*(index-1)+1)
00373 * sizeof_int() );
00374 return ( parent > firstparent && parent <= number_entries() )
00375 ? parent : firstparent;
00376 }
00377
00378 inline int EPOS_Wrapper::number_parents( int index ) {
00379 int firstparent = first_parent(index);
00380 return ( firstparent>0 ) ?
00381 ( 1+last_parent(index)-firstparent ) : 0;
00382 }
00383
00384 inline int EPOS_Wrapper::first_child( int index )
00385 {
00386 int child = byte_num_to_int( (2+4*max_number_entries()+2*(index-1))
00387 * sizeof_int() );
00388 return ( child > 0 && child <= number_entries() ) ?
00389 child : 0;
00390 }
00391
00392 inline int EPOS_Wrapper::last_child( int index )
00393 {
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 int firstchild = first_child(index);
00404 int child = byte_num_to_int( (2+4*max_number_entries()+2*(index-1)+1)
00405 * sizeof_int() );
00406 return ( child > firstchild && child <= number_entries() )
00407 ? child : firstchild;
00408 }
00409
00410 inline int EPOS_Wrapper::number_children( int index )
00411 {
00412 int firstchild = first_child(index);
00413 return ( firstchild>0 ) ?
00414 ( 1+last_child(index)-firstchild ) : 0;
00415 }
00416
00417 inline double EPOS_Wrapper::px( int index )
00418 {
00419 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00420 + (5*(index-1)+0) *sizeof_real() );
00421 }
00422
00423 inline double EPOS_Wrapper::py( int index )
00424 {
00425 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00426 + (5*(index-1)+1) *sizeof_real() );
00427 }
00428
00429
00430 inline double EPOS_Wrapper::pz( int index )
00431 {
00432 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00433 + (5*(index-1)+2) *sizeof_real() );
00434 }
00435
00436 inline double EPOS_Wrapper::e( int index )
00437 {
00438 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00439 + (5*(index-1)+3) *sizeof_real() );
00440 }
00441
00442 inline double EPOS_Wrapper::m( int index )
00443 {
00444 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00445 + (5*(index-1)+4) *sizeof_real() );
00446 }
00447
00448 inline double EPOS_Wrapper::x( int index )
00449 {
00450 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00451 + ( 5*max_number_entries()
00452 + (4*(index-1)+0) ) *sizeof_real() );
00453 }
00454
00455 inline double EPOS_Wrapper::y( int index )
00456 {
00457 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00458 + ( 5*max_number_entries()
00459 + (4*(index-1)+1) ) *sizeof_real() );
00460 }
00461
00462 inline double EPOS_Wrapper::z( int index )
00463 {
00464 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00465 + ( 5*max_number_entries()
00466 + (4*(index-1)+2) ) *sizeof_real() );
00467 }
00468
00469 inline double EPOS_Wrapper::t( int index )
00470 {
00471 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
00472 + ( 5*max_number_entries()
00473 + (4*(index-1)+3) ) *sizeof_real() );
00474 }
00475
00476 inline void EPOS_Wrapper::set_event_number( int evtno )
00477 { write_byte_num( evtno, 0 ); }
00478
00479 inline void EPOS_Wrapper::set_number_entries( int noentries )
00480 { write_byte_num( noentries, 1*sizeof_int() ); }
00481
00482 inline void EPOS_Wrapper::set_status( int index, int status )
00483 {
00484 if ( index <= 0 || index > max_number_entries() ) return;
00485 write_byte_num( status, (2+index-1) * sizeof_int() );
00486 }
00487
00488 inline void EPOS_Wrapper::set_id( int index, int id )
00489 {
00490 if ( index <= 0 || index > max_number_entries() ) return;
00491 write_byte_num( id, (2+max_number_entries()+index-1) *sizeof_int() );
00492 }
00493
00494 inline void EPOS_Wrapper::set_parents( int index, int firstparent,
00495 int lastparent )
00496 {
00497 if ( index <= 0 || index > max_number_entries() ) return;
00498 write_byte_num( firstparent, (2+2*max_number_entries()+2*(index-1))
00499 *sizeof_int() );
00500 write_byte_num( lastparent, (2+2*max_number_entries()+2*(index-1)+1)
00501 * sizeof_int() );
00502 }
00503
00504 inline void EPOS_Wrapper::set_children( int index, int firstchild,
00505 int lastchild )
00506 {
00507 if ( index <= 0 || index > max_number_entries() ) return;
00508 write_byte_num( firstchild, (2+4*max_number_entries()+2*(index-1))
00509 *sizeof_int() );
00510 write_byte_num( lastchild, (2+4*max_number_entries()+2*(index-1)+1)
00511 *sizeof_int() );
00512 }
00513
00514 inline void EPOS_Wrapper::set_momentum( int index, double px,
00515 double py, double pz, double e )
00516 {
00517 if ( index <= 0 || index > max_number_entries() ) return;
00518 write_byte_num( px, (2+6*max_number_entries()) *sizeof_int()
00519 + (5*(index-1)+0) *sizeof_real() );
00520 write_byte_num( py, (2+6*max_number_entries())*sizeof_int()
00521 + (5*(index-1)+1) *sizeof_real() );
00522 write_byte_num( pz, (2+6*max_number_entries())*sizeof_int()
00523 + (5*(index-1)+2) *sizeof_real() );
00524 write_byte_num( e, (2+6*max_number_entries())*sizeof_int()
00525 + (5*(index-1)+3) *sizeof_real() );
00526 }
00527
00528 inline void EPOS_Wrapper::set_mass( int index, double mass )
00529 {
00530 if ( index <= 0 || index > max_number_entries() ) return;
00531 write_byte_num( mass, (2+6*max_number_entries())*sizeof_int()
00532 + (5*(index-1)+4) *sizeof_real() );
00533 }
00534
00535 inline void EPOS_Wrapper::set_position( int index, double x, double y,
00536 double z, double t )
00537 {
00538 if ( index <= 0 || index > max_number_entries() ) return;
00539 write_byte_num( x, (2+6*max_number_entries())*sizeof_int()
00540 + ( 5*max_number_entries()
00541 + (4*(index-1)+0) ) *sizeof_real() );
00542 write_byte_num( y, (2+6*max_number_entries())*sizeof_int()
00543 + ( 5*max_number_entries()
00544 + (4*(index-1)+1) ) *sizeof_real() );
00545 write_byte_num( z, (2+6*max_number_entries())*sizeof_int()
00546 + ( 5*max_number_entries()
00547 + (4*(index-1)+2) ) *sizeof_real() );
00548 write_byte_num( t, (2+6*max_number_entries())*sizeof_int()
00549 + ( 5*max_number_entries()
00550 + (4*(index-1)+3) ) *sizeof_real() );
00551 }
00552
00553 inline void EPOS_Wrapper::zero_everything()
00554 {
00555 set_event_number( 0 );
00556 set_number_entries( 0 );
00557 for ( int i = 1; i<=max_number_entries(); ++i ) {
00558 set_status( i, 0 );
00559 set_id( i, 0 );
00560 set_parents( i, 0, 0 );
00561 set_children( i, 0, 0 );
00562 set_momentum( i, 0, 0, 0, 0 );
00563 set_mass( i, 0 );
00564 set_position( i, 0, 0, 0, 0 );
00565 }
00566 }
00567
00568 inline void EPOS_Wrapper::print_hepcom( std::ostream& ostr )
00569 {
00570 ostr << "________________________________________"
00571 << "________________________________________" << std::endl;
00572 ostr << "***** HEPEVT Common Event#: "
00573 << event_number()
00574 << ", " << number_entries() << " particles (max "
00575 << max_number_entries() << ") *****";
00576 ostr << sizeof_int() << "-byte integers, "
00577 << sizeof_real() << "-byte floating point numbers, "
00578 << max_number_entries() << "-allocated entries."
00579 << std::endl;
00580 print_legend(ostr);
00581 ostr << "________________________________________"
00582 << "________________________________________" << std::endl;
00583 for ( int i=1; i <= number_entries(); ++i ) {
00584 print_hepcom_particle( i, ostr );
00585 }
00586 ostr << "________________________________________"
00587 << "________________________________________" << std::endl;
00588 }
00589
00590 inline void EPOS_Wrapper::print_hepcom_particle( int i, std::ostream& ostr )
00591 {
00592 char outline[81];
00593 sprintf( outline,
00594 "%4d %+4d %4d %4d (%9.3g, %9.3g, %9.3g, %9.3g, %9.3g)"
00595 ,i, status(i), first_parent(i), first_child(i),
00596 px(i), py(i), pz(i), e(i), m(i) );
00597 ostr << outline << "\n";
00598 sprintf( outline,"%+9d %4d %4d (%9.3g, %9.3g, %9.3g, %9.3g)",
00599
00600 id(i), last_parent(i), last_child(i),
00601 x(i), y(i), z(i), t(i) );
00602 ostr << outline << std::endl;
00603 }
00604
00605 inline void EPOS_Wrapper::print_legend( std::ostream& ostr )
00606 {
00607 char outline[81];
00608 sprintf( outline,"%4s %4s %4s %5s %10s, %9s, %9s, %9s, %10s",
00609 "Indx","Stat","Par-","chil-",
00610 "( P_x","P_y","P_z","Energy","M ) ");
00611 ostr << outline << std::endl;
00612 sprintf( outline,"%9s %4s %4s %10s, %9s, %9s, %9s) %9s",
00613 "ID ","ents","dren",
00614 "Prod ( X","Y","Z","cT", "[mm]");
00615 ostr << outline << std::endl;
00616 }
00617
00618 }
00619
00620 #endif // HEPMC_EPOS_WRAPPER_H
00621
00622