5 Contact: Chiara.Zampolli@bo.infn.it
6 Link: www.bo.infn.it/~zampolli
9 Number of events needed: 10000
10 Input Files: TOF<nrun>.raw, where <nrun> is the run number
11 Output Files: TOFoutPulserLDC_<LDCid>.root, where <LDCid> is the id of the LDC which is read (2 characters field, e.g. TOFoutPulserLDC_03.root),to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT (for the time being)
25 #include <AliTOFRawStream.h>
26 #include <AliRawReaderDate.h>
27 #include <AliRawReader.h>
28 #include <AliTOFGeometry.h>
30 #include <AliTOFHitData.h>
31 #include <AliTOFHitDataBuffer.h>
32 #include <AliTOFDecoder.h>
33 #include <AliTOFNoiseConfigHandler.h>
43 #include "TPluginManager.h"
44 #include "TSAXParser.h"
47 Arguments: list of DATE raw data files
49 int main(int argc, char **argv) {
51 /* magic line from Rene */
52 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
58 AliTOFGeometry * geom = new AliTOFGeometry();
60 static const Int_t size = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
61 TH1F::AddDirectory(0);
62 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", size,-0.5,size-0.5);
63 for (Int_t ibin =1;ibin<=size;ibin++)
64 htofNoise->SetBinContent(ibin,-1);
71 /* log start of process */
72 printf("TOF DA started\n");
74 /* check that we got some arguments = list of files */
76 printf("Wrong number of arguments\n");
80 /* retrieve config file */
81 int getConfigFile = daqDA_DB_getFile("TOFNoiseConfig.xml","TOFNoiseConfig.xml");
82 if (getConfigFile != 0){
83 printf("Failed to retrieve config file from DB! returning...\n");
87 AliTOFNoiseConfigHandler* tofHandler = new AliTOFNoiseConfigHandler();
88 TSAXParser *parser = new TSAXParser();
89 parser->ConnectToHandler("AliTOFNoiseConfigHandler", tofHandler);
90 if (parser->ParseFile("./TOFNoiseConfig.xml") != 0) {
91 printf("Failed parsing config file! retunring... \n");
95 Int_t debugFlag = tofHandler->GetDebugFlag();
96 printf("the debug flag is %i\n",debugFlag);
98 /* init some counters */
99 int nevents_physics=0;
102 Int_t nPDBEntriesToT = 0;
103 Int_t nDBEntriesToT = 0;
104 AliTOFHitData *HitData = 0;
107 for (Int_t i=0;i<5;i++) Volume[i]=-1;
108 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream();
109 AliTOFDecoder * decoderTOF = new AliTOFDecoder();
110 AliTOFHitDataBuffer *DataBuffer[AliDAQ::NumberOfDdls("TOF")];
111 AliTOFHitDataBuffer *PackedDataBuffer[AliDAQ::NumberOfDdls("TOF")];
112 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++) {
113 DataBuffer[i]=new AliTOFHitDataBuffer();
114 PackedDataBuffer[i]=new AliTOFHitDataBuffer();
116 Int_t currentEquipment;
120 Int_t nDBEntries = 0;
121 Int_t nPDBEntries = 0;
123 struct eventHeaderStruct *event;
124 eventTypeType eventT;
126 /* read the data files */
128 for (n=1;n<argc;n++) {
130 status=monitorSetDataSource( argv[n] );
132 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
139 rawStreamTOF->Clear();
140 currentEquipment = 0;
152 status=monitorGetEventDynamic((void **)&event);
153 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
155 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
159 /* retry if got no event */
163 /* use event - here, just write event id to result file */
164 eventT=event->eventType;
166 if (eventT==PHYSICS_EVENT) {
167 //printf ("event %i \n", nevents_physics);
169 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
170 rawStreamTOF->SetRawReader(rawReader);
172 while (rawReader->ReadHeader()) {
173 ldcId = rawReader->GetLDCId();
174 //debugging printings
175 if (debugFlag && ldcId!=ldcIdOLD) {
177 printf ("ldcId = %i \n",ldcId);
180 //memory leak prevention (actually data should be always 0x0 here)
181 if (data != 0x0) delete [] data;
183 //get equipment infos
184 currentEquipment = rawReader->GetEquipmentId();
185 currentDDL = rawReader->GetDDLID();
186 const AliRawDataHeader *currentCDH = (AliRawDataHeader*)rawReader->GetDataHeader();
192 //Int_t * array = new Int_t[nchDDL];
194 for (Int_t ii=0; ii<nchDDL; ii++) array[ii] = 0;
195 decoderTOF->GetArrayDDL(array, currentDDL);
197 for (Int_t i=0;i<nchDDL;i++)
198 if (htofNoise->GetBinContent(array[i]+1)<0) htofNoise->SetBinContent(array[i]+1,0);
200 //debugging printings
201 //if (debugFlag) printf(" Equipment = %i, and DDL = %i \n", currentEquipment,currentDDL);
202 const Int_t kDataSize = rawReader->GetDataSize();
203 const Int_t kDataWords = kDataSize / 4;
204 data = new UChar_t[kDataSize];
205 decoderTOF->SetDataBuffer(DataBuffer[currentDDL]);
206 decoderTOF->SetPackedDataBuffer(PackedDataBuffer[currentDDL]);
208 if (!rawReader->ReadNext(data, kDataSize)) {
209 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLdataReading);
210 printf("Error while reading DDL data. Go to next equipment \n");
215 if (decoderTOF->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
216 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLDecoder,Form("DDL # = %d",currentDDL));
217 printf("Error while decoding DDL # %d: decoder returned with errors \n", currentDDL);
220 nDBEntries = DataBuffer[currentDDL]->GetEntries();
221 nPDBEntries = PackedDataBuffer[currentDDL]->GetEntries();
222 nPDBEntriesToT+=nPDBEntries;
223 nDBEntriesToT+=nDBEntries;
225 DataBuffer[currentDDL]->Reset();
227 /* read data buffer hits */
228 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
229 HitData = PackedDataBuffer[currentDDL]->GetHit(iHit);
230 /* add volume information */
231 HitData->SetDDLID(currentDDL);
232 for (Int_t i=0;i<5;i++) Volume[i]=-1;
233 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
238 Volume[4]==-1) continue;
241 Volume[3] = Volume[4];
243 Int_t index = geom->GetIndex(Volume);
244 // to check array indexes
246 Bool_t found =kFALSE;
247 for (Int_t j=0;j<nchDDL;j++){
248 if (index==array[j]) {
253 printf ("index = %6d, found = %6d\n",index, (Int_t)found);
255 //printf ("index = %6d \n",index);
256 htofNoise->Fill(index); //channel index start from 0, bin index from 1
257 //debugging printings
258 //if (debugFlag) printf("sector %2d, plate %1d, strip %2d, padz %1d, padx %2d \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]); // too verbose
262 PackedDataBuffer[currentDDL]->Reset();
268 //debugging printings
270 // printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT); // too verbose
271 // printf(" Hit Buffer Entries = %i \n",nDBEntriesToT); // too verbose
289 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
290 delete DataBuffer[i];
291 delete PackedDataBuffer[i];
300 Int_t noisyChannels = 0;
301 Int_t checkedChannels = 0;
302 Float_t time = nevents_physics; // acquisition time in number of events
303 //debugging printings
304 if (debugFlag) printf(" Noise run lasted %f \n",time);
305 for (Int_t ibin =1;ibin<=size;ibin++){
306 Float_t cont = htofNoise->GetBinContent(ibin);
309 //debugging printings
310 if (debugFlag && cont) printf(" content = %f \n", cont);
311 htofNoise->SetBinContent(ibin,cont/time);
312 //debugging printings
313 if (debugFlag && cont) printf(" scaled content = %f \n", cont/time);
314 if (cont != 0) noisyChannels++;
320 printf("Number of checked channels = %i\n",checkedChannels);
321 printf("Number of noisy channels (before applying threshold) = %i\n",noisyChannels);
324 //write the Run level file
326 sprintf(filename,"TOFoutNoiseLDC_%02i.root",ldcId);
327 TFile * fileRun = new TFile (filename,"RECREATE");
332 printf("Run #%s, received %d physics events out of %d\n",
333 getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
337 /* store the result file on FES */
338 status=daqDA_FES_storeFile(filename,"NOISE");