Circular dependency
[u/mrichter/AliRoot.git] / STEER / AliCTPRawData.cxx
CommitLineData
867ef916 1/**************************************************************************
2 * Copyright(c) 1998-2003, 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////////////////////////////////////////////////////////////
17//This class contains the methods to create raw data //
18//for CTP (trigger). The CTP data format is taken as //
19//described in the Trigger TDR - pages 134 and 135. //
20////////////////////////////////////////////////////////////
21
22#include <TObject.h>
23#include <TString.h>
24#include <Riostream.h>
25#include "AliCTPRawData.h"
26#include "AliRunLoader.h"
27#include "AliCentralTrigger.h"
867ef916 28#include "AliRawDataHeader.h"
29#include "AliLog.h"
362c9d61 30#include "AliDAQ.h"
08f92f14 31#include "AliFstream.h"
867ef916 32
33ClassImp(AliCTPRawData)
34////////////////////////////////////////////////////////////////////////////////////////
35
36//______________________________________________________________________________
37AliCTPRawData::AliCTPRawData()
38{
39 // Default constructor
40}
41
42//______________________________________________________________________________
43AliCTPRawData::AliCTPRawData(const AliCTPRawData &source):
44 TObject(source)
45{
46 // Copy Constructor
47}
48
49//______________________________________________________________________________
50AliCTPRawData& AliCTPRawData::operator=(const AliCTPRawData &source)
51{
52 // Assigment operator
53 if(this==&source) return *this;
54 ((TObject *)this)->operator=(source);
55
56 return *this;
57}
58
59//______________________________________________________________________________
60void AliCTPRawData::RawData()
61{
62 // This method writes the CTP (trigger)
63 // raw data in a DDL file
64 ULong64_t l2class = 0;
1fa33d12 65 UChar_t l2cluster = 0;
867ef916 66 AliInfo("Storing the CTP DDL raw data...");
67 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
68 if (runloader) {
69 if (!runloader->LoadTrigger()) {
70 AliCentralTrigger *aCTP = runloader->GetTrigger();
71 if (AliDebugLevel() > 0)
72 aCTP->Dump();
73 // First get the trigger mask
74 l2class = aCTP->GetClassMask();
75 // Then get the detector cluster to be read out
1fa33d12 76 l2cluster = aCTP->GetClusterMask();
867ef916 77 }
78 else
79 AliWarning("No trigger can be loaded! Putting empty trigger class into the CTP raw data !");
80 }
81 else
82 AliError("No run loader is available! Putting empty trigger class into the CTP raw data !");
83
84 AliDebug(1,Form("CTP trigger mask = 0x%llx",l2class));
85 AliDebug(1,Form("CTP detector cluster = 0x%x",l2cluster));
86
87 char fileName[15];
362c9d61 88 strcpy(fileName,AliDAQ::DdlFileName("TRG",0));
867ef916 89 AliInfo(Form("Storing CTP raw data in %s",fileName));
08f92f14 90 AliFstream* outfile; // logical name of the output file
91 outfile = new AliFstream(fileName);
867ef916 92
93 AliRawDataHeader header;
94 // Write a dummy header
08f92f14 95 UInt_t dataHeaderPosition=outfile->Tellp();
96 outfile->WriteBuffer((char*)(&header),sizeof(header));
867ef916 97
98 // Writing CTP raw data here
99 // The format is taken as in
100 // pages 134 and 135 of the
101 // Trigger TDR
102
103 // If not 0, from where??
104 UInt_t bunchCross = 0;
105 UInt_t orbitId = 0;
106 Bool_t esr = 0; // Enable Segmented Readout flag
107
108 // First 3 words here - Bunch-crossing and orbit numbers
109 UInt_t word = 0;
110 word |= 0 << 13; // BlockID = 0 in case of CTP readout
f95e7d66 111 word |= bunchCross & 0xFFF;
867ef916 112 AliDebug(1,Form("CTP word1 = 0x%x",word));
08f92f14 113 outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
867ef916 114
115 word = 0;
116 word |= 0 << 13; // BlockID = 0 in case of CTP readout
f95e7d66 117 word |= (orbitId >> 12) & 0xFFF;
867ef916 118 AliDebug(1,Form("CTP word2 = 0x%x",word));
08f92f14 119 outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
867ef916 120 word = 0;
121 word |= 0 << 13; // BlockID = 0 in case of CTP readout
f95e7d66 122 word |= orbitId & 0xFFF;
867ef916 123 AliDebug(1,Form("CTP word3 = 0x%x",word));
08f92f14 124 outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
867ef916 125
126 // Now the 4th word
127 word = 0;
128 word |= 0 << 13; // BlockID = 0 in case of CTP readout
129 word |= ((UInt_t)esr) << 10;
130 word |= 0 << 8; // L2SwC - physics trigger
f95e7d66 131 word |= (l2cluster & 0x3F) << 2; // L2Cluster
80ebf966 132 word |= (UInt_t)((l2class >> 48) & 0x3);
867ef916 133 AliDebug(1,Form("CTP word4 = 0x%x",word));
08f92f14 134 outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
867ef916 135
136 // Then the last 4 words with the trigger classes
137 word = 0;
138 word |= 0 << 13; // BlockID = 0 in case of CTP readout
80ebf966 139 word |= (UInt_t)((l2class >> 36) & 0xFFF);
867ef916 140 AliDebug(1,Form("CTP word5 = 0x%x",word));
08f92f14 141 outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
867ef916 142 word = 0;
143 word |= 0 << 13; // BlockID = 0 in case of CTP readout
80ebf966 144 word |= (UInt_t)((l2class >> 24) & 0xFFF);
867ef916 145 AliDebug(1,Form("CTP word6 = 0x%x",word));
08f92f14 146 outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
867ef916 147 word = 0;
148 word |= 0 << 13; // BlockID = 0 in case of CTP readout
80ebf966 149 word |= (UInt_t)((l2class >> 12) & 0xFFF);
867ef916 150 AliDebug(1,Form("CTP word7 = 0x%x",word));
08f92f14 151 outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
867ef916 152 word = 0;
153 word |= 0 << 13; // BlockID = 0 in case of CTP readout
80ebf966 154 word |= (UInt_t)(l2class & 0xFFF);
867ef916 155 AliDebug(1,Form("CTP word8 = 0x%x",word));
08f92f14 156 outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
867ef916 157
158 // Write the real data header
08f92f14 159 UInt_t currentFilePosition=outfile->Tellp();
160 outfile->Seekp(dataHeaderPosition);
867ef916 161 header.fSize=currentFilePosition-dataHeaderPosition;
162 header.SetAttribute(0); // valid data
163 header.SetTriggerClass(l2class);
08f92f14 164 outfile->WriteBuffer((char*)(&header),sizeof(header));
165 delete outfile;
867ef916 166
167 return;
168}