When attempting to run the LHE primary generator with a file that does not exist, we get a confusing no next <event> error. This implies to the user that the file does exist but has fewer events in it then requested by the simulation. While this type of error is not very difficult to deduce when running locally, it is very confusing on a computing cluster where the filesystem may be networked and therefore go down occasionally causing a previously-working setup to break. In addition, this is helpful to avoid path typos or using a path that is not mounted into the running container.
Fix
I think we should put in some helpful checks in the config module and (maybe) the C++ generator itself.
In the config module, we could check that the file exists and throw an exception if it doesn't.
if not os.path.isfile(filePath):
# could discuss a more helpful wording of this exception
raise ValueError(f'Provided LHE file {filePath} does not exist or cannot be read by ldmx-sw.')
This simple update would catch path typos, unmounted paths, and filesystem drops as early as possible.
In addition, we could (if possible) do a more thorough test within the C++ where we check that the input file
has the LHE file format.
This could be done within the linked constructor above or within the LHEReader. Implementing this additional check on the format of the input file might nicely fit into a new refactor of the LHE reading including LDMX-Software/SimCore#41 and maybe a more complete rewrite as discussed in LDMX-Software/ldmx-sw#1316
Replicate
I get the terminal error
Opening LHE file dne.lhe
[ Process ] 1 : Processing 1 Run 9001 Event 1 (2024-02-19 15:33:22.867849000+0000)
WARNING: No next <event> element was found by the LHE reader.
[ LHEPrimaryGenerator ] : Ran out of input events so run will be aborted!
[ fire ] 4 : [NoPrimaries] : No primary vertices were produced by any of the generators.
at /code/SimCore/src/SimCore/G4User/PrimaryGeneratorAction.cxx:141 in GeneratePrimaries
Stack trace:
0 /usr/local/lib/libSimCore_G4User.so(+0x9f10) [0x7f608b043f10]
1 G4RunManager::GenerateEvent(int) + 179
2 G4RunManager::ProcessOneEvent(int) + 24
3 simcore::Simulator::produce(framework::Event&) + 438
4 framework::Process::process(int, framework::Event&) const + 113
5 framework::Process::run() + 9030
6 main + 461 addr2line: 'fire': No such file
7 /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f608e4f6d90]
when running the config (dne.lhe is a file that does not exist).
When attempting to run the LHE primary generator with a file that does not exist, we get a confusing
no next <event>
error. This implies to the user that the file does exist but has fewer events in it then requested by the simulation. While this type of error is not very difficult to deduce when running locally, it is very confusing on a computing cluster where the filesystem may be networked and therefore go down occasionally causing a previously-working setup to break. In addition, this is helpful to avoid path typos or using a path that is not mounted into the running container.Fix
I think we should put in some helpful checks in the config module and (maybe) the C++ generator itself.
In the config module, we could check that the file exists and throw an exception if it doesn't.
https://github.com/LDMX-Software/SimCore/blob/c8a30c1f735eeaa020e178dc3a8b8e59bf8263b5/python/generators.py.in#L98
This simple update would catch path typos, unmounted paths, and filesystem drops as early as possible. In addition, we could (if possible) do a more thorough test within the C++ where we check that the input file has the LHE file format.
https://github.com/LDMX-Software/SimCore/blob/c8a30c1f735eeaa020e178dc3a8b8e59bf8263b5/src/SimCore/Generators/LHEPrimaryGenerator.cxx#L28-L29
This could be done within the linked constructor above or within the
LHEReader
. Implementing this additional check on the format of the input file might nicely fit into a new refactor of the LHE reading including LDMX-Software/SimCore#41 and maybe a more complete rewrite as discussed in LDMX-Software/ldmx-sw#1316Replicate
I get the terminal error
when running the config (
dne.lhe
is a file that does not exist).