From 5ca4e0a07f15d9552a3b5e8c885dab2fbe07d5f8 Mon Sep 17 00:00:00 2001 From: cvetan Date: Thu, 25 Jun 2009 09:05:20 +0000 Subject: [PATCH] Initial version of the RCU ALTRO V3 format encoder. It derives from the old encoder and implements only the methods which are needed in order to produce the new format. To be tested first on TPC and then finalized. --- RAW/AliAltroBuffer.h | 10 +-- RAW/AliAltroBufferV3.cxx | 159 ++++++++++++++++++++++++++++++++++++ RAW/AliAltroBufferV3.h | 51 ++++++++++++ RAW/CMake_libRAWDatasim.txt | 1 + RAW/RAWDatasimLinkDef.h | 1 + RAW/libRAWDatasim.pkg | 4 +- 6 files changed, 219 insertions(+), 7 deletions(-) create mode 100644 RAW/AliAltroBufferV3.cxx create mode 100644 RAW/AliAltroBufferV3.h diff --git a/RAW/AliAltroBuffer.h b/RAW/AliAltroBuffer.h index 65e0b482c55..9ec3de42d61 100644 --- a/RAW/AliAltroBuffer.h +++ b/RAW/AliAltroBuffer.h @@ -37,19 +37,19 @@ class AliAltroBuffer: public TObject { virtual void WriteTrailer(Int_t wordsNumber, Short_t hwAddress); //this method is used to write the trailer - virtual void WriteChannel(Int_t padNumber, Int_t rowNumber, Int_t secNumber, + void WriteChannel(Int_t padNumber, Int_t rowNumber, Int_t secNumber, Int_t nTimeBins, const Int_t* adcValues, Int_t threshold = 0); //this method is used to write all ADC values and the trailer of a channel - virtual void WriteChannel(Short_t hwAddress, + void WriteChannel(Short_t hwAddress, Int_t nTimeBins, const Int_t* adcValues, Int_t threshold = 0); //this method is used to write all ADC values and the trailer of a channel - virtual Int_t WriteBunch(Int_t nTimeBins, const Int_t* adcValues, + Int_t WriteBunch(Int_t nTimeBins, const Int_t* adcValues, Int_t threshold = 0); //this method is used to write all ADC values - virtual void WriteDataHeader(Bool_t dummy, Bool_t compressed); + void WriteDataHeader(Bool_t dummy, Bool_t compressed); //this method is used to write the data header virtual void WriteRCUTrailer(Int_t rcuId); @@ -59,7 +59,7 @@ class AliAltroBuffer: public TObject { //this method is used to set the verbose level //level 0 no output messages //level !=0 some messages are displayed during the run - virtual void Flush(); + void Flush(); //this method is used to fill the buffer with 2AA hexadecimal value and save it into the output file void SetMapping(AliAltroMapping *mapping) { fMapping = mapping; } diff --git a/RAW/AliAltroBufferV3.cxx b/RAW/AliAltroBufferV3.cxx new file mode 100644 index 00000000000..f2d5fc85188 --- /dev/null +++ b/RAW/AliAltroBufferV3.cxx @@ -0,0 +1,159 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +// Interface to the Altro format +// to read and write digits +// To be used in Alice Data Challenges +// and in the compression of the RAW data + +#include "AliAltroBufferV3.h" +#include "AliRawDataHeaderSim.h" +#include "AliLog.h" +#include "AliFstream.h" + +ClassImp(AliAltroBufferV3) + +//_____________________________________________________________________________ +AliAltroBufferV3::AliAltroBufferV3(const char* fileName, AliAltroMapping *mapping): +AliAltroBuffer(fileName,mapping), + fN(0) +{ + // Constructor +} + +//_____________________________________________________________________________ +AliAltroBufferV3::~AliAltroBufferV3() +{ +// destructor + + if (fVerbose) Info("~AliAltroBufferV3", "File Created"); + + delete fFile; + +} + +//_____________________________________________________________________________ +AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source): + AliAltroBuffer(source), + fN(source.fN) +{ +// Copy Constructor + + Fatal("AliAltroBufferV3", "copy constructor not implemented"); +} + +//_____________________________________________________________________________ +AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& /*source*/) +{ +//Assigment operator + + Fatal("operator =", "assignment operator not implemented"); + return *this; +} + +//_____________________________________________________________________________ +void AliAltroBufferV3::FillBuffer(Int_t val) +{ +//Fills the Buffer with 16 ten bits words and write into a file + + if ((val > 0x3FF) || (val < 0)) { + Error("FillBuffer", "Value out of range (10 bits): %d", val); + val = 0x3FF; + } + + if (fN >= (kMaxWords-1)) { + Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!"); + return; + } + + fArray[fN++] = val; +} + +//_____________________________________________________________________________ +void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress) +{ + //Writes a trailer (header) of 32 bits using + //a given hardware adress + UInt_t temp = hwAddress & 0xFFF; + temp = (wordsNumber << 16) & 0x3FF; + temp |= (0x1 << 30); + + fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t)); + + ReverseAndWrite(); +} + +//_____________________________________________________________________________ +void AliAltroBufferV3::ReverseAndWrite() +{ + // Reverse the altro data order and + // write the buffer to the file + UInt_t temp = 0; + Int_t shift = 20; + for(Int_t i = fN; i >= 0; i--) { + temp |= (fArray[i] << shift); + shift -= 10; + if (shift < 0) { + fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t)); + temp = 0; + shift = 20; + } + } + + if (shift != 20) { + fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t)); + } + + fN = 0; +} + +//_____________________________________________________________________________ +void AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId) +{ + // Writes the RCU trailer + // rcuId the is serial number of the corresponding + // RCU. The basic format of the trailer can be + // found in the RCU manual. + // This method should be called at the end of + // raw data writing. + + UInt_t currentFilePos = fFile->Tellp(); + UInt_t size = currentFilePos-fDataHeaderPos; + size -= sizeof(AliRawDataHeader); + + if ((size % 5) != 0) { + AliFatal(Form("The current raw data payload is not a mutiple of 5 (%d) ! Can not write the RCU trailer !",size)); + return; + } + + // Now put the size in unit of number of 40bit words + size /= 5; + fFile->WriteBuffer((char *)(&size),sizeof(UInt_t)); + + // Now several not yet full defined fields + // In principle they are supposed to contain + // information about the sampling frequency, + // L1 phase, list of 'dead' FECs, etc. + // UInt_t buffer[n]; + // fFile->WriteBuffer((char *)(buffer),sizeof(UInt_t)*n); + + // Now the RCU identifier and size of the trailer + // FOr the moment the triler size is 2 32-bit words + UInt_t buffer = (2 & 0x7F); + buffer |= ((rcuId & 0x1FF) << 7); + buffer |= 0xAAAA << 16; + fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); + +} diff --git a/RAW/AliAltroBufferV3.h b/RAW/AliAltroBufferV3.h new file mode 100644 index 00000000000..886f7333c71 --- /dev/null +++ b/RAW/AliAltroBufferV3.h @@ -0,0 +1,51 @@ +/* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +///////////////////////////////////////////////////// +// Class used for read-write the ALTRO data format // +///////////////////////////////////////////////////// + +/*This class is an interface between the altro format file and the + user, and can be used in write or read mode + In the write mode a new altro file is created and filled using the method FillBuffer(). + The name of the file is specified as parameter in the constructor as well as the type mode. + In the Read mode the specified file is open and the values can be read using the + methods GetNext() and GetNextBackWord(). + The first method is used to read the file forward while the second is used to read backward +*/ + +#ifndef AliALTROBUFFERV3_H +#define AliALTROBUFFERV3_H + +#include "AliAltroBuffer.h" + +class AliAltroBufferV3: public AliAltroBuffer { + public: + AliAltroBufferV3(const char* fileName, AliAltroMapping *mapping = NULL); + virtual ~AliAltroBufferV3(); + + virtual void FillBuffer(Int_t val); + //this method stores a word into the buffer + + virtual void WriteTrailer(Int_t wordsNumber, Short_t hwAddress); + //this method is used to write the trailer + + virtual void WriteRCUTrailer(Int_t rcuId); + //this method is used to write the RCU trailer + + enum { kMaxWords = 1024 }; + + protected: + void ReverseAndWrite(); + //this method reverse the altro data order and write the buffer to the file + + AliAltroBufferV3(const AliAltroBufferV3& source); + AliAltroBufferV3& operator = (const AliAltroBufferV3& source); + + UShort_t fArray[kMaxWords]; // Temporary array needed in reverting data order + Int_t fN; // Size of the temporary array + + ClassDef(AliAltroBufferV3,0) // Interface to the Altro format +}; + +#endif diff --git a/RAW/CMake_libRAWDatasim.txt b/RAW/CMake_libRAWDatasim.txt index 7c34c34af1b..c04e5764bed 100644 --- a/RAW/CMake_libRAWDatasim.txt +++ b/RAW/CMake_libRAWDatasim.txt @@ -3,6 +3,7 @@ set(SRCS AliBitPacking.cxx AliAltroBuffer.cxx +AliAltroBufferV3.cxx ) # fill list of header files from list of source files diff --git a/RAW/RAWDatasimLinkDef.h b/RAW/RAWDatasimLinkDef.h index 86669939580..5ed5a350b77 100644 --- a/RAW/RAWDatasimLinkDef.h +++ b/RAW/RAWDatasimLinkDef.h @@ -6,5 +6,6 @@ #pragma link C++ class AliBitPacking+; #pragma link C++ class AliAltroBuffer+; +#pragma link C++ class AliAltroBufferV3+; #endif diff --git a/RAW/libRAWDatasim.pkg b/RAW/libRAWDatasim.pkg index aa751c972d2..5bcfdd58e85 100644 --- a/RAW/libRAWDatasim.pkg +++ b/RAW/libRAWDatasim.pkg @@ -1,6 +1,6 @@ #-*- Mode: Makefile -*- -SRCS:= AliBitPacking.cxx AliAltroBuffer.cxx +SRCS:= AliBitPacking.cxx AliAltroBuffer.cxx AliAltroBufferV3.cxx HDRS:= $(SRCS:.cxx=.h) @@ -16,7 +16,7 @@ ifdef DATE_ROOT EINCLUDE+= ${DATE_COMMON_DEFS} endif -EXPORT:= AliAltroBuffer.h AliBitPacking.h +EXPORT:= AliAltroBuffer.h AliAltroBufferV3.h AliBitPacking.h ifeq (win32gcc,$(ALICE_TARGET)) PACKSOFLAGS:= $(SOFLAGS) -L$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET) \ -- 2.43.0