Index: trunk/MagicSoft/Simulation/Corsika/MaxiSingle/Makefile
===================================================================
--- trunk/MagicSoft/Simulation/Corsika/MaxiSingle/Makefile	(revision 790)
+++ trunk/MagicSoft/Simulation/Corsika/MaxiSingle/Makefile	(revision 790)
@@ -0,0 +1,227 @@
+##################################################################
+#
+# makefile
+#
+# @file        makefile 
+# @title       Simulation of the camera and trigger logic
+# @author      J C Gonz\'alez
+# @email       gonzalez@mppmu.mpg.de
+# @date        Fri Mar 12 11:51:11 MET 1999
+#
+#_______________________________________________________________
+#
+# Created: Fri Mar 12 11:51:11 MET 1999
+# Author:  Jose Carlos Gonzalez
+# Purpose: Makefile for the compilation of the camera program
+# Notes:   
+#    
+#---------------------------------------------------------------
+#
+# $RCSfile: Makefile,v $
+# $Revision: 1.1.1.1 $
+# $Author: domingo $ 
+# $Date: 2001-05-16 12:02:20 $
+#
+##################################################################
+# @maintitle
+
+# @code
+
+INCLUDEMK = config.mk.${OSTYPE}
+include ${INCLUDEMK}
+
+# @endcode
+
+# @code 
+
+# common flags
+INCLUDES = -I${INCLUDE}      \
+	   -I${INCLUDE_COR}  \
+	   -I${INCLUDE_ROOT}  \
+	   -I${INCLUDE_SIMO} \
+           -I/usr/include  -I/usr/include/g++
+
+RANLIB  = -L${RANLIBDIR} -lranlib
+
+# what is needed for ROOT is declared in config.mk file
+
+
+# special flags
+
+osf_FORLIBS = -lUfor -lfor -lutil -lots -lm 
+linux_FORLIBS = -lm 
+generic_FORLIBS = -lm 
+
+FORLIBS = ${${SYSTEM}_FORLIBS}
+
+# compilation and linking flags
+
+CXXFLAGS  = -D__${SYSTEM}__ ${INCLUDES} ${OPTIM} ${DEBUG}
+CFLAGS    = ${CXXFLAGS}
+FFLAGS    = ${CXXFLAGS}
+LIBS      = ${RANLIB} ${ROOTLIBS} ${ROOTGLIBS} ${GLIBS} ${FORLIBS} 
+#LIBS      = ${CERNLIB} ${RANLIB} ${FORLIBS} 
+
+#------------------------------------------------------------------------------
+
+#.SILENT:
+
+.SUFFIXES: .c .cxx .C .c++ .h .hxx .H .h++ .o .so .f
+
+SRCS = \
+	${INCLUDE_COR}/CORRunHeader.cxx \
+	${INCLUDE_COR}/CORRunEnd.cxx \
+	${INCLUDE_COR}/COREventHeader.cxx \
+	${INCLUDE_COR}/COREventEnd.cxx \
+	${INCLUDE_COR}/CORParticle.cxx \
+	maxisingle.cxx      
+
+HEADERS = \
+	${INCLUDE_COR}/CORRunHeader.hxx \
+ 	${INCLUDE_COR}/CORRunEnd.hxx \
+	${INCLUDE_COR}/COREventHeader.hxx \
+	${INCLUDE_COR}/COREventEnd.hxx \
+	${INCLUDE_COR}/CORParticle.hxx \
+	maxisingle.hxx
+
+OBJS = \
+	${INCLUDE_COR}/CORRunHeader.o \
+        ${INCLUDE_COR}/CORRunEnd.o \
+	${INCLUDE_COR}/COREventHeader.o \
+	${INCLUDE_COR}/COREventEnd.o \
+	${INCLUDE_COR}/CORParticle.o \
+	maxisingle.o     
+
+PROGRAM=maxisingle
+
+############################################################
+
+all: ${PROGRAM}
+
+depend:
+	@makedepend $(SRCS) -fMakefile 2> /dev/null
+
+doc: reflector-doc
+
+reflector-doc: 
+	@echo "Generating documentation for camera . . . "
+	$(DOCUM) -latex -o reflector.tex \
+	reflector.cxx reflector.h \
+	readparam.cxx readparam.h \
+	atm.cxx atm.h
+	latex "\nonstopmode\input{reflector.tex}" && \
+	makeindex reflector && \
+	latex "\nonstopmode\input{reflector.tex}" && \
+	latex "\nonstopmode\input{reflector.tex}"
+	@echo "Files reflector.tex and reflector.dvi generated."
+
+rate: 
+	@echo "Rating documentation inside code . . . "
+	$(RATE) \
+	reflector.cxx reflector.h \
+	readparam.cxx readparam.h \
+	atm.cxx atm.h
+
+${PROGRAM}: $(OBJS)
+	@echo "Linking..." $@
+	$(CXX) $(CXXFLAGS) $(OBJS) $(LIBS) -o $@
+	@echo "done."
+
+.cxx.o:	
+	@echo "Compiling " $<
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+.c.o:	
+	@echo "Compiling " $<
+	$(CC) $(CFLAGS) -c $< -o $@
+
+.f.o:	
+	@echo "Compiling " $<
+	$(F77) $(FFLAGS) -c $< -o $@
+
+lclean:
+	@echo "Cleanning..."
+	@rm -f *.o core 
+
+clean:
+	@echo "Cleanning..."
+	@rm -f $(OBJS) core 
+
+mrproper: clean
+	@echo "Mr.Proper in action . . ."
+	@rm -f $(PROGRAM)
+
+ctags:
+	@echo "Creating CTAGS file . . ."
+	@ctags -txw $(SRCS) $(HEADERS) > CTAGS
+
+etags:
+	@echo "Creating TAGS file . . ."
+	@etags -C $(SRCS) $(HEADERS)
+
+listsrc:
+	@ls -m $(SRCS) $(HEADERS) | sed 's/,//g'
+
+redo: clean all
+
+# @endcode
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+../../Detector/include-CORSIKA/CORRunHeader.o: ../../Detector/include-CORSIKA/CORRunHeader.hxx
+../../Detector/include-CORSIKA/CORRunHeader.o: /usr/include/stdlib.h
+../../Detector/include-CORSIKA/CORRunHeader.o: /usr/include/standards.h
+../../Detector/include-CORSIKA/CORRunHeader.o: /usr/include/getopt.h
+../../Detector/include-CORSIKA/CORRunHeader.o: /usr/include/sys/types.h
+../../Detector/include-CORSIKA/CORRunHeader.o: /usr/include/mach/machine/vm_types.h
+../../Detector/include-CORSIKA/CORRunHeader.o: /usr/include/sys/select.h
+../../Detector/include-CORSIKA/CORRunHeader.o: /usr/include/math.h
+../../Detector/include-CORSIKA/CORRunHeader.o: ../../Detector/include-CORSIKA/COREventHeader.hxx
+../../Detector/include-CORSIKA/CORRunEnd.o: ../../Detector/include-CORSIKA/CORRunEnd.hxx
+../../Detector/include-CORSIKA/CORRunEnd.o: /usr/include/stdlib.h
+../../Detector/include-CORSIKA/CORRunEnd.o: /usr/include/standards.h
+../../Detector/include-CORSIKA/CORRunEnd.o: /usr/include/getopt.h
+../../Detector/include-CORSIKA/CORRunEnd.o: /usr/include/sys/types.h
+../../Detector/include-CORSIKA/CORRunEnd.o: /usr/include/mach/machine/vm_types.h
+../../Detector/include-CORSIKA/CORRunEnd.o: /usr/include/sys/select.h
+../../Detector/include-CORSIKA/CORRunEnd.o: /usr/include/math.h
+../../Detector/include-CORSIKA/CORRunEnd.o: ../../Detector/include-CORSIKA/COREventHeader.hxx
+../../Detector/include-CORSIKA/COREventHeader.o: ../../Detector/include-CORSIKA/COREventHeader.hxx
+../../Detector/include-CORSIKA/COREventHeader.o: /usr/include/stdlib.h
+../../Detector/include-CORSIKA/COREventHeader.o: /usr/include/standards.h
+../../Detector/include-CORSIKA/COREventHeader.o: /usr/include/getopt.h
+../../Detector/include-CORSIKA/COREventHeader.o: /usr/include/sys/types.h
+../../Detector/include-CORSIKA/COREventHeader.o: /usr/include/mach/machine/vm_types.h
+../../Detector/include-CORSIKA/COREventHeader.o: /usr/include/sys/select.h
+../../Detector/include-CORSIKA/COREventHeader.o: /usr/include/math.h
+../../Detector/include-CORSIKA/COREventEnd.o: ../../Detector/include-CORSIKA/COREventEnd.hxx
+../../Detector/include-CORSIKA/COREventEnd.o: /usr/include/stdlib.h
+../../Detector/include-CORSIKA/COREventEnd.o: /usr/include/standards.h
+../../Detector/include-CORSIKA/COREventEnd.o: /usr/include/getopt.h
+../../Detector/include-CORSIKA/COREventEnd.o: /usr/include/sys/types.h
+../../Detector/include-CORSIKA/COREventEnd.o: /usr/include/mach/machine/vm_types.h
+../../Detector/include-CORSIKA/COREventEnd.o: /usr/include/sys/select.h
+../../Detector/include-CORSIKA/COREventEnd.o: /usr/include/math.h
+../../Detector/include-CORSIKA/CORParticle.o: ../../Detector/include-CORSIKA/CORParticle.hxx
+../../Detector/include-CORSIKA/CORParticle.o: /usr/include/stdlib.h
+../../Detector/include-CORSIKA/CORParticle.o: /usr/include/standards.h
+../../Detector/include-CORSIKA/CORParticle.o: /usr/include/getopt.h
+../../Detector/include-CORSIKA/CORParticle.o: /usr/include/sys/types.h
+../../Detector/include-CORSIKA/CORParticle.o: /usr/include/mach/machine/vm_types.h
+../../Detector/include-CORSIKA/CORParticle.o: /usr/include/sys/select.h
+../../Detector/include-CORSIKA/CORParticle.o: /usr/include/math.h
+maxisingle.o: /usr/include/stdlib.h /usr/include/standards.h
+maxisingle.o: /usr/include/getopt.h /usr/include/sys/types.h
+maxisingle.o: /usr/include/mach/machine/vm_types.h /usr/include/sys/select.h
+maxisingle.o: /usr/include/stdio.h /usr/include/sys/seek.h
+maxisingle.o: /usr/include/va_list.h /usr/include/sys/limits.h
+maxisingle.o: /usr/include/sys/machine/machlimits.h
+maxisingle.o: /usr/include/sys/syslimits.h
+maxisingle.o: /usr/include/sys/machine/machtime.h
+maxisingle.o: /usr/include/sys/rt_limits.h
+maxisingle.o: ../../Detector/include-CORSIKA/COREventHeader.hxx
+maxisingle.o: /usr/include/math.h
+maxisingle.o: ../../Detector/include-CORSIKA/COREventEnd.hxx
+maxisingle.o: ../../Detector/include-CORSIKA/CORParticle.hxx
+maxisingle.o: ../../Detector/include-CORSIKA/CORRunHeader.hxx
+maxisingle.o: ../../Detector/include-CORSIKA/CORRunEnd.hxx
Index: trunk/MagicSoft/Simulation/Corsika/MaxiSingle/config.mk.linux-gnu
===================================================================
--- trunk/MagicSoft/Simulation/Corsika/MaxiSingle/config.mk.linux-gnu	(revision 790)
+++ trunk/MagicSoft/Simulation/Corsika/MaxiSingle/config.mk.linux-gnu	(revision 790)
@@ -0,0 +1,71 @@
+##################################################################
+#
+# config.mk
+#
+# @file        config.mk
+# @title       small configuration file for Makefile
+# @author      J C Gonz\'alez
+# @email       gonzalez@mppmu.mpg.de
+# @date        Fri Mar 12 11:51:11 MET 1999
+#
+#_______________________________________________________________
+#
+# Created: Fri Mar 12 11:51:11 MET 1999
+# Author:  Jose Carlos Gonzalez
+# Purpose: Makefile for the compilation of the reflector program
+# Notes:   
+#    
+#---------------------------------------------------------------
+# $RCSfile: config.mk.linux-gnu,v $
+# $Revision: 1.1.1.1 $
+# $Author: domingo $ 
+# $Date: 2001-05-16 12:02:20 $
+##################################################################
+# @maintitle
+
+# @code
+
+# program
+
+# PROGRAM = camera
+
+# compilers & tools
+
+CC            = gcc
+CXX           = g++
+F77           = g77
+
+DOCUM         = ../sus/sus
+RATE          = ../../comstat/comstat -g -p 
+
+# includes		
+
+INCLUDE       = ../../Detector/include-GENERAL
+INCLUDE_COR   = ../../Detector/include-CORSIKA
+INCLUDE_ROOT  = ${ROOTSYS}/include  
+INCLUDE_SIMO  = .
+
+OPTIM    = 
+DEBUG    = -g
+
+# libraries
+
+
+ROOTLIBS      = -L/cern/root/lib -lNew -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lm -ldl -lpthread -rdynamic 
+
+ROOTGLIBS     = -lGpad -lGui -lGX11 -lX3d -lX11
+
+
+GLIBS         = $(ROOTLIBS) $(ROOTGLIBS) -L/usr/X11R6/lib \
+                -lXpm -lX11  -lm -ldl 
+
+
+RANLIBDIR = ../../Detector/lib
+CERNDIR = /CERN
+
+# system
+
+SYSTEM  = linux
+
+# @endcode
+##EOF
Index: trunk/MagicSoft/Simulation/Corsika/MaxiSingle/config.mk.osf1
===================================================================
--- trunk/MagicSoft/Simulation/Corsika/MaxiSingle/config.mk.osf1	(revision 790)
+++ trunk/MagicSoft/Simulation/Corsika/MaxiSingle/config.mk.osf1	(revision 790)
@@ -0,0 +1,73 @@
+
+##################################################################
+#
+# config.mk
+#
+# @file        config.mk
+# @title       small configuration file for Makefile
+# @author      J C Gonz\'alez
+# @email       gonzalez@mppmu.mpg.de
+# @date        Fri Mar 12 11:51:11 MET 1999
+#
+#_______________________________________________________________
+#
+# Created: Fri Mar 12 11:51:11 MET 1999
+# Author:  Jose Carlos Gonzalez
+# Purpose: Makefile for the compilation of the reflector program
+# Notes:   
+#    
+#---------------------------------------------------------------
+# $RCSfile: config.mk.osf1,v $
+# $Revision: 1.1.1.1 $
+# $Author: domingo $ 
+# $Date: 2001-05-16 12:02:20 $
+##################################################################
+# @maintitle
+
+# @code
+
+# program
+
+#PROGRAM = camera
+
+# compilers & tools
+
+CC            = cc
+CXX           = cxx
+F77           = f77
+
+DOCUM         = ../sus/sus
+RATE          = ../../comstat/comstat -g -p 
+
+# includes		
+
+INCLUDE       = ../../Detector/include-GENERAL
+INCLUDE_COR   = ../../Detector/include-CORSIKA
+INCLUDE_ROOT  = ${ROOTSYS}/include  
+INCLUDE_SIMO  = .
+
+OPTIM    = -O
+DEBUG    = -g
+
+# libraries
+
+ROOTLIBS =  	-L/CERN/root/lib -lNew -lCore -lCint -lHist \
+		-lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript \
+		-lMatrix -lPhysics -lm  
+
+ROOTGLIBS = 	-L/CERN/root/lib -lNew -lCore -lCint -lHist \
+		-lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript \
+		-lMatrix -lPhysics -lGui -lm  
+
+GLIBS = 	$(ROOTLIBS) $(ROOTGLIBS)
+
+
+RANLIBDIR = ../../Detector/lib
+CERNDIR = /CERN
+
+# system
+
+SYSTEM  = osf
+
+# @endcode
+##EOF
Index: trunk/MagicSoft/Simulation/Corsika/MaxiSingle/maxisingle.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Corsika/MaxiSingle/maxisingle.cxx	(revision 790)
+++ trunk/MagicSoft/Simulation/Corsika/MaxiSingle/maxisingle.cxx	(revision 790)
@@ -0,0 +1,243 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+//  PROGRAM MaxiSingle
+//
+//  MAXI files (multiple event) built form SINGLE event files
+//  version 1.0
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+//
+//  AUTHOR Carles Domingo
+//  May 15, 2001
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+//  PROCEDURE
+//
+//  This program reads a set of files in the old MMCS output format (one
+//  file per event) and writes the information from those files in the
+//  new MMCS output format (one file per run).
+//
+//  To perform this task, the information to fill in the Run headers, the
+//  run end records and the event end record (which were missing in the
+//  old format files) has to be rebuilt from the information read for
+//  the events.
+//
+//  Some new CORtype classes had to be defined to cope with this 
+//  information in an adequate way. The classes COREventEnd, CORRunHeader
+//  and CORRunEnd are now defined and operational.
+//
+//  In order to run the program you must supply as an argument the full
+//  path of a directory containing the output files (cer and dat), starting
+//  from 000001 of a given (old) MMCS run. The program will automatically  
+//  create inside this directory two files (named cer_allfiles and 
+//  dat_allfiles) containing the information of the complete run in the
+//  new single file per run output format. Afterwards you can use this files
+//  for the new reflector, camera, and guisimone programs. 
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+//  REMARKS
+//
+//  Tricky stuff for locating the event ends in the dat FILES!! See comments
+//  on the program
+//
+//
+//   ATTENTION: The estructure of the input CER files and that of 
+//   the DAT files is different in the "one file per event" version 
+//   of the MMCS program. 
+//
+//   CER files have:
+//     Event header EVTH
+//     A bunch of cerenkov photons (in blocks of 7*39=273 bytes)
+//
+//   while DAT files have:
+//     Event header EVTH
+//     A bunch of particles (in blocks of 7*39=273 bytes)
+//     Event end EVTE
+//
+/////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////// 
+//
+//  NOTE
+//
+//  If anybody modifies this program, make sure it is well documented !!!!
+//
+/////////////////////////////////////////////////////////////////////////////
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "COREventHeader.hxx"
+#include "COREventEnd.hxx"
+#include "CORParticle.hxx"
+#include "CORRunHeader.hxx"
+#include "CORRunEnd.hxx"
+
+int main(int argc, char **argv)
+{
+  char  incername[120] ;
+  char  indatname[120] ;
+  char  outcername[120] ;
+  char  outdatname[120] ;
+
+  Float_t  NumberRun ;
+  Float_t  EvtsProc ;  
+  Float_t  TestVal ;
+
+  ifstream   incerfile ;
+  ifstream   indatfile ;
+  ofstream   outcerfile ;
+  ofstream   outdatfile ; 
+  
+  COREventHeader Event ;
+  COREventHeader EventDat ;
+  COREventEnd    EventE ;   
+  CORParticle    Photon ;
+  CORParticle    Particle ; 
+  CORRunHeader   Run ;
+  CORRunEnd      RunE ;
+  
+  cout << " ============================================================" << endl ; 
+  cout << " MaxiSingle" << endl ; 
+  cout << "       " << endl ; 
+  cout << " MAXI (multiple events) file from SINGLE event multiple files" << endl ; 
+  cout << "       " << endl ; 
+  cout << " ============================================================" << endl ; 
+
+  if ( argc <= 1 ) {
+    cout << endl ; 
+    cout << " INFO: You have to start the program with "<< endl << endl ; 
+    cout << "        -> maxisingle DIRECTORY_WITH_CER_FILES" << endl << endl ; 
+    cout << "        no SLASH at the end of the directory name"<< endl ; 
+    cout << "        (example: -> maxisingle /hd123/Protons   "<< endl ;
+    cout << "  " << endl ; 
+    exit (-1) ; 
+  }
+
+  //   create and open the OUTput filenames
+  
+  sprintf ( outcername, "%s/cer_allfiles", argv[1] ) ;
+  sprintf ( outdatname, "%s/dat_allfiles", argv[1] ) ;
+  outcerfile.open (outcername) ;
+  if ( outcerfile.bad() ) { 
+    cout << "Cannot open CER output file:  " << outcername << endl ;
+    exit (1) ; 
+  } 
+  outdatfile.open (outdatname) ;
+  if ( outdatfile.bad() ) { 
+    cout << "Cannot open DAT output file:  " << outdatname << endl ;
+    exit (1) ; 
+  }   
+
+  EvtsProc = 0 ;
+  for (int i_cer = 1; i_cer <= 100000; i_cer++ ) {
+
+    //   inform about progress
+      
+    if (!( i_cer %100) ) cout << " Processing event number: " << i_cer << endl ; 
+   
+    //   create the file names 
+      
+    sprintf ( incername, "%s/cer%06d", argv[1], i_cer ) ;
+    sprintf ( indatname, "%s/dat%06d", argv[1], i_cer ) ; 
+      
+    //   try to open the files
+      
+    incerfile.open( incername );
+    if ( incerfile.bad() )  break ;
+    indatfile.open( indatname );
+    if ( indatfile.bad() )  break ;
+
+    //   read and write the event header
+      
+    Event.read( incerfile ) ;
+    EventDat.read( indatfile ) ;
+  
+    //   if first event, create and write a RUN header in
+    //   both outcerfile and outdatfile
+  
+    if (i_cer == 1 ) { 
+      //      Event.print() ;
+      Run.transport (&Event) ;
+      NumberRun = Run.get_number () ;
+      Run.write (outcerfile) ;
+      Run.write (outdatfile) ;
+      //      Run.print () ;
+    }
+   
+    Event.write( outcerfile ) ;
+    EventDat.write( outdatfile ) ;
+    EvtsProc++ ;
+      
+    //   loop over the photons in incerfile, read and write them
+      
+    while( ! (incerfile.eof() || incerfile.bad() )) {
+      Photon.read ( incerfile ) ;
+      Photon.write ( outcerfile ) ;
+    }
+    
+    //   loop over the particles in indatfile, read and write them
+    //   This procedure is somewhat tricky, in order to find the event end record
+    
+    while( ! (indatfile.eof() || indatfile.bad() )) {
+      
+      Particle.read ( indatfile ) ; 
+      //      Particle.print () ;       
+
+      //  TRICKY STUFF
+      //
+      //  here we get the value which is in the first position of the particle
+      //  record. Whenever there is a particle, this Float_t variable has an
+      //  integer value. If there is no particle (but we still have a particle 
+      //  type record that MMCS has filled with zeroes), the value is 0. But if
+      //  the EVENT END record is found, we find the Char_t identifier 'EVTE' 
+      //  in that first position. If 'EVTE' is read as Float_t it returns a value 
+      //  of 3397.39 both in OSF1 and Linux, so we can easyly check for that value,
+      //  also making sure that it is not integer (any number between 3397.38 and
+      //  3397.40 CANNOT be integer)... so it is sure it is NOT a real particle.
+
+      TestVal = Particle.get_id () ;
+      if (TestVal > 3397.38 && TestVal < 3397.40) {
+
+	//  Go back in the file to read again the record not as a particle record
+	//  but as EVENT END
+
+	indatfile.seekg( -28, ios::cur  ) ; 	
+	EventE.read( indatfile );
+      	break ; 
+      }  
+      Particle.write ( outdatfile ) ;
+      //      Particle.print () ;
+    }
+
+    //   close input files and write the EVENT end record in outputs
+    
+    incerfile.close () ;
+    indatfile.close () ;
+    // EventE.print () ;
+    EventE.write( outcerfile );
+    EventE.write( outdatfile );
+    
+  } 
+    
+  //  write the RUN end record and close output files      
+	
+  cout << " ---> Processed a total of " << EvtsProc << " events" << endl ;
+  RunE.fill ( NumberRun , EvtsProc ) ;
+  RunE.write( outcerfile );
+  RunE.write( outdatfile );
+  outcerfile.close ();
+  outdatfile.close ();
+  
+}
+
+
+
+
+
+
+
+
