]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/alirawdump_main.cxx
consolidate zero-length arrays (aka struct hack)
[u/mrichter/AliRoot.git] / RAW / alirawdump_main.cxx
CommitLineData
e255ff6a 1// Author: Cvetan Cheshkov 29/01/2008
2
3//////////////////////////////////////////////////////////////////////////
4// //
5// alirawdump //
6// //
7// Program can used to dump the raw-data files in ROOT format. //
8// It dumps the event,sub-event,equipment and common-data header. //
9// Additional application of the program is to check if the CDHs //
10// of different raw-data payloads are compatible. In this sense //
11// it replaces the DAQ online checks in case the DAQ is running //
12// UNCHECKED partition. //
13// //
14// Written by: Cvetan Cheshkov, 29/01/2008. //
15// //
16//////////////////////////////////////////////////////////////////////////
17
18#include <TROOT.h>
19#include <TError.h>
20#include <TFile.h>
21#include <TTree.h>
35904953 22#include <TGrid.h>
e255ff6a 23
33314186 24#include "AliRawVEvent.h"
e255ff6a 25#include "AliRawEventHeaderBase.h"
33314186 26#include "AliRawVEquipment.h"
e255ff6a 27#include "AliRawEquipmentHeader.h"
28#include "AliRawDataHeader.h"
29#include "AliRawData.h"
35904953 30#include "AliDAQ.h"
e255ff6a 31
32#include <Riostream.h>
33
c64cb1f6 34using std::cout;
35using std::endl;
36
35904953 37static Int_t miniEventIDOffset[AliDAQ::kNDetectors] = {3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565,3565};
38static Bool_t detTriggerClasses[AliDAQ::kNDetectors] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
39
e255ff6a 40//______________________________________________________________________________
41static void Usage(const char *prognam)
42{
43 // Prints the usage
44 // of the alirawdump program
45 fprintf(stderr, "Usage: %s <raw_data_root_file>\n",
46 prognam);
47 fprintf(stderr, " <raw_data_root_file> = file with ROOT formatted raw data\n");
48}
49
50//______________________________________________________________________________
51static bool DumpCDH(AliRawDataHeader *cdh)
52{
53 // Dumps the CDH
54 // ...
55 cout << " Size: " << cdh->fSize << endl;
56 cout << " Version: " << (Int_t)cdh->GetVersion() << endl;
57 cout << " Orbit: " << cdh->GetEventID2() << " Bunch-crossing: " << cdh->GetEventID1() << endl;
58 cout << " L1 trigger message: " << (UInt_t)cdh->GetL1TriggerMessage() << endl;
59 cout << " Participating sub-detectors: " << cdh->GetSubDetectors() << endl;
60 cout << " Block attributes: " << (Int_t)cdh->GetAttributes() << endl;
61 cout << " Status: " << cdh->GetStatus() << endl;
62 cout << " Mini event ID: " << cdh->GetMiniEventID() << endl;
63 cout << " Trigger classes: " << cdh->GetTriggerClasses() << endl;
64 cout << " ROI: " << cdh->GetROI() << endl;
65
66 return true;
67}
68
e96196b8 69//______________________________________________________________________________
70static bool CheckCDH(AliRawDataHeader *cdhRef,AliRawDataHeader *cdh)
71{
72 // Check the consistency of the CDHs
73 // ...
35904953 74 bool iserror = false;
75 if ((cdhRef->GetEventID1() != cdh->GetEventID1())) {
76 cout << "ERROR: CDH mismatch detected in EventID1: " << cdhRef->GetEventID1() << " != " << cdh->GetEventID1() << endl;
77 iserror = true;
e96196b8 78 }
35904953 79// if ((cdhRef->GetVersion() != cdh->GetVersion())) {
80// cout << "ERROR: CDH mismatch detected in Version: " << (Int_t)cdhRef->GetVersion() << " != " << (Int_t)cdh->GetVersion() << endl;
81// iserror = true;
82// }
83 if ((cdhRef->GetEventID2() != cdh->GetEventID2())) {
84 cout << "ERROR: CDH mismatch detected in EventID2: " << cdhRef->GetEventID2() << " != " << cdh->GetEventID2() << endl;
85 iserror = true;
86 }
87// if ((cdhRef->GetMiniEventID() != cdh->GetMiniEventID())) {
88// cout << "ERROR: CDH mismatch detected in MiniEventID: " << cdhRef->GetMiniEventID() << " != " << cdh->GetMiniEventID() << endl;
89// iserror = true;
90// }
91// if ((cdhRef->GetTriggerClasses() != cdh->GetTriggerClasses())) {
92// cout << "ERROR: CDH mismatch detected in TriggerClasses: " << cdhRef->GetTriggerClasses() << " != " << cdh->GetTriggerClasses() << endl;
93// iserror = true;
94// }
95
96// if ((cdhRef->GetL1TriggerMessage() != cdh->GetL1TriggerMessage())) {
97// cout << "ERROR: CDH mismatch detected in L1TriggerMessage: " << (Int_t)cdhRef->GetL1TriggerMessage() << " != " << (Int_t)cdh->GetL1TriggerMessage() << endl;
98// iserror = true;
99// }
100 if ((cdhRef->GetSubDetectors() != cdh->GetSubDetectors())) {
101 cout << "ERROR: CDH mismatch detected in ParticipatingSubDetectors: " << cdhRef->GetSubDetectors() << " != " << cdh->GetSubDetectors() << endl;
102 iserror = true;
103 }
104
105 if (iserror) return false;
106 else return true;
e96196b8 107}
108
e255ff6a 109//______________________________________________________________________________
33314186 110static bool DumpEvent(const char *progname, AliRawVEvent *rawEvent)
e255ff6a 111{
112 // Dumps and checks one
113 // raw-data event
114 AliRawEventHeaderBase *rawEventHeader = rawEvent->GetHeader();
115
116 if (rawEventHeader->GetMagic() != 0xDA1E5AFE) {
117 Error(progname,"Wrong magic number ( 0x%x != 0xDA1E5AFE )",rawEventHeader->GetMagic());
118 return false;
119 }
120
121 cout << " *********** Event header ***********" << endl;
122 rawEventHeader->Print();
123
e96196b8 124 AliRawDataHeader *cdhRef = NULL;
125
e255ff6a 126 for(Int_t iSubEvent=0; iSubEvent < rawEvent->GetNSubEvents(); iSubEvent++) {
33314186 127 AliRawVEvent *rawSubEvent = rawEvent->GetSubEvent(iSubEvent);
e255ff6a 128 AliRawEventHeaderBase *rawSubEventHeader = rawSubEvent->GetHeader();
129 cout << " *********** Sub-event header ***********" << endl;
130 rawSubEventHeader->Print(" ");
131
132 for(Int_t iEquipment=0; iEquipment < rawSubEvent->GetNEquipments(); iEquipment++) {
33314186 133 AliRawVEquipment *rawEquip = rawSubEvent->GetEquipment(iEquipment);
e255ff6a 134 AliRawEquipmentHeader *rawEquipHeader = rawEquip->GetEquipmentHeader();
135 cout << " *********** Equipment event header ***********" << endl;
136 rawEquipHeader->Print(" ");
137 cout << " *********** Common Data Header ***********" << endl;
138 AliRawData *rawData = rawEquip->GetRawData();
139 AliRawDataHeader *cdh = (AliRawDataHeader*)rawData->GetBuffer();
35904953 140
141 Int_t ddlID;
142 Int_t detID = AliDAQ::DetectorIDFromDdlID(rawEquipHeader->GetId(),ddlID);
e6fbf576 143 if (detID < 0) {
144 return false;
145 }
35904953 146 Int_t idOffset = cdh->GetMiniEventID() - cdh->GetEventID1();
147 if (idOffset < 0) idOffset += 3564;
148 if (miniEventIDOffset[detID] == 3565) {
149 miniEventIDOffset[detID] = idOffset;
150 cout << "MiniEvenID offset for detector " << AliDAQ::DetectorName(detID) << " is set to " << idOffset << endl;
151 }
152 else {
153 if (miniEventIDOffset[detID] != idOffset) {
154 cout << "ERROR: MiniEventID offset for detector " << AliDAQ::DetectorName(detID) << " has changed ( " << idOffset << " != " << miniEventIDOffset[detID] << " )" << endl;
155 }
156 }
157
158 // TPC is using version 1
159 if ((cdh->GetVersion() != 2) && (detID != 3))
160 cout << "ERROR: Bad CDH version: " << (Int_t)cdh->GetVersion() << endl;
161
162 if (cdh->GetTriggerClasses() == 0) {
163 if (detTriggerClasses[detID])
164 cout << "Empty trigger class mask for detector " << AliDAQ::DetectorName(detID) << endl;
165 detTriggerClasses[detID] = false;
166 }
167
e255ff6a 168 if (!DumpCDH(cdh)) return false;
e96196b8 169 // check the CDH consistency
170 if (cdhRef == NULL) {
171 cdhRef = cdh;
172 }
173 else {
35904953 174 // TPC L1 trigger message is shifted by 2 bits??
175 UShort_t l1Message = cdh->GetL1TriggerMessage();
176 UShort_t l1MessageRef = cdhRef->GetL1TriggerMessage();
35904953 177
178 if (l1Message != l1MessageRef)
179 cout << "ERROR: CDH mismatch detected in L1TriggerMessage for detector " << AliDAQ::DetectorName(detID) << ": " << (Int_t)l1MessageRef << " ( " << (Int_t)cdhRef->GetL1TriggerMessage() << " ) " << " != " << (Int_t)l1Message << " ( " << (Int_t)cdh->GetL1TriggerMessage() << " )" << endl;
180
181 if ((cdhRef->GetTriggerClasses() == 0) && (cdh->GetTriggerClasses() != 0)) {
182 // update the reference trigger class mask
183 cdhRef->fTriggerClassLow = cdh->fTriggerClassLow;
184 cdhRef->fROILowTriggerClassHigh = (((cdhRef->fROILowTriggerClassHigh >> 28) & 0xF) << 28) | (cdh->fROILowTriggerClassHigh & 0x1FFFF);
185 }
186 if (cdh->GetTriggerClasses() != 0) {
187 if (cdhRef->GetTriggerClasses() != cdh->GetTriggerClasses()) {
188 cout << "ERROR: CDH mismatch detected in TriggerClasses: " << cdhRef->GetTriggerClasses() << " != " << cdh->GetTriggerClasses() << endl;
189 }
190 }
191
192 CheckCDH(cdhRef,cdh);
193 // if (!CheckCDH(cdhRef,cdh)) return false;
e96196b8 194 }
e255ff6a 195 }
196 }
197
198 return true;
199}
200
201//______________________________________________________________________________
202int main(int argc, char **argv)
203{
204 // Dumps a ROOT formatted
205 // raw-data file
206
207 gROOT->SetBatch();
208
209 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) || argc != 2) {
210 Usage(argv[0]);
211 return 1;
212 }
35904953 213
214 TString str = argv[1];
215 if (str.BeginsWith("alien://"))
216 TGrid::Connect("alien://");
217
e255ff6a 218 TFile *rawFile = TFile::Open(argv[1],"READ");
219 if (!rawFile) {
220 Error(argv[0],"Raw data file %s can not be opened!",argv[1]);
221 return 1;
222 }
223
224 TTree *rawTree=(TTree *)rawFile->Get("RAW");
225 if(!rawTree) {
226 Error(argv[0],"Error getting RAW tree from file %s",argv[1]);
227 return 1;
228 }
229
33314186 230 AliRawVEvent *rawEvent=NULL;
e255ff6a 231
232 rawTree->SetBranchAddress("rawevent", &rawEvent);
233
234 Int_t nEvents = rawTree->GetEntries();
235
236 cout << "*******************************************" << endl;
237 cout << "File: " << argv[1] << endl;
238 cout << "GUID: " << rawFile->GetUUID().AsString() << endl;
239 cout << "Total number of events: " << nEvents << endl;
240 cout << "*******************************************" << endl;
241
242 for(Int_t iEvent=0; iEvent < nEvents; iEvent++) {
51c3974f 243 // rawEvent=NULL;
e255ff6a 244 rawTree->GetEntry(iEvent);
245 cout << " *********** Event " << iEvent << " *******" << endl;
246 DumpEvent(argv[0],rawEvent);
51c3974f 247 // delete rawEvent;
248 rawEvent->Clear();
e255ff6a 249 }
250
51c3974f 251 delete rawEvent;
252
e255ff6a 253 cout << "*******************************************" << endl;
254 cout << "EOF" << endl;
255 cout << "*******************************************" << endl;
256 delete rawTree;
257 rawFile->Close();
258}