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