1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Artur Szostak
4 // Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
6 ////////////////////////////////////////////////////////////////////////////////
8 #include "../src/TriggerRecord.hpp"
11 // TODO: fix the endian encoding of the data format.
13 /* Generates .trigrec binary files with the following structure:
18 00 size - Size of the structure in 32-bit words (excluding this word).
20 04 Trigger ID offset - The offset to add to the trigger record index number
21 to get full trigger ID of any trigger record.
23 // First TriggerRecord structure.
24 08 sign - Signed integer, possible values: -1, 0, +1
25 12 pt - Transverse momentum as a 32bit floating point number.
31 // Next TriggerRecord structure.
34 void MakeTriggerRecordFiles(const char* outputpath = ".")
36 //gSystem->Load("../lib/Linux-debug/libMUONHLT.so");
37 gSystem->Load("../lib/Linux/libMUONHLT.so");
39 using namespace AliMUONHLT;
41 AliMUONDataInterface data;
44 // Load the trigger data.
45 AliMUONHLT::TriggerSource ts;
46 ts.DataToUse(AliMUONHLT::TriggerSource::FromHits);
49 dHLT::UInt triggerIDoffset;
51 for (Int_t event = 0; event < ts.NumberOfEvents(); event++)
55 // For every event create a new file.
57 char* filename = &buffer[0];
58 sprintf(filename, "%s/event%d.trigrec", outputpath, event);
59 FILE* file = fopen(filename, "w+b");
62 Error("MakeTriggerRecordFiles", "Could not create/open file: %s", filename);
66 // Compute and write the size of the whole data structure in 32bit words:
68 for (Int_t block = 0; block < ts.NumberOfBlocks(); block++)
71 size += (ts.NumberOfTriggers() * sizeof(dHLT::TriggerRecord)) / 4;
73 size += sizeof(triggerIDoffset) / 4; // Add word count of triggerIDoffset.
75 fwrite(&size, sizeof(size), 1, file);
78 Error("MakeTriggerRecordFiles", "Could not write to file: %s", filename);
82 // Compute and write the trigger ID offset.
83 triggerIDoffset = 0; // very simple case.
84 fwrite(&triggerIDoffset, sizeof(triggerIDoffset), 1, file);
87 Error("MakeTriggerRecordFiles", "Could not write to file: %s", filename);
91 // Write all the TriggerRecord structures into the file.
92 for (Int_t block = 0; block < ts.NumberOfBlocks(); block++)
95 for ( const TriggerRecord* trigger = ts.GetFirstTrigger();
97 trigger = ts.GetNextTrigger()
100 dHLT::TriggerRecord record;
101 record.sign = trigger->ParticleSign();
102 record.pt = trigger->Pt();
103 record.station1impact.x = trigger->Station1Point().fX;
104 record.station1impact.y = trigger->Station1Point().fY;
105 record.station2impact.x = trigger->Station2Point().fX;
106 record.station2impact.y = trigger->Station2Point().fY;
108 fwrite(&record, sizeof(record), 1, file);
111 Error("MakeTriggerRecordFiles", "Could not write to file: %s", filename);