]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/macros/MakeTriggerRecordFiles.C
Using AliPHOSLoader instead of AliPHOSGetter
[u/mrichter/AliRoot.git] / HLT / MUON / macros / MakeTriggerRecordFiles.C
CommitLineData
8356cc1d 1////////////////////////////////////////////////////////////////////////////////
2//
3// Author: Artur Szostak
4// Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
5//
6////////////////////////////////////////////////////////////////////////////////
7
8#include "../src/TriggerRecord.hpp"
9
10
11// TODO: fix the endian encoding of the data format.
12
13/* Generates .trigrec binary files with the following structure:
14
15 Byte # Field
16
17 // Header
18 00 size - Size of the structure in 32-bit words (excluding this word).
19
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.
22
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.
26 16 station1impact.x -
27 20 station1impact.y -
28 24 station2impact.x -
29 28 station2impact.y -
30
31 // Next TriggerRecord structure.
32 // ...
33 */
34void MakeTriggerRecordFiles(const char* outputpath = ".")
35{
36 //gSystem->Load("../lib/Linux-debug/libMUONHLT.so");
37 gSystem->Load("../lib/Linux/libMUONHLT.so");
38
39 using namespace AliMUONHLT;
40
41 AliMUONDataInterface data;
42 data.SetFile();
43
44 // Load the trigger data.
45 AliMUONHLT::TriggerSource ts;
46 ts.DataToUse(AliMUONHLT::TriggerSource::FromHits);
47 ts.FillFrom(&data);
48
49 dHLT::UInt triggerIDoffset;
50
51 for (Int_t event = 0; event < ts.NumberOfEvents(); event++)
52 {
53 ts.GetEvent(event);
54
55 // For every event create a new file.
56 char buffer[1024];
57 char* filename = &buffer[0];
58 sprintf(filename, "%s/event%d.trigrec", outputpath, event);
59 FILE* file = fopen(filename, "w+b");
60 if (file == NULL)
61 {
62 Error("MakeTriggerRecordFiles", "Could not create/open file: %s", filename);
63 return;
64 };
65
66 // Compute and write the size of the whole data structure in 32bit words:
67 dHLT::UInt size = 0;
68 for (Int_t block = 0; block < ts.NumberOfBlocks(); block++)
69 {
70 ts.GetBlock(block);
71 size += (ts.NumberOfTriggers() * sizeof(dHLT::TriggerRecord)) / 4;
72 };
73 size += sizeof(triggerIDoffset) / 4; // Add word count of triggerIDoffset.
74
75 fwrite(&size, sizeof(size), 1, file);
76 if (ferror(file))
77 {
78 Error("MakeTriggerRecordFiles", "Could not write to file: %s", filename);
79 return;
80 };
81
82 // Compute and write the trigger ID offset.
83 triggerIDoffset = 0; // very simple case.
84 fwrite(&triggerIDoffset, sizeof(triggerIDoffset), 1, file);
85 if (ferror(file))
86 {
87 Error("MakeTriggerRecordFiles", "Could not write to file: %s", filename);
88 return;
89 };
90
91 // Write all the TriggerRecord structures into the file.
92 for (Int_t block = 0; block < ts.NumberOfBlocks(); block++)
93 {
94 ts.GetBlock(block);
95 for ( const TriggerRecord* trigger = ts.GetFirstTrigger();
96 ts.MoreTriggers();
97 trigger = ts.GetNextTrigger()
98 )
99 {
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;
107
108 fwrite(&record, sizeof(record), 1, file);
109 if (ferror(file))
110 {
111 Error("MakeTriggerRecordFiles", "Could not write to file: %s", filename);
112 return;
113 };
114 };
115 };
116
117 fclose(file);
118 };
119};
120