Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rest-for-physics/framework
Browse files Browse the repository at this point in the history
* 'master' of github.com:rest-for-physics/framework:
  TRestEventSelectionProcess upgrade (#528)
  Bump actions/checkout from 3 to 4
  • Loading branch information
lobis committed Jun 25, 2024
2 parents 187791e + 2ffc29d commit 69bb959
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v3
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
container:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build and install
uses: rest-for-physics/framework/.github/actions/build@master
with:
Expand All @@ -53,7 +53,7 @@ jobs:
container:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build and install
uses: rest-for-physics/framework/.github/actions/build@master
with:
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
needs: [ framework-install ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: rest-for-physics/framework
path: framework
Expand All @@ -109,7 +109,7 @@ jobs:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
needs: [ framework-install ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: rest-for-physics/framework
path: framework
Expand Down Expand Up @@ -155,7 +155,7 @@ jobs:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
needs: [ framework-install ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: rest-for-physics/framework
path: framework
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
needs: [ framework-install ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: rest-for-physics/framework
path: framework
Expand Down Expand Up @@ -230,7 +230,7 @@ jobs:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
needs: [ framework-install ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: rest-for-physics/framework
path: framework
Expand Down Expand Up @@ -283,7 +283,7 @@ jobs:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
needs: [ framework-install ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: rest-for-physics/framework
path: framework
Expand Down Expand Up @@ -374,7 +374,7 @@ jobs:
container:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-reference-jun2022
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build and install
uses: rest-for-physics/framework/.github/actions/build@master
with:
Expand Down Expand Up @@ -405,7 +405,7 @@ jobs:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics-reference-jun2022
needs: [ framework-install-reference ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: rest-for-physics/framework
path: framework
Expand Down
7 changes: 3 additions & 4 deletions source/framework/analysis/inc/TRestEventSelectionProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
#define RestProcess_TRestEventSelectionProcess

#include <TH1D.h>
#include <TRestEventProcess.h>

#include <iostream>

#include "TRestEventProcess.h"

//! A template process to serve as an example to create new TRestRawSignalEventProcess
class TRestEventSelectionProcess : public TRestEventProcess {
private:
TRestEvent* fEvent; //!
std::string fFileWithIDs = "";
std::string fConditions = "";
std::string fFileWithIDs;
std::string fConditions;
std::vector<Int_t> fList;

/// A list with the event ids that have been selected.
Expand Down
35 changes: 25 additions & 10 deletions source/framework/analysis/src/TRestEventSelectionProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//////////////////////////////////////////////////////////////////////////
/// The TRestEventSelectionProcess allows procesing of selected events only.
///
/// There are two ways of selecting events:
/// There are three ways of selecting events:
///
/// * Providing a txt file with the IDs of the events to be processed (fileWithIDs).
/// It reads the list, if an event is not in the list it returns NULL,
Expand All @@ -32,6 +32,11 @@
/// * Providing a root file (fileWithIDs) and the conditions to select the events (conditions).
/// Only events that satisfy the conditions will be processed.
///
/// * Not providing any fileWithIDs (empty string). In this case, the process will use the TRestAnalysisTree
/// of the processing file itself to evaluate the conditions and select the events. Make sure that the
/// analysis processes that generate the obervables needed for the conditions are executed before this
/// process. See TRestAnalysisTree::EvaluateCuts for more information on conditions format.
///
/// Examples for rml files:
/// <addProcess type="TRestEventSelectionProcess" name="evSelection" fileWithIDs="/path/to/file/IDs.txt"
/// value="ON" verboseLevel="info"/>
Expand All @@ -41,7 +46,7 @@
///
/// <hr>
///
/// \warning **? REST is under continous development.** This documentation
/// \warning ** REST is under continous development.** This documentation
/// is offered to you by the REST community. Your HELP is needed to keep this code
/// up to date. Your feedback will be worth to support this software, please report
/// any problems/suggestions you may find while using it at [The REST Framework
Expand All @@ -66,16 +71,21 @@
/// 2021-Mar: Read IDs from root with conditions
/// David Diez
///
/// 2024-Jun: Use of the processing file itself (no need for external fileWithIDs)
/// Alvaro Ezquerro
///
/// \class TRestEventSelectionProcess
/// \author Javier Galan
/// \author David Diez
/// \author Alvaro Ezquerro
///
/// <hr>
///

#include "TRestEventSelectionProcess.h"

using namespace std;

ClassImp(TRestEventSelectionProcess);

///////////////////////////////////////////////
Expand Down Expand Up @@ -112,9 +122,10 @@ void TRestEventSelectionProcess::InitProcess() {
File.close();
}
} else if (TRestTools::GetFileNameExtension(fFileWithIDs) == "root") {
TRestRun* run = new TRestRun(fFileWithIDs);
fList = run->GetEventIdsWithConditions(fConditions);
delete run;
TRestRun run(fFileWithIDs);
fList = run.GetEventIdsWithConditions(fConditions);
} else {
RESTDebug << "TRestEventSelectionProcess: using the processing file itself." << RESTendl;
}
}

Expand All @@ -124,8 +135,14 @@ void TRestEventSelectionProcess::InitProcess() {
TRestEvent* TRestEventSelectionProcess::ProcessEvent(TRestEvent* inputEvent) {
fEvent = inputEvent;

for (unsigned int i = 0; i < fList.size(); i++) {
if (fList[i] == fEvent->GetID()) {
if (fFileWithIDs.empty()) {
if (this->GetAnalysisTree()->EvaluateCuts(fConditions)) {
return fEvent;
}
}

for (auto id : fList) {
if (id == fEvent->GetID()) {
return fEvent;
}
}
Expand All @@ -140,9 +157,7 @@ void TRestEventSelectionProcess::PrintMetadata() {
BeginPrintProcess();

RESTMetadata << "File with IDs: " << fFileWithIDs << RESTendl;
if (fFileWithIDs.substr(fFileWithIDs.length() - 4) == "root") {
RESTMetadata << "Conditions: " << fConditions << RESTendl;
}
RESTMetadata << "Conditions: " << fConditions << RESTendl;

EndPrintProcess();
}

0 comments on commit 69bb959

Please sign in to comment.