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