1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Artur Szostak <artursz@iafrica.com> *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
17 #if !defined(__CINT__) || defined(__MAKECINT__)
19 #include "AliHLTHOMERReader.h"
20 #include "AliHLTMessage.h"
21 #include "Riostream.h"
26 #include "TDirectory.h"
27 #include "TTimeStamp.h"
32 #error You must compile this macro. Try the following command "> aliroot MonitorRawData.C++"
36 TH1D* gErrorHist = NULL;
37 TH1D* gManuHist = NULL;
38 TH1D* gSignalHist = NULL;
41 const char* DataTypeToString(homer_uint64 type)
51 for (int i = 0; i < 8; i++)
55 str[8] = '\0'; // Null terminate the string.
60 const char* OriginToString(homer_uint32 origin)
70 for (int i = 0; i < 4; i++)
74 str[4] = '\0'; // Null terminate the string.
79 bool UpdateHists(AliHLTHOMERReader& homerReader, const char* hostname, UShort_t port, bool addHists)
81 /// This routine just reads all the data blocks from the HOMER reader interface,
82 /// and checks if they are histogram objects we can deal with.
83 /// Any histogram objects with the following strings in their names:
84 /// "rawDataErrors", "manuDistrib" or "signalDistrib"
85 /// will be added to the global cumulative histograms.
87 int result = homerReader.ReadNextEvent(3000000); // 3 second timeout.
91 if (result != ETIMEDOUT)
93 cerr << "ERROR: Could not read another event from HLT on "
94 << hostname << ":" << port << "\t" << now.AsString() << endl;
99 cerr << "Timed out when trying to read from HLT on "
100 << hostname << ":" << port << "\t" << now.AsString() << endl;
105 cout << "Reading stats up to event: " << homerReader.GetEventID()
106 << "\t" << now.AsString() << endl;
108 for (unsigned long n = 0; n < homerReader.GetBlockCnt(); n++)
110 char* buffer = new char[homerReader.GetBlockDataLength(n)];
111 memcpy(buffer, homerReader.GetBlockData(n), homerReader.GetBlockDataLength(n));
112 AliHLTMessage msg(buffer, homerReader.GetBlockDataLength(n));
113 TClass* objclass = msg.GetClass();
114 if (objclass == NULL)
116 cerr << "WARNING: Do not know how to handle block " << n
117 << ", block type = " << DataTypeToString(homerReader.GetBlockDataType(n))
118 << ", origin = " << OriginToString(homerReader.GetBlockDataOrigin(n))
119 << ", but unknown class type. Skipping block." << endl;
123 TObject* obj = msg.ReadObject(objclass);
126 cerr << "WARNING: Could not read object from block " << n
127 << ", class type = " << objclass->GetName()
128 << ". Skipping block." << endl;
132 if (obj->IsA() != TH1D::Class())
134 cerr << "WARNING: Do not know how to handle object of type "
135 << obj->ClassName() << " recevied in block " << n
136 << ". Skipping block." << endl;
141 TH1D* hist = static_cast<TH1D*>(obj);
142 TString name = hist->GetName();
143 if (name.Contains("rawDataErrors"))
145 if (! addHists) gErrorHist->Reset("M");
146 gErrorHist->Add(hist);
148 else if (name.Contains("manuDistrib"))
150 if (! addHists) gManuHist->Reset("M");
151 gManuHist->Add(hist);
153 else if (name.Contains("signalDistrib"))
155 if (! addHists) gSignalHist->Reset("M");
156 gSignalHist->Add(hist);
160 cerr << "WARNING: Do not know how to handle histogram " << name
161 << " found in data block " << n << endl;
170 void MonitorRawData(const char* hostname = "alihlt-dcs0", UShort_t port = 58784, bool addHists = false)
172 if (gErrorHist == NULL && gDirectory->Get("errorHist") == NULL)
174 gErrorHist = new TH1D("errorHist", "Error codes found in raw data", 40, 0.5, 40.5);
175 gErrorHist->SetXTitle("Error code");
176 gErrorHist->SetYTitle("Number of errors");
178 if (gManuHist == NULL && gDirectory->Get("manuHist") == NULL)
180 gManuHist = new TH1D("manuHist", "Distribution of signals found per MANU", 2048, -0.5, 2047.5);
181 gManuHist->SetXTitle("MANU number (as seen in raw data)");
182 gManuHist->SetYTitle("Number of signals received.");
184 if (gSignalHist == NULL && gDirectory->Get("signalHist") == NULL)
186 gSignalHist = new TH1D("signalHist", "Distribution of ADC signal values", 4096, -0.5, 4095.5);
187 gSignalHist->SetXTitle("Channels");
188 gSignalHist->SetYTitle("dN/dChannel");
191 TCanvas* c1 = new TCanvas("errorCanvas", "Error histogram", 0, 0, 600, 450);
193 TCanvas* c2 = new TCanvas("manuCanvas", "MANU histogram", 610, 00, 600, 450);
194 if (gManuHist->GetEntries() > 0) c2->SetLogy();
196 TCanvas* c3 = new TCanvas("signalCanvas", "Signal histogram", 0, 480, 600, 450);
197 if (gSignalHist->GetEntries() > 0) c3->SetLogy();
202 bool updateOk = true;
204 AliHLTHOMERReader homerReader(hostname, port);
205 int status = homerReader.GetConnectionStatus();
210 updateOk = UpdateHists(homerReader, hostname, port, addHists);
214 cerr << "ERROR: exception occured. Trying to recover and continue..." << endl;
219 cerr << "ERROR: Could not connect to HLT on " << hostname << ":" << port << endl;
222 // Clear histograms on errors. This is usualy due to end of run.
223 if (! updateOk || status != 0)
225 gErrorHist->Reset("M");
226 gManuHist->Reset("M");
227 gSignalHist->Reset("M");
238 if (gManuHist->GetEntries() > 0) c2->SetLogy();
239 if (gSignalHist->GetEntries() > 0) c3->SetLogy();
245 // Effectively wait for 2 seconds but dispatch ROOT events while waiting.
246 for (int i = 0; i < 200; i++)
248 gSystem->DispatchOneEvent(kTRUE);