X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TPC%2FAliTPCAltroEmulator.cxx;h=35e3ce1fd2ae2d420ea98391b21f5f99f43526f3;hb=ada6b882ca8069d28a8b4bb7be23007ad3ff615d;hp=7b920304bbae3d8d8b54aa2f4db089b439a9251d;hpb=9389f9a4e9dab8831aa7f447656724d700262577;p=u%2Fmrichter%2FAliRoot.git diff --git a/TPC/AliTPCAltroEmulator.cxx b/TPC/AliTPCAltroEmulator.cxx index 7b920304bba..35e3ce1fd2a 100644 --- a/TPC/AliTPCAltroEmulator.cxx +++ b/TPC/AliTPCAltroEmulator.cxx @@ -17,6 +17,7 @@ * \verbinclude Altro/Altro.C.log * */ + ///////////////////////////////////////////////////////////////////////////////////////////////////// // Class for emulation of the ALTRO chip (Altro digital Chain) in C++ // // Author: Roland Bramm // @@ -27,7 +28,19 @@ // Stefan Rossegger, 8th february 2008 // ///////////////////////////////////////////////////////////////////////////////////////////////////// -#include "AliTPCAltroEmulator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + /** @brief Consturctor of Altro Class * @@ -36,13 +49,13 @@ * Altro Processed Data in the Channel Pointer.\n * * @param timebins an int sets the length of the input Data (Channel) - * @param Channel an short* Pointer to a 1d short Array with the input Data + * @param Channel an short* Pointer to a 1d Short_tArray with the input Data */ ClassImp(AliTPCAltroEmulator) -AliTPCAltroEmulator::AliTPCAltroEmulator(int timebins, short* Channel) : +AliTPCAltroEmulator::AliTPCAltroEmulator(Int_t timebins, short* Channel) : TNamed(), ftimebins(timebins), // fChannelIn(Channel), @@ -57,11 +70,12 @@ AliTPCAltroEmulator::AliTPCAltroEmulator(int timebins, short* Channel) : fConfiguredAltro(0), // ConfiguredAltro fConfiguredBSL1(0), // ConfiguredBSL1 fConfiguredTCF(0), // ConfiguredTCF + fConfiguredTCFraw(0), // ConfiguredTCF fConfiguredBSL2(0), // ConfiguredBSL2 fConfiguredZSU(0), // ConfiguredZSU fBSL1mode(0), // BSL1mode fBSL1ValuePeDestal(0), // BSL1ValuePeDestal - fBSL1PedestalMem(0), // BSL1PedestalMem + fBSL1PedestalMem(0), // BSL1PedestalMem fBSL1polarity(0), // BSL1polarity fTCFK1(0), // K1 @@ -88,131 +102,73 @@ AliTPCAltroEmulator::AliTPCAltroEmulator(int timebins, short* Channel) : fZSUMinSamplesaboveThreshold(0), // ZSUMinSamplesaboveThreshold fZSUPresamples(0), // ZSUPresamples - fZSUPostsamples(0) // ZSUPostsamples - -{ + fZSUPostsamples(0), // ZSUPostsamples + + fReader(0), // for Altro Emulation on Raw Reader + fDecoder(0), + fRunNumber(0), + fDDLFolderName("./"), + fOutputDateFileName("./tmpRaw.date"), + fOutputRootFileName("./tmpRaw.root"), + fIsRandom(kTRUE), + fChannels(0), + fCDHs(0), + fADCs(0), + fTrailers(0), + fRawData(0) { // // Constructor of Altro Class // - /* - ftimebins = timebins; - - fChannelShort = Channel; - - fOnBSL1 = 0; - fOnTCF = 0; - fOnBSL2 = 0; - fOnClip = 0; - fOnZSU = 0; - - fConfiguredAltro = 0; - fConfiguredBSL1 = 0; - fConfiguredTCF = 0; - fConfiguredBSL2 = 0; - fConfiguredZSU = 0; - */ -} + fADCkeep = new Short_t[1024]; -AliTPCAltroEmulator::AliTPCAltroEmulator(const AliTPCAltroEmulator &altro): - TNamed(), - ftimebins(altro.ftimebins), -// fChannelIn(Channel), - fChannelShort(altro.fChannelShort), - fADCkeep(0), - fOnBSL1(0), - fOnTCF(0), - fOnBSL2(0), - fOnClip(0), - fOnZSU(0), - - fConfiguredAltro(0), // ConfiguredAltro - fConfiguredBSL1(0), // ConfiguredBSL1 - fConfiguredTCF(0), // ConfiguredTCF - fConfiguredBSL2(0), // ConfiguredBSL2 - fConfiguredZSU(0), // ConfiguredZSU - fBSL1mode(0), // BSL1mode - fBSL1ValuePeDestal(0), // BSL1ValuePeDestal - fBSL1PedestalMem(0), // BSL1PedestalMem - fBSL1polarity(0), // BSL1polarity - - fTCFK1(0), // K1 - fTCFK2(0), // K2 - fTCFK3(0), // K3 - fTCFL1(0), // L1 - fTCFL2(0), // L2 - fTCFL3(0), // L3 - - fTCFK1Int(0), // K1Int - fTCFK2Int(0), // K2Int - fTCFK3Int(0), // K3Int - fTCFL1Int(0), // L1Int - fTCFL2Int(0), // L2Int - fTCFL3Int(0), // L3Int - - fBSL2HighThreshold(0), // BSL2HighThreshold - fBSL2LowThreshold(0), // BSL2LowThreshold - fBSL2Offset(0), // BSL2Offset - fBSL2Presamples(0), // BSL2Presamples(0), - fBSL2Postsamples(0), // BSL2Postsamples - - fZSUThreshold(0), // ZSUThreshold - - fZSUMinSamplesaboveThreshold(0), // ZSUMinSamplesaboveThreshold - fZSUPresamples(0), // ZSUPresamples - fZSUPostsamples(0) // ZSUPostsamples - -{ - // - // copy constructor of Altro Class - // + fTCFK1IntROC[0]=0; fTCFK1IntROC[1]=0; // dummy defaults + fTCFK2IntROC[0]=0; fTCFK2IntROC[1]=0; // dummy defaults + fTCFK3IntROC[0]=0; fTCFK3IntROC[1]=0; // dummy defaults + fTCFL1IntROC[0]=0; fTCFL1IntROC[1]=0; // dummy defaults + fTCFL2IntROC[0]=0; fTCFL2IntROC[1]=0; // dummy defaults + fTCFL3IntROC[0]=0; fTCFL3IntROC[1]=0; // dummy defaults } + /** @brief Destructor of Altro Class * * Destructor of Altro Class\n */ -AliTPCAltroEmulator::~AliTPCAltroEmulator(){ +AliTPCAltroEmulator::~AliTPCAltroEmulator() { // // Destructor of Altro Class // - if(fConfiguredZSU == 1) - delete fADCkeep; -} - -//_____________________________________________________________________________ -AliTPCAltroEmulator& AliTPCAltroEmulator::operator = (const AliTPCAltroEmulator &source) -{ - // - // AliTPCAltroEmulator assignment operator - // - - if (&source == this) return *this; - new (this) AliTPCAltroEmulator(source); + // if(fConfiguredZSU == 1) + delete[] fADCkeep; - return *this; + delete[] fChannels; + delete[] fCDHs ; + delete[] fADCs ; + delete[] fTrailers; + delete[] fRawData ; + delete fDecoder ; } - /** @brief Configures which modules of the Altro should be on. * * Configures which modules of the Altro should be on. Each of the modules * which are configured to be on, have to be configured later before running * the emulation!\n * - * @param ONBaselineCorrection1 an int Switch (0,1) to turn on the Base Line Correction 1 (BSL1) Module - * @param ONTailcancellation an int Switch (0,1) to turn on the Tail Cancellation Filter (TCF) Module - * @param ONBaselineCorrection2 an int Switch (0,1) to turn on the Moving Average Filter (BSL2) Module - * @param ONClipping an int Switch (0,1) to turn on the Clipping Module. This is not possible in the real Altro, there it is always on. - * @param ONZerosuppression an int Switch (0,1) to turn on the Zero Suppression (ZSU) Module - * @param ONDataFormatting an int Switch (0,1) to turn on the Data Formatting on (not implemented) + * @param ONBaselineCorrection1 an Int_t Switch (0,1) to turn on the Base Line Correction 1 (BSL1) Module + * @param ONTailcancellation an Int_t Switch (0,1) to turn on the Tail Cancellation Filter (TCF) Module + * @param ONBaselineCorrection2 an Int_t Switch (0,1) to turn on the Moving Average Filter (BSL2) Module + * @param ONClipping an Int_t Switch (0,1) to turn on the Clipping Module. This is not possible in the real Altro, there it is always on. + * @param ONZerosuppression an Int_t Switch (0,1) to turn on the Zero Suppression (ZSU) Module + * @param ONDataFormatting an Int_t Switch (0,1) to turn on the Data Formatting on (not implemented) */ -void AliTPCAltroEmulator::ConfigAltro(int ONBaselineCorrection1, int ONTailcancellation, int ONBaselineCorrection2, int ONClipping, int ONZerosuppression, int ONDataFormatting){ +void AliTPCAltroEmulator::ConfigAltro(Int_t ONBaselineCorrection1, Int_t ONTailcancellation, Int_t ONBaselineCorrection2, Int_t ONClipping, Int_t ONZerosuppression, Int_t ONDataFormatting){ // // Configures which modules of the Altro should be on // @@ -221,8 +177,10 @@ void AliTPCAltroEmulator::ConfigAltro(int ONBaselineCorrection1, int ONTailcance fOnBSL2 = InRange(ONBaselineCorrection2,0,1,"AliTPCAltroEmulator::ConfigAltro","ONBaselineCorrection2"); fOnClip = InRange(ONClipping,0,1,"AliTPCAltroEmulator::ConfigAltro","ONClipping"); fOnZSU = InRange(ONZerosuppression,0,1,"AliTPCAltroEmulator::ConfigAltro","ONZerosuppression"); - ONDataFormatting; // does not have to be checked fConfiguredAltro = 1; + if (!fConfiguredAltro) { //dummy code to avoid warning + printf("%d\n",ONDataFormatting); // does not have to be checked + } } /** @brief Configures the Base Line Correction 1 (BSL1) Module @@ -233,16 +191,16 @@ void AliTPCAltroEmulator::ConfigAltro(int ONBaselineCorrection1, int ONTailcance * All configurable values are "Range checked" and if out of the Range set to the nearest extreme. * So the Emulation will work, but the result is maybe not the expected one. * - * @param mode an int sets the mode of the Baseline Correction. See the Altro manual for a description - * @param ValuePeDestal an int this is the baseline of the Channel. - * @param PedestalMem an *int Pointer to a 1d short Array with the pedestal memory Data - * @param polarity an int Switch (0,1) for the polarity + * @param mode an Int_t sets the mode of the Baseline Correction. See the Altro manual for a description + * @param ValuePeDestal an Int_t this is the baseline of the Channel. + * @param PedestalMem an *Int_t Pointer to a 1d Short_t Array with the pedestal memory Data + * @param polarity an Int_t Switch (0,1) for the polarity */ -void AliTPCAltroEmulator::ConfigBaselineCorrection1(int mode, int ValuePeDestal, int *PedestalMem, int polarity){ +void AliTPCAltroEmulator::ConfigBaselineCorrection1(Int_t mode, Int_t ValuePeDestal, Int_t *PedestalMem, Int_t polarity){ // // Configures the Base Line Correction 1 (BSL1) Module // - fBSL1mode = InRange(mode,0,10,"AliTPCAltroEmulator::ConfigBaselineCorrection1","mode"); + fBSL1mode = InRange(mode,0,16,"AliTPCAltroEmulator::ConfigBaselineCorrection1","mode"); fBSL1ValuePeDestal = InRange(ValuePeDestal,0,1023,"AliTPCAltroEmulator::BaselineCorrection1","ValuePeDestal"); fBSL1PedestalMem = PedestalMem; fBSL1polarity = InRange(polarity,0,1,"AliTPCAltroEmulator::BaselineCorrection1","polarity"); @@ -253,24 +211,24 @@ void AliTPCAltroEmulator::ConfigBaselineCorrection1(int mode, int ValuePeDestal, * * Configures the Tail Cancellation Filter (TCF) Module. You have to set the coefficients in the * Integer version.\n - * To convert from int to float use (int)*(pow(2,-16)-1) - * To convert from float to int usw (float)*(pow(2,16)-1) + * To convert from Int_t to Float_t use (int)*(pow(2,-16)-1) + * To convert from Float_t to Int_t usw (Float_t)*(pow(2,16)-1) * All configurable values are "Range checked" and if out of the Range set to the nearest extreme. * So the Emulation will work, but the result is maybe not the expected one. * - * @param K1 an int sets the K1 coeeficient of the TCF - * @param K2 an int sets the K2 coeeficient of the TCF - * @param K3 an int sets the K3 coeeficient of the TCF - * @param L1 an int sets the L1 coeeficient of the TCF - * @param L2 an int sets the L2 coeeficient of the TCF - * @param L3 an int sets the L3 coeeficient of the TCF + * @param K1 an Int_t sets the K1 coeeficient of the TCF + * @param K2 an Int_t sets the K2 coeeficient of the TCF + * @param K3 an Int_t sets the K3 coeeficient of the TCF + * @param L1 an Int_t sets the L1 coeeficient of the TCF + * @param L2 an Int_t sets the L2 coeeficient of the TCF + * @param L3 an Int_t sets the L3 coeeficient of the TCF */ -void AliTPCAltroEmulator::ConfigTailCancellationFilter(int K1, int K2, int K3, int L1, int L2, int L3){ +void AliTPCAltroEmulator::ConfigTailCancellationFilter(Int_t K1, Int_t K2, Int_t K3, Int_t L1, Int_t L2, Int_t L3){ // // Configures the Tail Cancellation Filter (TCF) Module // - // conf from int to fp: (int)*(pow(2,-16)-1) - // backway: (float)*(pow(2,16)-1) + // conf from Int_t to fp: (int)*(pow(2,-16)-1) + // backway: (Float_t)*(pow(2,16)-1) fTCFK1Int = InRange(K1,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K1"); fTCFK2Int = InRange(K2,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K2"); fTCFK3Int = InRange(K3,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K3"); @@ -280,6 +238,33 @@ void AliTPCAltroEmulator::ConfigTailCancellationFilter(int K1, int K2, int K3, i fTCFL3Int = InRange(L3,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L3"); fConfiguredTCF = 1; } +void AliTPCAltroEmulator::ConfigTailCancellationFilterForRAWfiles(const Int_t *K1, const Int_t *K2, const Int_t *K3, + const Int_t *L1, const Int_t *L2, const Int_t *L3){ + // + // Configures the Tail Cancellation Filter (TCF) Module - Different settings for IROC and OROC + // + // conf from Int_t to fp: (int)*(pow(2,-16)-1) + // backway: (Float_t)*(pow(2,16)-1) + + // IROC + fTCFK1IntROC[0] = InRange(K1[0],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K1[0]"); + fTCFK2IntROC[0] = InRange(K2[0],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K2[0]"); + fTCFK3IntROC[0] = InRange(K3[0],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K3[0]"); + fTCFL1IntROC[0] = InRange(L1[0],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L1[0]"); + fTCFL2IntROC[0] = InRange(L2[0],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L2[0]"); + fTCFL3IntROC[0] = InRange(L3[0],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L3[0]"); + // OROC + fTCFK1IntROC[1] = InRange(K1[1],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K1[1]"); + fTCFK2IntROC[1] = InRange(K2[1],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K2[1]"); + fTCFK3IntROC[1] = InRange(K3[1],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K3[1]"); + fTCFL1IntROC[1] = InRange(L1[1],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L1[1]"); + fTCFL2IntROC[1] = InRange(L2[1],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L2[1]"); + fTCFL3IntROC[1] = InRange(L3[1],0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L3[1]"); + + + fConfiguredTCFraw = 1; +} + /** @brief Configures the Moving Average Filter (BSL2) Module * @@ -287,13 +272,13 @@ void AliTPCAltroEmulator::ConfigTailCancellationFilter(int K1, int K2, int K3, i * All configurable values are "Range checked" and if out of the Range set to the nearest extreme. * So the Emulation will work, but the result is maybe not the expected one. * - * @param HighThreshold an int sets the high Threshold - * @param LowThreshold an int sets the low Theshold - * @param Offset an int sets the the offset which is added to the Signal - * @param Presamples an int sets the number of pre samples excluded from the moving average caclulation - * @param Postsamples an int sets the number of post samples excluded from the moving average caclulation + * @param HighThreshold an Int_t sets the high Threshold + * @param LowThreshold an Int_t sets the low Theshold + * @param Offset an Int_t sets the the offset which is added to the Signal + * @param Presamples an Int_t sets the number of pre samples excluded from the moving average caclulation + * @param Postsamples an Int_t sets the number of post samples excluded from the moving average caclulation */ -void AliTPCAltroEmulator::ConfigBaselineCorrection2(int HighThreshold, int LowThreshold, int Offset, int Presamples, int Postsamples){ +void AliTPCAltroEmulator::ConfigBaselineCorrection2(Int_t HighThreshold, Int_t LowThreshold, Int_t Offset, Int_t Presamples, Int_t Postsamples){ // // Configures the Moving Average Filter (BSL2) Module // @@ -311,12 +296,12 @@ void AliTPCAltroEmulator::ConfigBaselineCorrection2(int HighThreshold, int LowTh * All configurable values are "Range checked" and if out of the Range set to the nearest extreme. * So the Emulation will work, but the result is maybe not the expected one. * - * @param Threshold an int sets the Threshold - * @param MinSamplesaboveThreshold an int sets the minimum number of samples which have to be greater than the threshold - * @param Presamples an int sets the number of pre samples which are kept - * @param Postsamples an int sets the number of post samples which are kept + * @param Threshold an Int_t sets the Threshold + * @param MinSamplesaboveThreshold an Int_t sets the minimum number of samples which have to be greater than the threshold + * @param Presamples an Int_t sets the number of pre samples which are kept + * @param Postsamples an Int_t sets the number of post samples which are kept */ -void AliTPCAltroEmulator::ConfigZerosuppression(int Threshold, int MinSamplesaboveThreshold, int Presamples, int Postsamples){ +void AliTPCAltroEmulator::ConfigZerosuppression(Int_t Threshold, Int_t MinSamplesaboveThreshold, Int_t Presamples, Int_t Postsamples){ // // Configures the Zero Suppression Module (ZSU) // @@ -324,9 +309,8 @@ void AliTPCAltroEmulator::ConfigZerosuppression(int Threshold, int MinSamplesabo fZSUMinSamplesaboveThreshold = InRange(MinSamplesaboveThreshold,1,3,"AliTPCAltroEmulator::BaselineCorrection1","MinSamplesaboveThreshold"); fZSUPresamples = InRange(Presamples,0,3,"AliTPCAltroEmulator::BaselineCorrection1","Presamples"); fZSUPostsamples = InRange(Postsamples,0,7,"AliTPCAltroEmulator::BaselineCorrection1","Postsamples"); - fADCkeep = (short *)calloc(sizeof(short),ftimebins); - for(int i = 0; i < ftimebins; i++){ + for(Int_t i = 0; i < ftimebins; i++){ fADCkeep[i] = 0; } fConfiguredZSU = 1; @@ -360,12 +344,12 @@ void AliTPCAltroEmulator::PrintParameters(){ } if(fConfiguredTCF == 1){ cout << "Parameters set in the TCF (TailCancellation Filter) Module:" << endl << endl; - cout << "K1 (int|float) : " << fTCFK1Int << " | " << fTCFK1Int/(float)((1<<16)-1) << endl; - cout << "K2 (int|float) : " << fTCFK2Int << " | " << fTCFK2Int/(float)((1<<16)-1) << endl; - cout << "K3 (int|float) : " << fTCFK3Int << " | " << fTCFK3Int/(float)((1<<16)-1) << endl; - cout << "L1 (int|float) : " << fTCFL1Int << " | " << fTCFL1Int/(float)((1<<16)-1) << endl; - cout << "L2 (int|float) : " << fTCFL2Int << " | " << fTCFL2Int/(float)((1<<16)-1) << endl; - cout << "L3 (int|float) : " << fTCFL3Int << " | " << fTCFL3Int/(float)((1<<16)-1) << endl << endl << endl; + cout << "K1 (int|Float_t) : " << fTCFK1Int << " | " << fTCFK1Int/(Float_t)((1<<16)-1) << endl; + cout << "K2 (int|Float_t) : " << fTCFK2Int << " | " << fTCFK2Int/(Float_t)((1<<16)-1) << endl; + cout << "K3 (int|Float_t) : " << fTCFK3Int << " | " << fTCFK3Int/(Float_t)((1<<16)-1) << endl; + cout << "L1 (int|Float_t) : " << fTCFL1Int << " | " << fTCFL1Int/(Float_t)((1<<16)-1) << endl; + cout << "L2 (int|Float_t) : " << fTCFL2Int << " | " << fTCFL2Int/(Float_t)((1<<16)-1) << endl; + cout << "L3 (int|Float_t) : " << fTCFL3Int << " | " << fTCFL3Int/(Float_t)((1<<16)-1) << endl << endl << endl; }else{ cout << "TCF (TailCancellation Filter) Module not configured!" << endl << endl << endl; } @@ -390,16 +374,33 @@ void AliTPCAltroEmulator::PrintParameters(){ } } + +void AliTPCAltroEmulator::SetChannelData(Int_t timebins, Short_t* channelData) { + // + // Set channel data, for example a new channel + // + + ftimebins = timebins; + fChannelShort = channelData; + +} + + /** @brief Runs the emulation of all configured Modules. * * Runs the emulation of all configured Modules. This changes then the content of the * input Array */ -void AliTPCAltroEmulator::RunEmulation(){ +void AliTPCAltroEmulator::RunEmulation(Int_t roc){ // // Runs the emulation of all configured Modules. // + if (!fChannelShort) { + printf("ERROR cant run Altro Emulation: Channel input not set.\nUse for example: SetChannelData(Int_t timebins, Short_t* Channel)\n"); + return; + } + //cout << "AliTPCAltroEmulator::RunEmulation | start" << endl; if(fConfiguredAltro == 0){ cout << "ERROR cant run Altro Emulation because not configured" << endl; @@ -418,11 +419,28 @@ void AliTPCAltroEmulator::RunEmulation(){ //cout << "AliTPCAltroEmulator::RunEmulation | start TCF on: " << fOnTCF << " configures: " << fConfiguredTCF << endl; if(fOnTCF == 1){ - if(fConfiguredTCF == 1){ - TailCancellationFilterFixedPoint(fTCFK1Int, fTCFK2Int, fTCFK3Int, fTCFL1Int, fTCFL2Int, fTCFL3Int); - }else{ - cout << "ERROR cant run Tail Cancellation Filter because not configured" << endl; - return; + if (roc==-1) { // use one set of TCF params + if(fConfiguredTCF == 1){ + TailCancellationFilterFixedPoint(fTCFK1Int, fTCFK2Int, fTCFK3Int, fTCFL1Int, fTCFL2Int, fTCFL3Int); + }else{ + cout << "ERROR cant run Tail Cancellation Filter because not configured" << endl; + return; + } + } else { // use different TCF params for IROC and OROC + if(fConfiguredTCFraw == 1){ + if (roc==0) //IROC + TailCancellationFilterFixedPoint(fTCFK1IntROC[0], fTCFK2IntROC[0], fTCFK3IntROC[0], + fTCFL1IntROC[0], fTCFL2IntROC[0], fTCFL3IntROC[0]); + else if (roc==1) // OROC + TailCancellationFilterFixedPoint(fTCFK1IntROC[1], fTCFK2IntROC[1], fTCFK3IntROC[1], + fTCFL1IntROC[1], fTCFL2IntROC[1], fTCFL3IntROC[1]); + else + cout << "ERROR cant run Tail Cancellation Filter because TCF settings for ROC not found" << endl; + } else { + cout << "ERROR cant run Tail Cancellation Filter because not configured (for RAW data files!)" << endl; + return; + } + } } @@ -448,71 +466,89 @@ void AliTPCAltroEmulator::RunEmulation(){ return; } } + + + } -void AliTPCAltroEmulator::BaselineCorrection1(int mode, int ValuePeDestal, int *PedestalMem, int polarity){ +void AliTPCAltroEmulator::BaselineCorrection1(Int_t mode, Int_t ValuePeDestal, Int_t *PedestalMem, Int_t polarity){ // // BaselineCorrection1 // //VPD == 0 !! - int fixedPeDestal = 0; - + Int_t fixedPeDestal = 0; + + // take first and last bins to calculate a mean pedestal value + Int_t window = 3; + Int_t meanPeDestal = 0; + if (mode == kDINxMPD && ftimebins>=6) { + for(Int_t i = 0; i < window; i++) { + meanPeDestal += fChannelShort[i]; + meanPeDestal += fChannelShort[ftimebins-1-i]; + } + meanPeDestal /= (window*2); + } + if(polarity ==1){ - for(int i = 0; i < ftimebins; i++){ + for(Int_t i = 0; i < ftimebins; i++){ fChannelShort[i] = 1023 - fChannelShort[i]; } } switch(mode) { case kDINxFPD: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = fChannelShort[i] - fixedPeDestal; break; case kDINxFT: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = fChannelShort[i] - PedestalMem[i]; break; case kDINxFDIN: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = fChannelShort[i] - PedestalMem[ fChannelShort[i] ]; break; case kDINxFDINxVPD: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = fChannelShort[i] - PedestalMem[ fChannelShort[i] - ValuePeDestal]; break; case kDINxVPDxFPD: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = fChannelShort[i] - ValuePeDestal - fixedPeDestal; break; case kDINxVPDxFT: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = fChannelShort[i] - ValuePeDestal - PedestalMem[i]; break; case kDINxVPDxFDIN: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = fChannelShort[i] - ValuePeDestal - PedestalMem[ fChannelShort[i] ]; break; case kDINxVPDxFDINxVPD: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = fChannelShort[i] - ValuePeDestal - PedestalMem[ fChannelShort[i] - ValuePeDestal ]; break; case kFDINxFPD: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = PedestalMem[ fChannelShort[i] ] - fixedPeDestal; break; case kFDINxVPDxFPD: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = PedestalMem[ fChannelShort[i] - ValuePeDestal ] - fixedPeDestal; break; case kFTxFPD: - for(int i = 0; i < ftimebins; i++) + for(Int_t i = 0; i < ftimebins; i++) fChannelShort[i] = PedestalMem[i] - fixedPeDestal; break; + case kDINxMPD: + for(Int_t i = 0; i < ftimebins; i++) + fChannelShort[i] = fChannelShort[i] - meanPeDestal; + break; } } -int AliTPCAltroEmulator::Multiply36(int P, int N){ +Int_t AliTPCAltroEmulator::Multiply36(Int_t P, Int_t N){ // // multiply function to emulate the 36 bit fixed point multiplication of the Altro. // @@ -528,41 +564,44 @@ int AliTPCAltroEmulator::Multiply36(int P, int N){ } return retval; } -long long AliTPCAltroEmulator::Mask(long long in, int left, int right){ - // +long long AliTPCAltroEmulator::Mask(long long in, Int_t left, Int_t right){ // + // mask // long long retval; long long pattern; long long length = abs(left - right)+1; - pattern = ((1<>right)&pattern; return retval; } -void AliTPCAltroEmulator::TailCancellationFilterFixedPoint(int K1, int K2, int K3, int L1, int L2, int L3){ +void AliTPCAltroEmulator::TailCancellationFilterFixedPoint(Int_t K1, Int_t K2, Int_t K3, Int_t L1, Int_t L2, Int_t L3){ // // TailCancellationFilterFixedPoint // - int c1n = 0, c2n = 0, c3n = 0; - int c1o = 0, c2o = 0, c3o = 0; - int d1 = 0, d2 = 0; - int dout = 0; - int din = 0; - int bit = 0; - for(int i = 0; i < ftimebins; i++){ + Int_t c1n = 0, c2n = 0, c3n = 0; + Int_t c1o = 0, c2o = 0, c3o = 0; + Int_t d1 = 0, d2 = 0; + Int_t dout = 0; + Int_t din = 0; + Int_t bit = 0; + + // printf("%5d %5d %5d %5d %5d %5d\n",K1,K2,K3,L1,L2,L3); + + for(Int_t i = 0; i < ftimebins; i++){ din = fChannelShort[i]; din = (din<<2); @@ -599,7 +638,7 @@ void AliTPCAltroEmulator::TailCancellationFilterFixedPoint(int K1, int K2, int K } } -void AliTPCAltroEmulator::BaselineCorrection2RTL(int HighThreshold, int LowThreshold, int Offset, int Presamples, int Postsamples){ +void AliTPCAltroEmulator::BaselineCorrection2RTL(Int_t HighThreshold, Int_t LowThreshold, Int_t Offset, Int_t Presamples, Int_t Postsamples){ // // BaselineCorrection2RTL // @@ -607,44 +646,44 @@ void AliTPCAltroEmulator::BaselineCorrection2RTL(int HighThreshold, int LowThres //cout << "Altro::BaselineCorrection2RTL | HighThreshold: " << HighThreshold << " LowThreshold: " << LowThreshold << " Offset: " << Offset << " Presamples: " << Presamples << " Postsamples: " << Postsamples << endl; //more or less direct "translation" of the hdl code. //Input signals - int din; - int dout; - int edges[6]; // = Postsamples*4 + Presamples; - int offset = Offset; - int thrlo = LowThreshold;//called thr_mau[19] ... - int thrhi = HighThreshold; + Int_t din; + Int_t dout; + Int_t edges[6]; // = Postsamples*4 + Presamples; + Int_t offset = Offset; + Int_t thrlo = LowThreshold;//called thr_mau[19] ... + Int_t thrhi = HighThreshold; // Variables - int fOld[4]; //flag pipe - int fNew[4]; //flag pipe - int dOld[4]; //data pipe - int dNew[4]; //data pipe - int dxOld; - int dxNew; - int pstscnt; // Counter for Postsamples - int zOld[9]; // Filter stages - int zNew[9]; // Filter stages - int zxOld; //Accumulator stage - int zxNew; //Accumulator stage - int valcntOld; //Valid sample counter - int valcntNew = 0; //Valid sample counter + Int_t fOld[4]; //flag pipe + Int_t fNew[4]; //flag pipe + Int_t dOld[4]; //data pipe + Int_t dNew[4]; //data pipe + Int_t dxOld; + Int_t dxNew; + Int_t pstscnt; // Counter for Postsamples + Int_t zOld[9]; // Filter stages + Int_t zNew[9]; // Filter stages + Int_t zxOld; //Accumulator stage + Int_t zxNew; //Accumulator stage + Int_t valcntOld; //Valid sample counter + Int_t valcntNew = 0; //Valid sample counter - int valid; //Valid flag - int fx; //postsample flag - //int s07; // differentiator result - int s8; // Acc + Diff result - int flag; - //int bsth; //baseline threshold - //int din_p; //Data input strictly positive - int bsl; - //int dx_bsls; // dx -bsl - //int dx_clip; // dxbsl clipped - //int bsl_of = 0; + Int_t valid; //Valid flag + Int_t fx; //postsample flag + //Int_t s07; // differentiator result + Int_t s8; // Acc + Diff result + Int_t flag; + //Int_t bsth; //baseline threshold + //Int_t din_p; //Data input strictly positive + Int_t bsl; + //Int_t dx_bsls; // dx -bsl + //Int_t dx_clip; // dxbsl clipped + //Int_t bsl_of = 0; //initialisation - for(int i = 0; i < 9 ; i++) + for(Int_t i = 0; i < 9 ; i++) zOld[i] = 0; - for(int i = 0; i < 4 ; i++){ + for(Int_t i = 0; i < 4 ; i++){ fOld[i] = 0; dOld[i] = 0; } @@ -653,20 +692,20 @@ void AliTPCAltroEmulator::BaselineCorrection2RTL(int HighThreshold, int LowThres zxOld = 0; valcntOld = 0; valid = 0; - for(int i = 0; i < 2 ; i++){ + for(Int_t i = 0; i < 2 ; i++){ edges[i] = (Presamples&(1<>i; } - for(int i = 0; i < 4 ; i++){ + for(Int_t i = 0; i < 4 ; i++){ edges[(3-i)+2] = (Postsamples&(1<>i; } /*cout << "edges :"; - for(int i = 0; i < 6 ; i++) + for(Int_t i = 0; i < 6 ; i++) cout << edges[i] << ":"; cout << " Presamples: " << Presamples << " Postsamples: " << Postsamples << endl;*/ //Loop //cout << "AliTPCAltroEmulator::BaselineCorrection2_RTL | starting Loop" << endl; - for(int timebin = -12; timebin < ftimebins+10; timebin++){ + for(Int_t timebin = -12; timebin < ftimebins+10; timebin++){ //cout << "AliTPCAltroEmulator::BaselineCorrection2_RTL | in Loop timebin: " << timebin << endl; din = GetElement(fChannelShort,timebin); @@ -711,7 +750,7 @@ void AliTPCAltroEmulator::BaselineCorrection2RTL(int HighThreshold, int LowThres fNew[0] = 0; dxNew = dOld[0]; - for(int i = 0; i < 3; i++) + for(Int_t i = 0; i < 3; i++) dNew[i] = dOld[i+1]; dNew[3] = din; @@ -725,12 +764,12 @@ void AliTPCAltroEmulator::BaselineCorrection2RTL(int HighThreshold, int LowThres valcntNew = ++valcntOld; zxNew = s8; - for(int i = 0; i < 8; i++) + for(Int_t i = 0; i < 8; i++) zNew[i] = zOld[i+1]; zNew[8] = dOld[0]; }else{ zxNew = zxOld; - for(int i = 0; i < 9; i++) + for(Int_t i = 0; i < 9; i++) zNew[i] = zOld[i]; } dout = dxOld - (bsl - offset); @@ -739,10 +778,10 @@ void AliTPCAltroEmulator::BaselineCorrection2RTL(int HighThreshold, int LowThres SetElement(fChannelShort,timebin-5,(short)dout); //sim clockschange - for(int i = 0; i < 9 ; i++) + for(Int_t i = 0; i < 9 ; i++) zOld[i] = zNew[i]; zxOld = zxNew; - for(int i = 0; i < 4 ; i++){ + for(Int_t i = 0; i < 4 ; i++){ fOld[i] = fNew[i]; dOld[i] = dNew[i]; } @@ -755,30 +794,32 @@ void AliTPCAltroEmulator::Clipping(){ // // implement if no BC2 clipping has to run // - for(int i = 0; i < ftimebins; i++){ - if(fChannelShort[i] < 0) - fChannelShort[i] = 0; + for(Int_t i = 0; i < ftimebins; i++){ + if(fChannelShort[i] < -1) + fChannelShort[i] = -1; } } -void AliTPCAltroEmulator::Zerosuppression(int Threshold, int MinSamplesaboveThreshold, int Presamples, int Postsamples){ +void AliTPCAltroEmulator::Zerosuppression(Int_t Threshold, Int_t MinSamplesaboveThreshold, Int_t Presamples, Int_t Postsamples){ // // add again altro feature // //TODO: Implement "Altro zsu merging" - //int Postsamplecounter = 0; - //int setPostsample = 0; - for(int i = 0; i < ftimebins; i++){ - if(fChannelShort[i] >= Threshold){ + //Int_t Postsamplecounter = 0; + //Int_t setPostsample = 0; + + for(Int_t i = 0; i < ftimebins; i++){ + if(fChannelShort[i] >= Threshold) fADCkeep[i] = 1; - } + else + fADCkeep[i] = 0; } + + Int_t startofclustersequence = -1; + Int_t endofClustersInSequence = -1; - int startofclustersequence = -1; - int endofClustersInSequence = -1; - - for(int i = 0; i < ftimebins; i++){ + for(Int_t i = 0; i < ftimebins; i++){ if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i-1) == 0) ){ startofclustersequence = i; } @@ -789,7 +830,7 @@ void AliTPCAltroEmulator::Zerosuppression(int Threshold, int MinSamplesaboveThre if( (startofclustersequence != -1) && (endofClustersInSequence != -1) ){ //cout << " found! " << (endofClustersInSequence - startofclustersequence + 1); if ( (endofClustersInSequence - startofclustersequence + 1) < MinSamplesaboveThreshold ){ - for(int j = startofclustersequence; j <= endofClustersInSequence ; j++){ + for(Int_t j = startofclustersequence; j <= endofClustersInSequence ; j++){ fADCkeep[j] = 0; } } @@ -799,28 +840,28 @@ void AliTPCAltroEmulator::Zerosuppression(int Threshold, int MinSamplesaboveThre //cout << endl; } - /*for(int i = 0; i < ftimebins; i++){ + /*for(Int_t i = 0; i < ftimebins; i++){ if( (GetElement(fADCkeep,i-1) == 1) && (GetElement(fADCkeep,i) == 0) && (GetElement(fADCkeep,i+1) == 1) ){ SetElement(fADCkeep,i,1); } }*/ - for(int i = 0; i < ftimebins; i++){ + for(Int_t i = 0; i < ftimebins; i++){ if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i-1) == 0) ){ - for(int j = i-Presamples ; j <= i; j++){ + for(Int_t j = i-Presamples ; j <= i; j++){ SetElement(fADCkeep,j,1); } } } - for(int i = ftimebins; i >= 0; i--){ + for(Int_t i = ftimebins; i >= 0; i--){ if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i+1) == 0) ){ - for(int j = i ; j <= i+Postsamples; j++){ + for(Int_t j = i ; j <= i+Postsamples; j++){ SetElement(fADCkeep,j,1); } } } /*cout << " Postsamplecounter: " << Postsamplecounter; - for(int j = i+1 ; j <= i+Postsamples; j++){ + for(Int_t j = i+1 ; j <= i+Postsamples; j++){ SetElement(fADCkeep,j,1); i+=Postsamples; } @@ -829,12 +870,20 @@ void AliTPCAltroEmulator::Zerosuppression(int Threshold, int MinSamplesaboveThre cout << i << " ADCK: " << GetElement(fADCkeep,i); cout << " Postsam: " << Postsamplecounter << " ADCK: " << GetElement(fADCkeep,i);*/ - for(int i = 0; i < ftimebins; i++){ + for(Int_t i = 0; i < ftimebins; i++){ if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i+1) == 0) && ( (GetElement(fADCkeep,i+3) == 1) || (GetElement(fADCkeep,i+2) == 1) ) ){ SetElement(fADCkeep,i+1,1); SetElement(fADCkeep,i+2,1); } } + + for(Int_t i = 0; i < ftimebins; i++){ + if( !GetKeepChannel(i) ) { + SetElement(fChannelShort,i,-1); // set non relevant data to -1 + } + } + + } /** @brief formats the data like the ALTRO. Result is a 64 bit array @@ -856,20 +905,20 @@ void AliTPCAltroEmulator::DataFormater(){ * * calculates the compression out of the bitmask with the set adc values * - * @return \c float consisting of the compression factor + * @return \c Float_t consisting of the compression factor */ -float AliTPCAltroEmulator::CalculateCompression(){ +Float_t AliTPCAltroEmulator::CalculateCompression() { // // calculates the compression out of the bitmask // // calculation is based on altro 10 bit words .. - int sample = 0; - int cluster = 0; - int data = 0; - float retval = 0.0; + Int_t sample = 0; + Int_t cluster = 0; + Int_t data = 0; + Float_t retval = 0.0; - for(int i = 0; i < ftimebins; i++){ + for(Int_t i = 0; i < ftimebins; i++){ if(fADCkeep[i] == 1){ sample++; } @@ -880,16 +929,16 @@ float AliTPCAltroEmulator::CalculateCompression(){ data = sample + cluster*2; data = data + data%4 + 4; if(data >0){ - retval = ftimebins / (float)data;//num of timebins is equal to max number of samples + retval = ftimebins / (Float_t)data;//num of timebins is equal to max number of samples }else{ retval = 1.0; } return retval; } -short AliTPCAltroEmulator::GetElement(short* Array,int index){ - // +Short_t AliTPCAltroEmulator::GetElement(short* Array,Int_t index){ // + // GetElement of array // if (index < 0) return 0; @@ -899,9 +948,9 @@ short AliTPCAltroEmulator::GetElement(short* Array,int index){ return Array[index]; } -void AliTPCAltroEmulator::SetElement(short* Array,int index,short value){ - // +void AliTPCAltroEmulator::SetElement(short* Array,Int_t index,Short_t value){ // + // SetElement of array // if (index < 0) return; @@ -911,31 +960,31 @@ void AliTPCAltroEmulator::SetElement(short* Array,int index,short value){ Array[index] = value; } -int AliTPCAltroEmulator::InBand(int ADC,int bsl, int LowThreshold, int HighThreshold){ - // +Int_t AliTPCAltroEmulator::InBand(Int_t ADC,Int_t bsl, Int_t LowThreshold, Int_t HighThreshold){ // + // check if it's within the band of search // - int fLow = bsl - LowThreshold; - int fHigh = bsl + HighThreshold; + Int_t fLow = bsl - LowThreshold; + Int_t fHigh = bsl + HighThreshold; if( (ADC <= fHigh) && (ADC >= fLow) ) return 1; else return 0; } -int AliTPCAltroEmulator::InRange(int parameter,int Low,int High,char *Module,char *ParameterName){ - // +Int_t AliTPCAltroEmulator::InRange(Int_t parameter,Int_t Low,Int_t High,const char *Module,const char *ParameterName){ // + // checks it it's within the range // char out[255]; - int retval; + Int_t retval; if(parameter > High){ - sprintf(out,"Error | %s | Parameter %s is to big, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,High); + snprintf(out,255,"Error | %s | Parameter %s is to big, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,High); cout << out << endl; retval = High; }else if(parameter < Low){ - sprintf(out,"Error | %s | Parameter %s is to small, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,Low); + snprintf(out,255,"Error | %s | Parameter %s is to small, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,Low); cout << out << endl; retval = Low; }else{ @@ -944,16 +993,422 @@ int AliTPCAltroEmulator::InRange(int parameter,int Low,int High,char *Module,cha return retval; } -short AliTPCAltroEmulator::GetShortChannel(int i){ - // +Short_t AliTPCAltroEmulator::GetShortChannel(Int_t i){ // + // GetElement of channel // return GetElement(fChannelShort,i); } -short AliTPCAltroEmulator::GetKeepChannel(int i){ - // +Short_t AliTPCAltroEmulator::GetKeepChannel(Int_t i){ // + // GetElement of Keep Channel // return GetElement(fADCkeep,i); } + +Bool_t AliTPCAltroEmulator::WriteEvent(Int_t ievent) { + // + // Write event to the DDL data folders + // + + for (Int_t ddlID=0;ddlID<216;++ddlID) { + Bool_t *channelsDDL=fChannels+ddlID*4096 ; + Short_t *adcsDDL =fADCs +ddlID*4096*1024; + UInt_t *cdhDDL =fCDHs +ddlID*8 ; + UInt_t *trailerDDL =fTrailers+ddlID*9 ; + + FILE *file=fopen(Form("%s/raw%d/TPC_%03d.ddl", + fDDLFolderName.Data(),ievent,768+ddlID), + "wb"); + if (!file) { + return kFALSE; + } else { + Int_t i32; + // write CDH (first word to be altered later) + for (i32=0;i32<8;++i32) + fRawData[i32]=cdhDDL[i32]; + + // process payload + for (Int_t hwaddr=0;hwaddr<4096;++hwaddr) if (channelsDDL[hwaddr]) { + Short_t *adcsChannel=adcsDDL+hwaddr*1024; + // merge custers + // TODO: acqusition window + for (Int_t it=0;it<1024-3;++it) { + if (adcsChannel[it]>=0&&adcsChannel[it+3]>=0) { + if (adcsChannel[it+1]<0) { + // printf("merge"); + adcsChannel[it+1]=0; + } + if (adcsChannel[it+2]<0) { + // printf("merge"); + adcsChannel[it+2]=0; + } + } + } + Int_t i10=3; + Int_t icw=0; + Int_t its=1; + Int_t cw =0; + Int_t ts =0; + for (Int_t it=1023;it>=0;--it) { + Short_t w10=adcsChannel[it]; + if (w10>=0) { + if (cw<0) { + icw=i10++; + its=i10++; + cw =0 ; + ts=it ; + } + fRawData[i32+i10/3]|=w10<<(10*(2-i10%3)); + ++i10; + ++cw; + } + else { + if (cw>=0) { + cw+=2; + fRawData[i32+icw/3]|=cw <<(10*(2-icw%3)); + fRawData[i32+its/3]|=ts <<(10*(2-its%3)); + cw=-1; + } + } + } + fRawData[i32]=0x1<<30|(i10-3)<<16|hwaddr; + i32+=(i10+2)/3; + + // clean up + for (Int_t i=0;i<1024;++i) adcsChannel[i]=-1; + channelsDDL[hwaddr]=kFALSE; + } + + // write RCU trailer + fRawData[i32]=0x2<<30|(i32-8);i32++; + for (Int_t i=0;i<8;++i) + fRawData[i32++]=trailerDDL[i]; + + // write first word of CDH + fRawData[0]=i32*4; + + Int_t nwritten=fwrite(fRawData,sizeof(UInt_t),i32,file); + fclose(file); + + if (nwritten!=i32) return kFALSE; + + // clean up + do {fRawData[--i32]=0;} while (i32>0); + } + } + return kTRUE; +} + +Bool_t AliTPCAltroEmulator::GDC2DDLs(AliRawVEvent *gdc,Int_t ievent) { + // + // Converte GDC data to DDL format + // + for(Int_t iLDC=0;iLDCGetNSubEvents();++iLDC) { + AliRawVEvent *ldc=gdc->GetSubEvent(iLDC); + for(Int_t iEq=0;iEqGetNEquipments();++iEq) { + AliRawVEquipment *eq=ldc->GetEquipment(iEq); + AliRawEquipmentHeader *eqHeader=eq->GetEquipmentHeader(); + Int_t eqSize=eqHeader->GetEquipmentSize(); + if (eqSize>0) { + Int_t ddlIndex; + Int_t detId=AliDAQ::DetectorIDFromDdlID(eqHeader->GetId(),ddlIndex); + Int_t nwritten=0; + FILE *ddlFile=fopen(Form("%s/raw%d/%s", + fDDLFolderName.Data(), + ievent, + AliDAQ::DdlFileName(detId,ddlIndex)), + "wb"); + AliRawData *rawData=eq->GetRawData(); + if (ddlFile) { + nwritten=fwrite(rawData->GetBuffer(),1,rawData->GetSize(),ddlFile); + fclose(ddlFile); + } + if (nwrittenGetSize()) return kFALSE; + } + } + } + return kTRUE; +} + + +Bool_t AliTPCAltroEmulator::ConvertRawFilesToDate(Int_t nevents) { + // + // Convertes Raw files to Date format + // + + // from $ALICE_ROOT/STEER/AliSimulation.cxx + + char command[100]; + FILE *pipe; + + printf(" RAW to DATE CONVERSION: Run Number %d\n",fRunNumber); + + if (fRunNumber>0) + pipe=gSystem->OpenPipe(Form("dateStream -c -s -D -o %s -C -# %d -run %d", + fOutputDateFileName.Data(), + nevents, + fRunNumber), + "w"); + else + pipe=gSystem->OpenPipe(Form("dateStream -c -s -D -o %s -C -# %d", + fOutputDateFileName.Data(), + nevents), + "w"); + if (!pipe) { + fprintf(stderr,"error: cannot execute command: %s",command); + return kFALSE; + } + + for (Int_t ievent=0;ieventClosePipe(pipe); + return (result == 0); +} + +void AliTPCAltroEmulator::InitBuffers() { + // + // Initialization of the Buffers + // + if (!fChannels) fChannels=new Bool_t [216*4096 ]; + if (!fCDHs ) fCDHs =new UInt_t [216*8 ]; + if (!fADCs ) fADCs =new Short_t[216*4096*1024]; + if (!fTrailers) fTrailers=new UInt_t [216*9 ]; + if (!fRawData ) fRawData =new UInt_t [ 1*4096*1024]; // be save... + + for (Int_t i=0;i<216*4096 ;++i) fChannels[i]=kFALSE; + // no need to init CDHs + for (Int_t i=0;i<216*4096*1024;++i) fADCs [i]=-1 ; + // no need to init trailers + for (Int_t i=0;i< 1*4096*1024;++i) fRawData [i]= 0 ; +} + +Bool_t AliTPCAltroEmulator::ConvertDateToRoot() { + // + // convert a DATE file to a root file with the program "alimdc" + // + + // from $ALICE_ROOT/STEER/AliSimulation.cxx + + printf(" DATE to ROOT CONVERSION: Run Number %d\n",fRunNumber); + + // ALIMDC setup + const Int_t kDBSize = 2000000000; //2GB + const Int_t kTagDBSize = 1000000000; + const Bool_t kFilter = kFALSE; + const Int_t kCompression = 1; + + // AliInfo(Form("converting DATE file %s to root file %s", + // dateFileName, rootFileName)); + + const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" }; + const char* tagDBFS = "/tmp/mdc1/tags"; + + // User defined file system locations + if (gSystem->Getenv("ALIMDC_RAWDB1")) + rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1"); + if (gSystem->Getenv("ALIMDC_RAWDB2")) + rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2"); + if (gSystem->Getenv("ALIMDC_TAGDB")) + tagDBFS = gSystem->Getenv("ALIMDC_TAGDB"); + + gSystem->Exec(Form("rm -rf %s",rawDBFS[0])); + gSystem->Exec(Form("rm -rf %s",rawDBFS[1])); + gSystem->Exec(Form("rm -rf %s",tagDBFS)); + + gSystem->Exec(Form("mkdir %s",rawDBFS[0])); + gSystem->Exec(Form("mkdir %s",rawDBFS[1])); + gSystem->Exec(Form("mkdir %s",tagDBFS)); + + Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s", + kDBSize, kTagDBSize, kFilter, kCompression, fOutputDateFileName.Data())); + gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0],fOutputRootFileName.Data())); + + gSystem->Exec(Form("rm -rf %s",rawDBFS[0])); + gSystem->Exec(Form("rm -rf %s",rawDBFS[1])); + gSystem->Exec(Form("rm -rf %s",tagDBFS)); + + return (result == 0); +} + +void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plotFlag) { + // + // Run the Altro Emulation on a full Raw data set (AliRawReader) + // plus write the outcome in a RAW data format + // + + if (!reader) { + printf("ERROR cant run Altro Emulation: AliRawReader is zero. No RAW data file.\n"); + return; + } + + fReader=reader; + if (fDecoder) delete fDecoder; + fDecoder=new AliTPCRawStreamV3(reader); + + InitBuffers(); + + Int_t chanCount=0; + TH1F hisO("DINO","DINO",1024,0,1024); + TH1F his("DIN","DIN",1024,0,1024); + his.GetYaxis()->SetRangeUser(-20,90); + Short_t *data = new Short_t[1024]; + TCanvas *c1 =0; + if (plotFlag) { + c1 = new TCanvas("c1","c1"); + c1->SetGridx(); c1->SetGridy(); + } + + // event loop + Int_t ievent=0; + while (fReader->NextEvent()) { + + if (fReader->GetRunNumber()>0) fRunNumber=fReader->GetRunNumber(); + gSystem->Exec(Form("mkdir -p %s/raw%d/",fDDLFolderName.Data(),ievent)); + GDC2DDLs(const_cast(fReader->GetEvent()),ievent); + + Int_t ddlC =0; + while (fDecoder->NextDDL()) { + Int_t ddlID=fDecoder->GetDDLNumber(); + printf("ddl: %d (%d/216)\n",ddlID,++ddlC); + + Bool_t *channelsDDL=fChannels+ddlID*4096 ; + Short_t *adcsDDL =fADCs +ddlID*4096*1024 ; + UInt_t *cdhDDL =fCDHs +ddlID*8 ; + UInt_t *trailerDDL =fTrailers+ddlID*9 ; + + // CDH + for (Int_t i=0;i<8;++i) + // just to show how ugly it is... + cdhDDL[i]=reinterpret_cast(const_cast(fReader->GetDataHeader()))[i]; + + // PAYLOAD + while (fDecoder->NextChannel()) { + Int_t hwaddr=fDecoder->GetHWAddress(); + Int_t sector=fDecoder->GetSector(); + Int_t row=fDecoder->GetRow(); + Int_t pad=fDecoder->GetPad(); + Short_t *adcsChannel=adcsDDL+hwaddr*1024; + while (fDecoder->NextBunch()) { + UInt_t ts =fDecoder->GetStartTimeBin(); + Int_t cw =fDecoder->GetBunchLength() ; + const UShort_t *signals=fDecoder->GetSignals() ; + for (Int_t ci=0;ci0x3ff) + adcsChannel[t]=0x3ff; + } + } + } + + // search start of aquisition + Int_t t0 = 0; while (adcsChannel[t0]==-1) t0++; + // search end of aquisition + Int_t tE = 1024; while (adcsChannel[tE]==-1) tE--; + + // channel is complete - Perform Altro Emulation + if (plotFlag!=0 && !(chanCount%plotFlag) ) { + for (Int_t t=0; t<1024; t++) { + his.SetBinContent(t+1,adcsChannel[t]); + } + his.SetTitle(Form("sig_sec%d_row%d_pad%d",sector,row,pad)); + his.SetStats(0); his.GetXaxis()->SetTitle("timebin"); + his.DrawCopy(); + } + + // FEED THE ALTRO EMULATOR WITH CLEAN SIGNAL (no aquisition-window ghosts) + Int_t timebins = tE-t0+1; + for (Int_t t=t0;t<(t0+timebins);t++) + data[t-t0]=adcsChannel[t]; + SetChannelData(timebins,data); + + Int_t roc = (sector%36)>=18; // 0 for IROC, 1 for OROC + RunEmulation(roc); + for (Int_t t=t0;t<(t0+timebins);t++) + adcsChannel[t]=data[t-t0]; + + if (plotFlag!=0 && !(chanCount%plotFlag) ) { + for (Int_t t=0; t<1024; t++) + hisO.SetBinContent(t+1,adcsChannel[t]); + hisO.SetStats(0); hisO.SetLineColor(2); + hisO.DrawCopy("same"); + + c1->SaveAs(Form("%s/sig_sec%02d_row%02d_pad%03d_%s_%d%d%d%d%d.png", + fDDLFolderName.Data(),sector,row,pad, + fOutputRootFileName.Data(), + fOnBSL1,fOnTCF,fOnBSL2,fOnClip,fOnZSU)); + + his.Reset(); + hisO.Reset(); + + } + chanCount++; + + } + + // TRAILER + UChar_t *rcuTrailer; + fDecoder->GetRCUTrailerData(rcuTrailer); + for (Int_t i=0;i<= /* (!) */ fDecoder->GetRCUTrailerSize()/4;++i) + trailerDDL[i]=reinterpret_cast(rcuTrailer)[i]; // again: UGLY! + + } + + if (ddlC>0) WriteEvent(ievent++); + } + + delete[] data; // free space + + // convert to date and back + ConvertRawFilesToDate(ievent); + ConvertDateToRoot(); + + +}