bug fixed
[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);
140 Int_t idOffset = cdh->GetMiniEventID() - cdh->GetEventID1();
141 if (idOffset < 0) idOffset += 3564;
142 if (miniEventIDOffset[detID] == 3565) {
143 miniEventIDOffset[detID] = idOffset;
144 cout << "MiniEvenID offset for detector " << AliDAQ::DetectorName(detID) << " is set to " << idOffset << endl;
145 }
146 else {
147 if (miniEventIDOffset[detID] != idOffset) {
148 cout << "ERROR: MiniEventID offset for detector " << AliDAQ::DetectorName(detID) << " has changed ( " << idOffset << " != " << miniEventIDOffset[detID] << " )" << endl;
149 }
150 }
151
152 // TPC is using version 1
153 if ((cdh->GetVersion() != 2) && (detID != 3))
154 cout << "ERROR: Bad CDH version: " << (Int_t)cdh->GetVersion() << endl;
155
156 if (cdh->GetTriggerClasses() == 0) {
157 if (detTriggerClasses[detID])
158 cout << "Empty trigger class mask for detector " << AliDAQ::DetectorName(detID) << endl;
159 detTriggerClasses[detID] = false;
160 }
161
e255ff6a 162 if (!DumpCDH(cdh)) return false;
e96196b8 163 // check the CDH consistency
164 if (cdhRef == NULL) {
165 cdhRef = cdh;
166 }
167 else {
35904953 168 // TPC L1 trigger message is shifted by 2 bits??
169 UShort_t l1Message = cdh->GetL1TriggerMessage();
170 UShort_t l1MessageRef = cdhRef->GetL1TriggerMessage();
35904953 171
172 if (l1Message != l1MessageRef)
173 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;
174
175 if ((cdhRef->GetTriggerClasses() == 0) && (cdh->GetTriggerClasses() != 0)) {
176 // update the reference trigger class mask
177 cdhRef->fTriggerClassLow = cdh->fTriggerClassLow;
178 cdhRef->fROILowTriggerClassHigh = (((cdhRef->fROILowTriggerClassHigh >> 28) & 0xF) << 28) | (cdh->fROILowTriggerClassHigh & 0x1FFFF);
179 }
180 if (cdh->GetTriggerClasses() != 0) {
181 if (cdhRef->GetTriggerClasses() != cdh->GetTriggerClasses()) {
182 cout << "ERROR: CDH mismatch detected in TriggerClasses: " << cdhRef->GetTriggerClasses() << " != " << cdh->GetTriggerClasses() << endl;
183 }
184 }
185
186 CheckCDH(cdhRef,cdh);
187 // if (!CheckCDH(cdhRef,cdh)) return false;
e96196b8 188 }
e255ff6a 189 }
190 }
191
192 return true;
193}
194
195//______________________________________________________________________________
196int main(int argc, char **argv)
197{
198 // Dumps a ROOT formatted
199 // raw-data file
200
201 gROOT->SetBatch();
202
203 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) || argc != 2) {
204 Usage(argv[0]);
205 return 1;
206 }
35904953 207
208 TString str = argv[1];
209 if (str.BeginsWith("alien://"))
210 TGrid::Connect("alien://");
211
e255ff6a 212 TFile *rawFile = TFile::Open(argv[1],"READ");
213 if (!rawFile) {
214 Error(argv[0],"Raw data file %s can not be opened!",argv[1]);
215 return 1;
216 }
217
218 TTree *rawTree=(TTree *)rawFile->Get("RAW");
219 if(!rawTree) {
220 Error(argv[0],"Error getting RAW tree from file %s",argv[1]);
221 return 1;
222 }
223
33314186 224 AliRawVEvent *rawEvent=NULL;
e255ff6a 225
226 rawTree->SetBranchAddress("rawevent", &rawEvent);
227
228 Int_t nEvents = rawTree->GetEntries();
229
230 cout << "*******************************************" << endl;
231 cout << "File: " << argv[1] << endl;
232 cout << "GUID: " << rawFile->GetUUID().AsString() << endl;
233 cout << "Total number of events: " << nEvents << endl;
234 cout << "*******************************************" << endl;
235
236 for(Int_t iEvent=0; iEvent < nEvents; iEvent++) {
33314186 237 rawEvent=NULL;
e255ff6a 238 rawTree->GetEntry(iEvent);
239 cout << " *********** Event " << iEvent << " *******" << endl;
240 DumpEvent(argv[0],rawEvent);
241 delete rawEvent;
242 }
243
244 cout << "*******************************************" << endl;
245 cout << "EOF" << endl;
246 cout << "*******************************************" << endl;
247 delete rawTree;
248 rawFile->Close();
249}