Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

CalorimeterSIO.cc

Go to the documentation of this file.
00001 //  CalorimeterSIO.cxx
00002 //
00003 
00004 //#include <iostream>
00005 //using namespace std;
00006 
00007 #include "SIO_recordManager.h"
00008 #include "SIO_record.h"
00009 #include "SIO_definitions.h"
00010 #include "SIO_functions.h"
00011 
00012 #include "CalorimeterSIO.h"
00013 #include <stdio.h>
00014 #include <vector>
00015 using std::vector;
00016 
00017 // set unit conversion factors here
00018 const double cm = 10.0; // mm, which is the default in Geant4
00019 const double GeV = 1000.0; // MeV, which is the default in Geant4
00020 
00021 // constructor
00022 CalorimeterSIO::CalorimeterSIO(  const char* i_name, vector<CalorimeterHit> calHits) : SIO_block(i_name), _calHits(calHits)
00023 {
00024   // SIO init --  join the event record.
00025   SIO_record* record;
00026   record = SIO_recordManager::get( "LCD_LCDG4_Event" );
00027   if (record != NULL)
00028     record->connect(this);
00029 }
00030 
00031 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00032 void CalorimeterSIO::clear()
00033   //-----------------------
00034 {
00035   _calHits.erase(_calHits.begin(),_calHits.end());
00036 }
00037 
00038 void CalorimeterSIO::addHit(CalorimeterHit hit)
00039 {
00040   _calHits.push_back(hit);
00041 }
00042 
00043 // ----------------------------------------------------------------------------
00044 // Perform SIO transfer.
00045 // ----------------------------------------------------------------------------
00046 unsigned int CalorimeterSIO::xfer
00047 (
00048  SIO_stream*     stream,
00049  SIO_operation   op,
00050  unsigned int    version
00051  )
00052 {
00053   // Make compiler happy about unused vars
00054   if(op || version) ;
00055 
00056   unsigned int status;
00057 
00058   // write out the number of calorimeter hits...
00059   int nHits = _calHits.size();
00060   status = SIO_DATA( stream, &nHits, 1 );
00061 
00062   // loop over calorimeter hits and write them out...
00063 
00064   std::vector<CalorimeterHit>::const_iterator it;
00065   for(it=_calHits.begin(); it!=_calHits.end(); ++it)
00066     {
00067       CalorimeterHit hit = *it;
00068       // cell ID
00069       unsigned int id = hit.id();
00070       SIO_DATA(stream, &id,     1);
00071       // energy
00072       float energy = hit.energy()/GeV;
00073       SIO_DATA(stream, &energy, 1);
00074 
00075       // For debugging
00076       //printf("CalorimeterSIO::hit.energy()=%f\n",hit.energy());
00077 
00078       // now loop over the individual contributions to this cell...
00079       CalorimeterHit::McEnergyMap mcmap = hit.getMcEnergyMap();
00080       CalorimeterHit::McEnergyMap::const_iterator mapit;
00081       int mapsize = mcmap.size();
00082       SIO_DATA(stream, &mapsize, 1)
00083         for(mapit = mcmap.begin(); mapit!=mcmap.end(); ++mapit)
00084           {
00085             //MCParticle*
00086             SIO_PNTR(stream, &((*mapit).first)                         );
00087             // energy
00088             float energy = mapit->second / GeV;
00089             SIO_DATA(stream, &energy, 1);
00090 //          SIO_DATA(stream, const_cast<float *>(&((*mapit).second)), 1);
00091           }
00092     }
00093 
00094   //
00095   // That's all folks!
00096   //
00097   return( SIO_BLOCK_SUCCESS );
00098 }
00099 
00100 // ----------------------------------------------------------------------------
00101 // Return SIO version number.
00102 // ----------------------------------------------------------------------------
00103 
00104 #define SIO_CALORIMETER_MAJOR 1
00105 #define SIO_CALORIMETER_MINOR 0
00106 
00107 unsigned int CalorimeterSIO::version()
00108 { return( SIO_VERSION_ENCODE( SIO_CALORIMETER_MAJOR,
00109                               SIO_CALORIMETER_MINOR ) ); }

Generated on Thu Oct 7 18:44:46 2004 for LCDG4 by doxygen 1.3.4