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