LCOV - code coverage report
Current view: top level - RAW/RAWDatarec - AliRawReader.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 122 432 28.2 %
Date: 2016-06-14 17:26:59 Functions: 14 30 46.7 %

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

Generated by: LCOV version 1.11