]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDBaseDA.cxx
Changes to make DAs publish information to AMORE.
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.cxx
CommitLineData
a0180e76 1/**************************************************************************
2 * Copyright(c) 2004, 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/** @file AliFMDBaseDA.cxx
17 @author Hans Hjersing Dalsgaard <canute@nbi.dk>
18 @date Wed Mar 26 11:30:45 2008
19 @brief Base class for detector algorithms.
20*/
21//
e9c06036 22// This is the implementation of the (virtual) base class for the FMD
23// detector algorithms(DA). It implements the creation of the relevant
24// containers and handles the loop over the raw data. The derived
25// classes can control the parameters and action to be taken making
26// this the base class for the Pedestal, Gain and Physics DA.
a0180e76 27//
28
29#include "AliFMDBaseDA.h"
30#include "iostream"
a0180e76 31#include "AliFMDRawReader.h"
1656783c 32#include "AliFMDCalibSampleRate.h"
bd727bee 33#include "AliFMDCalibStripRange.h"
a0180e76 34#include "AliLog.h"
3effc6e7 35#include "AliRawEventHeaderBase.h"
6cf6e7a0 36#include <TDatime.h>
37#include <TSystem.h>
2a082c96 38#include <TH2F.h>
3effc6e7 39
a0180e76 40//_____________________________________________________________________
41ClassImp(AliFMDBaseDA)
e9c06036 42#if 0
43; // Do not delete - to let Emacs for mat the code
44#endif
45
46//_____________________________________________________________________
47const char*
48AliFMDBaseDA::GetStripPath(UShort_t det,
49 Char_t ring,
50 UShort_t sec,
51 UShort_t str,
52 Bool_t full) const
53{
6cf6e7a0 54 // Get the strip path
55 //
56 // Parameters
57 // det Detector number
58 // ring Ring identifier
59 // sec Sector number
60 // str Strip number
61 // full If true, return full path
62 //
63 // Return
64 // The path
e9c06036 65 return Form("%s%sFMD%d%c[%02d,%03d]",
66 (full ? GetSectorPath(det, ring, sec, full) : ""),
67 (full ? "/" : ""), det, ring, sec, str);
68}
69//_____________________________________________________________________
70const char*
71AliFMDBaseDA::GetSectorPath(UShort_t det,
72 Char_t ring,
73 UShort_t sec,
74 Bool_t full) const
75{
6cf6e7a0 76 // Get the strip path
77 //
78 // Parameters
79 // det Detector number
80 // ring Ring identifier
81 // sec Sector number
82 // str Strip number
83 // full If true, return full path
84 //
85 // Return
86 // The path
e9c06036 87 return Form("%s%sFMD%d%c[%02d]",
88 (full ? GetRingPath(det, ring, full) : ""),
89 (full ? "/" : ""), det, ring, sec);
90}
91//_____________________________________________________________________
92const char*
93AliFMDBaseDA::GetRingPath(UShort_t det,
94 Char_t ring,
95 Bool_t full) const
96{
6cf6e7a0 97 // Get the strip path
98 //
99 // Parameters
100 // det Detector number
101 // ring Ring identifier
102 // sec Sector number
103 // str Strip number
104 // full If true, return full path
105 //
106 // Return
107 // The path
e9c06036 108 return Form("%s%sFMD%d%c",
109 (full ? GetDetectorPath(det, full) : ""),
110 (full ? "/" : ""), det, ring);
111}
112//_____________________________________________________________________
113const char*
114AliFMDBaseDA::GetDetectorPath(UShort_t det,
115 Bool_t full) const
116{
6cf6e7a0 117 // Get the strip path
118 //
119 // Parameters
120 // det Detector number
121 // ring Ring identifier
122 // sec Sector number
123 // str Strip number
124 // full If true, return full path
125 //
126 // Return
127 // The path
e9c06036 128 return Form("%s%sFMD%d",
129 (full ? fDiagnosticsFilename.Data() : ""),
130 (full ? ":/" : ""), det);
131}
a0180e76 132
133//_____________________________________________________________________
427e8f99 134AliFMDBaseDA::AliFMDBaseDA() :
135 TNamed(),
a0180e76 136 fDiagnosticsFilename("diagnosticsHistograms.root"),
137 fOutputFile(),
ce5a8b1a 138 fConditionsFile(),
a0180e76 139 fSaveHistograms(kFALSE),
2a082c96 140 fMakeSummaries(kFALSE),
a0180e76 141 fDetectorArray(),
29b7c86f 142 fPulseSize(10),
143 fPulseLength(10),
144 fRequiredEvents(0),
6cf6e7a0 145 fCurrentEvent(0),
2a082c96 146 fRunno(0),
147 fSummaries(0)
c5569fbc 148{
149 //Constructor
6cf6e7a0 150 fSeenDetectors[0] = fSeenDetectors[1] = fSeenDetectors[2] = kFALSE;
a0180e76 151 fDetectorArray.SetOwner();
6cf6e7a0 152 Rotate("conditions.csv", 3);
ce5a8b1a 153 fConditionsFile.open("conditions.csv");
a0180e76 154}
155//_____________________________________________________________________
156AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
157 TNamed(baseDA),
a7e41e8d 158 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
a0180e76 159 fOutputFile(),
ce5a8b1a 160 fConditionsFile(),
a0180e76 161 fSaveHistograms(baseDA.fSaveHistograms),
2a082c96 162 fMakeSummaries(baseDA.fMakeSummaries),
a0180e76 163 fDetectorArray(baseDA.fDetectorArray),
427e8f99 164 fPulseSize(baseDA.fPulseSize),
165 fPulseLength(baseDA.fPulseLength),
a0180e76 166 fRequiredEvents(baseDA.fRequiredEvents),
6cf6e7a0 167 fCurrentEvent(baseDA.fCurrentEvent),
2a082c96 168 fRunno(baseDA.fRunno),
169 fSummaries(0)
a0180e76 170{
c5569fbc 171 //Copy constructor
408bf2b4 172 fSeenDetectors[0] = baseDA.fSeenDetectors[0];
173 fSeenDetectors[1] = baseDA.fSeenDetectors[1];
174 fSeenDetectors[2] = baseDA.fSeenDetectors[2];
175
a0180e76 176 fDetectorArray.SetOwner();
177
178}
179
82d71828 180
a0180e76 181//_____________________________________________________________________
e9c06036 182AliFMDBaseDA::~AliFMDBaseDA()
183{
a0180e76 184 //destructor
a0180e76 185}
186
187//_____________________________________________________________________
e9c06036 188void AliFMDBaseDA::Run(AliRawReader* reader)
189{
c5569fbc 190 //Run the FMD DA
e9c06036 191 TFile* diagFile = 0;
192 if (fSaveHistograms)
193 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
a0180e76 194
427e8f99 195
3effc6e7 196
427e8f99 197
7bce699b 198
a0180e76 199 reader->Reset();
6cf6e7a0 200 fRunno = reader->GetRunNumber();
201
e9c06036 202 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
203 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
3effc6e7 204
c5569fbc 205 Bool_t sodread = kFALSE;
200d06f9 206
207 for(Int_t i=0;i<3;i++) {
208 reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
29b7c86f 209
200d06f9 210 UInt_t eventType = reader->GetType();
211 if(eventType == AliRawEventHeaderBase::kStartOfData ||
212 eventType == AliRawEventHeaderBase::kFormatError) {
213
214 WriteConditionsData(fmdReader);
215 Init();
c5569fbc 216 sodread = kTRUE;
200d06f9 217 break;
218 }
29b7c86f 219 }
200d06f9 220
7bce699b 221 InitContainer(diagFile);
222
c5569fbc 223 if(!sodread)
29b7c86f 224 AliWarning("No SOD event detected!");
3effc6e7 225
1656783c 226 int lastProgress = 0;
a0180e76 227
7bce699b 228
229
e9c06036 230 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
231 if(!reader->NextEvent()) continue;
3effc6e7 232 SetCurrentEvent(n);
e9c06036 233 digitArray->Clear();
234 fmdReader->ReadAdcs(digitArray);
7bce699b 235
e9c06036 236 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
237 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
408bf2b4 238 fSeenDetectors[digit->Detector()-1] = kTRUE;
e9c06036 239 FillChannels(digit);
a0180e76 240 }
e9c06036 241
7bce699b 242
e9c06036 243 FinishEvent();
7bce699b 244
e9c06036 245 int progress = int((n *100)/ GetRequiredEvents()) ;
246 if (progress <= lastProgress) continue;
247 lastProgress = progress;
248 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
7bce699b 249
e9c06036 250 }
7bce699b 251
a0180e76 252 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
253 WriteHeaderToFile();
254
255 for(UShort_t det=1;det<=3;det++) {
408bf2b4 256 if (!fSeenDetectors[det-1]) continue;
e9c06036 257 std::cout << "FMD" << det << std::endl;
c5569fbc 258 UShort_t firstRing = (det == 1 ? 1 : 0);
259 for (UShort_t ir = firstRing; ir < 2; ir++) {
a0180e76 260 Char_t ring = (ir == 0 ? 'O' : 'I');
261 UShort_t nsec = (ir == 0 ? 40 : 20);
262 UShort_t nstr = (ir == 0 ? 256 : 512);
2a082c96 263
264 if (fMakeSummaries) MakeSummary(det, ring);
265
e9c06036 266 std::cout << " Ring " << ring << ": " << std::flush;
a0180e76 267 for(UShort_t sec =0; sec < nsec; sec++) {
268 for(UShort_t strip = 0; strip < nstr; strip++) {
269 Analyse(det,ring,sec,strip);
a0180e76 270 }
e9c06036 271 std::cout << '.' << std::flush;
a0180e76 272 }
427e8f99 273 if(fSaveHistograms)
7bce699b 274 diagFile->Flush();
e9c06036 275 std::cout << "done" << std::endl;
a0180e76 276 }
277 }
7bce699b 278
a0180e76 279 if(fOutputFile.is_open()) {
a0180e76 280 fOutputFile.write("# EOF\n",6);
281 fOutputFile.close();
a0180e76 282 }
283
7bce699b 284 Terminate(diagFile);
285
a0180e76 286 if(fSaveHistograms ) {
f7f0b643 287
e9c06036 288 AliInfo("Closing diagnostics file - please wait ...");
289 // diagFile->Write();
ce5a8b1a 290 diagFile->Close();
e9c06036 291 AliInfo("done");
7bce699b 292
a0180e76 293 }
294}
295//_____________________________________________________________________
296
e9c06036 297void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
298{
c5569fbc 299 //Prepare container for diagnostics
a0180e76 300 TObjArray* detArray;
301 TObjArray* ringArray;
302 TObjArray* sectorArray;
303
e9c06036 304 TDirectory* savDir = gDirectory;
305
a0180e76 306 for(UShort_t det=1;det<=3;det++) {
307 detArray = new TObjArray();
308 detArray->SetOwner();
309 fDetectorArray.AddAtAndExpand(detArray,det);
e9c06036 310
311 TDirectory* detDir = 0;
312 if (diagFile) {
313 diagFile->cd();
314 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
315 }
316
a0180e76 317 UShort_t FirstRing = (det == 1 ? 1 : 0);
318 for (UShort_t ir = FirstRing; ir < 2; ir++) {
319 Char_t ring = (ir == 0 ? 'O' : 'I');
320 UShort_t nsec = (ir == 0 ? 40 : 20);
321 UShort_t nstr = (ir == 0 ? 256 : 512);
322 ringArray = new TObjArray();
323 ringArray->SetOwner();
324 detArray->AddAtAndExpand(ringArray,ir);
e9c06036 325
326
327 TDirectory* ringDir = 0;
328 if (detDir) {
329 detDir->cd();
330 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
331 }
332
333
a0180e76 334 for(UShort_t sec =0; sec < nsec; sec++) {
335 sectorArray = new TObjArray();
336 sectorArray->SetOwner();
337 ringArray->AddAtAndExpand(sectorArray,sec);
e9c06036 338
339
340 TDirectory* secDir = 0;
341 if (ringDir) {
342 ringDir->cd();
343 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
344 }
345
a0180e76 346 for(UShort_t strip = 0; strip < nstr; strip++) {
e9c06036 347 if (secDir) {
348 secDir->cd();
349 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
350 }
a0180e76 351 AddChannelContainer(sectorArray, det, ring, sec, strip);
352 }
353 }
354 }
355 }
e9c06036 356 savDir->cd();
a0180e76 357}
ce5a8b1a 358
359//_____________________________________________________________________
3effc6e7 360void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
e9c06036 361{
c5569fbc 362 //Write the conditions data to file
ce5a8b1a 363 AliFMDParameters* pars = AliFMDParameters::Instance();
364 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
6cf6e7a0 365 TDatime now;
366 fConditionsFile << "# This file created from run number " << fRunno
367 << " at " << now.AsString() << std::endl;
427e8f99 368
3effc6e7 369 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
370 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
427e8f99 371
408bf2b4 372 fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
373 fSeenDetectors);
bd727bee 374
408bf2b4 375 sampleRate->WriteToFile(fConditionsFile, fSeenDetectors);
376 stripRange->WriteToFile(fConditionsFile, fSeenDetectors);
bd727bee 377
378
427e8f99 379 // Zero Suppresion
380
381 // Strip Range
382
29b7c86f 383 fConditionsFile.write("# Gain Events \n",15);
bd727bee 384
29b7c86f 385 for(UShort_t det=1; det<=3;det++) {
408bf2b4 386 if (!fSeenDetectors[det-1]) {
387 continue;
388 }
29b7c86f 389 UShort_t firstring = (det == 1 ? 1 : 0);
390 for(UShort_t iring = firstring; iring <=1;iring++) {
391 Char_t ring = (iring == 1 ? 'I' : 'O');
392 for(UShort_t board =0 ; board <=1; board++) {
393
394 Int_t idx = GetHalfringIndex(det,ring,board);
395
396 fConditionsFile << det << ','
397 << ring << ','
398 << board << ','
399 << fPulseLength.At(idx) << "\n";
400
401 }
402 }
403 }
bd727bee 404
29b7c86f 405 fConditionsFile.write("# Gain Pulse \n",14);
bd727bee 406
29b7c86f 407 for(UShort_t det=1; det<=3;det++) {
408bf2b4 408 if (!fSeenDetectors[det-1]) {
409 continue;
410 }
29b7c86f 411 UShort_t firstring = (det == 1 ? 1 : 0);
412 for(UShort_t iring = firstring; iring <=1;iring++) {
413 Char_t ring = (iring == 1 ? 'I' : 'O');
414 for(UShort_t board =0 ; board <=1; board++) {
415
416 Int_t idx = GetHalfringIndex(det,ring,board);
417
418 fConditionsFile << det << ','
419 << ring << ','
420 << board << ','
421 << fPulseSize.At(idx) << "\n";
422
423 }
424 }
425 }
1656783c 426 if(fConditionsFile.is_open()) {
ce5a8b1a 427
427e8f99 428 fConditionsFile.write("# EOF\n",6);
1656783c 429 fConditionsFile.close();
430
431 }
ce5a8b1a 432
433}
427e8f99 434//_____________________________________________________________________
6cf6e7a0 435Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring,
436 UShort_t board) const
437{
438 // Get the index corresponding to a half-ring
439 //
440 // Parameters:
441 // det Detector number
442 // ring Ring identifier
443 // board Board number
444 //
445 // Return
446 // Internal index of the board
427e8f99 447 UShort_t iring = (ring == 'I' ? 1 : 0);
448
449 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
450
29b7c86f 451 return index-2;
427e8f99 452
453}
6cf6e7a0 454//_____________________________________________________________________
455void AliFMDBaseDA::Rotate(const char* base, int max) const
456{
457 //
458 // Rotate a set of files. base is the basic name of the files.
459 // If the file base.max exists it is removed.
460 // If the file base.n exists (where n < max) it is renamed to
461 // base.(n-1).
462 // If the file base exists, it is renamed to base.1
463 //
464 // Parameters:
465 // base Base name of the files
466 // max Maximum number to keep (minus one for the current).
467
468 // Note: TSystem::AccessPathName returns false if the condition is
469 // fulfilled!
470
471 // Check if we have base.max, and if so, remove it.
472 TString testName(Form("%s.%d", base, max));
473 if (!gSystem->AccessPathName(testName.Data()))
474 gSystem->Unlink(testName.Data());
475
476 // Loop down from max-1 to 1 and move files
477 for (int i = max-1; i >= 1; i--) {
478 testName = Form("%s.%d", base, i);
479 if (!gSystem->AccessPathName(testName.Data())) {
480 TString newName(Form("%s.%d", base, i+1));
481 gSystem->Rename(testName.Data(), newName.Data());
482 }
483 }
484
485 // If we have the file base, rename it to base.1
486 testName = Form("%s", base);
487 if (!gSystem->AccessPathName(testName.Data())){
488 TString newName(Form("%s.%d", base, 1));
489 gSystem->Rename(testName.Data(), newName.Data());
490 }
491}
427e8f99 492
2a082c96 493//_____________________________________________________________________
494TH2*
495AliFMDBaseDA::MakeSummaryHistogram(const char* prefix, const char* title,
496 UShort_t d, Char_t r)
497{
498 Int_t nX = ((d == 1 || r == 'I' || r == 'i') ? 20 : 40);
499 Int_t nY = ((d == 1 || r == 'I' || r == 'i') ? 512 : 256);
500
501 TH2* ret = new TH2F(Form("%sFMD%d%c", prefix, d, r),
502 Form("%s for FMD%d%c", title, d, r),
503 nX, -0.5, nX-0.5, nY, -0.5, nY-0.5);
504 ret->SetXTitle("Sector #");
505 ret->SetYTitle("Strip #");
506
507 // if (!fSummaries) fSummaries = new TObjArray;
508 fSummaries.Add(ret);
509 return ret;
510}
ce5a8b1a 511
a0180e76 512//_____________________________________________________________________
513//
514// EOF
515//