Skip to content

Writer

hipo::writer

Primary entry point for creating HIPO files.

Construction

writer();

Schema Registration

dictionary& getDictionary();
void addDictionary(dictionary& dict);

Important

Schemas must be added to writer.getDictionary() before calling open(). They are written into the file header and cannot be changed afterward.

User Configuration

void addUserConfig(const char *key, const char *value);
void setUserIntegerOne(long userIntOne);
void setUserIntegerTwo(long userIntTwo);

User config is stored in the dictionary record as key-value pairs.

File Operations

void open(const char *filename);
void close();
void flush();

close() flushes remaining events, writes the file trailer (record index), and patches the file header with the trailer position.

Writing Events

void addEvent(hipo::event& hevent);
void addEvent(std::vector<char>& vec, int size = -1);

Events are buffered in records. When the buffer is full (100K events or 8 MB), the record is automatically compressed and written to disk.

Manual Record Control

void writeRecord(recordbuilder& builder);
void flush();

Display

void showSummary();
void setVerbose(int level);

Example

// 1. Define schemas
hipo::schema schemaPart("event::particle", 100, 1);
schemaPart.parse("pid/S,px/F,py/F,pz/F");

hipo::schema schemaDet("event::detector", 100, 2);
schemaDet.parse("pindex/I,detectorid/I,x/F,y/F,z/F,time/F,energy/F");

// 2. Create writer and register schemas
hipo::writer writer;
writer.getDictionary().addSchema(schemaPart);
writer.getDictionary().addSchema(schemaDet);

// 3. Optionally add user config
writer.addUserConfig("run", "12345");
writer.addUserConfig("beam_energy", "10.6");

// 4. Open file
writer.open("output.hipo");

// 5. Write events
hipo::event event;
for (int i = 0; i < 25000; i++) {
    int nparts = 2 + rand() % 10;
    hipo::bank partBank(schemaPart, nparts);

    for (int row = 0; row < nparts; row++) {
        partBank.putShort("pid", row, 211);
        partBank.putFloat("px", row, 0.5f * row);
        partBank.putFloat("py", row, 0.3f * row);
        partBank.putFloat("pz", row, 1.0f + 0.1f * row);
    }

    event.reset();
    event.addStructure(partBank);
    writer.addEvent(event);
}

// 6. Close (writes trailer and finalizes)
writer.close();

Copy/Filter Pattern

Reading from one file and writing selected events to another:

hipo::reader reader;
reader.open("input.hipo");

hipo::dictionary dict;
reader.readDictionary(dict);

hipo::writer writer;
writer.addDictionary(dict);
writer.open("output.hipo");

hipo::event event;
while (reader.next()) {
    reader.read(event);
    // optionally filter or modify event
    writer.addEvent(event);
}

writer.close();