]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/alirawdump_main.cxx
Updated Publisher Mrian)
[u/mrichter/AliRoot.git] / RAW / alirawdump_main.cxx
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>
22
23 #include "AliRawEvent.h"
24 #include "AliRawEventHeaderBase.h"
25 #include "AliRawEquipment.h"
26 #include "AliRawEquipmentHeader.h"
27 #include "AliRawDataHeader.h"
28 #include "AliRawData.h"
29
30 #include <Riostream.h>
31
32 //______________________________________________________________________________
33 static void Usage(const char *prognam)
34 {
35   // Prints the usage
36   // of the alirawdump program
37       fprintf(stderr, "Usage: %s <raw_data_root_file>\n",
38               prognam);
39       fprintf(stderr, " <raw_data_root_file> = file with ROOT formatted raw data\n");
40 }
41
42 //______________________________________________________________________________
43 static bool DumpCDH(AliRawDataHeader *cdh)
44 {
45   // Dumps the CDH
46   // ...
47   cout << "        Size: " << cdh->fSize << endl;
48   cout << "        Version: " << (Int_t)cdh->GetVersion() << endl;
49   cout << "        Orbit: " << cdh->GetEventID2() << " Bunch-crossing: " << cdh->GetEventID1() << endl;
50   cout << "        L1 trigger message: " << (UInt_t)cdh->GetL1TriggerMessage() << endl;
51   cout << "        Participating sub-detectors: " << cdh->GetSubDetectors() << endl;
52   cout << "        Block attributes: " << (Int_t)cdh->GetAttributes() << endl;
53   cout << "        Status: " << cdh->GetStatus() << endl;
54   cout << "        Mini event ID: " << cdh->GetMiniEventID() << endl;
55   cout << "        Trigger classes: " << cdh->GetTriggerClasses() << endl;
56   cout << "        ROI: " << cdh->GetROI() << endl;
57
58   return true;
59 }
60
61 //______________________________________________________________________________
62 static bool CheckCDH(AliRawDataHeader *cdhRef,AliRawDataHeader *cdh)
63 {
64   // Check the consistency of the CDHs
65   // ...
66   if ((cdhRef->GetEventID1() != cdh->GetEventID1()) ||
67       (cdhRef->GetVersion() != cdh->GetVersion()) ||
68       (cdhRef->GetEventID2() != cdh->GetEventID2()) ||
69       (cdhRef->GetMiniEventID() != cdh->GetMiniEventID()) ||
70       (cdhRef->GetTriggerClasses() != cdh->GetTriggerClasses())) {
71     cout << "CDH mismatch detected:" << endl;
72     DumpCDH(cdhRef);
73     DumpCDH(cdh);
74     return false;
75   }
76   return true;
77 }
78
79 //______________________________________________________________________________
80 static bool DumpEvent(const char *progname, AliRawEvent *rawEvent)
81 {
82   // Dumps and checks one
83   // raw-data event
84   AliRawEventHeaderBase *rawEventHeader = rawEvent->GetHeader();
85
86   if (rawEventHeader->GetMagic() != 0xDA1E5AFE) {
87     Error(progname,"Wrong magic number ( 0x%x != 0xDA1E5AFE )",rawEventHeader->GetMagic());
88     return false;
89   }
90
91   cout << "  *********** Event header ***********" << endl;
92   rawEventHeader->Print();
93
94   AliRawDataHeader *cdhRef = NULL;
95
96   for(Int_t iSubEvent=0; iSubEvent < rawEvent->GetNSubEvents(); iSubEvent++) {
97     AliRawEvent *rawSubEvent = rawEvent->GetSubEvent(iSubEvent);
98     AliRawEventHeaderBase *rawSubEventHeader = rawSubEvent->GetHeader();
99     cout << "    *********** Sub-event header ***********" << endl;
100     rawSubEventHeader->Print("  ");
101
102     for(Int_t iEquipment=0; iEquipment < rawSubEvent->GetNEquipments(); iEquipment++) {
103       AliRawEquipment *rawEquip = rawSubEvent->GetEquipment(iEquipment);
104       AliRawEquipmentHeader *rawEquipHeader = rawEquip->GetEquipmentHeader();
105       cout << "      *********** Equipment event header ***********" << endl;
106       rawEquipHeader->Print("    ");
107       cout << "        *********** Common Data Header ***********" << endl;
108       AliRawData *rawData = rawEquip->GetRawData();
109       AliRawDataHeader *cdh = (AliRawDataHeader*)rawData->GetBuffer();
110       if (!DumpCDH(cdh)) return false;
111       // check the CDH consistency
112       if (cdhRef == NULL) {
113         cdhRef = cdh;
114       }
115       else {
116         if (!CheckCDH(cdhRef,cdh)) return false;
117       }
118     }
119   }
120
121   return true;
122 }
123
124 //______________________________________________________________________________
125 int main(int argc, char **argv)
126 {
127   // Dumps a ROOT formatted
128   // raw-data file
129
130   gROOT->SetBatch();
131   
132   if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) || argc != 2) {
133       Usage(argv[0]);
134       return 1;
135   }
136   
137   TFile *rawFile = TFile::Open(argv[1],"READ");
138   if (!rawFile) {
139     Error(argv[0],"Raw data file %s can not be opened!",argv[1]);
140     return 1;
141   }
142
143   TTree *rawTree=(TTree *)rawFile->Get("RAW");
144   if(!rawTree) {
145     Error(argv[0],"Error getting RAW tree from file %s",argv[1]);
146     return 1;
147   }
148
149   AliRawEvent *rawEvent=NULL;
150  
151   rawTree->SetBranchAddress("rawevent", &rawEvent);
152
153   Int_t nEvents = rawTree->GetEntries();
154
155   cout << "*******************************************" << endl;
156   cout << "File: " << argv[1] << endl;
157   cout << "GUID: " << rawFile->GetUUID().AsString() << endl;
158   cout << "Total number of events: " << nEvents << endl;
159   cout << "*******************************************" << endl;
160
161   for(Int_t iEvent=0; iEvent < nEvents; iEvent++) {
162     rawEvent=new AliRawEvent;
163     rawTree->GetEntry(iEvent);
164     cout << "  *********** Event " << iEvent << " *******" << endl;
165     DumpEvent(argv[0],rawEvent);
166     delete rawEvent;
167   }
168
169   cout << "*******************************************" << endl;
170   cout << "EOF" << endl;
171   cout << "*******************************************" << endl;
172   delete rawTree;
173   rawFile->Close();
174 }