Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 1597)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 1674)
@@ -21,7 +21,7 @@
 //
 // $RCSfile: camera.cxx,v $
-// $Revision: 1.46 $
+// $Revision: 1.47 $
 // $Author: blanch $ 
-// $Date: 2002-11-08 17:51:00 $
+// $Date: 2002-12-10 17:19:31 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -408,4 +408,5 @@
 
   char flag[SIZE_OF_FLAGS + 1];  //@< flags in the .rfl file
+  char flag_new[4];              //@< New flag for the run header in the .rfl file
 
   int reflector_file_version;  //@< vrsion of he reflector file
@@ -1218,6 +1219,4 @@
     if(!isA( flag, FLAG_START_OF_RUN )){
 
-      //  We exit
-      //error( SIGNATURE, "Expected start of run flag, but found: %s\n", flag );
       //  We break the main loop
       cout<<"Warning: Expected start of run flag, but found:"<<flag<<endl;
@@ -1227,4 +1226,18 @@
     else { // found start of run
 
+      fread( flag_new, 4, 1, inputfile );
+
+      if(!isA( flag_new, FLAG_START_OF_HEADER)){
+
+	//  We break the main loop
+	cout<<"Warning: Expected start of run header flag, but found:"<<flag<<endl;
+	cout<<"         We break the main loop"<<endl;
+	break;      
+      }
+
+      Float_t flag_temp[SIZE_OF_MCRUNHEADER];
+      
+      fread( flag_temp, (SIZE_OF_MCRUNHEADER)*sizeof(float), 1, inputfile );
+
       nshow=0;
 
@@ -1232,4 +1245,14 @@
 
       while( isA( flag, FLAG_START_OF_EVENT   )){ // while there is a next event
+	fread( flag_new, 4, 1, inputfile );
+
+	if(!isA( flag_new, FLAG_EVENT_HEADER)){
+
+	//  We break while events loop
+	  cout<<"Warning: Expected start of event header flag, but found:"<<flag<<endl;
+	  cout<<"         We break the while events loop"<<endl;
+	  break;      
+	}
+
 	//
 	// Clear Trigger and Fadc
@@ -1279,5 +1302,5 @@
 	
 	// read the direction of the incoming shower
-	
+
 	if (reflector_file_version<6){
 	  thetashw = mcevth.get_theta();
@@ -1758,5 +1781,72 @@
 	    
 	    if (Write_McEvt){
-		}
+	      Float_t ftime, ltime;
+	      if (reflector_file_version<6){
+		mcevth.get_times(&ftime, &ltime);
+		McEvt->Fill( -1.0, 
+			     (UShort_t) mcevth.get_primary() , 
+			     mcevth.get_energy(),
+			     -1.0,
+			     -1.0,
+			     -1.0, 
+			     mcevth.get_theta(), 
+			     mcevth.get_phi(), 
+			     mcevth.get_core(),
+			     mcevth.get_coreX(),
+			     mcevth.get_coreY(),
+			     impactD,
+			     mcevth_2.get_theta_CT(),
+			     mcevth_2.get_phi_CT(),
+			     ftime,
+			     ltime,
+			     0,
+			     0,
+			     0,
+			     0,
+			     0,
+			     0,
+			     0,
+			     (UInt_t)mcevth.get_CORSIKA(), 
+			     (UInt_t)mcevth.get_AtmAbs(), 
+			     (UInt_t)mcevth.get_MirrAbs()+mcevth.get_OutOfMirr()+mcevth.get_BlackSpot(), 
+			     (UInt_t) ncph, 
+			     (UInt_t) inumphe,
+			     (UInt_t) inumphensb+inumphe);
+	      }
+	      else{
+		Float_t Nmax, t0, tmax, a, b, c, chi2;
+		mcevth.get_times(&ftime, &ltime);
+		chi2=mcevth_2.get_NKGfit(&Nmax, &t0, &tmax, &a, &b, &c);
+		McEvt->Fill( mcevth_2.get_evt_number(),
+			     (UShort_t) mcevth_2.get_primary() , 
+			     mcevth_2.get_energy(),
+			     mcevth_2.get_thick0(),
+			     mcevth_2.get_first_target(),
+			     mcevth_2.get_z_first_int(),
+			     mcevth_2.get_theta(), 
+			     mcevth_2.get_phi(), 
+			     mcevth_2.get_core(),
+			     mcevth_2.get_coreX(),
+			     mcevth_2.get_coreY(),
+			     impactD,
+			     mcevth_2.get_theta_CT(),
+			     mcevth_2.get_phi_CT(),
+			     ftime,
+			     ltime,
+			     Nmax,
+			     t0,
+			     tmax,
+			     a,
+			     b,
+			     c,
+			     chi2,
+			     (UInt_t)mcevth_2.get_CORSIKA(), 
+			     (UInt_t)mcevth_2.get_AtmAbs(), 
+			     (UInt_t)mcevth_2.get_MirrAbs()+mcevth_2.get_OutOfMirr()+mcevth_2.get_BlackSpot(), 
+			     (UInt_t) ncph, 
+			     (UInt_t) inumphe,
+			     (UInt_t) inumphensb+inumphe);
+	      }
+	    }
 	    //   We don not count photons out of the camera.	
 	    
@@ -1833,4 +1923,5 @@
       if( !isA( flag, FLAG_END_OF_RUN   )){
 	error( SIGNATURE, "Expected end of run flag, but found: %s\n", flag );
+	break;
       }
       else { // found end of run
@@ -1843,5 +1934,7 @@
 	  log(SIGNATURE, "End of file . . .\n");
 	  still_in_loop  = FALSE;
-  
+	  log(SIGNATURE, "Reading ASCII files at the end of the reflector file.  . .\n");
+	  read_ascii(inputfile);
+	  break;
 	  if ((! Data_From_STDIN) && ( !feof(inputfile) )){
 	    
@@ -1850,5 +1943,8 @@
 
 	    if((reflector_file_version=check_reflector_file( inputfile ))==FALSE){
-	      exit(1);
+	      // exit(1);
+	      log(SIGNATURE, "Next file is not recognised as a reflector file.\n");
+	      log(SIGNATURE, "Stopping ...\n");
+	      break;
 	    }
 	    
@@ -1916,5 +2012,5 @@
 		    mcevth.get_CWaveUpper(),
 		    mcevth.get_slope(),
-		    mcevth.get_NumObsLev(),
+		    1,
 		    heights,
 		    corsika,
@@ -1922,5 +2018,5 @@
 		    (UInt_t)(VERSION*100),
 		    0);
-  
+
   //  Fill the Header Tree with the current leaves of each branch
   HeaderTree.Fill() ;
@@ -2725,4 +2821,19 @@
 //!@}
 
+//!-----------------------------------------------------------
+// @name read_ascii  
+//                          
+// @desc read ascii configuration files used by the reflector
+//
+// @date tue dec 10 17:14:10 CET 2002
+//------------------------------------------------------------
+// @function
+
+//!@{
+void 
+read_ascii(FILE *sp)
+{
+  cout<<"To be implemented..."<<endl;
+}
 
 //!-----------------------------------------------------------
@@ -3684,4 +3795,7 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.46  2002/11/08 17:51:00  blanch
+// *** empty log message ***
+//
 // Revision 1.45  2002/10/29 17:15:27  blanch
 // Reading several reflector versions.
@@ -3823,4 +3937,7 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.46  2002/11/08 17:51:00  blanch
+// *** empty log message ***
+//
 // Revision 1.45  2002/10/29 17:15:27  blanch
 // Reading several reflector versions.
