That's the heart of the lock: the cart comes from the leftmost downramp and must make it all the way to the right-hand pressure plate, in the holding loop. To achieve this, the two hatches in the direct line must be open, as well as the door. With both straight ramps passable at full speed, the cart reaches derail speed and can jump the corner, and if the door's open, it will pass through and find its way to the pressure plate. Of course, it's not so easy. The first cart that starts into the circuit starts out on the leftmost hatch. And that's the very cart that's needed to hold down a pressure plate so the door is open. The right-hand ramp pit's hatch is operated by one of the lock levers, but the branch leads in the completely wrong direction for _that_ cart. Instead, it has to find its way through here:
In the north, our straight ramp, to the south an XOR/XNOR gate, giving three different outputs - both inputs equal, first input on and second off, first input off and second on. The output is dragged through this splitting array:
To the west, the second pit of the X gate can be seen. Each output is sent through a pressure-plate controlled ramp, and the plate is set for a maximum weight of 300, letting the first cart through, the second not (yes, we have _two_ minecarts, but they're processing sequentially). If the inputs were equal (north) or if the first input was off and the second on (south), the cart is sent into a holding loop holding down a pressure plate. If the first input was on and the second off, the cart is sent away to the north, to the first failure condition (the cart also arrives there if the first gate, the yes/no one, is open).
Now, the second, heavier cart is started. It is funnelled directly into the yes/no gate, so can't reach derail speed and will once again cause failure if the first gate is open. It, too, has to pass the X gate, and will return from the weight-check. This cart will go to the failure condition if both inputs were equal. Incidentally, starting the cart will also activate the actual failure condition if the first cart failed.
The heavy cart is, if successful, sent here, either into the northern or the southern check. Depending on where it passed through, the first cart will hold open _one_ of these. If the active cart goes through the open gate, it touches a pressure plate sending a pulse to the first cart's starting hatch. There's enough intermittent time guaranteed that this will _close_ the hatch, preventing the cart from reaching derail speed.
If the cart went past the correct, closed gate, _closing_ its control lever will send it out of the southern loop, over the pressure plate which activates the exit hatches of the first cart's holding loops, so that cart can advance further east. Once again depending on where it first landed, it will have to pass either an AND or a NOR gate (i.e. in one case, both inputs used must be on, in the other, both must be off). This uses the second and third main control levers, since now the heavier cart must make its check for the first gate and the door. If the first cart passes the last gate, it gets hold moving across the pressure plate which holds the door open, and if the second cart managed to avoid the pressure plate that 'waved' the hatch, it can achieve sufficient speed.
If anything was done wrong, the cart(s) end up here:
There's another weight check built in, as well as speed limiters galore. The heavier cart ends up either in the eastern or the western branch, activating one of two possible failure plates. The lighter cart's failures are collected and all end up in the same, middle branch.
The whole thing is operated from here. The three input levers are to the north, the two operation levers for the two carts to the south and southeast, the reset lever to the southwest. To the east there are the two sets of brass bars which retreat in case of success, to the west the floodgate which gets opened in case of 'failure mode II', only activatable by the heavier minecart and only by failure on the yes/no gate. The channel transports pumped magma from the big magma pool. The other failure mode retracts a bridge over a hole in the ceiling, letting water, pumped from the brook, inside. Both failures can happen at once...
The pictures were taken before the pumps were activated. Currently, there are extra floodgates in place, operated from a separate lever. I'm not going to magmafy my own dwarfs.
Originally, only the first cart's lever and the reset lever are accessible. Activating it will open a hatch over a passage to the reset lever and retreat the silver bars blocking access to the second operation lever. Activating the second operation lever will open a hatch over a pit in the passage to the first operation lever, the lever must be deactivated before access to the first lever is again possible. Only after the second lever has been used will the reset lever be able to actually reset the system.
I've tested all three success cases and the basic failure modes as well as resetting, and after a lot of debugging it seems to work correctly. It's seriously crazy, but it does show some of the possibilities with lock designs.