View | Details | Raw Unified | Return to problem 2241
Collapse All | Expand All

(-)geant4.10.06.p01/source/materials/include/G4OpticalSurface.hh (+3 lines)
Lines 199-204 Link Here
199
	void DumpInfo() const;
199
	void DumpInfo() const;
200
        // Prints information about the optical surface.
200
        // Prints information about the optical surface.
201
201
202
        void ReadLUTFileToStream( G4String filename , std::istringstream& iss );
203
        // Method to read the Look-Up-Table into array AngularDistribution
204
202
        void ReadLUTFile(void);
205
        void ReadLUTFile(void);
203
        // Method to read the Look-Up-Table into array AngularDistribution
206
        // Method to read the Look-Up-Table into array AngularDistribution
204
207
(-)geant4.10.06.p01/source/materials/src/G4OpticalSurface.cc (-7 / +67 lines)
Lines 38-43 Link Here
38
// mail:        gum@triumf.ca
38
// mail:        gum@triumf.ca
39
////////////////////////////////////////////////////////////////////////
39
////////////////////////////////////////////////////////////////////////
40
40
41
#include <zlib.h>
41
#include <iostream>
42
#include <iostream>
42
#include <fstream>
43
#include <fstream>
43
44
Lines 300-305 Link Here
300
  }
301
  }
301
}
302
}
302
303
304
void G4OpticalSurface::ReadLUTFileToStream( G4String filename , std::istringstream& iss )
305
{
306
  G4String* data=0;
307
  G4String compfilename(filename);
308
  compfilename += ".z";
309
  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
310
  if ( in->good() )
311
  {
312
     // Use the compressed file
313
     G4int file_size = in->tellg();
314
     in->seekg( 0 , std::ios::beg );
315
     Bytef* compdata = new Bytef[ file_size ];
316
317
     while ( *in )
318
     { // Loop checking, 11.05.2015, T. Koi
319
        in->read( (char*)compdata , file_size );
320
     }
321
322
     uLongf complen = (uLongf) ( file_size*4 );
323
     Bytef* uncompdata = new Bytef[complen];
324
325
     while ( Z_OK != uncompress ( uncompdata , &complen , compdata , file_size ) )
326
     { // Loop checking, 11.05.2015, T. Koi
327
        delete[] uncompdata;
328
        complen *= 2;
329
        uncompdata = new Bytef[complen];
330
     }
331
     delete [] compdata;
332
     //                                 Now "complen" has uncomplessed size
333
     data = new G4String ( (char*)uncompdata , (G4long)complen );
334
     delete [] uncompdata;
335
  }
336
  else
337
  {
338
     // Use regular text file
339
     std::ifstream thefData( filename , std::ios::in | std::ios::ate );
340
     if ( thefData.good() )
341
     {
342
        G4int file_size = thefData.tellg();
343
        thefData.seekg( 0 , std::ios::beg );
344
        char* filedata = new char[ file_size ];
345
        while ( thefData )
346
        { // Loop checking, 11.05.2015, T. Koi
347
           thefData.read( filedata , file_size );
348
        }
349
        thefData.close();
350
        data = new G4String ( filedata , file_size );
351
        delete [] filedata;
352
     }
353
     else
354
     {
355
        // found no data file
356
        // set error bit to the stream
357
        iss.setstate( std::ios::badbit );
358
     }
359
  }
360
  in->close(); delete in;
361
  delete data;
362
}
363
303
void G4OpticalSurface::ReadLUTFile()
364
void G4OpticalSurface::ReadLUTFile()
304
{
365
{
305
  G4String readLUTFileName = " ";
366
  G4String readLUTFileName = " ";
Lines 382-388 Link Here
382
443
383
  readLUTFileName = pathString + "/" + readLUTFileName;
444
  readLUTFileName = pathString + "/" + readLUTFileName;
384
445
385
  std::ifstream readLUTFileHandle(readLUTFileName, std::ios::in);
446
  std::istringstream readLUTFileHandle(std::ios::in);
447
  ReadLUTFileToStream(readLUTFileName, readLUTFileHandle);
386
448
387
  if (readLUTFileHandle) {
449
  if (readLUTFileHandle) {
388
     G4int idxmax = incidentIndexMax*thetaIndexMax*phiIndexMax;
450
     G4int idxmax = incidentIndexMax*thetaIndexMax*phiIndexMax;
Lines 406-412 Link Here
406
                 FatalException, excep);
468
                 FatalException, excep);
407
     return;
469
     return;
408
  }
470
  }
409
  readLUTFileHandle.close();
410
}
471
}
411
472
412
void G4OpticalSurface::ReadLUTDAVISFile()
473
void G4OpticalSurface::ReadLUTDAVISFile()
Lines 447-453 Link Here
447
508
448
  readLUTDAVISFileName = pathString + "/" + readLUTDAVISFileName;
509
  readLUTDAVISFileName = pathString + "/" + readLUTDAVISFileName;
449
510
450
  std::ifstream readLUTDAVISFileHandle(readLUTDAVISFileName, std::ios::in);
511
  std::istringstream readLUTDAVISFileHandle(std::ios::in);
512
  ReadLUTFileToStream(readLUTDAVISFileName, readLUTDAVISFileHandle);
451
513
452
  if (readLUTDAVISFileHandle) {
514
  if (readLUTDAVISFileHandle) {
453
515
Lines 472-478 Link Here
472
                 FatalException, excep);
534
                 FatalException, excep);
473
     return;
535
     return;
474
  }
536
  }
475
  readLUTDAVISFileHandle.close();
476
}
537
}
477
538
478
void G4OpticalSurface::ReadReflectivityLUTFile()
539
void G4OpticalSurface::ReadReflectivityLUTFile()
Lines 521-528 Link Here
521
582
522
  readReflectivityLUTFileName = pathString + "/" + readReflectivityLUTFileName;
583
  readReflectivityLUTFileName = pathString + "/" + readReflectivityLUTFileName;
523
584
524
  std::ifstream readReflectivityLUTFileHandle(readReflectivityLUTFileName,
585
  std::istringstream readReflectivityLUTFileHandle(std::ios::in);
525
                                              std::ios::in);
586
  ReadLUTFileToStream(readReflectivityLUTFileName, readReflectivityLUTFileHandle);
526
587
527
  if (readReflectivityLUTFileHandle) {
588
  if (readReflectivityLUTFileHandle) {
528
     for (G4int i = 0; i<RefMax; i++) {
589
     for (G4int i = 0; i<RefMax; i++) {
Lines 546-552 Link Here
546
                 FatalException, excep);
607
                 FatalException, excep);
547
     return;
608
     return;
548
  }
609
  }
549
  readReflectivityLUTFileHandle.close();
550
}
610
}
551
611
552
void G4OpticalSurface::ReadDichroicFile()
612
void G4OpticalSurface::ReadDichroicFile()

Return to problem 2241