Commit 293cfefb authored by Valentina Fioretti's avatar Valentina Fioretti
Browse files

new input logic, removed flag to activate MT, cleaning

parent 09c84f4b
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -50,11 +50,12 @@ To configure, change into the build directory and run CMake
- Setting the Geant4 version: `-DGEANT4_VERSION=-DGEANT4_11_1` (default GEANT4_11_1)
- Activating the ROOT dependance: `-DNOROOTBUILD=OFF` (default=ON)

`> cmake -DSQLBUILD=ON -DMONGODBBUILD=ON -DGEANT4_VERSION=-DGEANT4_11_1 -DNOROOTBUILD=OFF <pathto>/BoGEMMS-HPC`

## Usage

- Single node (no mpi): `bogemms <conf file> <starting number> <mac file>`
- multinode (with mpi): `mpiexec -n <task number> bogemms <conf file> <starting number> <mac file>`
- Single node (no mpi): `bogemms -c <conf file> -m <mac file> [OPTIONAL: -s seed]`
- multinode (with mpi): `mpiexec -n <task number> bogemms -c <conf file> -m <mac file> [OPTIONAL: -s seed]`

For more details, check the [getting started guide](./doc/getting_started.md).

@@ -66,7 +67,8 @@ Work in progress

## Authors

see doc/AUTHORS
Coordinator: V. Fioretti (INAF OAS Bologna, valentina.fioretti <at> inaf.it)
Contributors: V. Fioretti (INAF OAS Bologna), A. Ciabattoni (INAF OAS Bologna), A. Bulgarelli (INAF OAS Bologna), N. Parmiggiani (INAF OAS Bologna)


## License
@@ -76,4 +78,4 @@ See doc/LICENSE

## Acknowledgment

This is supported by Centro Nazionale di Ricerca in High-Performance Computing, Big Data and Quantum Computing (CN_00000013 - CUP C53C22000350006).
BoGEMMS-HPC is supported by Centro Nazionale di Ricerca in High-Performance Computing, Big Data and Quantum Computing (CN_00000013 - CUP C53C22000350006).
+4 −15
Original line number Diff line number Diff line
@@ -64,19 +64,10 @@ BoGEMMSGlobalMemory::BoGEMMSGlobalMemory() {
    enableWriteXYZ = true;

    //scrivi i file di output in formato FITS
    enableWriteFITS = false;
    enableWriteFITS = true;
    
    enableFITSCompression= true;

    enableWriteFITSEnd = false;

    //scrivi i file di output in formato TXT
    enableWriteTXT = false;

    enableLowEnergyPhysic = true;

    enableHighEnergyPhysic = true;

    nfileFITSXYZ = 0;
    nfileSQLXYZ = 0;
    nfileMONGODBXYZ = 0;
@@ -98,12 +89,10 @@ void BoGEMMSGlobalMemory::OpenConfigFile() {
    config = new ConfigFile(gm.configFileName);
    config->readInto(enableWriteFITS, "IO.FILETYPE.FITS");
    config->readInto(enableFITSCompression, "IO.FILETYPE.FITS.COMPRESS");
    config->readInto(enableWriteFITSEnd, "IO.FILETYPE.FITSEND");
    config->readInto(enableWriteSQlite3, "IO.FILETYPE.SQLITE3");
    config->readInto(enableWriteMONGODB, "IO.FILETYPE.MONGODB");
    config->readInto(enableWriteXYZ, "IO.FILE.XYZ");
    cout << "IO.FILETYPE.FITS " << enableWriteFITS << endl;
    cout << "IO.FILETYPE.FITSEND " << enableWriteFITSEnd << endl;
    cout << "IO.FILETYPE.SQLITE3 " << enableWriteSQlite3 << endl;
    cout << "IO.FILETYPE.MONGODB " << enableWriteMONGODB << endl;
    cout << "IO.FILE.XYZ " << enableWriteXYZ << endl;
@@ -187,17 +176,17 @@ G4String BoGEMMSGlobalMemory::GetOutputSQLliteXYZFileName() {

G4String BoGEMMSGlobalMemory::GetOutputMongoXYZCollectionName() {
    G4int rank = G4MPImanager::GetManager()->GetRank();
    G4String collection_name = "";
    G4String collection_name = "collection_name";
    gm.config->readInto(collection_name, "IO.FILETYPE.MONGODB.COLLECTION_NAME");
    char fn[255];
    snprintf(fn, sizeof(fn), "%s_collection_task%d", collection_name.c_str(), rank);
    snprintf(fn, sizeof(fn), "%s_task%d", collection_name.c_str(), rank);
    outputXYZCollectionNameMongo_base = fn;
    
    return outputXYZCollectionNameMongo_base;
}

G4String BoGEMMSGlobalMemory::GetMongoUri() {
    G4String uri_address = "";
    G4String uri_address = "mongodb://localhost:27017/?minPoolSize=1&maxPoolSize=100";
    gm.config->readInto(uri_address, "IO.FILETYPE.MONGODB.ADDRESS");
    cout << "IO.FILETYPE.MONGODB.ADDRESS " << uri_address << endl;
    return uri_address;
+0 −12
Original line number Diff line number Diff line
@@ -63,8 +63,6 @@ public:

    G4int event_id;

    G4bool DOWNLOADGEOMETRY;

    int compressionlevel;

    void AddXYZDetector(G4LogicalVolume* logs);
@@ -114,22 +112,12 @@ public:

    int detector_volmax;

    //configuration (see constructor)

    bool enableLowEnergyPhysic;

    bool enableHighEnergyPhysic;

    G4bool enableWriteINOUT;

    G4bool enableWriteXYZ;

    G4bool enableWriteFITS;

    G4bool enableFITSCompression;
    
    G4bool enableWriteFITSEnd;
    
    G4bool enableWriteSQlite3;
    
    G4bool enableWriteMONGODB;

code/THELGlobalMemory.cc

deleted100644 → 0
+0 −436
Original line number Diff line number Diff line
// Copyright 2025 Valentina Fioretti
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// **********************************************************************

#include "G4MPImanager.hh"
#include "THELGlobalMemory.hh"
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include "G4LogicalVolume.hh"
#include <G4VPhysicalVolume.hh>
#include "G4ThreeVector.hh"
#include <G4VSolid.hh>
#include "G4PVPlacement.hh"
#include "G4VUserDetectorConstruction.hh"
#include "G4PVReplica.hh"
#include "G4SDManager.hh"
#include "G4Element.hh"
#include "G4Material.hh"
#include "G4PVPlacement.hh"
#include "G4Box.hh"
#include "G4Tubs.hh"
#include "G4LogicalVolume.hh"
#include "G4ThreeVector.hh"
#include "G4VisAttributes.hh"
#include "G4SubtractionSolid.hh"
#include "G4Region.hh"
#include "G4RegionStore.hh"
#include "globals.hh"
#include "G4VUserDetectorConstruction.hh"

#include "FITSOutput_XYZ.hh"
#include "CXYZSD.hh"

#if defined(GEANT4_11_1)
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"
#endif

#include "SQLliteOutput_XYZ.hh"
#include "MongoOutput_XYZ.hh"


#include <fitsio.h>

using namespace std;

THELGlobalMemory gm;

THELGlobalMemory::THELGlobalMemory() {

    //scrivi il file XYZ
    enableWriteXYZ = true;

    //scrivi i file di output in formato FITS
    enableWriteFITS = false;
    
    enableFITSCompression= true;

    enableWriteFITSEnd = false;

    //scrivi i file di output in formato TXT
    enableWriteTXT = false;

    enableLowEnergyPhysic = true;

    enableHighEnergyPhysic = true;

    nfileFITSXYZ = 0;
    nfileSQLXYZ = 0;
    nfileMONGODBXYZ = 0;

    compressionlevel = 9;

    DOWNLOADGEOMETRY = false;

    detector_volmin = -1;
    detector_volmax = -1;
    

// 	G4cout << "THELGlobalMemory::THELGlobalMemory()" << G4endl;
}


THELGlobalMemory::~THELGlobalMemory() {
}

void THELGlobalMemory::OpenConfigFile() {
    config = new ConfigFile(gm.configFileName);
    config->readInto(enableWriteFITS, "IO.FILETYPE.FITS");
    config->readInto(enableFITSCompression, "IO.FILETYPE.FITS.COMPRESS");
    config->readInto(enableWriteFITSEnd, "IO.FILETYPE.FITSEND");
    config->readInto(enableWriteSQlite3, "IO.FILETYPE.SQLITE3");
    config->readInto(enableWriteMONGODB, "IO.FILETYPE.MONGODB");
    config->readInto(enableWriteXYZ, "IO.FILE.XYZ");
    cout << "IO.FILETYPE.FITS " << enableWriteFITS << endl;
    cout << "IO.FILETYPE.FITSEND " << enableWriteFITSEnd << endl;
    cout << "IO.FILETYPE.SQLITE3 " << enableWriteSQlite3 << endl;
    cout << "IO.FILETYPE.MONGODB " << enableWriteMONGODB << endl;
    cout << "IO.FILE.XYZ " << enableWriteXYZ << endl;
    config->readInto(geomVersion, "GEOM.VERSION");
    config->readInto(physVersion, "ENERGYPROCESS.VERSION");
    cout << "GEOM.VERSION " << geomVersion << endl;
    cout << "ENERGYPROCESS.VERSION " << physVersion << endl;

}

void THELGlobalMemory::InitFiles() {
    if(enableWriteFITS && enableWriteXYZ) {
        fits_xyz = new FITSOutput_XYZ();
        fits_xyz->init();
    }
	

    #ifdef SQLITE3
        if(enableWriteSQlite3 && enableWriteXYZ) {
            sqlite3_config(SQLITE_CONFIG_SERIALIZED);
            sqlite3_xyz = new SQLliteOutput_XYZ();
            sqlite3_xyz->init();
        }
    #endif
    
    #ifdef MONGODB
        if(enableWriteMONGODB && enableWriteXYZ) {
            mongodb_xyz = new MongoOutput_XYZ();
            mongodb_xyz->init();
        }
    #endif
}

G4String THELGlobalMemory::GetOutputXYZFileNameTXT() {
    char fn[255];
    //sprintf(fn, "xyz.%ld.out", nfileFITSXYZ);
    snprintf(fn, sizeof(fn), "xyz.%ld.out", nfileFITSXYZ);
    std::ofstream asciiFile(fn, std::ios::app);
    if(asciiFile.is_open()) {
        long pos;
        pos=asciiFile.tellp();
        if(pos > 1700000000)
            nfileFITSXYZ++;
    }
    //sprintf(fn, "xyz.%ld.out", nfileFITSXYZ);
    snprintf(fn, sizeof(fn), "xyz.%ld.out", nfileFITSXYZ);
    outputXYZFileNameTXT = fn;
    return outputXYZFileNameTXT;
}


G4String THELGlobalMemory::GetOutputXYZFileNameFITS() {
    char fn[255];
    char fn2[255];
    G4String name;
    name = "";
    gm.config->readInto(name, "TEMPFITSOUTPUT.PREFIX");
    G4int rank = G4MPImanager::GetManager()->GetRank();
    //sprintf(fn, "%sxyz.%ld.task%d.fits", name.data(), nfileFITSXYZ, rank);
    snprintf(fn, sizeof(fn), "%sxyz.%ld.task%d.fits", name.data(), nfileFITSXYZ, rank);
    //sprintf(fn2, "xyz.%ld.task%d.fits", nfileFITSXYZ, rank);
    snprintf(fn2, sizeof(fn2), "xyz.%ld.task%d.fits", nfileFITSXYZ, rank);

    outputXYZFileNameFITS = fn;
    outputXYZFileNameFITS_base = fn2;
    nfileFITSXYZ++;
    return outputXYZFileNameFITS;
}

G4String THELGlobalMemory::GetOutputSQLliteXYZFileName() {
    
    G4int rank = G4MPImanager::GetManager()->GetRank();
    char fn[255];
    //sprintf(fn, "xyz.%ld.task%d.db", nfileSQLXYZ, rank);
    snprintf(fn, sizeof(fn), "xyz.%ld.task%d.db", nfileSQLXYZ, rank);
    outputXYZFileNameSQLlite_base = fn;
    
    nfileSQLXYZ++;
    return outputXYZFileNameSQLlite_base;
}

G4String THELGlobalMemory::GetOutputMongoXYZCollectionName() {
    G4int rank = G4MPImanager::GetManager()->GetRank();
    G4String collection_name = "";
    gm.config->readInto(collection_name, "IO.FILETYPE.MONGODB.COLLECTION_NAME");
    char fn[255];
    snprintf(fn, sizeof(fn), "%s_collection_task%d", collection_name.c_str(), rank);
    outputXYZCollectionNameMongo_base = fn;
    
    return outputXYZCollectionNameMongo_base;
}

G4String THELGlobalMemory::GetMongoUri() {
    G4String uri_address = "";
    gm.config->readInto(uri_address, "IO.FILETYPE.MONGODB.ADDRESS");
    cout << "IO.FILETYPE.MONGODB.ADDRESS " << uri_address << endl;
    return uri_address;
}

bool THELGlobalMemory::GetFITSCompressionStatus(){
    return enableFITSCompression;
}


int THELGlobalMemory::CopyFileFits(char* in, char* out) {
    G4String ins;
    ins = in;
    G4String outs;
    outs = out;
    if(ins == outs)
        return 0;
    G4cout << "Copy files from " << ins << " to " << outs << G4endl;
    fitsfile *infptr, *outfptr;   /* FITS file pointers defined in fitsio.h */
    int status = 0;       /* status must always be initialized = 0  */
    /* Open the input file */
    if ( !fits_open_file(&infptr, in, READONLY, &status) )
    {
        /* Create the output file */
        if ( !fits_create_file(&outfptr, out, &status) )
        {

            /* copy the previous, current, and following HDUs */
            fits_copy_file(infptr, outfptr, 1, 1, 1, &status);

            fits_close_file(outfptr,  &status);
        }
        fits_delete_file(infptr, &status);
    }
    //delete temp file
// 	fits_delete_file(infptr, &status);
    /* if error occured, print out error message */
    if (status) fits_report_error(stderr, status);
    return(status);

}

void THELGlobalMemory::AddXYZDetector(G4LogicalVolume* log) {
    gm.logs_sd.push_back(log);
}

void THELGlobalMemory::AddXYZDetector() {
    std::vector<G4LogicalVolume*>::iterator log_it;
    for (log_it = gm.logs_sd.begin(); log_it != gm.logs_sd.end(); ++log_it)
    {
        G4LogicalVolume* log = *log_it;
        G4SDManager* SDman_XYZ = G4SDManager::GetSDMpointer();
        G4String name_xyz = log->GetName();
        name_xyz += "SD";
        CXYZSD *vsd = new CXYZSD(name_xyz);
        SDman_XYZ->AddNewDetector(vsd);
        log->SetSensitiveDetector(vsd);
    }
}

G4VPhysicalVolume* THELGlobalMemory::ConstructWorld() {
    
    G4double WorldSizeX;
    G4double WorldSizeY;
    G4double WorldSizeZ;
    
    G4double WorldSize_input = 0;
    gm.config->readInto(WorldSize_input, "WORLD.BOX.SIDE");
    G4cout << "WORLD.BOX.SIDE: " << WorldSize_input << G4endl;
    
    if (WorldSize_input > 0.0) {
        WorldSizeX=WorldSize_input*mm;
        WorldSizeY=WorldSize_input*mm;
        WorldSizeZ=WorldSize_input*mm;
        
    } else {
        
        WorldSizeX=40000.0*mm;
        WorldSizeY=40000.0*mm;
        WorldSizeZ=40000.0*mm;

    }
    
    
    //G4double WorldSizeX=4000.000*mm;
    //G4double WorldSizeY=4000.000*mm;
    //G4double WorldSizeZ=4000.000*mm;

    G4cout << "######################################################" << G4endl;
    G4cout << "World dimension: " << WorldSizeX << " * " << WorldSizeY << " * " << WorldSizeZ << G4endl;
    G4cout << "######################################################" << G4endl;

    G4String name, symbol;
    G4double a, z, density;

    G4double temperature, pressure;
    density     = universe_mean_density;
    pressure    = 3.e-18*pascal;
    temperature = 2.73*kelvin;


    World_mat = new G4Material(name="Galactic", z=1., a=1.01*g/mole, density,kStateGas,temperature,pressure);

    G4Box* solidWorld = new G4Box("World",
                                  WorldSizeX/2,WorldSizeY/2,WorldSizeZ/2);

    World_log = new G4LogicalVolume(solidWorld,
                                    World_mat,
                                    "World");
    
    World_log->SetVisAttributes (&G4VisAttributes::GetInvisible);

    World_phys = new G4PVPlacement(0,G4ThreeVector(),
                                   World_log,
                                   "World",
                                   0,
                                   false,
                                   0);

    return World_phys;
}

unsigned char THELGlobalMemory::LUTParticleType(G4String p) {
    unsigned char particleID;
    particleID = 0;
    if(p == "gamma")
        particleID = 1;
    if(p == "e-")
        particleID = 2;
    if(p == "e+")
        particleID = 3;
    if(p == "proton")
        particleID = 4;
    if(p == "mu+")
        particleID = 5;
    if(p == "mu-")
        particleID = 6;
    if(p == "tau+")
        particleID = 7;
    if(p == "tau-")
        particleID = 8;
    if(p == "GenericIon")
        particleID = 9;
    if(p == "neutron")
        particleID = 10;
    if(p == "pi+")
        particleID = 11;
    if(p == "pi-")
        particleID = 12;
    if(p == "triton")
        particleID = 13;
    if(p == "sigma-")
        particleID = 14;
    if(p == "sigma+")
        particleID = 15;
    if(p == "nu_mu")
        particleID = 16;
    if(p == "nu_e")
        particleID = 17;
    if(p == "lambda")
        particleID = 18;
    if(p == "kaon0S")
        particleID = 19;
    if(p == "kaon0L")
        particleID = 20;
    if(p == "kaon-")
        particleID = 21;
    if(p == "kaon+")
        particleID = 22;
    if(p == "deuteron")
        particleID = 23;
    if(p == "anti_xi0")
        particleID = 24;
    if(p == "anti_xi-")
        particleID = 25;
    if(p == "anti_sigma-")
        particleID = 26;
    if(p == "anti_proton")
        particleID = 27;
    if(p == "anti_nu_mu")
        particleID = 28;
    if(p == "anti_nu_e")
        particleID = 29;
    if(p == "anti_neutron")
        particleID = 30;
    if(p == "anti_lambda")
        particleID = 31;
    if(p == "alpha")
        particleID = 32;
    if(p == "Si30[0.0]")
        particleID = 33;
    if(p == "Si29[0.0]")
        particleID = 34;
    if(p == "Si28[0.0] ")
        particleID = 35;

    return particleID;
}

unsigned char THELGlobalMemory::LUTProcessType(G4String p) {
    unsigned char processID;
    processID = 0;
    if(p == "UserLimit")
        processID = 1;
    if(p == "Transportation")
        processID = 2;
    if(p == "hLowEIoni")
        processID = 3;
    if(p == "msc")
        processID = 4;
    if(p == "LowEnergyIoni")
        processID = 5;
    if(p == "LowEnBrem")
        processID = 6;
    if(p == "eIoni")
        processID = 7;
    if(p == "eBrem")
        processID = 8;
    if(p == "annihil")
        processID = 9;
    if(p == "phot")
        processID = 10;
    if(p == "compt")
        processID = 11;
    if(p == "conv")
        processID = 12;
    if(p == "LowEnPhotoElec")
        processID = 13;
    if(p == "LowEnCompton")
        processID=14;
    return processID;
}

code/THELGlobalMemory.hh

deleted100644 → 0
+0 −165
Original line number Diff line number Diff line
// Copyright 2025 Valentina Fioretti
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// **********************************************************************

#ifndef SXGLOBALMEMORY_H
#define SXGLOBALMEMORY_H

#define USE_FITS 1


#include "G4ios.hh"
#include "G4String.hh"
#include "CXYZSD.hh"
#include "ConfigFile.hh"

class G4VPhysicalVolume;
class FITSOutput_XYZ;
class G4LogicalVolume;
class G4VPhysicalVolume;
class G4Material;

#ifdef SQLITE3
class SQLliteOutput_XYZ;
#endif

#ifdef MONGODB
class MongoOutput_XYZ;
#endif

class THELGlobalMemory {
public:
    THELGlobalMemory();

    ~THELGlobalMemory();

    G4String configFileName; //the name of the config file

    G4String GetOutputXYZFileNameTXT();

    G4String GetOutputXYZFileNameFITS();
    
    bool GetFITSCompressionStatus();
    
    G4String GetOutputSQLliteXYZFileName();
    
    G4String GetOutputMongoXYZCollectionName();
    
    G4String GetMongoUri();
    

    void OpenConfigFile();

    G4int event_id;

    G4bool DOWNLOADGEOMETRY;

    int compressionlevel;

    void AddXYZDetector(G4LogicalVolume* logs);

    void AddXYZDetector();

    FITSOutput_XYZ* fits_xyz;

    
#ifdef SQLITE3
	
	SQLliteOutput_XYZ* sqlite3_xyz;
	
#endif

#ifdef MONGODB
    
    MongoOutput_XYZ* mongodb_xyz;
    
#endif

    void InitFiles();

    long nfileFITSXYZ;
    long nfileSQLXYZ;
    long nfileMONGODBXYZ;

    ConfigFile* config;

    G4VPhysicalVolume* ConstructWorld();

    G4LogicalVolume* World_log;

    G4VPhysicalVolume* World_phys;

    G4Material* World_mat;

    unsigned char LUTParticleType(G4String p);

    unsigned char LUTProcessType(G4String p);

    int CopyFileFits(char* in, char* out);

public:

    int detector_volmin;

    int detector_volmax;

    //configuration (see constructor)

    bool enableLowEnergyPhysic;

    bool enableHighEnergyPhysic;

    G4bool enableWriteINOUT;

    G4bool enableWriteXYZ;

    G4bool enableWriteFITS;

    G4bool enableFITSCompression;
    
    G4bool enableWriteFITSEnd;
    
    G4bool enableWriteSQlite3;
    
    G4bool enableWriteMONGODB;

    G4bool enableWriteTXT;

    G4String geomVersion;

    G4String physVersion;


public:


    G4String outputXYZFileNameTXT;

    G4String outputXYZFileNameFITS;

    G4String outputXYZFileNameFITS_base;
    
    G4String outputXYZFileNameSQLlite_base;
    
    G4String outputXYZCollectionNameMongo_base;

    std::vector<G4LogicalVolume*> logs_sd;

};

extern THELGlobalMemory gm;

#endif

Loading