]>
Commit | Line | Data |
---|---|---|
a6e7b125 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
bea6b2a4 | 16 | /* $Id$ */ |
17 | ||
a6e7b125 | 18 | /////////////////////////////////////////////////////////////////////////////// |
bea6b2a4 | 19 | /// |
20 | /// This is the base class for reading raw data. | |
21 | /// | |
22 | /// The derived classes, which operate on concrete raw data formats, | |
23 | /// should implement | |
24 | /// - ReadHeader to read the next (data/equipment) header | |
25 | /// - ReadNextData to read the next raw data block (=1 DDL) | |
26 | /// - ReadNext to read a given number of bytes | |
27 | /// - several getters like GetType | |
28 | /// | |
29 | /// Sequential access to the raw data is provided by the methods | |
30 | /// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar | |
31 | /// | |
32 | /// If only data from a specific detector (and a given range of DDL numbers) | |
33 | /// should be read, this can be achieved by the Select method. | |
34 | /// Several getters provide information about the current event and the | |
35 | /// current type of raw data. | |
36 | /// | |
a6e7b125 | 37 | /////////////////////////////////////////////////////////////////////////////// |
38 | ||
43787b8e | 39 | #include <TClass.h> |
40 | #include <TPluginManager.h> | |
41 | #include <TROOT.h> | |
56918e2f | 42 | #include <TInterpreter.h> |
13b20641 | 43 | #include <TSystem.h> |
764daca3 | 44 | #include <TPRegexp.h> |
5dfb32c1 | 45 | #include <THashList.h> |
43787b8e | 46 | |
0cfe2438 | 47 | #include <Riostream.h> |
a6e7b125 | 48 | #include "AliRawReader.h" |
43787b8e | 49 | #include "AliRawReaderFile.h" |
50 | #include "AliRawReaderDate.h" | |
51 | #include "AliRawReaderRoot.h" | |
a6e0640d | 52 | #include "AliRawReaderChain.h" |
362c9d61 | 53 | #include "AliDAQ.h" |
38cf12f3 | 54 | #include "AliLog.h" |
8de97894 | 55 | |
a6e7b125 | 56 | ClassImp(AliRawReader) |
57 | ||
58 | ||
c946ab02 | 59 | AliRawReader::AliRawReader() : |
0cfe2438 | 60 | fEquipmentIdsIn(NULL), |
61 | fEquipmentIdsOut(NULL), | |
18882b3b | 62 | fRequireHeader(kTRUE), |
39f9963f | 63 | fHeader(NULL), |
c946ab02 | 64 | fCount(0), |
f224de6c | 65 | fSelectEquipmentType(-1), |
66 | fSelectMinEquipmentId(-1), | |
67 | fSelectMaxEquipmentId(-1), | |
39f9963f | 68 | fSkipInvalid(kFALSE), |
dd9a70fe | 69 | fSelectEventType(-1), |
00665a00 | 70 | fSelectTriggerMask(0), |
56918e2f | 71 | fSelectTriggerExpr(), |
38cf12f3 | 72 | fErrorCode(0), |
73 | fEventNumber(-1), | |
edd06192 | 74 | fErrorLogs("AliRawDataErrorLog",100), |
a97af23d | 75 | fHeaderSwapped(NULL), |
b21d9ff2 | 76 | fIsValid(kTRUE), |
77 | fIsTriggerClassLoaded(kFALSE) | |
a6e7b125 | 78 | { |
42d20574 | 79 | // default constructor: initialize data members |
edd06192 | 80 | // Allocate the swapped header in case of Mac |
81 | #ifndef R__BYTESWAP | |
82 | fHeaderSwapped=new AliRawDataHeader(); | |
83 | #endif | |
0cfe2438 | 84 | } |
42d20574 | 85 | |
0cfe2438 | 86 | Bool_t AliRawReader::LoadEquipmentIdsMap(const char *fileName) |
87 | { | |
88 | // Open the mapping file | |
89 | // and load the mapping data | |
90 | ifstream input(fileName); | |
91 | if (input.is_open()) { | |
92 | Warning("AliRawReader","Equipment ID mapping file is found !"); | |
93 | const Int_t kMaxDDL = 256; | |
94 | fEquipmentIdsIn = new TArrayI(kMaxDDL); | |
95 | fEquipmentIdsOut = new TArrayI(kMaxDDL); | |
96 | Int_t equipIn, equipOut; | |
97 | Int_t nIds = 0; | |
98 | while (input >> equipIn >> equipOut) { | |
99 | if (nIds >= kMaxDDL) { | |
100 | Error("AliRawReader","Too many equipment Id mappings found ! Truncating the list !"); | |
101 | break; | |
102 | } | |
103 | fEquipmentIdsIn->AddAt(equipIn,nIds); | |
104 | fEquipmentIdsOut->AddAt(equipOut,nIds); | |
105 | nIds++; | |
106 | } | |
107 | fEquipmentIdsIn->Set(nIds); | |
108 | fEquipmentIdsOut->Set(nIds); | |
109 | input.close(); | |
110 | return kTRUE; | |
111 | } | |
112 | else { | |
113 | Error("AliRawReader","equipment id map file is not found ! Skipping the mapping !"); | |
114 | return kFALSE; | |
115 | } | |
a6e7b125 | 116 | } |
117 | ||
42d20574 | 118 | AliRawReader::AliRawReader(const AliRawReader& rawReader) : |
c946ab02 | 119 | TObject(rawReader), |
0cfe2438 | 120 | fEquipmentIdsIn(rawReader.fEquipmentIdsIn), |
121 | fEquipmentIdsOut(rawReader.fEquipmentIdsOut), | |
18882b3b | 122 | fRequireHeader(rawReader.fRequireHeader), |
39f9963f | 123 | fHeader(rawReader.fHeader), |
c946ab02 | 124 | fCount(rawReader.fCount), |
f224de6c | 125 | fSelectEquipmentType(rawReader.fSelectEquipmentType), |
126 | fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId), | |
127 | fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId), | |
39f9963f | 128 | fSkipInvalid(rawReader.fSkipInvalid), |
dd9a70fe | 129 | fSelectEventType(rawReader.fSelectEventType), |
00665a00 | 130 | fSelectTriggerMask(rawReader.fSelectTriggerMask), |
56918e2f | 131 | fSelectTriggerExpr(rawReader.fSelectTriggerExpr), |
38cf12f3 | 132 | fErrorCode(0), |
133 | fEventNumber(-1), | |
edd06192 | 134 | fErrorLogs("AliRawDataErrorLog",100), |
a97af23d | 135 | fHeaderSwapped(NULL), |
b21d9ff2 | 136 | fIsValid(rawReader.fIsValid), |
137 | fIsTriggerClassLoaded(rawReader.fIsTriggerClassLoaded) | |
42d20574 | 138 | { |
139 | // copy constructor | |
edd06192 | 140 | // Allocate the swapped header in case of Mac |
141 | #ifndef R__BYTESWAP | |
142 | fHeaderSwapped=new AliRawDataHeader(*rawReader.fHeaderSwapped); | |
143 | #endif | |
42d20574 | 144 | } |
145 | ||
146 | AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader) | |
147 | { | |
148 | // assignment operator | |
2a4ff083 | 149 | if(&rawReader == this) return *this; |
0cfe2438 | 150 | fEquipmentIdsIn = rawReader.fEquipmentIdsIn; |
151 | fEquipmentIdsOut = rawReader.fEquipmentIdsOut; | |
42d20574 | 152 | |
39f9963f | 153 | fHeader = rawReader.fHeader; |
42d20574 | 154 | fCount = rawReader.fCount; |
155 | ||
39f9963f | 156 | fSelectEquipmentType = rawReader.fSelectEquipmentType; |
157 | fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId; | |
158 | fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId; | |
159 | fSkipInvalid = rawReader.fSkipInvalid; | |
dd9a70fe | 160 | fSelectEventType = rawReader.fSelectEventType; |
00665a00 | 161 | fSelectTriggerMask = rawReader.fSelectTriggerMask; |
56918e2f | 162 | fSelectTriggerExpr = rawReader.fSelectTriggerExpr; |
42d20574 | 163 | |
b4857df7 | 164 | fErrorCode = rawReader.fErrorCode; |
165 | ||
38cf12f3 | 166 | fEventNumber = rawReader.fEventNumber; |
167 | fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone()); | |
168 | ||
a97af23d | 169 | fIsValid = rawReader.fIsValid; |
b21d9ff2 | 170 | fIsTriggerClassLoaded = rawReader.fIsTriggerClassLoaded; |
a97af23d | 171 | |
42d20574 | 172 | return *this; |
173 | } | |
174 | ||
0cfe2438 | 175 | AliRawReader::~AliRawReader() |
176 | { | |
177 | // destructor | |
178 | // delete the mapping arrays if | |
179 | // initialized | |
180 | if (fEquipmentIdsIn) delete fEquipmentIdsIn; | |
181 | if (fEquipmentIdsOut) delete fEquipmentIdsOut; | |
79dac785 | 182 | fErrorLogs.Delete(); |
edd06192 | 183 | if (fHeaderSwapped) delete fHeaderSwapped; |
0cfe2438 | 184 | } |
185 | ||
43787b8e | 186 | AliRawReader* AliRawReader::Create(const char *uri) |
187 | { | |
188 | // RawReader's factory | |
189 | // It instantiate corresponding raw-reader implementation class object | |
190 | // depending on the URI provided | |
191 | // Normal URIs point to files, while the URI starting with | |
192 | // 'mem://:' or 'mem://<filename>' will create | |
193 | // AliRawReaderDateOnline object which is supposed to be used | |
194 | // in the online reconstruction | |
195 | ||
196 | TString strURI = uri; | |
197 | ||
198 | if (strURI.IsNull()) { | |
199 | AliWarningClass("No raw-reader created"); | |
200 | return NULL; | |
201 | } | |
202 | ||
3f7450e0 | 203 | TObjArray *fields = strURI.Tokenize("?"); |
204 | TString &fileURI = ((TObjString*)fields->At(0))->String(); | |
205 | ||
43787b8e | 206 | AliRawReader *rawReader = NULL; |
3ae8c60d | 207 | if (fileURI.BeginsWith("mem://") || fileURI.BeginsWith("^")) { |
208 | if (fileURI.BeginsWith("mem://")) fileURI.ReplaceAll("mem://",""); | |
3f7450e0 | 209 | AliInfoClass(Form("Creating raw-reader in order to read events in shared memory (option=%s)",fileURI.Data())); |
43787b8e | 210 | |
211 | TPluginManager* pluginManager = gROOT->GetPluginManager(); | |
212 | TString rawReaderName = "AliRawReaderDateOnline"; | |
213 | TPluginHandler* pluginHandler = pluginManager->FindHandler("AliRawReader", "online"); | |
214 | // if not, add a plugin for it | |
215 | if (!pluginHandler) { | |
216 | pluginManager->AddHandler("AliRawReader", "online", | |
217 | "AliRawReaderDateOnline", "RAWDatarecOnline", "AliRawReaderDateOnline(const char*)"); | |
218 | pluginHandler = pluginManager->FindHandler("AliRawReader", "online"); | |
219 | } | |
220 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
3f7450e0 | 221 | rawReader = (AliRawReader*)pluginHandler->ExecPlugin(1,fileURI.Data()); |
43787b8e | 222 | } |
223 | else { | |
a6e0640d | 224 | delete fields; |
43787b8e | 225 | return NULL; |
226 | } | |
227 | } | |
2f954aba | 228 | else if (fileURI.BeginsWith("amore://")) { |
229 | // A special raw-data URL used in case | |
230 | // the raw-data reading is steered from | |
231 | // ouside, i.e. from AMORE | |
232 | fileURI.ReplaceAll("amore://",""); | |
233 | AliInfoClass("Creating raw-reader in order to read events sent by AMORE"); | |
234 | rawReader = new AliRawReaderDate((void *)NULL); | |
235 | } | |
a6e0640d | 236 | else if (fileURI.BeginsWith("collection://")) { |
237 | fileURI.ReplaceAll("collection://",""); | |
238 | AliInfoClass(Form("Creating raw-reader in order to read raw-data files collection defined in %s",fileURI.Data())); | |
239 | rawReader = new AliRawReaderChain(fileURI); | |
240 | } | |
bb0edcaf | 241 | else if (fileURI.BeginsWith("raw://run")) { |
242 | fileURI.ReplaceAll("raw://run",""); | |
243 | if (fileURI.IsDigit()) { | |
244 | rawReader = new AliRawReaderChain(fileURI.Atoi()); | |
245 | } | |
246 | else { | |
247 | AliErrorClass(Form("Invalid syntax: %s",fileURI.Data())); | |
248 | fields->Delete(); | |
249 | return NULL; | |
250 | } | |
251 | } | |
a6e0640d | 252 | else { |
253 | AliInfoClass(Form("Creating raw-reader in order to read raw-data file: %s",fileURI.Data())); | |
13b20641 | 254 | TString filename(gSystem->ExpandPathName(fileURI.Data())); |
255 | if (filename.EndsWith("/")) { | |
256 | rawReader = new AliRawReaderFile(filename); | |
257 | } else if (filename.EndsWith(".root")) { | |
258 | rawReader = new AliRawReaderRoot(filename); | |
a6e0640d | 259 | } else { |
13b20641 | 260 | rawReader = new AliRawReaderDate(filename); |
a6e0640d | 261 | } |
262 | } | |
43787b8e | 263 | |
a97af23d | 264 | if (!rawReader->IsRawReaderValid()) { |
265 | AliErrorClass(Form("Raw-reader is invalid - check the input URI (%s)",fileURI.Data())); | |
266 | delete rawReader; | |
267 | fields->Delete(); | |
268 | delete fields; | |
269 | return NULL; | |
270 | } | |
271 | ||
3f7450e0 | 272 | // Now apply event selection criteria (if specified) |
273 | if (fields->GetEntries() > 1) { | |
274 | Int_t eventType = -1; | |
275 | ULong64_t triggerMask = 0; | |
56918e2f | 276 | TString triggerExpr; |
3f7450e0 | 277 | for(Int_t i = 1; i < fields->GetEntries(); i++) { |
278 | if (!fields->At(i)) continue; | |
279 | TString &option = ((TObjString*)fields->At(i))->String(); | |
280 | if (option.BeginsWith("EventType=",TString::kIgnoreCase)) { | |
281 | option.ReplaceAll("EventType=",""); | |
282 | eventType = option.Atoi(); | |
283 | continue; | |
284 | } | |
285 | if (option.BeginsWith("Trigger=",TString::kIgnoreCase)) { | |
286 | option.ReplaceAll("Trigger=",""); | |
56918e2f | 287 | if (option.IsDigit()) { |
288 | triggerMask = option.Atoll(); | |
289 | } | |
290 | else { | |
291 | triggerExpr = option.Data(); | |
292 | } | |
3f7450e0 | 293 | continue; |
294 | } | |
295 | AliWarningClass(Form("Ignoring invalid event selection option: %s",option.Data())); | |
296 | } | |
56918e2f | 297 | AliInfoClass(Form("Event selection criteria specified: eventype=%d trigger mask=%llx trigger expression=%s", |
298 | eventType,triggerMask,triggerExpr.Data())); | |
299 | rawReader->SelectEvents(eventType,triggerMask,triggerExpr.Data()); | |
3f7450e0 | 300 | } |
301 | ||
302 | fields->Delete(); | |
303 | delete fields; | |
304 | ||
43787b8e | 305 | return rawReader; |
306 | } | |
307 | ||
0cfe2438 | 308 | Int_t AliRawReader::GetMappedEquipmentId() const |
309 | { | |
310 | if (!fEquipmentIdsIn || !fEquipmentIdsOut) { | |
311 | Error("AliRawReader","equipment Ids mapping is not initialized !"); | |
312 | return GetEquipmentId(); | |
313 | } | |
314 | Int_t equipmentId = GetEquipmentId(); | |
315 | for(Int_t iId = 0; iId < fEquipmentIdsIn->GetSize(); iId++) { | |
316 | if (equipmentId == fEquipmentIdsIn->At(iId)) { | |
317 | equipmentId = fEquipmentIdsOut->At(iId); | |
318 | break; | |
319 | } | |
320 | } | |
321 | return equipmentId; | |
322 | } | |
323 | ||
324 | Int_t AliRawReader::GetDetectorID() const | |
325 | { | |
326 | // Get the detector ID | |
327 | // The list of detector IDs | |
362c9d61 | 328 | // can be found in AliDAQ.h |
0cfe2438 | 329 | Int_t equipmentId; |
330 | if (fEquipmentIdsIn && fEquipmentIdsIn) | |
331 | equipmentId = GetMappedEquipmentId(); | |
332 | else | |
333 | equipmentId = GetEquipmentId(); | |
334 | ||
362c9d61 | 335 | if (equipmentId >= 0) { |
336 | Int_t ddlIndex; | |
337 | return AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex); | |
338 | } | |
0cfe2438 | 339 | else |
340 | return -1; | |
341 | } | |
342 | ||
343 | Int_t AliRawReader::GetDDLID() const | |
344 | { | |
345 | // Get the DDL ID (within one sub-detector) | |
346 | // The list of detector IDs | |
362c9d61 | 347 | // can be found in AliDAQ.h |
0cfe2438 | 348 | Int_t equipmentId; |
349 | if (fEquipmentIdsIn && fEquipmentIdsIn) | |
350 | equipmentId = GetMappedEquipmentId(); | |
351 | else | |
352 | equipmentId = GetEquipmentId(); | |
353 | ||
362c9d61 | 354 | if (equipmentId >= 0) { |
355 | Int_t ddlIndex; | |
356 | AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex); | |
357 | return ddlIndex; | |
358 | } | |
0cfe2438 | 359 | else |
360 | return -1; | |
361 | } | |
8de97894 | 362 | |
362c9d61 | 363 | void AliRawReader::Select(const char *detectorName, Int_t minDDLID, Int_t maxDDLID) |
364 | { | |
365 | // read only data of the detector with the given name and in the given | |
366 | // range of DDLs (minDDLID <= DDLID <= maxDDLID). | |
367 | // no selection is applied if a value < 0 is used. | |
368 | Int_t detectorID = AliDAQ::DetectorID(detectorName); | |
369 | if(detectorID >= 0) | |
370 | Select(detectorID,minDDLID,maxDDLID); | |
371 | } | |
372 | ||
8de97894 | 373 | void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID) |
a6e7b125 | 374 | { |
8de97894 | 375 | // read only data of the detector with the given ID and in the given |
f224de6c | 376 | // range of DDLs (minDDLID <= DDLID <= maxDDLID). |
8de97894 | 377 | // no selection is applied if a value < 0 is used. |
a6e7b125 | 378 | |
0cfe2438 | 379 | fSelectEquipmentType = -1; |
362c9d61 | 380 | |
381 | if (minDDLID < 0) | |
382 | fSelectMinEquipmentId = AliDAQ::DdlIDOffset(detectorID); | |
383 | else | |
384 | fSelectMinEquipmentId = AliDAQ::DdlID(detectorID,minDDLID); | |
385 | ||
386 | if (maxDDLID < 0) | |
387 | fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,AliDAQ::NumberOfDdls(detectorID)-1); | |
388 | else | |
389 | fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,maxDDLID); | |
8de97894 | 390 | } |
a6e7b125 | 391 | |
f224de6c | 392 | void AliRawReader::SelectEquipment(Int_t equipmentType, |
393 | Int_t minEquipmentId, Int_t maxEquipmentId) | |
394 | { | |
395 | // read only data of the equipment with the given type and in the given | |
396 | // range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId). | |
397 | // no selection is applied if a value < 0 is used. | |
398 | ||
399 | fSelectEquipmentType = equipmentType; | |
400 | fSelectMinEquipmentId = minEquipmentId; | |
401 | fSelectMaxEquipmentId = maxEquipmentId; | |
402 | } | |
403 | ||
56918e2f | 404 | void AliRawReader::SelectEvents(Int_t type, ULong64_t triggerMask, |
405 | const char *triggerExpr) | |
dd9a70fe | 406 | { |
00665a00 | 407 | // read only events with the given type and optionally |
408 | // trigger mask. | |
56918e2f | 409 | // no selection is applied if value = 0 is used. |
410 | // Trigger selection can be done via string (triggerExpr) | |
411 | // which defines the trigger logic to be used. It works only | |
412 | // after LoadTriggerClass() method is called for all involved | |
413 | // trigger classes. | |
dd9a70fe | 414 | |
415 | fSelectEventType = type; | |
00665a00 | 416 | fSelectTriggerMask = triggerMask; |
56918e2f | 417 | if (triggerExpr) fSelectTriggerExpr = triggerExpr; |
418 | } | |
419 | ||
420 | void AliRawReader::LoadTriggerClass(const char* name, Int_t index) | |
421 | { | |
422 | // Loads the list of trigger classes defined. | |
423 | // Used in conjunction with IsEventSelected in the | |
424 | // case when the trigger selection is given by | |
425 | // fSelectedTriggerExpr | |
426 | ||
427 | if (fSelectTriggerExpr.IsNull()) return; | |
428 | ||
b21d9ff2 | 429 | fIsTriggerClassLoaded = kTRUE; |
430 | ||
764daca3 | 431 | if (index >= 0) |
432 | fSelectTriggerExpr.ReplaceAll(name,Form("[%d]",index)); | |
433 | else | |
434 | fSelectTriggerExpr.ReplaceAll(name,"0"); | |
dd9a70fe | 435 | } |
436 | ||
5dfb32c1 | 437 | void AliRawReader::LoadTriggerAlias(const THashList *lst) |
438 | { | |
439 | // Loads the list of trigger aliases defined. | |
440 | // Replaces the alias by the OR of the triggers included in it. | |
441 | // The subsiquent call to LoadTriggerClass is needed | |
442 | // to obtain the final expression in | |
443 | // fSelectedTriggerExpr | |
444 | ||
445 | if (fSelectTriggerExpr.IsNull()) return; | |
446 | ||
447 | // Make a THashList alias -> trigger classes | |
448 | ||
449 | THashList alias2trig; | |
450 | TIter iter(lst); | |
451 | TNamed *nmd = 0; | |
452 | ||
453 | // Loop on triggers | |
454 | ||
455 | while((nmd = dynamic_cast<TNamed*>(iter.Next()))){ | |
456 | ||
457 | TString aliasList(nmd->GetTitle()); | |
458 | TObjArray* arrAliases = aliasList.Tokenize(','); | |
459 | Int_t nAliases = arrAliases->GetEntries(); | |
460 | ||
461 | // Loop on aliases for the current trigger | |
462 | for(Int_t i=0; i<nAliases; i++){ | |
463 | ||
464 | TObjString *alias = (TObjString*) arrAliases->At(i); | |
465 | ||
466 | // Find the current alias in the hash list. If it is not there, add TNamed entry | |
467 | TNamed * inlist = (TNamed*)alias2trig.FindObject((alias->GetString()).Data()); | |
468 | if (!inlist) { | |
469 | inlist = new TNamed((alias->GetString()).Data(),nmd->GetName()); | |
470 | alias2trig.Add(inlist); | |
471 | } | |
472 | else { | |
473 | TString tt(inlist->GetTitle()); | |
474 | tt += " || "; | |
475 | tt += nmd->GetName(); | |
476 | inlist->SetTitle(tt.Data()); | |
477 | } | |
478 | } | |
479 | ||
480 | delete arrAliases; | |
481 | } | |
482 | alias2trig.Sort(kSortDescending); | |
483 | ||
484 | // Replace all the aliases by the OR of triggers | |
485 | TIter iter1(&alias2trig); | |
486 | while((nmd = dynamic_cast<TNamed*>(iter1.Next()))){ | |
487 | fSelectTriggerExpr.ReplaceAll(nmd->GetName(),nmd->GetTitle()); | |
488 | } | |
489 | } | |
490 | ||
42d20574 | 491 | Bool_t AliRawReader::IsSelected() const |
a6e7b125 | 492 | { |
8de97894 | 493 | // apply the selection (if any) |
494 | ||
39f9963f | 495 | if (fSkipInvalid && !IsValid()) return kFALSE; |
f224de6c | 496 | |
0cfe2438 | 497 | if (fSelectEquipmentType >= 0) |
f224de6c | 498 | if (GetEquipmentType() != fSelectEquipmentType) return kFALSE; |
0cfe2438 | 499 | |
500 | Int_t equipmentId; | |
501 | if (fEquipmentIdsIn && fEquipmentIdsIn) | |
502 | equipmentId = GetMappedEquipmentId(); | |
503 | else | |
504 | equipmentId = GetEquipmentId(); | |
505 | ||
506 | if ((fSelectMinEquipmentId >= 0) && | |
507 | (equipmentId < fSelectMinEquipmentId)) | |
508 | return kFALSE; | |
509 | if ((fSelectMaxEquipmentId >= 0) && | |
510 | (equipmentId > fSelectMaxEquipmentId)) | |
511 | return kFALSE; | |
f224de6c | 512 | |
8de97894 | 513 | return kTRUE; |
a6e7b125 | 514 | } |
515 | ||
dd9a70fe | 516 | Bool_t AliRawReader::IsEventSelected() const |
517 | { | |
00665a00 | 518 | // apply the event selection (if any) |
dd9a70fe | 519 | |
00665a00 | 520 | // First check the event type |
dd9a70fe | 521 | if (fSelectEventType >= 0) { |
522 | if (GetType() != (UInt_t) fSelectEventType) return kFALSE; | |
523 | } | |
524 | ||
00665a00 | 525 | // Then check the trigger pattern and compared it |
526 | // to the required trigger mask | |
527 | if (fSelectTriggerMask != 0) { | |
528 | if ((GetClassMask() & fSelectTriggerMask) != fSelectTriggerMask) return kFALSE; | |
529 | } | |
530 | ||
b21d9ff2 | 531 | if ( fIsTriggerClassLoaded && !fSelectTriggerExpr.IsNull()) { |
56918e2f | 532 | TString expr(fSelectTriggerExpr); |
533 | ULong64_t mask = GetClassMask(); | |
534 | for(Int_t itrigger = 0; itrigger < 50; itrigger++) { | |
535 | if (mask & (1 << itrigger)) { | |
536 | expr.ReplaceAll(Form("[%d]",itrigger),"1"); | |
537 | } | |
538 | else { | |
539 | expr.ReplaceAll(Form("[%d]",itrigger),"0"); | |
540 | } | |
541 | } | |
31572b9e | 542 | // Possibility to introduce downscaling |
764daca3 | 543 | TPRegexp("(%\\s*\\d+)").Substitute(expr,Form("&& !(%d$1)",GetEventIndex()),"g"); |
56918e2f | 544 | Int_t error; |
545 | if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) && | |
546 | (error == TInterpreter::kNoError)) { | |
547 | return kFALSE; | |
548 | } | |
549 | } | |
550 | ||
dd9a70fe | 551 | return kTRUE; |
552 | } | |
553 | ||
91f76e9b | 554 | UInt_t AliRawReader::SwapWord(UInt_t x) const |
555 | { | |
556 | // Swap the endianess of the integer value 'x' | |
557 | ||
558 | return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) | | |
559 | ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24)); | |
560 | } | |
561 | ||
562 | UShort_t AliRawReader::SwapShort(UShort_t x) const | |
563 | { | |
564 | // Swap the endianess of the short value 'x' | |
565 | ||
566 | return (((x & 0x00ffU) << 8) | ((x & 0xff00U) >> 8)) ; | |
567 | } | |
a6e7b125 | 568 | |
a6e7b125 | 569 | Bool_t AliRawReader::ReadNextInt(UInt_t& data) |
570 | { | |
8de97894 | 571 | // reads the next 4 bytes at the current position |
572 | // returns kFALSE if the data could not be read | |
a6e7b125 | 573 | |
574 | while (fCount == 0) { | |
c946ab02 | 575 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 576 | } |
8de97894 | 577 | if (fCount < (Int_t) sizeof(data)) { |
578 | Error("ReadNextInt", | |
579 | "too few data left (%d bytes) to read an UInt_t!", fCount); | |
580 | return kFALSE; | |
581 | } | |
582 | if (!ReadNext((UChar_t*) &data, sizeof(data))) { | |
a6e7b125 | 583 | Error("ReadNextInt", "could not read data!"); |
584 | return kFALSE; | |
585 | } | |
91f76e9b | 586 | #ifndef R__BYTESWAP |
587 | data=SwapWord(data); | |
588 | #endif | |
a6e7b125 | 589 | return kTRUE; |
590 | } | |
591 | ||
592 | Bool_t AliRawReader::ReadNextShort(UShort_t& data) | |
593 | { | |
8de97894 | 594 | // reads the next 2 bytes at the current position |
595 | // returns kFALSE if the data could not be read | |
a6e7b125 | 596 | |
597 | while (fCount == 0) { | |
c946ab02 | 598 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 599 | } |
8de97894 | 600 | if (fCount < (Int_t) sizeof(data)) { |
601 | Error("ReadNextShort", | |
602 | "too few data left (%d bytes) to read an UShort_t!", fCount); | |
603 | return kFALSE; | |
604 | } | |
605 | if (!ReadNext((UChar_t*) &data, sizeof(data))) { | |
a6e7b125 | 606 | Error("ReadNextShort", "could not read data!"); |
607 | return kFALSE; | |
608 | } | |
91f76e9b | 609 | #ifndef R__BYTESWAP |
610 | data=SwapShort(data); | |
611 | #endif | |
a6e7b125 | 612 | return kTRUE; |
613 | } | |
614 | ||
615 | Bool_t AliRawReader::ReadNextChar(UChar_t& data) | |
616 | { | |
617 | // reads the next 1 byte at the current stream position | |
8de97894 | 618 | // returns kFALSE if the data could not be read |
a6e7b125 | 619 | |
620 | while (fCount == 0) { | |
c946ab02 | 621 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 622 | } |
8de97894 | 623 | if (!ReadNext((UChar_t*) &data, sizeof(data))) { |
a6e7b125 | 624 | Error("ReadNextChar", "could not read data!"); |
625 | return kFALSE; | |
626 | } | |
a6e7b125 | 627 | return kTRUE; |
628 | } | |
629 | ||
66964465 | 630 | Bool_t AliRawReader::GotoEvent(Int_t event) |
636c1780 | 631 | { |
66964465 | 632 | // Random access to certain |
633 | // event index. Could be very slow | |
634 | // for some non-root raw-readers. | |
635 | // So it should be reimplemented there. | |
636 | if (event < fEventNumber) RewindEvents(); | |
637 | ||
638 | while (fEventNumber < event) { | |
639 | if (!NextEvent()) return kFALSE; | |
640 | } | |
641 | ||
642 | return kTRUE; | |
636c1780 | 643 | } |
b4857df7 | 644 | |
645 | Int_t AliRawReader::CheckData() const | |
646 | { | |
647 | // check the consistency of the data | |
648 | // derived classes should overwrite the default method which returns 0 (no err) | |
649 | ||
650 | return 0; | |
651 | } | |
652 | ||
509a7696 | 653 | |
654 | void AliRawReader::DumpData(Int_t limit) | |
655 | { | |
656 | // print the raw data | |
657 | // if limit is not negative, only the first and last "limit" lines of raw data | |
658 | // are printed | |
659 | ||
660 | Reset(); | |
661 | if (!ReadHeader()) { | |
662 | Error("DumpData", "no header"); | |
663 | return; | |
664 | } | |
665 | printf("header:\n" | |
666 | " type = %d run = %d ", GetType(), GetRunNumber()); | |
667 | if (GetEventId()) { | |
668 | printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]); | |
669 | } else { | |
670 | printf("event = -------- --------\n"); | |
671 | } | |
672 | if (GetTriggerPattern()) { | |
673 | printf(" trigger = %8.8x %8.8x ", | |
674 | GetTriggerPattern()[1], GetTriggerPattern()[0]); | |
675 | } else { | |
676 | printf(" trigger = -------- -------- "); | |
677 | } | |
678 | if (GetDetectorPattern()) { | |
679 | printf("detector = %8.8x\n", GetDetectorPattern()[0]); | |
680 | } else { | |
681 | printf("detector = --------\n"); | |
682 | } | |
683 | if (GetAttributes()) { | |
684 | printf(" attributes = %8.8x %8.8x %8.8x ", | |
685 | GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]); | |
686 | } else { | |
687 | printf(" attributes = -------- -------- -------- "); | |
688 | } | |
689 | printf("GDC = %d\n", GetGDCId()); | |
690 | printf("\n"); | |
691 | ||
692 | do { | |
693 | printf("-------------------------------------------------------------------------------\n"); | |
694 | printf("LDC = %d\n", GetLDCId()); | |
695 | ||
696 | printf("equipment:\n" | |
697 | " size = %d type = %d id = %d\n", | |
698 | GetEquipmentSize(), GetEquipmentType(), GetEquipmentId()); | |
699 | if (GetEquipmentAttributes()) { | |
700 | printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2], | |
701 | GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]); | |
702 | } else { | |
703 | printf(" attributes = -------- -------- -------- "); | |
704 | } | |
705 | printf("element size = %d\n", GetEquipmentElementSize()); | |
706 | ||
39f9963f | 707 | printf("data header:\n" |
708 | " size = %d version = %d valid = %d compression = %d\n", | |
709 | GetDataSize(), GetVersion(), IsValid(), IsCompressed()); | |
509a7696 | 710 | |
711 | printf("\n"); | |
712 | if (limit == 0) continue; | |
713 | ||
714 | Int_t size = GetDataSize(); | |
715 | char line[70]; | |
716 | for (Int_t i = 0; i < 70; i++) line[i] = ' '; | |
717 | line[69] = '\0'; | |
718 | Int_t pos = 0; | |
719 | Int_t max = 16; | |
720 | UChar_t byte; | |
721 | ||
722 | for (Int_t n = 0; n < size; n++) { | |
723 | if (!ReadNextChar(byte)) { | |
724 | Error("DumpData", "couldn't read byte number %d\n", n); | |
725 | break; | |
726 | } | |
727 | if (pos >= max) { | |
728 | printf("%8.8x %s\n", n-pos, line); | |
729 | for (Int_t i = 0; i < 70; i++) line[i] = ' '; | |
730 | line[69] = '\0'; | |
731 | pos = 0; | |
732 | if ((limit > 0) && (n/max == limit)) { | |
733 | Int_t nContinue = ((size-1)/max+1-limit) * max; | |
734 | if (nContinue > n) { | |
735 | printf(" [skipping %d bytes]\n", nContinue-n); | |
736 | n = nContinue-1; | |
737 | continue; | |
738 | } | |
739 | } | |
740 | } | |
741 | Int_t offset = pos/4; | |
742 | if ((byte > 0x20) && (byte < 0x7f)) { | |
743 | line[pos+offset] = byte; | |
744 | } else { | |
745 | line[pos+offset] = '.'; | |
746 | } | |
747 | char hex[3]; | |
669f9a12 | 748 | snprintf(hex, 3, "%2.2x", byte); |
509a7696 | 749 | line[max+max/4+3+2*pos+offset] = hex[0]; |
750 | line[max+max/4+4+2*pos+offset] = hex[1]; | |
751 | pos++; | |
752 | } | |
753 | ||
754 | if (pos > 0) printf("%8.8x %s\n", size-pos, line); | |
755 | printf("\n"); | |
756 | ||
757 | } while (ReadHeader()); | |
758 | } | |
38cf12f3 | 759 | |
9fc249d9 | 760 | void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level, |
761 | Int_t code, | |
38cf12f3 | 762 | const char *message) |
763 | { | |
764 | // Add a raw data error message to the list | |
765 | // of raw-data decoding errors | |
766 | if (fEventNumber < 0) { | |
38cf12f3 | 767 | return; |
768 | } | |
3aea4e5e | 769 | Int_t ddlId = GetEquipmentId(); |
38cf12f3 | 770 | if (ddlId < 0) { |
771 | AliError("No ddl raw data have been read so far! Impossible to add a raw data error log!"); | |
772 | return; | |
773 | } | |
774 | ||
79dac785 | 775 | Int_t prevEventNumber = -1; |
776 | Int_t prevDdlId = -1; | |
777 | Int_t prevErrorCode = -1; | |
778 | AliRawDataErrorLog *prevLog = (AliRawDataErrorLog *)fErrorLogs.Last(); | |
779 | if (prevLog) { | |
780 | prevEventNumber = prevLog->GetEventNumber(); | |
781 | prevDdlId = prevLog->GetDdlID(); | |
782 | prevErrorCode = prevLog->GetErrorCode(); | |
783 | } | |
784 | ||
785 | if ((prevEventNumber != fEventNumber) || | |
786 | (prevDdlId != ddlId) || | |
787 | (prevErrorCode != code)) { | |
788 | new (fErrorLogs[fErrorLogs.GetEntriesFast()]) | |
789 | AliRawDataErrorLog(fEventNumber, | |
790 | ddlId, | |
791 | level, | |
792 | code, | |
793 | message); | |
794 | } | |
795 | else | |
796 | if (prevLog) prevLog->AddCount(); | |
797 | ||
38cf12f3 | 798 | } |
66964465 | 799 | |
800 | Bool_t AliRawReader::GotoEventWithID(Int_t event, | |
801 | UInt_t period, | |
802 | UInt_t orbitID, | |
803 | UShort_t bcID) | |
804 | { | |
805 | // Go to certain event number by | |
806 | // checking the event ID. | |
807 | // Useful in case event-selection | |
808 | // is applied and the 'event' is | |
809 | // relative | |
810 | if (!GotoEvent(event)) return kFALSE; | |
811 | ||
812 | while (GetBCID() != period || | |
813 | GetOrbitID() != orbitID || | |
814 | GetPeriod() != bcID) { | |
815 | if (!NextEvent()) return kFALSE; | |
816 | } | |
817 | ||
818 | return kTRUE; | |
819 | } | |
820 |