diff --git a/.github/pr-badge.yml b/.github/pr-badge.yml index f6df80e01..a3888ba61 100644 --- a/.github/pr-badge.yml +++ b/.github/pr-badge.yml @@ -15,3 +15,5 @@ when: "$additions < 100" - imageUrl: "https://gitlab.cern.ch/rest-for-physics/framework/badges/$branchName/pipeline.svg" url: "https://gitlab.cern.ch/rest-for-physics/framework/-/commits/$branchName" +- imageUrl: "https://github.com/rest-for-physics/framework/actions/workflows/validation.yml/badge.svg?branch=$branchName" + url: "https://github.com/rest-for-physics/framework/commits/$branchName" \ No newline at end of file diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index fb0475052..212d6ce18 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -21,7 +21,6 @@ defaults: run: shell: bash -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: build-test: @@ -75,32 +74,6 @@ jobs: path: ${{ env.REST_PATH }} retention-days: 1 - framework-install-reference: - name: Build with reference version of dependencies - runs-on: ubuntu-latest - container: - image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-reference-jun2022 - steps: - - uses: actions/checkout@v3 - - name: Build and install - uses: ./.github/actions/build - with: - cmake-flags: "-DCMAKE_INSTALL_PREFIX=${{ env.REST_PATH }} -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} -DCMAKE_PREFIX_PATH=$GARFIELD_INSTALL -DREST_ALL_LIBS=ON -DREST_G4=ON -DREST_GARFIELD=ON" - branch: ${{ env.BRANCH_NAME }} - - name: Test REST - run: | - printenv - cat ${{ env.REST_PATH }}/thisREST.sh - source ${{ env.REST_PATH }}/thisREST.sh - restManager ListMacros - restRoot -b -q - - name: Cache framework installation - id: framework-install-cache-reference - uses: actions/cache@v3 - with: - key: ${{ env.BRANCH_NAME }}-${{ github.sha }} - path: ${{ env.REST_PATH }} - metadata: name: "Metadata" runs-on: ubuntu-latest @@ -155,8 +128,8 @@ jobs: name: "PandaX-III" runs-on: ubuntu-latest container: - image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-reference-jun2022 - needs: [ framework-install-reference ] + image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-dev + needs: [ framework-install ] steps: - uses: actions/checkout@v3 with: @@ -168,7 +141,7 @@ jobs: ./scripts/checkoutRemoteBranch.sh ${{ env.BRANCH_NAME }} - name: Restore cache uses: actions/cache@v3 - id: framework-install-cache-reference + id: framework-install-cache with: key: ${{ env.BRANCH_NAME }}-${{ github.sha }} path: ${{ env.REST_PATH }} @@ -176,21 +149,22 @@ jobs: run: | source ${{ env.REST_PATH }}/thisREST.sh cd framework/pipeline/pandaxiii_MC - restG4 Xe136bb0n.rml - restRoot -b -q ValidateG4.C'("Xe136bb0n_n2E06.root")' + restG4 Xe136bb0n.rml -o Xe136bb0n.root + restRoot -b -q ValidateG4.C'("Xe136bb0n.root")' - name: Upload Artifacts uses: actions/upload-artifact@v3 with: name: Xe136bb - path: framework/pipeline/pandaxiii_MC/Xe136bb0n_n2E06.root + path: framework/pipeline/pandaxiii_MC/Xe136bb0n.root retention-days: 1 - name: PandaXIII Topological run: | source ${{ env.REST_PATH }}/thisREST.sh cd framework/pipeline/pandaxiii_MC - restManager --c AllProcesses.rml --i testInput.root --o testOutput.root --j 1 --e 10 - restRoot -b -q ../MakeBasicTree.C'("testOutput.root")' - restRoot -b -q ../ValidateTrees.C'("validation.root")' + restManager --c AllProcesses.rml --i Xe136bb0n_small_reference.root --o Xe136bb0n_small_reference_processed.root --j 1 --e 10 + restRoot -b -q ../MakeBasicTree.C'("Xe136bb0n_small_reference_processed.root")' + restRoot -b -q ../ValidateTrees.C'("Xe136bb0n_validation.root")' + # restManager --c plots.rml --i Xe136bb0n_small_reference_processed.root # This command is failing in the docker, reproducible locally, not clear why... # echo | sleep 5 | restManager --c plots.rml --i testOutput.root # - name: Upload Artifacts @@ -204,14 +178,14 @@ jobs: source ${{ env.REST_PATH }}/thisREST.sh cd framework/pipeline/pandaxiii_MC echo "using just-generated g4 file" - restManager --c AllProcesses.rml --i Xe136bb0n_n2E06.root --o testOutput.root --j 1 --e 10 - restRoot -b -q ../MakeBasicTree.C'("testOutput.root")' - restRoot -b -q ../ValidateTrees.C'("validation.root")' + restManager --c AllProcesses.rml --i Xe136bb0n.root --o Xe136bb0n_processed.root --j 1 --e 10 + restRoot -b -q ../MakeBasicTree.C'("Xe136bb0n_processed.root")' + restRoot -b -q ../ValidateTrees.C'("Xe136bb0n_validation.root")' - name: Upload Artifacts uses: actions/upload-artifact@v3 with: name: PandaTestOutput - path: framework/pipeline/pandaxiii_MC/testOutput.root + path: framework/pipeline/pandaxiii_MC/Xe136bb0n_processed.root retention-days: 1 - name: PandaXIII Data run: | @@ -282,6 +256,194 @@ jobs: examples: name: Run examples runs-on: ubuntu-latest + container: + image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-dev + needs: [ framework-install ] + steps: + - uses: actions/checkout@v3 + with: + repository: rest-for-physics/framework + path: framework + - name: Checkout framework branch + run: | + cd framework + ./scripts/checkoutRemoteBranch.sh ${{ env.BRANCH_NAME }} + - name: Restore cache + uses: actions/cache@v3 + id: framework-install-cache + with: + key: ${{ env.BRANCH_NAME }}-${{ github.sha }} + path: ${{ env.REST_PATH }} + - name: Test Metadata + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd ${{ env.REST_PATH }}/examples + restManager --c saveMetadataFile.rml --o meta.root + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: Metadata + path: ${{ env.REST_PATH }}/examples/meta.root + retention-days: 1 + - name: 01_NLDBD + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd ${{ env.REST_PATH }}/examples/restG4/01.NLDBD/ + restG4 NLDBD.rml + restRoot -b -q Validate.C'("Run00001_NLDBD_Test.root")' + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: NLDBD + path: ${{ env.REST_PATH }}/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root + retention-days: 1 + - name: Event Selection + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd framework/pipeline/selection + restManager --c g4Analysis.rml --f ${{ env.REST_PATH }}/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root + restManager --c g4OnSelection.rml --f Run00001_NLDBD_Test_g4Analysis.root + restRoot -b -q Validate.C'("Run00001_NLDBD_Test_EvSelection.root")' + restManager --c g4EvSelectionIDsFromFile.rml --f Run00001_NLDBD_Test_g4Analysis.root + restRoot -b -q ValidateIDsFromFile.C'("Run00001_NLDBD_Test_EvSelectionIDsFromFile.root")' + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: EventSelection + path: framework/pipeline/selection/IDs.txt + retention-days: 1 + - name: 08_alphas + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd ${{ env.REST_PATH }}/examples/restG4/08.Alphas/ + mkdir data + export REST_ENERGY=5 + export REST_FOIL=1 + restG4 alphas.rml + # - name: Upload Artifacts + # uses: actions/upload-artifact@v3 + # with: + # name: Alphas + # path: ${{ env.REST_PATH }}/examples/restG4/08.Alphas/data/Run_5MeV_1um.root + # retention-days: 1 + - name: 01_alphaTrack + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd ${{ env.REST_PATH }}/examples/01.alphaTrack/ + mkdir data + export RAW_PROCESSING=ON + export HIT_PROCESSING=ON + export TRACK_PROCESSING=ON + restManager --c processing.rml --f ../restG4/08.Alphas/data/Run_5MeV_1um.root + restRoot -b -q Validate.C'("data/Response_5MeV_1um.root")' + # - name: Upload Artifacts + # uses: actions/upload-artifact@v3 + # with: + # name: AlphaTrack + # path: ${{ env.REST_PATH }}/examples/restG4/08.Alphas/data/Run_5MeV_1um.root + # retention-days: 1 + + # Reference dependencies version + + framework-install-reference: + name: Build with reference version of dependencies + runs-on: ubuntu-latest + container: + image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-reference-jun2022 + steps: + - uses: actions/checkout@v3 + - name: Build and install + uses: ./.github/actions/build + with: + cmake-flags: "-DCMAKE_INSTALL_PREFIX=${{ env.REST_PATH }} -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} -DCMAKE_PREFIX_PATH=$GARFIELD_INSTALL -DREST_ALL_LIBS=ON -DREST_G4=ON -DREST_GARFIELD=ON" + branch: ${{ env.BRANCH_NAME }} + - name: Test REST + run: | + printenv + cat ${{ env.REST_PATH }}/thisREST.sh + source ${{ env.REST_PATH }}/thisREST.sh + restManager ListMacros + restRoot -b -q + - name: Cache framework installation + id: framework-install-cache-reference + uses: actions/cache@v3 + with: + key: ${{ env.BRANCH_NAME }}-${{ github.sha }} + path: ${{ env.REST_PATH }} + + + pandax-iii-reference: + name: "PandaX-III on reference version" + runs-on: ubuntu-latest + container: + image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-reference-jun2022 + needs: [ framework-install-reference ] + steps: + - uses: actions/checkout@v3 + with: + repository: rest-for-physics/framework + path: framework + - name: Checkout framework branch + run: | + cd framework + ./scripts/checkoutRemoteBranch.sh ${{ env.BRANCH_NAME }} + - name: Restore cache + uses: actions/cache@v3 + id: framework-install-cache-reference + with: + key: ${{ env.BRANCH_NAME }}-${{ github.sha }} + path: ${{ env.REST_PATH }} + - name: 02_PandaXiiiMC + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd framework/pipeline/pandaxiii_MC + restG4 Xe136bb0n.rml -o Xe136bb0n.root + restRoot -b -q ValidateG4.C'("Xe136bb0n.root")' + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: Xe136bb + path: framework/pipeline/pandaxiii_MC/Xe136bb0n.root + retention-days: 1 + - name: PandaXIII Topological + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd framework/pipeline/pandaxiii_MC + restManager --c AllProcesses.rml --i Xe136bb0n_small_reference.root --o Xe136bb0n_small_reference_processed.root --j 1 --e 10 + restRoot -b -q ../MakeBasicTree.C'("Xe136bb0n_small_reference_processed.root")' + restRoot -b -q ../ValidateTrees.C'("Xe136bb0n_validation.root")' + # restManager --c plots.rml --i Xe136bb0n_small_reference_processed.root + - name: PandaXIII Topological from Geant4 + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd framework/pipeline/pandaxiii_MC + echo "using just-generated g4 file" + restManager --c AllProcesses.rml --i Xe136bb0n.root --o Xe136bb0n_processed.root --j 1 --e 10 + restRoot -b -q ../MakeBasicTree.C'("Xe136bb0n_processed.root")' + restRoot -b -q ../ValidateTrees.C'("Xe136bb0n_validation_G4_v10.4.3.root")' + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: PandaTestOutput + path: framework/pipeline/pandaxiii_MC/Xe136bb0n_processed.root + retention-days: 1 + - name: PandaXIII Data + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd framework/pipeline/pandaxiii_data + restManager --c P3AutoChain.rml --i CoBo_AsAd0_2019-03-15.graw --o testOutput.root --j 1 + restRoot -b -q ../MakeBasicTree.C'("testOutput.root")' + restRoot -b -q ../ValidateTrees.C'("validation.root")' + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: PandaTriggerRate + path: framework/pipeline/pandaxiii_data/TriggerRate.png + retention-days: 1 + + examples-reference: + name: Run examples on reference version + runs-on: ubuntu-latest container: image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-reference-jun2022 needs: [ framework-install-reference ] @@ -329,7 +491,7 @@ jobs: cd framework/pipeline/selection restManager --c g4Analysis.rml --f ${{ env.REST_PATH }}/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root restManager --c g4OnSelection.rml --f Run00001_NLDBD_Test_g4Analysis.root - restRoot -b -q Validate.C'("Run00001_NLDBD_Test_EvSelection.root")' + restRoot -b -q Validate.C'("Run00001_NLDBD_Test_EvSelection.root", true)' restManager --c g4EvSelectionIDsFromFile.rml --f Run00001_NLDBD_Test_g4Analysis.root restRoot -b -q ValidateIDsFromFile.C'("Run00001_NLDBD_Test_EvSelectionIDsFromFile.root")' - name: Upload Artifacts @@ -338,6 +500,17 @@ jobs: name: EventSelection path: framework/pipeline/selection/IDs.txt retention-days: 1 + - name: 07_decay + run: | + source ${{ env.REST_PATH }}/thisREST.sh + cd ${{ env.REST_PATH }}/examples/restG4/07.FullChainDecay/ + restG4 fullChain.rml -o Run00001_U238_FullChainDecay.root + restRoot -b -q Validate.C'("Run00001_U238_FullChainDecay.root", 15)' + restG4 singleDecay.rml -o Run00002_U238_SingleChainDecay.root + restRoot -b -q Validate.C'("Run00002_U238_SingleChainDecay.root", 1)' + export REST_ISOTOPE=Be7 + restG4 singleDecay.rml + restRoot -b -q Validate.C'("Run00002_Be7_SingleChainDecay.root", 1)' - name: 08_alphas run: | source ${{ env.REST_PATH }}/thisREST.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c14eb6768..bc56fdafd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics +image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-dev # variables: # GIT_SUBMODULE_STRATEGY: recursive @@ -32,13 +32,13 @@ stages: - examples # Stage to validate data chain processing constructions (TREX-DM data, PandaX-III topology, etc). - - restManager_process + - restManager process # Stage to validate tasks or executions over preprocessed data files - postProcessing # Stage to validate other restManager tasks (metadata generation, script loading, etc). - - restManager_generate + - restManager generate # Scripts to launch more complete tests. TRestGas file generation, Geant4 physics validation, etc. - deploy @@ -111,7 +111,7 @@ Build and Install: paths: - ${CI_PROJECT_DIR}/install expire_in: 1 day - + Load REST Libraries: stage: install script: @@ -126,7 +126,7 @@ List REST Macros: - source ${CI_PROJECT_DIR}/install/thisREST.sh - restManager ListMacros -01_NLDBD: +01.NLDBD: stage: restG4 script: - source ${CI_PROJECT_DIR}/install/thisREST.sh @@ -139,19 +139,19 @@ List REST Macros: - ${CI_PROJECT_DIR}/install/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root expire_in: 1 day -02_PandaXiiiMC: +PandaX-III MC: stage: restG4 script: - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC - - restG4 Xe136bb0n.rml - - restRoot -b -q ValidateG4.C'("Xe136bb0n_n2E06.root")' + - restG4 Xe136bb0n.rml -o Xe136bb0n.root + - restRoot -b -q ValidateG4.C'("Xe136bb0n.root")' artifacts: paths: - - ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC/Xe136bb0n_n2E06.root + - ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC/Xe136bb0n.root expire_in: 1 day -08_alphas: +08.alphas: stage: restG4 script: - source ${CI_PROJECT_DIR}/install/thisREST.sh @@ -165,7 +165,7 @@ List REST Macros: - ${CI_PROJECT_DIR}/install/examples/restG4/08.Alphas/data/Run_5MeV_1um.root expire_in: 1 day -01_alphaTrack: +01.alphaTrack: stage: examples script: - source ${CI_PROJECT_DIR}/install/thisREST.sh @@ -225,7 +225,7 @@ Basic Readout: - restRoot -b -q BasicValidation.C'("basic.root", "pixelDecoding")' Test Metadata: - stage: restManager_generate + stage: restManager generate script: - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/install/examples @@ -236,7 +236,7 @@ Test Metadata: expire_in: 1 day TREX-DM Latest Data: - stage: restManager_process + stage: restManager process script: - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/trex @@ -254,36 +254,36 @@ TREX-DM Latest Data: - ${CI_PROJECT_DIR}/pipeline/trex/Hits_01928.root expire_in: 1 day -PandaXIII Topological: - stage: restManager_process +PandaX-III Topological from reference file: + stage: restManager process script: - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC - - restManager --c AllProcesses.rml --i testInput.root --o testOutput.root --j 1 --e 10 - - restRoot -b -q ../MakeBasicTree.C'("testOutput.root")' - - restRoot -b -q ../ValidateTrees.C'("validation.root")' - - restManager --c plots.rml --i testOutput.root + - restManager --c AllProcesses.rml --i Xe136bb0n_small_reference.root --o Xe136bb0n_small_reference_processed.root --j 1 --e 10 + - restRoot -b -q ../MakeBasicTree.C'("Xe136bb0n_small_reference_processed.root")' + - restRoot -b -q ../ValidateTrees.C'("Xe136bb0n_validation.root")' + - restManager --c plots.rml --i Xe136bb0n_small_reference_processed.root artifacts: paths: - ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC/trackParameter.png expire_in: 1 week -PandaXIII Topological from Geant4: - stage: restManager_process +PandaX-III Topological from Geant4: + stage: restManager process script: - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC - echo "using just-generated g4 file" - - restManager --c AllProcesses.rml --i Xe136bb0n_n2E06.root --o testOutput.root --j 1 --e 10 - - restRoot -b -q ../MakeBasicTree.C'("testOutput.root")' - - restRoot -b -q ../ValidateTrees.C'("validation.root")' + - restManager --c AllProcesses.rml --i Xe136bb0n.root --o Xe136bb0n_processed.root --j 1 --e 10 + - restRoot -b -q ../MakeBasicTree.C'("Xe136bb0n_processed.root")' + - restRoot -b -q ../ValidateTrees.C'("Xe136bb0n_validation.root")' artifacts: paths: - - ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC/testOutput.root + - ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC/Xe136bb0n_processed.root expire_in: 1 week -PandaXIII Data: - stage: restManager_process +PandaX-III Data: + stage: restManager process script: - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_data @@ -296,15 +296,15 @@ PandaXIII Data: expire_in: 1 week Event Selection: - stage: restManager_process + stage: restManager process script: - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/selection - restManager --c g4Analysis.rml --f "${CI_PROJECT_DIR}/install/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root" - + - restManager --c g4OnSelection.rml --f Run00001_NLDBD_Test_g4Analysis.root - restRoot -b -q Validate.C'("Run00001_NLDBD_Test_EvSelection.root")' - + - restManager --c g4EvSelectionIDsFromFile.rml --f Run00001_NLDBD_Test_g4Analysis.root - restRoot -b -q ValidateIDsFromFile.C'("Run00001_NLDBD_Test_EvSelectionIDsFromFile.root")' diff --git a/examples/01.alphaTrack/Validate.C b/examples/01.alphaTrack/Validate.C index cdba78ea7..5e85ae8d9 100644 --- a/examples/01.alphaTrack/Validate.C +++ b/examples/01.alphaTrack/Validate.C @@ -1,11 +1,14 @@ -Int_t Validate(string fname) { - TRestRun* run = new TRestRun(fname); - cout << "Run entries : " << run->GetEntries() << endl; - if (run->GetEntries() < 4350 || run->GetEntries() > 4500) { - cout << "The number of entries is not in the range (4350,4500)!" << endl; +Int_t Validate(const char* filename) { + TRestRun run(filename); + cout << "Run entries : " << run.GetEntries() << endl; + + constexpr double numberOfEntriesRef = 4551; + constexpr double tolerance = 0.05; + + if (TMath::Abs(run.GetEntries() - numberOfEntriesRef) / numberOfEntriesRef > tolerance) { + cout << "The number of entries does not match the reference value of " << numberOfEntriesRef << endl; return 1; } - delete run; cout << "[\033[92m OK \x1b[0m]" << endl; return 0; diff --git a/pipeline/ValidateTrees.C b/pipeline/ValidateTrees.C index d07bc5a4c..3b44ae166 100644 --- a/pipeline/ValidateTrees.C +++ b/pipeline/ValidateTrees.C @@ -5,13 +5,21 @@ #include Int_t ValidateTrees(const char* validationFilename, const char* inputFilename = "results.root") { - TFile inputFile(inputFilename); - TTree* inputTree = inputFile.Get("bTree"); + TFile* inputFile = TFile::Open(inputFilename); + if (inputFile == nullptr) { + cout << "Input file '" << inputFilename << " does not exist" << endl; + exit(1); + } + TTree* inputTree = inputFile->Get("bTree"); std::vector* inputObservableVector = 0; inputTree->SetBranchAddress("doubleObservables", &inputObservableVector); - TFile validationFile(validationFilename); - TTree* validationTree = validationFile.Get("bTree"); + TFile* validationFile = TFile::Open(validationFilename); + if (validationFile == nullptr) { + cout << "Validation file '" << validationFilename << " does not exist" << endl; + exit(1); + } + TTree* validationTree = validationFile->Get("bTree"); std::vector* validationObservableVector = 0; validationTree->SetBranchAddress("doubleObservables", &validationObservableVector); diff --git a/pipeline/pandaxiii_MC/AllProcesses.rml b/pipeline/pandaxiii_MC/AllProcesses.rml index 63dab703a..c869f477b 100644 --- a/pipeline/pandaxiii_MC/AllProcesses.rml +++ b/pipeline/pandaxiii_MC/AllProcesses.rml @@ -1,65 +1,67 @@ - - - - - - - %options are : silent, warning, info, debug - // set to 0 as random seed - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + %options are : silent, warning, info, debug + + // set to 0 as random seed + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + diff --git a/pipeline/pandaxiii_MC/README.md b/pipeline/pandaxiii_MC/README.md index 0c513ecbf..cd2f7df5c 100644 --- a/pipeline/pandaxiii_MC/README.md +++ b/pipeline/pandaxiii_MC/README.md @@ -1,14 +1,15 @@ The following scripts are used to validate the PandaX-III simulation & topological analysis chain. -step 1: Use Xe136bb0n.rml to tun restG4 for Geant4 simulation. Use ValidateG4.C to check if the simulation -goes smoothly. i.e. all 500 events are simulated and metadata is correctly recorded. The output file will -be used later on +- **step 1**: Use `restG4 Xe136bb0n.rml` to run test Geant4 simulation. Use `ValidateG4.C` to check if the simulation + produced the expected output. i.e. all 500 events are simulated and metadata is correctly recorded. The output file + will be used later on. -step 2: Use AllProcesses.rml to run restManager for REST simulation and topological analysis. processes_2D.rml -and readout-140kg.rml is included by it. +- **step 2**: Use `AllProcesses.rml` to run restManager for REST simulation and topological analysis. `processes_2D.rml` + and `readout-140kg.rml` is included by it. -step 3: Use plots.rml to check the plots can be successfully drawn by TRestAnalysisPlot +- **step 3**: Use `plots.rml` to check the plots can be successfully drawn by TRestAnalysisPlot + +File `Xe136bb0n_small_reference.root` corresponds to the file generated by step 1 using Geant4 11.0.2 but with a smaller +number of simulated events to reduce size. events. -If geant4 version is not 10.4.2, we will use testInput.root instead of the one generated in step 1 as the input -of step 2. This file is generated manually with 10.4.2 with only 10 events saved. diff --git a/pipeline/pandaxiii_MC/ValidateG4.C b/pipeline/pandaxiii_MC/ValidateG4.C index 44efe8173..fdafd62fd 100644 --- a/pipeline/pandaxiii_MC/ValidateG4.C +++ b/pipeline/pandaxiii_MC/ValidateG4.C @@ -1,52 +1,52 @@ -Int_t ValidateG4(string fname) { - TRestRun* run = new TRestRun(fname); +Int_t ValidateG4(const char* filename) { + TRestRun run(filename); - if (run->GetParentRunNumber() != 0) { - cout << "Parent run number value : " << run->GetParentRunNumber() << endl; + if (run.GetParentRunNumber() != 0) { + cout << "Parent run number value : " << run.GetParentRunNumber() << endl; cout << "The parent run number from restG4 generated file should be 0" << endl; return 1; } - if (run->GetRunNumber() != 1) { - cout << "Run number value : " << run->GetRunNumber() << endl; + if (run.GetRunNumber() != 1) { + cout << "Run number value : " << run.GetRunNumber() << endl; cout << "The run number on the validation chain should be 1 by default!" << endl; return 2; } - if (run->GetRunType() != "restG4") { - cout << "Run type : " << run->GetRunType() << endl; + if (run.GetRunType() != "restG4") { + cout << "Run type : " << run.GetRunType() << endl; cout << "The run type of restG4 generated data should be 'restG4'!" << endl; return 3; } - if (run->GetRunTag() != "SimulationofXe136bb0ndecayfromgas.") { - cout << "Run tag : " << run->GetRunTag() << endl; + if (run.GetRunTag() != "SimulationofXe136bb0ndecayfromgas.") { + cout << "Run tag : " << run.GetRunTag() << endl; cout << "The run tag of the basic validation test should be 'NLDBD'!" << endl; return 4; } - if (run->GetEntries() != 500) { - cout << "Run entries : " << run->GetEntries() << endl; + if (run.GetEntries() != 500) { + cout << "Run entries : " << run.GetEntries() << endl; cout << "The NLDBD simulation is launched from gas. It should always generate 50000 events." << endl; return 5; } cout << "Testing reading of Geant4 metadata class" << endl; - TRestGeant4Metadata* g4Md = (TRestGeant4Metadata*)run->GetMetadataClass("TRestGeant4Metadata"); - if (!g4Md) { + TRestGeant4Metadata* geant4Metadata = (TRestGeant4Metadata*)run.GetMetadataClass("TRestGeant4Metadata"); + if (!geant4Metadata) { cout << "Problem reading Geant4 metadata class!" << endl; return 6; } - g4Md->PrintMetadata(); + geant4Metadata->PrintMetadata(); - if (g4Md->GetNumberOfActiveVolumes() != 1) { + if (geant4Metadata->GetNumberOfActiveVolumes() != 1) { cout << "The number of registered volumes is not 1!" << endl; return 7; } // Other tests like opening other metadata classes. Detector TGeoManager, etc. - cout << "G4 file good" << endl; + cout << "Validation passes" << endl; return 0; } diff --git a/pipeline/pandaxiii_MC/Xe136bb0n.rml b/pipeline/pandaxiii_MC/Xe136bb0n.rml index 3ad66e8c5..06de25451 100644 --- a/pipeline/pandaxiii_MC/Xe136bb0n.rml +++ b/pipeline/pandaxiii_MC/Xe136bb0n.rml @@ -8,69 +8,67 @@ from a given volume gas defined in the geometry.ml --> - - - %options are : silent, warning, info, debug - + + + + %options are : silent, warning, info, debug + - - - - - - - + + + + + + + - - - - - - + + + + + - - - - + + + + - - - - + + + + - + - + - - - + + + - - - - + + + + - - - - + + - - - - - + + + + + - - - - - - + + + + + + - + diff --git a/pipeline/pandaxiii_MC/Xe136bb0n_small_reference.root b/pipeline/pandaxiii_MC/Xe136bb0n_small_reference.root new file mode 100644 index 000000000..db40a66e9 Binary files /dev/null and b/pipeline/pandaxiii_MC/Xe136bb0n_small_reference.root differ diff --git a/pipeline/pandaxiii_MC/Xe136bb0n_validation.root b/pipeline/pandaxiii_MC/Xe136bb0n_validation.root new file mode 100644 index 000000000..2759b9b74 Binary files /dev/null and b/pipeline/pandaxiii_MC/Xe136bb0n_validation.root differ diff --git a/pipeline/pandaxiii_MC/Xe136bb0n_validation_G4_v10.4.3.root b/pipeline/pandaxiii_MC/Xe136bb0n_validation_G4_v10.4.3.root new file mode 100644 index 000000000..4deb656af Binary files /dev/null and b/pipeline/pandaxiii_MC/Xe136bb0n_validation_G4_v10.4.3.root differ diff --git a/pipeline/pandaxiii_MC/validation_6.20.root b/pipeline/pandaxiii_MC/Xe136bb0n_validation_root6.20.root similarity index 100% rename from pipeline/pandaxiii_MC/validation_6.20.root rename to pipeline/pandaxiii_MC/Xe136bb0n_validation_root6.20.root diff --git a/pipeline/pandaxiii_MC/plots.rml b/pipeline/pandaxiii_MC/plots.rml index 04eafb350..efc5ec537 100644 --- a/pipeline/pandaxiii_MC/plots.rml +++ b/pipeline/pandaxiii_MC/plots.rml @@ -1,77 +1,74 @@ - - - - //change this value to "auto" to enable database - //change this value to "auto" to enable database - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + //change this value to "auto" to enable database + //change this value to "auto" to enable database + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pipeline/pandaxiii_MC/processes_2D.rml b/pipeline/pandaxiii_MC/processes_2D.rml index 10cd16847..f36896906 100644 --- a/pipeline/pandaxiii_MC/processes_2D.rml +++ b/pipeline/pandaxiii_MC/processes_2D.rml @@ -1,443 +1,458 @@ - - + + - - - + + + - - // fwhm - // absolute gain // parameter name="electronicsGain" value="671744" // electrons for 4096 ADC units + + // fwhm + // absolute gain // parameter name="electronicsGain" + value="671744" // electrons for 4096 ADC units - + - - // fwhm - // absolute gain // parameter name="electronicsGain" value="671744" // electrons for 4096 ADC units + + // fwhm + // absolute gain // parameter name="electronicsGain" + value="671744" // electrons for 4096 ADC units - - - - - - - - - - + + + + + + + + + + - - // Number of sigmas to perform the calculation + + // Number of sigmas to perform the calculation - // // electrons in each time bin + // // electrons in each time bin - - - + + + - + - + - + - - + + - - + + - + - - - + + + - + - - - - + + + + - - - - - + + + + + - - + + - - + + - + - + - - - - - - - - + + + + + + + + - - - - - - - + + + + + + + - + - - - + + + - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - + - - - + + + - - - - - - - - - + + + + + + + + + - + - - + + - - + + - - + + - - + + - + - - - - - - - - + + + + + + + + - - - + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - + - + - - - + + + @@ -475,97 +490,98 @@ --> - - - - + + + + - + - + - + - + - - - + + + - //response file to be used to shape the signal + //response file to be used + to shape the signal - + - + - - - - + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pipeline/pandaxiii_MC/readout-140kg.rml b/pipeline/pandaxiii_MC/readout-140kg.rml index 5009ef0e9..e44415e5d 100644 --- a/pipeline/pandaxiii_MC/readout-140kg.rml +++ b/pipeline/pandaxiii_MC/readout-140kg.rml @@ -2,128 +2,136 @@ - - - - - - - - - - //The Microbulk MicroMegas - - - // Y-strips (pixel has fixed x coordinate) - - - - + + + + + + + + + + //The Microbulk MicroMegas + + + // Y-strips (pixel has fixed x coordinate) + + + + + + + - - - - - // Last strip is special - - - - - - - - - // X-strips (pixel has fixed y coordinate) - - // First strip is special - - - - - - - - - + + // Last strip is special + + + + + + + + + // X-strips (pixel has fixed y coordinate) + + // First strip is special + + + + + + + + + + + - - - - - - - - - - - - - - - - - - // 4 modules - - - - - // 6-modules - - - - - // 8-modules - - - - - // 8-modules - - - - - // 8-modules - - - - - // 8-modules - - - - - // 6-modules - - - - - // 4-modules - - - - - - - - + + + + + + + + + + + + + + + + // 4 modules + + + + + // 6-modules + + + + + // 8-modules + + + + + // 8-modules + + + + + // 8-modules + + + + + // 8-modules + + + + + // 6-modules + + + + + // 4-modules + + + + + + + + diff --git a/pipeline/pandaxiii_MC/readouts.rml b/pipeline/pandaxiii_MC/readouts.rml index 54b7e7b45..cac55487c 100644 --- a/pipeline/pandaxiii_MC/readouts.rml +++ b/pipeline/pandaxiii_MC/readouts.rml @@ -3,328 +3,340 @@ - - - - - - - - - - //The Microbulk MicroMegas - - - // Y-strips (pixel has fixed x coordinate) - - - - + + + + + + + + + + //The Microbulk MicroMegas + + + // Y-strips (pixel has fixed x coordinate) + + + + + + + - - - - - // Last strip is special - - - - - - - - - // X-strips (pixel has fixed y coordinate) - - // First strip is special - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Last strip is special + + + + + + + + + // X-strips (pixel has fixed y coordinate) + + // First strip is special + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 4 modules - - - - - // 6-modules - - - - - // 7-modules - - - - - // 7-modules - - - - - // 7-modules - - - - - // 6-modules - - - - - // 4-modules - - - - - - - - - - - - - - - - - - - - - - // 2 modules - - - - - // 5-modules - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - // 6-modules - - + + + + + + + + + + + + + + + // 4 modules + + + + + // 6-modules + + + + + // 7-modules + + + + + // 7-modules + + + + + // 7-modules + + + + + // 6-modules + + + + + // 4-modules + + + + - - // 7-modules - - - - - // 6-modules - - - - - // 5-modules - - - - - // 2-modules - - + + + + + + + + + + + + + + + + + + // 2 modules + + + + + // 5-modules + + + + + // 6-modules + + + + + // 7-modules + + + + + // 6-modules + + + + + // 5-modules + + + + + // 2-modules + + + + - - - + \ No newline at end of file diff --git a/pipeline/pandaxiii_MC/testInput.root b/pipeline/pandaxiii_MC/testInput.root deleted file mode 100644 index a5ae71e61..000000000 Binary files a/pipeline/pandaxiii_MC/testInput.root and /dev/null differ diff --git a/pipeline/pandaxiii_MC/validation.root b/pipeline/pandaxiii_MC/validation.root deleted file mode 100644 index 12cef457e..000000000 Binary files a/pipeline/pandaxiii_MC/validation.root and /dev/null differ diff --git a/pipeline/selection/Validate.C b/pipeline/selection/Validate.C index 2ed366658..92c90a336 100644 --- a/pipeline/selection/Validate.C +++ b/pipeline/selection/Validate.C @@ -3,30 +3,42 @@ #include #include -Int_t Validate(TString fname) { - TFile* f = new TFile(fname); - TTree* tr = (TTree*)f->Get("AnalysisTree"); - tr->Scan("eventID:g4Ana_totalEdep:g4Ana_energyPrimary"); +Int_t Validate(const char* filename, const bool isReferenceGeant4Version = false) { + TFile* file = TFile::Open(filename); + TTree* analysisTree = file->Get("AnalysisTree"); - if (tr->GetEntries() != 1) { + analysisTree->Scan("eventID:g4Ana_totalEdep:g4Ana_energyPrimary"); + + const size_t expectedNumberOfEntries = (!isReferenceGeant4Version) ? 16 : 19; + + if (analysisTree->GetEntries() != expectedNumberOfEntries) { cout << "Number of entries is not the same!" << endl; - cout << "Expected: 1. Obtained: " << tr->GetEntries() << endl; + cout << "Expected: " << expectedNumberOfEntries << ". Obtained: " << analysisTree->GetEntries() + << endl; return 1; } // Check IDs. - std::vector ids = {1}; - for (Int_t i = 0; i < tr->GetEntries(); i++) { - tr->GetEntry(i); - if (tr->GetLeaf("eventID")->GetValue(0) != ids[i]) { + bool success = true; + const std::vector ids = + (!isReferenceGeant4Version) + ? std::vector{5, 15, 19, 22, 29, 46, 50, 58, 65, 80, 88, 89, 93, 95, 97, 99} + : std::vector{7, 8, 10, 13, 14, 15, 17, 19, 25, 27, 37, 44, 55, 58, 77, 84, 90, 92, 94}; + for (Int_t i = 0; i < analysisTree->GetEntries(); i++) { + analysisTree->GetEntry(i); + if (analysisTree->GetLeaf("eventID")->GetValue(0) != ids[i]) { cout << "Same number of entries but different IDs" << endl; - cout << "Found entry " << i << " with ID: " << tr->GetLeaf("eventID")->GetValue(0) << endl; + cout << "Found entry " << i << " with ID: " << analysisTree->GetLeaf("eventID")->GetValue(0) + << endl; cout << "Expected entry " << i << " with ID: " << ids[i] << endl; - return 2; + success = false; } } + if (!success) { + return 2; + } - cout << "Tree validation sucess!" << endl; + cout << "Tree validation success!" << endl; return 0; } diff --git a/pipeline/selection/ValidateIDsFromFile.C b/pipeline/selection/ValidateIDsFromFile.C index c9e832a5c..6996afeab 100644 --- a/pipeline/selection/ValidateIDsFromFile.C +++ b/pipeline/selection/ValidateIDsFromFile.C @@ -3,27 +3,35 @@ #include #include -Int_t Validate(TString fname) { - TFile* f = new TFile(fname); - TTree* tr = (TTree*)f->Get("AnalysisTree"); - if (tr->GetEntries() != 3) { +Int_t ValidateIDsFromFile(const char* filename) { + TFile* file = TFile::Open(filename); + TTree* analysisTree = file->Get("AnalysisTree"); + + constexpr size_t expectedNumberOfEntries = 3; + if (analysisTree->GetEntries() != expectedNumberOfEntries) { cout << "Number of entries is not the same!" << endl; - cout << "Expected: 3. Obtained: " << tr->GetEntries() << endl; + cout << "Expected: " << expectedNumberOfEntries << ". Obtained: " << analysisTree->GetEntries() + << endl; return 1; } // Check IDs. + bool success = true; std::vector ids = {0, 3, 6}; - for (Int_t i = 0; i < tr->GetEntries(); i++) { - tr->GetEntry(i); - if (tr->GetLeaf("eventID")->GetValue(0) != ids[i]) { + for (Int_t i = 0; i < analysisTree->GetEntries(); i++) { + analysisTree->GetEntry(i); + if (analysisTree->GetLeaf("eventID")->GetValue(0) != ids[i]) { cout << "Same number of entries but different IDs" << endl; - cout << "Found entry " << i << " with ID: " << tr->GetLeaf("eventID")->GetValue(0) << endl; + cout << "Found entry " << i << " with ID: " << analysisTree->GetLeaf("eventID")->GetValue(0) + << endl; cout << "Expected entry " << i << " with ID: " << ids[i] << endl; - return 2; + success = false; } } + if (!success) { + return 2; + } cout << "Tree validation sucess!" << endl; return 0; diff --git a/pipeline/selection/g4Analysis.rml b/pipeline/selection/g4Analysis.rml index ce45052a7..3dff4bf0a 100644 --- a/pipeline/selection/g4Analysis.rml +++ b/pipeline/selection/g4Analysis.rml @@ -3,34 +3,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pipeline/selection/g4EvSelectionIDsFromFile.rml b/pipeline/selection/g4EvSelectionIDsFromFile.rml index f037a146b..37be16f15 100644 --- a/pipeline/selection/g4EvSelectionIDsFromFile.rml +++ b/pipeline/selection/g4EvSelectionIDsFromFile.rml @@ -3,32 +3,34 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pipeline/selection/g4OnSelection.rml b/pipeline/selection/g4OnSelection.rml index 10e46dd69..a61e2ca05 100644 --- a/pipeline/selection/g4OnSelection.rml +++ b/pipeline/selection/g4OnSelection.rml @@ -3,33 +3,36 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/framework/core/inc/TRestBrowser.h b/source/framework/core/inc/TRestBrowser.h index 11038b80c..10af1cba6 100644 --- a/source/framework/core/inc/TRestBrowser.h +++ b/source/framework/core/inc/TRestBrowser.h @@ -50,8 +50,8 @@ class TRestBrowser { Int_t fEventId = 0; //! Int_t fEventSubId = 0; //! - TBrowser* b = nullptr; //! - TRestRun* r = nullptr; //! + TBrowser* fBrowser = nullptr; //! + TRestRun* fRestRun = nullptr; //! #endif private: @@ -62,17 +62,17 @@ class TRestBrowser { TRestEventViewer* fEventViewer = nullptr; //! void SetViewer(TRestEventViewer* eV); - void SetViewer(TString viewerName); + void SetViewer(const TString& viewerName); void SetButtons(); - Bool_t LoadEventId(Int_t id, Int_t subid = -1); + Bool_t LoadEventId(Int_t eventID, Int_t subEventID = -1); Bool_t LoadEventEntry(Int_t n); #endif public: // tool method - void Initialize(TString opt = "FI"); + void Initialize(const TString& opt = "FI"); void InitFromConfigFile(); - Bool_t OpenFile(TString filename); + Bool_t OpenFile(const TString& filename); // setters void SetInputEvent(TRestEvent*); @@ -96,7 +96,7 @@ class TRestBrowser { // Constructors TRestBrowser(); - TRestBrowser(TString viewerName); + TRestBrowser(const TString& viewerName); // Destructor ~TRestBrowser(); diff --git a/source/framework/core/inc/TRestRun.h b/source/framework/core/inc/TRestRun.h index d88fbc07c..8c6a41047 100644 --- a/source/framework/core/inc/TRestRun.h +++ b/source/framework/core/inc/TRestRun.h @@ -124,7 +124,7 @@ class TRestRun : public TRestMetadata { RESTWarning << "REST Warning! A null metadata wants to be added in TRestRun!" << RESTendl; } } - void AddEventBranch(TRestEvent* eve); + void AddEventBranch(TRestEvent* event); void SkipEventTree() {} void cd() { @@ -178,8 +178,8 @@ class TRestRun : public TRestMetadata { inline TTree* GetEventTree() const { return fEventTree; } inline Int_t GetInputFileNumber() const { return fFileProcess == nullptr ? fInputFileNames.size() : 1; } - TRestMetadata* GetMetadata(const TString& name, TFile* f = nullptr); - TRestMetadata* GetMetadataClass(const TString& type, TFile* f = nullptr); + TRestMetadata* GetMetadata(const TString& name, TFile* file = nullptr); + TRestMetadata* GetMetadataClass(const TString& type, TFile* file = nullptr); std::vector GetMetadataStructureNames(); std::vector GetMetadataStructureTitles(); inline int GetNumberOfMetadataStructures() const { return fMetadata.size(); } diff --git a/source/framework/core/src/TRestBrowser.cxx b/source/framework/core/src/TRestBrowser.cxx index 3312a6419..d57c25584 100644 --- a/source/framework/core/src/TRestBrowser.cxx +++ b/source/framework/core/src/TRestBrowser.cxx @@ -34,12 +34,12 @@ TRestBrowser::TRestBrowser() { OpenFile(gDirectory->GetFile()->GetName()); cout << "Loaded File : " << fInputFileName << endl; } else { - b = new TBrowser("Browser", 0, "REST Browser"); - r = new TRestRun(); + fBrowser = new TBrowser("Browser", nullptr, "REST Browser"); + fRestRun = new TRestRun(); } } -TRestBrowser::TRestBrowser(TString viewerName) { +TRestBrowser::TRestBrowser(const TString& viewerName) { Initialize("I"); SetViewer(viewerName); } @@ -49,29 +49,29 @@ TRestBrowser::~TRestBrowser() { // delete frmMain; } -void TRestBrowser::Initialize(TString opt) { +void TRestBrowser::Initialize(const TString& opt) { pureAnalysis = kFALSE; - r = new TRestRun(); + fRestRun = new TRestRun(); - b = new TBrowser("Browser", 0, "REST Browser", opt); - TGMainFrame* fr = b->GetBrowserImp()->GetMainFrame(); + fBrowser = new TBrowser("Browser", 0, "REST Browser", opt); + TGMainFrame* fr = fBrowser->GetBrowserImp()->GetMainFrame(); if (fr == nullptr) { RESTWarning << "No x11 interface is available. Cannot call the browser window!" << RESTendl; exit(1); } fr->DontCallClose(); - b->StartEmbedding(0, -1); + fBrowser->StartEmbedding(0, -1); frmMain = new TGMainFrame(gClient->GetRoot(), 300); frmMain->SetCleanup(kDeepCleanup); frmMain->SetWindowName("Controller"); SetButtons(); - b->StopEmbedding(); + fBrowser->StopEmbedding(); - b->StartEmbedding(1, -1); + fBrowser->StartEmbedding(1, -1); fCanDefault = new TCanvas(); - b->StopEmbedding(); + fBrowser->StopEmbedding(); // frmMain->DontCallClose(); frmMain->MapSubwindows(); // frmMain->Resize(); @@ -87,12 +87,12 @@ void TRestBrowser::SetViewer(TRestEventViewer* eV) { if (eV != nullptr) { fEventViewer = eV; // b->StartEmbedding(1, -1); - eV->Embed(b); + eV->Embed(fBrowser); // b->StopEmbedding(); } } -void TRestBrowser::SetViewer(TString viewerName) { +void TRestBrowser::SetViewer(const TString& viewerName) { if (Count((string)viewerName, "Viewer") > 0) { TRestEventViewer* viewer = REST_Reflection::Assembly((string)viewerName); if (viewer != nullptr) { @@ -112,86 +112,86 @@ void TRestBrowser::SetViewer(TString viewerName) { void TRestBrowser::SetButtons() { TString icondir = (TString)getenv("ROOTSYS") + "/icons/"; - auto fVFrame = new TGVerticalFrame(frmMain); - fVFrame->Resize(300, 200); + auto vFrame = new TGVerticalFrame(frmMain); + vFrame->Resize(300, 200); // row in the tree - fEventRowLabel = new TGLabel(fVFrame, "Entry:"); - fVFrame->AddFrame(fEventRowLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fEventRowLabel = new TGLabel(vFrame, "Entry:"); + vFrame->AddFrame(fEventRowLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fEventRowNumberBox = new TGNumberEntry(fVFrame, fEventRow); + fEventRowNumberBox = new TGNumberEntry(vFrame, fEventRow); fEventRowNumberBox->Connect("ValueSet(Long_t)", "TRestBrowser", this, "RowValueChangedAction(Long_t)"); - fVFrame->AddFrame(fEventRowNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + vFrame->AddFrame(fEventRowNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // event id and sub event id - auto labelbar = new TGHorizontalFrame(fVFrame); + auto labelBar = new TGHorizontalFrame(vFrame); { - fEventIdLabel = new TGLabel(labelbar, "Event ID:"); - labelbar->AddFrame(fEventIdLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fEventIdLabel = new TGLabel(labelBar, "Event ID:"); + labelBar->AddFrame(fEventIdLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fEventSubIdLabel = new TGLabel(labelbar, "Sub ID:"); - labelbar->AddFrame(fEventSubIdLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fEventSubIdLabel = new TGLabel(labelBar, "Sub ID:"); + labelBar->AddFrame(fEventSubIdLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); } - fVFrame->AddFrame(labelbar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + vFrame->AddFrame(labelBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - auto numberboxbar = new TGHorizontalFrame(fVFrame); + auto numberBoxBar = new TGHorizontalFrame(vFrame); { - fEventIdNumberBox = new TGNumberEntry(numberboxbar, fEventId); + fEventIdNumberBox = new TGNumberEntry(numberBoxBar, fEventId); fEventIdNumberBox->Connect("ValueSet(Long_t)", "TRestBrowser", this, "IdValueChangedAction(Long_t)"); - numberboxbar->AddFrame(fEventIdNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + numberBoxBar->AddFrame(fEventIdNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fEventSubIdNumberBox = new TGNumberEntry(numberboxbar, fEventSubId); + fEventSubIdNumberBox = new TGNumberEntry(numberBoxBar, fEventSubId); fEventSubIdNumberBox->Connect("ValueSet(Long_t)", "TRestBrowser", this, "IdValueChangedAction(Long_t)"); - numberboxbar->AddFrame(fEventSubIdNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + numberBoxBar->AddFrame(fEventSubIdNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); } - fVFrame->AddFrame(numberboxbar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + vFrame->AddFrame(numberBoxBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // event type to choose - fEventTypeLabel = new TGLabel(fVFrame, "Event Type:"); - fVFrame->AddFrame(fEventTypeLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fEventTypeLabel = new TGLabel(vFrame, "Event Type:"); + vFrame->AddFrame(fEventTypeLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fEventTypeComboBox = new TGComboBox(fVFrame); + fEventTypeComboBox = new TGComboBox(vFrame); fEventTypeComboBox->Connect("Selected(Int_t)", "TRestBrowser", this, "EventTypeChangedAction(Int_t)"); - fVFrame->AddFrame(fEventTypeComboBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + vFrame->AddFrame(fEventTypeComboBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // plot option buttons - fPlotOptionLabel = new TGLabel(fVFrame, "Plot Options:"); - fVFrame->AddFrame(fPlotOptionLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fPlotOptionLabel = new TGLabel(vFrame, "Plot Options:"); + vFrame->AddFrame(fPlotOptionLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fPlotOptionTextBox = new TGTextEntry(fVFrame, ""); + fPlotOptionTextBox = new TGTextEntry(vFrame, ""); fPlotOptionTextBox->SetText(""); fPlotOptionTextBox->Connect("ReturnPressed()", "TRestBrowser", this, "PlotAction()"); - fVFrame->AddFrame(fPlotOptionTextBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + vFrame->AddFrame(fPlotOptionTextBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - auto switchbuttonbar = new TGHorizontalFrame(fVFrame); + auto switchButtonBar = new TGHorizontalFrame(vFrame); { - fButOptPrev = new TGTextButton(switchbuttonbar, "<Connect("Clicked()", "TRestBrowser", this, "PreviousPlotOptionAction()"); - switchbuttonbar->AddFrame(fButOptPrev, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + switchButtonBar->AddFrame(fButOptPrev, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fButOptRefresh = new TGTextButton(switchbuttonbar, "Plot"); ///< Load Event button + fButOptRefresh = new TGTextButton(switchButtonBar, "Plot"); ///< Load Event button fButOptRefresh->Connect("Clicked()", "TRestBrowser", this, "PlotAction()"); - switchbuttonbar->AddFrame(fButOptRefresh, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + switchButtonBar->AddFrame(fButOptRefresh, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fButOptNext = new TGTextButton(switchbuttonbar, "Next>>"); ///< Load Event button + fButOptNext = new TGTextButton(switchButtonBar, "Next>>"); ///< Load Event button fButOptNext->Connect("Clicked()", "TRestBrowser", this, "NextPlotOptionAction()"); - switchbuttonbar->AddFrame(fButOptNext, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + switchButtonBar->AddFrame(fButOptNext, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); } - fVFrame->AddFrame(switchbuttonbar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + vFrame->AddFrame(switchButtonBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // tool buttons - fMenuOpen = new TGPictureButton(fVFrame, gClient->GetPicture(icondir + "bld_open.png")); + fMenuOpen = new TGPictureButton(vFrame, gClient->GetPicture(icondir + "bld_open.png")); fMenuOpen->Connect("Clicked()", "TRestBrowser", this, "LoadFileAction()"); - fVFrame->AddFrame(fMenuOpen, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + vFrame->AddFrame(fMenuOpen, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fExit = new TGTextButton(fVFrame, "EXIT"); ///< Exit button + fExit = new TGTextButton(vFrame, "EXIT"); ///< Exit button fExit->Connect("Clicked()", "TRestBrowser", this, "ExitAction()"); - fVFrame->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + vFrame->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - frmMain->Resize(TGDimension(300, frmMain->GetHeight() + fVFrame->GetHeight())); + frmMain->Resize(TGDimension(300, frmMain->GetHeight() + vFrame->GetHeight())); - frmMain->AddFrame(fVFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + frmMain->AddFrame(vFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // frmMain->DontCallClose(); frmMain->MapSubwindows(); // frmMain->Resize(); @@ -201,14 +201,14 @@ void TRestBrowser::SetButtons() { void TRestBrowser::InitFromConfigFile() { cout << __PRETTY_FUNCTION__ << endl; } -void TRestBrowser::SetInputEvent(TRestEvent* eve) { - if (r != nullptr) { - r->SetInputEvent(eve); +void TRestBrowser::SetInputEvent(TRestEvent* event) { + if (fRestRun != nullptr) { + fRestRun->SetInputEvent(event); } } Bool_t TRestBrowser::LoadEventEntry(Int_t n) { - if (r->GetInputFile() == nullptr || r->GetInputFile()->IsZombie()) { + if (fRestRun->GetInputFile() == nullptr || fRestRun->GetInputFile()->IsZombie()) { RESTWarning << "TRestBrowser::LoadEventEntry. No File..." << RESTendl; return kFALSE; } @@ -217,21 +217,21 @@ Bool_t TRestBrowser::LoadEventEntry(Int_t n) { return kFALSE; } - if (r->GetAnalysisTree() != nullptr && n < r->GetAnalysisTree()->GetEntries() && n >= 0) { - r->GetEntry(n); - TRestEvent* ev = r->GetInputEvent(); + if (fRestRun->GetAnalysisTree() != nullptr && n < fRestRun->GetAnalysisTree()->GetEntries() && n >= 0) { + fRestRun->GetEntry(n); + TRestEvent* ev = fRestRun->GetInputEvent(); if (!ev) { RESTError << "internal error!" << RESTendl; return kFALSE; } else { - fEventRow = r->GetCurrentEntry(); + fEventRow = fRestRun->GetCurrentEntry(); fEventId = ev->GetID(); fEventSubId = ev->GetSubID(); fEventRowNumberBox->SetIntNumber(fEventRow); fEventIdNumberBox->SetIntNumber(fEventId); fEventSubIdNumberBox->SetIntNumber(fEventSubId); - r->GetAnalysisTree()->PrintObservables(); + fRestRun->GetAnalysisTree()->PrintObservables(); } } else { RESTWarning << "TRestBrowser::LoadEventEntry. Event out of limits" << RESTendl; @@ -239,7 +239,7 @@ Bool_t TRestBrowser::LoadEventEntry(Int_t n) { } if (fEventViewer != nullptr) { - fEventViewer->AddEvent(r->GetInputEvent()); + fEventViewer->AddEvent(fRestRun->GetInputEvent()); fEventViewer->Plot(fPlotOptionTextBox->GetText()); cout << endl; } @@ -248,8 +248,8 @@ Bool_t TRestBrowser::LoadEventEntry(Int_t n) { return kTRUE; } -Bool_t TRestBrowser::LoadEventId(Int_t id, Int_t subid) { - if (r->GetInputFile() == nullptr || r->GetInputFile()->IsZombie()) { +Bool_t TRestBrowser::LoadEventId(Int_t eventID, Int_t subEventID) { + if (fRestRun->GetInputFile() == nullptr || fRestRun->GetInputFile()->IsZombie()) { RESTWarning << "TRestBrowser::LoadEventEntry. No File..." << RESTendl; return kFALSE; } @@ -259,20 +259,21 @@ Bool_t TRestBrowser::LoadEventId(Int_t id, Int_t subid) { return kFALSE; } - if (r->GetAnalysisTree() != nullptr && r->GetAnalysisTree()->GetEntries() > 0) { - TRestEvent* ev = r->GetEventWithID(id, subid); - if (!ev) { - RESTWarning << "Event ID : " << id << " with sub ID : " << subid << " not found!" << RESTendl; + if (fRestRun->GetAnalysisTree() != nullptr && fRestRun->GetAnalysisTree()->GetEntries() > 0) { + TRestEvent* event = fRestRun->GetEventWithID(eventID, subEventID); + if (event != nullptr) { + RESTWarning << "Event ID : " << eventID << " with sub ID : " << subEventID << " not found!" + << RESTendl; return kFALSE; } else { - fEventRow = r->GetCurrentEntry(); - fEventId = ev->GetID(); - fEventSubId = ev->GetSubID(); + fEventRow = fRestRun->GetCurrentEntry(); + fEventId = event->GetID(); + fEventSubId = event->GetSubID(); fEventRowNumberBox->SetIntNumber(fEventRow); fEventIdNumberBox->SetIntNumber(fEventId); fEventSubIdNumberBox->SetIntNumber(fEventSubId); - r->GetAnalysisTree()->PrintObservables(); + fRestRun->GetAnalysisTree()->PrintObservables(); } } else { RESTWarning << "TRestBrowser::LoadEventEntry. Event out of limits" << RESTendl; @@ -280,7 +281,7 @@ Bool_t TRestBrowser::LoadEventId(Int_t id, Int_t subid) { } if (fEventViewer != nullptr) { - fEventViewer->AddEvent(r->GetInputEvent()); + fEventViewer->AddEvent(fRestRun->GetInputEvent()); fEventViewer->Plot(fPlotOptionTextBox->GetText()); cout << endl; } @@ -289,13 +290,13 @@ Bool_t TRestBrowser::LoadEventId(Int_t id, Int_t subid) { return kTRUE; } -Bool_t TRestBrowser::OpenFile(TString filename) { +Bool_t TRestBrowser::OpenFile(const TString& filename) { if (filename.Contains("http") || TRestTools::fileExists(filename.Data())) { fInputFileName = filename; - r->OpenInputFile(fInputFileName); - TFile* f = r->GetInputFile(); - TTree* t = r->GetEventTree(); + fRestRun->OpenInputFile(fInputFileName); + TFile* f = fRestRun->GetInputFile(); + TTree* t = fRestRun->GetEventTree(); TGeoManager* geometry = gGeoManager; @@ -303,13 +304,13 @@ Bool_t TRestBrowser::OpenFile(TString filename) { // add entry for other event types TObjArray* branches = t->GetListOfBranches(); for (int i = 0; i <= branches->GetLast(); i++) { - TBranch* br = (TBranch*)branches->At(i); - if (((string)br->GetName()).find("EventBranch") != -1) { - string eventtype = Replace((string)br->GetName(), "Branch", ""); - fEventTypeComboBox->AddEntry(eventtype.c_str(), fEventTypeComboBox->GetNumberOfEntries()); + auto branch = (TBranch*)branches->At(i); + if (((string)branch->GetName()).find("EventBranch") != -1) { + string eventType = Replace((string)branch->GetName(), "Branch", ""); + fEventTypeComboBox->AddEntry(eventType.c_str(), fEventTypeComboBox->GetNumberOfEntries()); // we make the entry of input event being selected - if (r->GetInputEvent() != nullptr && - (string)r->GetInputEvent()->ClassName() == eventtype) { + if (fRestRun->GetInputEvent() != nullptr && + (string)fRestRun->GetInputEvent()->ClassName() == eventType) { fEventTypeComboBox->Select(fEventTypeComboBox->GetNumberOfEntries() - 1, false); } } @@ -324,11 +325,11 @@ Bool_t TRestBrowser::OpenFile(TString filename) { pureAnalysis = kTRUE; } - TRestEvent* ev = r->GetInputEvent(); + TRestEvent* ev = fRestRun->GetInputEvent(); if (!ev) { RESTError << "internal error!" << RESTendl; } else { - fEventRowNumberBox->SetIntNumber(r->GetCurrentEntry()); + fEventRowNumberBox->SetIntNumber(fRestRun->GetCurrentEntry()); fEventIdNumberBox->SetIntNumber(ev->GetID()); fEventSubIdNumberBox->SetIntNumber(ev->GetSubID()); } @@ -370,7 +371,7 @@ void TRestBrowser::PlotAction() { } void TRestBrowser::RowValueChangedAction(Long_t val) { - int rowold = fEventRow; + int eventRow = fEventRow; fEventRow = (Int_t)fEventRowNumberBox->GetNumber(); RESTDebug << "TRestBrowser::LoadEventAction. Entry:" << fEventRow << RESTendl; @@ -378,24 +379,24 @@ void TRestBrowser::RowValueChangedAction(Long_t val) { bool success = LoadEventEntry(fEventRow); if (!success) { - fEventRow = rowold; + fEventRow = eventRow; fEventRowNumberBox->SetIntNumber(fEventRow); } } void TRestBrowser::EventTypeChangedAction(Int_t id) { - string eventtype = fEventTypeComboBox->GetSelectedEntry()->GetTitle(); - TRestEvent* eve = REST_Reflection::Assembly(eventtype); + string eventType = fEventTypeComboBox->GetSelectedEntry()->GetTitle(); + TRestEvent* eve = REST_Reflection::Assembly(eventType); if (eve != nullptr) { - r->SetInputEvent(eve); + fRestRun->SetInputEvent(eve); RowValueChangedAction(0); } } void TRestBrowser::IdValueChangedAction(Long_t val) { - int idold = fEventId; - int subidold = fEventSubId; + int eventID = fEventId; + int subEventID = fEventSubId; fEventId = (Int_t)fEventIdNumberBox->GetNumber(); fEventSubId = (Int_t)fEventSubIdNumberBox->GetNumber(); @@ -406,8 +407,8 @@ void TRestBrowser::IdValueChangedAction(Long_t val) { bool success = LoadEventId(fEventId, fEventSubId); if (!success) { - fEventId = idold; - fEventSubId = subidold; + fEventId = eventID; + fEventSubId = subEventID; fEventIdNumberBox->SetIntNumber(fEventId); fEventSubIdNumberBox->SetIntNumber(fEventSubId); } diff --git a/source/framework/core/src/TRestRun.cxx b/source/framework/core/src/TRestRun.cxx index ec1df1ed2..2a1bc0b91 100644 --- a/source/framework/core/src/TRestRun.cxx +++ b/source/framework/core/src/TRestRun.cxx @@ -1227,25 +1227,17 @@ void TRestRun::SetExtProcess(TRestEventProcess* p) { void TRestRun::SetInputEvent(TRestEvent* event) { if (event != nullptr) { if (fEventTree != nullptr) { - // if (fEventBranchLoc != -1) { - // TBranch *br = (TBranch*)branches->At(fEventBranchLoc); - // br->SetAddress(0); - //} if (fInputEvent != nullptr) { - fEventTree->SetBranchAddress((TString)fInputEvent->ClassName() + "Branch", 0); + fEventTree->SetBranchAddress((TString)fInputEvent->ClassName() + "Branch", nullptr); fEventTree->SetBranchStatus((TString)fInputEvent->ClassName() + "Branch", false); } TObjArray* branches = fEventTree->GetListOfBranches(); string branchName = (string)event->ClassName() + "Branch"; for (int i = 0; i <= branches->GetLast(); i++) { - TBranch* br = (TBranch*)branches->At(i); - if ((string)br->GetName() == branchName) { + auto branch = (TBranch*)branches->At(i); + if ((string)branch->GetName() == branchName) { RESTDebug << "Setting input event.. Type: " << event->ClassName() << " Address: " << event << RESTendl; - // if (fInputEvent != nullptr && (char*)fInputEvent != (char*)eve) { - // delete fInputEvent; - //} - fInputEvent = event; fEventTree->SetBranchAddress(branchName.c_str(), &fInputEvent); fEventTree->SetBranchStatus(branchName.c_str(), false); @@ -1268,13 +1260,13 @@ void TRestRun::SetInputEvent(TRestEvent* event) { /////////////////////////////////////////////// /// \brief Add an event branch in output EventTree /// -void TRestRun::AddEventBranch(TRestEvent* eve) { - if (eve != nullptr) { +void TRestRun::AddEventBranch(TRestEvent* event) { + if (event != nullptr) { if (fEventTree != nullptr) { - string evename = (string)eve->ClassName(); - string branchName = evename + "Branch"; - fEventTree->Branch(branchName.c_str(), eve); - fEventTree->SetTitle((evename + "Tree").c_str()); + string eventName = (string)event->ClassName(); + string branchName = eventName + "Branch"; + fEventTree->Branch(branchName.c_str(), event); + fEventTree->SetTitle((eventName + "Tree").c_str()); } } } @@ -1297,7 +1289,7 @@ void TRestRun::ImportMetadata(const TString& File, const TString& name, const TS return; } - TFile* f = new TFile(thisFile); + TFile* file = TFile::Open(thisFile); // TODO give error in case we try to obtain a class that is not TRestMetadata if (type == "" && name == "") { RESTError << "(ImportMetadata) : metadata type and name is not " @@ -1308,17 +1300,17 @@ void TRestRun::ImportMetadata(const TString& File, const TString& name, const TS TRestMetadata* meta = nullptr; if (name != "") { - meta = GetMetadata(name, f); + meta = GetMetadata(name, file); } else if (type != "") { - meta = GetMetadataClass(type, f); + meta = GetMetadataClass(type, file); } if (meta == nullptr) { cout << "REST ERROR (ImportMetadata) : " << name << " does not exist." << endl; cout << "Inside root file : " << File << endl; GetChar(); - f->Close(); - delete f; + file->Close(); + delete file; return; } @@ -1329,8 +1321,8 @@ void TRestRun::ImportMetadata(const TString& File, const TString& name, const TS fMetadata.push_back(meta); meta->LoadConfigFromBuffer(); - f->Close(); - delete f; + file->Close(); + delete file; } Int_t TRestRun::Write(const char* name, Int_t option, Int_t bufsize) { @@ -1362,7 +1354,7 @@ int TRestRun::GetEntries() const { // Getters TRestEvent* TRestRun::GetEventWithID(Int_t eventID, Int_t subEventID, const TString& tag) { if (fAnalysisTree != nullptr) { - int nentries = fAnalysisTree->GetEntries(); + int nEntries = fAnalysisTree->GetEntries(); // set analysis tree to read only three branches fAnalysisTree->SetBranchStatus("*", false); @@ -1372,7 +1364,7 @@ TRestEvent* TRestRun::GetEventWithID(Int_t eventID, Int_t subEventID, const TStr // just look through the whole analysis tree and find the entry // this is not good! - for (int i = 0; i < nentries; i++) { + for (int i = 0; i < nEntries; i++) { fAnalysisTree->GetEntry(i); if (fAnalysisTree->GetEventID() == eventID) { if (subEventID != -1 && fAnalysisTree->GetSubEventID() != subEventID) continue; @@ -1397,7 +1389,7 @@ std::vector TRestRun::GetEventEntriesWithConditions(const string& cuts, int std::vector observables; std::vector operators; std::vector values; - // it is necessary that this vector vector is sorted from longest to shortest + // it is necessary that this vector is sorted from longest to shortest const std::vector validOperators = {"==", "<=", ">=", "=", ">", "<"}; vector cutsVector = Split(cuts, "&&", false, true); @@ -1546,19 +1538,19 @@ string TRestRun::GetRunInformation(const string& info) { return info; } -TRestMetadata* TRestRun::GetMetadataClass(const TString& type, TFile* f) { - if (f != nullptr) { - TIter nextkey(f->GetListOfKeys()); +TRestMetadata* TRestRun::GetMetadataClass(const TString& type, TFile* file) { + if (file != nullptr) { + TIter nextkey(file->GetListOfKeys()); TKey* key; while ((key = (TKey*)nextkey())) { string kName = key->GetClassName(); if (REST_Reflection::GetClassQuick(kName.c_str()) != nullptr && REST_Reflection::GetClassQuick(kName.c_str())->InheritsFrom(type)) { - TRestMetadata* a = (TRestMetadata*)f->Get(key->GetName()); + TRestMetadata* metadata = file->Get(key->GetName()); - if (a != nullptr && a->InheritsFrom("TRestMetadata")) { - return a; + if (metadata != nullptr && metadata->InheritsFrom("TRestMetadata")) { + return metadata; } else { RESTWarning << "TRestRun::GetMetadataClass() : The object to import is " "not inherited from TRestMetadata" @@ -1578,18 +1570,18 @@ TRestMetadata* TRestRun::GetMetadataClass(const TString& type, TFile* f) { return nullptr; } -TRestMetadata* TRestRun::GetMetadata(const TString& name, TFile* f) { - if (f != nullptr) { - TIter nextkey(f->GetListOfKeys()); +TRestMetadata* TRestRun::GetMetadata(const TString& name, TFile* file) { + if (file != nullptr) { + TIter nextkey(file->GetListOfKeys()); TKey* key; while ((key = (TKey*)nextkey())) { string kName = key->GetName(); if (kName == name) { - TRestMetadata* a = (TRestMetadata*)f->Get(name); + TRestMetadata* metadata = file->Get(name); - if (a->InheritsFrom("TRestMetadata")) { - return a; + if (metadata->InheritsFrom("TRestMetadata")) { + return metadata; } else { RESTWarning << "TRestRun::GetMetadata() : The object to import is not " "inherited from TRestMetadata" @@ -1600,10 +1592,6 @@ TRestMetadata* TRestRun::GetMetadata(const TString& name, TFile* f) { } else { for (unsigned int i = 0; i < fMetadata.size(); i++) if (fMetadata[i]->GetName() == name) return fMetadata[i]; - - // if (fInputFile != nullptr && this->GetVersionCode() >= - // ConvertVersionCode("2.2.1")) { return GetMetadata(name, fInputFile); - //} } return nullptr; diff --git a/source/framework/core/src/TRestThread.cxx b/source/framework/core/src/TRestThread.cxx index c98eba6d0..22799be15 100644 --- a/source/framework/core/src/TRestThread.cxx +++ b/source/framework/core/src/TRestThread.cxx @@ -404,18 +404,14 @@ void TRestThread::PrepareToProcess(bool* outputConfig) { fEventTree = new TTree((TString) "EventTree_" + ToString(fThreadId), "dummyTree"); // fEventTree->CreateEventBranches(); - if (outputConfig[2] == true) { + if (outputConfig[2]) { TString BranchName = (TString)fInputEvent->GetName() + "Branch"; if (fEventTree->GetBranch(BranchName) == nullptr) // avoid duplicated branch + { fEventTree->Branch(BranchName, fInputEvent->ClassName(), fInputEvent); + } } - // currently external process analysis is not supported! - - // if (fEventTree->GetListOfBranches()->GetLast() < 1) - //{ - // delete fEventTree; fEventTree = nullptr; - //} - // fAnalysisTree->CreateBranches(); + // currently, external process analysis is not supported! } if (outputConfigToDel) delete outputConfig; } @@ -432,7 +428,7 @@ void TRestThread::PrepareToProcess(bool* outputConfig) { /// Note: The methods GetNextevtFunc() and FillThreadEventFunc() are all from /// TRestProcessRunner. The later two will call back the method FillEvent(), /// EndProcess() in this class. The idea to do so is to make a unified -/// managemenet of these i-o related methods. In TRestRun the three methods are +/// management of these i-o related methods. In TRestRun the three methods are /// mutex locked. They will be paused until the host run allows it to run. This /// prevents segmentation violation due to simultaneously read/write. void TRestThread::StartProcess() { diff --git a/source/framework/tools/inc/TRestStringOutput.h b/source/framework/tools/inc/TRestStringOutput.h index 1671599a7..e37032cc4 100644 --- a/source/framework/tools/inc/TRestStringOutput.h +++ b/source/framework/tools/inc/TRestStringOutput.h @@ -144,18 +144,17 @@ struct endl_t { /// To use this tool class in the other classes, include this header file. /// You will get several global output objects: fout, info, essential, debug, etc. /// they works similarly as std::cout: `fout<<"hello world"< SeparatePathAndName(const std::string& fullname); static std::string GetPureFileName(const std::string& fullPathFileName); static std::string SearchFileInPath(std::vector path, std::string filename); - static Int_t CheckTheFile(std::string configFilename); + static bool CheckFileIsAccessible(const std::string&); static std::vector GetFilesMatchingPattern(std::string pattern); static int ConvertVersionCode(std::string in); static std::istream& GetLine(std::istream& is, std::string& t); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 3097ac72e..97fc85cc9 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -770,19 +770,19 @@ string TRestTools::SearchFileInPath(vector paths, string filename) { } /////////////////////////////////////////////// -/// \brief Checks if the config file can be openned. It returns OK in case of -/// success, ERROR otherwise. +/// \brief Checks if the config file can be opened (and thus exists). +/// It returns true in case of success, false otherwise. /// -Int_t TRestTools::CheckTheFile(std::string configFilename) { +bool TRestTools::CheckFileIsAccessible(const std::string& filename) { ifstream ifs; - ifs.open(configFilename.c_str()); + ifs.open(filename.c_str()); if (!ifs) { - return -1; - } else + return false; + } else { ifs.close(); - - return 0; + } + return true; } ///////////////////////////////////////////////