# FrameL RefData() Empty Bug - Root Cause Analysis

## Summary
FrAdcData::RefData() is empty when reading FrameL v6/v7/v8 files because the recursive loading mechanism fails to load nested FrVect objects due to a **class ID mismatch** in the resolver queue.

## Debug Logging Added
Added comprehensive debug logging to trace the recursive loading mechanism:

1. **FrameStream.cc::readRecursive()** - Traces resolver queue operations
2. **IOStream.hh::container_reference::Resolve()** - Traces dictionary lookups

## Key Findings

### 1. Initial Resolver Queue (Correct)
```
[DEBUG] readRecursive() entry - resolverContainer size: 3
[DEBUG] Adding PTR_STRUCT to queue - class: 7 instance: 0  (FrRawData)
[DEBUG] Adding PTR_STRUCT to queue - class: 12 instance: 0
[DEBUG] Adding PTR_STRUCT to queue - class: 4 instance: 0
[DEBUG] Resolver queue size after initialization: 3
```

### 2. FrAdcData Loading (Adds Reference to Queue)
```
[DEBUG] Read StreamRef - stream class: 5 stream instance: 0 FSI_id: 4 position: 3236
[DEBUG] Object is_needed: YES (queue size now: 2)
[DEBUG] Object read successfully - internal class: 4
[DEBUG] Adding object to dictionary - stream class: 5 stream instance: 0
...
[DEBUG] Object is_needed: NO (queue size now: 3)  ← Queue grew from 2 to 3!
```

**Observation**: When FrAdcData is loaded, it correctly adds its PTR_STRUCT reference (class 6, instance 0) to the queue, growing it from 2 to 3 items.

### 3. **THE BUG**: FrVect Not Recognized as Needed
```
[DEBUG] Read StreamRef - stream class: 6 stream instance: 0 FSI_id: 20 position: 3855
[DEBUG] Object is_needed: NO (queue size now: 3)  ← WRONG! Should be YES!
```

**Critical Issue**: FrVect (stream class 6, instance 0, FSI_id 20) is marked as "is_needed: NO" even though:
- The resolver queue contains an entry for it (queue size = 3)
- It's the correct object referenced by FrAdcData

### 4. Resolution Failure (Dictionary Lookup Fails)
```
[DEBUG] Resolve() - Looking up PTR_STRUCT - class: 6 instance: 0
[DEBUG] Resolve() - Dictionary lookup FAILED - no StreamRef found
```

**Result**: FrVect was never added to the dictionary because `removeRecursiveDependant()` returned false, so `Resolve()` cannot find it.

## Root Cause Hypothesis

The issue is likely a **class ID mismatch** between:

1. **Stream Class ID** (from file): 6
2. **Internal FSI_id** (frameCPP): 20 (FSI_FR_VECT)

### Class ID Mapping Issue

The `removeRecursiveDependant()` function likely compares:
- PTR_STRUCT class ID stored in queue: **6** (stream class ID from FrameL file)
- StreamRef class ID from file: **6** (stream class ID)

This *should* match, but the comparison might be using internal FSI_id (20) instead.

### Possible Explanations

1. **FrameL class ID mapping**: FrameL files use different class IDs than frameCPP
2. **Missing class ID translation**: The resolver queue stores internal FSI_ids, but the stream uses FrameL class IDs
3. **FrSH structure headers**: FrameL's self-describing format (FrSH/FrSE) might affect class ID mapping

## File Structure Validation

From `framecpp_dump_objects test/test_framel_v6.gwf`:

```
Position: 1048 length: 134 class (FrameH): 3 instance: 0
  rawData: 7-0                            ← PTR_STRUCT reference

Position: 2520 length: 54 class (FrRawData): 7 instance: 0
  firstAdc: 5-0                           ← PTR_STRUCT reference

Position: 3236 length: 104 class (FrAdcData): 5 instance: 0
  data: 6-0                               ← PTR_STRUCT reference (THIS IS THE BUG!)

Position: 3855 length: 901 class (FrVect): 6 instance: 0
  nData: 100
  nBytes: 800
```

**File structure is completely valid.** All PTR_STRUCT references are correct and the FrVect data exists at position 3855.

## Next Steps for Investigation

1. **Check `removeRecursiveDependant()` implementation** - How does it compare class IDs?
2. **Check `addRecursiveDependant()` implementation** - What class ID does it store in the queue?
3. **Check class ID mapping in Verify.cc** - How are FrameL class IDs mapped to internal FSI_ids?
4. **Compare frameCPP-written vs FrameL-written files** - Do they use different class ID schemes?

## Test Case
File: `test/test_framel_debug.cc`
Command: `./test/test_framel_debug`

Demonstrates the bug with full debug logging output.
