]>
Commit | Line | Data |
---|---|---|
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" | |
09b6c804 | 30 | #include "AliRawReader.h" |
31 | #include "AliFMDDigit.h" | |
32 | #include "AliFMDParameters.h" | |
a0180e76 | 33 | #include "AliFMDRawReader.h" |
1656783c | 34 | #include "AliFMDCalibSampleRate.h" |
bd727bee | 35 | #include "AliFMDCalibStripRange.h" |
a0180e76 | 36 | #include "AliLog.h" |
3effc6e7 | 37 | #include "AliRawEventHeaderBase.h" |
09b6c804 | 38 | #include "AliFMDDigit.h" |
39 | #include <TClonesArray.h> | |
40 | #include <TFile.h> | |
6cf6e7a0 | 41 | #include <TDatime.h> |
42 | #include <TSystem.h> | |
2a082c96 | 43 | #include <TH2F.h> |
a31ea3ce | 44 | #include <TStopwatch.h> |
45 | #include <TROOT.h> | |
46 | #include <TPluginManager.h> | |
09b6c804 | 47 | #include <iostream> |
48 | #include <fstream> | |
a31ea3ce | 49 | |
a0180e76 | 50 | //_____________________________________________________________________ |
51 | ClassImp(AliFMDBaseDA) | |
e9c06036 | 52 | #if 0 |
53 | ; // Do not delete - to let Emacs for mat the code | |
54 | #endif | |
55 | ||
56 | //_____________________________________________________________________ | |
57 | const char* | |
58 | AliFMDBaseDA::GetStripPath(UShort_t det, | |
59 | Char_t ring, | |
60 | UShort_t sec, | |
61 | UShort_t str, | |
62 | Bool_t full) const | |
63 | { | |
6cf6e7a0 | 64 | // Get the strip path |
65 | // | |
66 | // Parameters | |
67 | // det Detector number | |
68 | // ring Ring identifier | |
69 | // sec Sector number | |
70 | // str Strip number | |
71 | // full If true, return full path | |
72 | // | |
73 | // Return | |
74 | // The path | |
e9c06036 | 75 | return Form("%s%sFMD%d%c[%02d,%03d]", |
76 | (full ? GetSectorPath(det, ring, sec, full) : ""), | |
77 | (full ? "/" : ""), det, ring, sec, str); | |
78 | } | |
79 | //_____________________________________________________________________ | |
80 | const char* | |
81 | AliFMDBaseDA::GetSectorPath(UShort_t det, | |
82 | Char_t ring, | |
83 | UShort_t sec, | |
84 | Bool_t full) const | |
85 | { | |
6cf6e7a0 | 86 | // Get the strip path |
87 | // | |
88 | // Parameters | |
89 | // det Detector number | |
90 | // ring Ring identifier | |
91 | // sec Sector number | |
92 | // str Strip number | |
93 | // full If true, return full path | |
94 | // | |
95 | // Return | |
96 | // The path | |
e9c06036 | 97 | return Form("%s%sFMD%d%c[%02d]", |
98 | (full ? GetRingPath(det, ring, full) : ""), | |
99 | (full ? "/" : ""), det, ring, sec); | |
100 | } | |
101 | //_____________________________________________________________________ | |
102 | const char* | |
103 | AliFMDBaseDA::GetRingPath(UShort_t det, | |
104 | Char_t ring, | |
105 | Bool_t full) const | |
106 | { | |
6cf6e7a0 | 107 | // Get the strip path |
108 | // | |
109 | // Parameters | |
110 | // det Detector number | |
111 | // ring Ring identifier | |
112 | // sec Sector number | |
113 | // str Strip number | |
114 | // full If true, return full path | |
115 | // | |
116 | // Return | |
117 | // The path | |
e9c06036 | 118 | return Form("%s%sFMD%d%c", |
119 | (full ? GetDetectorPath(det, full) : ""), | |
120 | (full ? "/" : ""), det, ring); | |
121 | } | |
122 | //_____________________________________________________________________ | |
123 | const char* | |
124 | AliFMDBaseDA::GetDetectorPath(UShort_t det, | |
125 | Bool_t full) const | |
126 | { | |
6cf6e7a0 | 127 | // Get the strip path |
128 | // | |
129 | // Parameters | |
130 | // det Detector number | |
131 | // ring Ring identifier | |
132 | // sec Sector number | |
133 | // str Strip number | |
134 | // full If true, return full path | |
135 | // | |
136 | // Return | |
137 | // The path | |
e9c06036 | 138 | return Form("%s%sFMD%d", |
139 | (full ? fDiagnosticsFilename.Data() : ""), | |
140 | (full ? ":/" : ""), det); | |
141 | } | |
a0180e76 | 142 | |
143 | //_____________________________________________________________________ | |
427e8f99 | 144 | AliFMDBaseDA::AliFMDBaseDA() : |
145 | TNamed(), | |
a0180e76 | 146 | fDiagnosticsFilename("diagnosticsHistograms.root"), |
147 | fOutputFile(), | |
ce5a8b1a | 148 | fConditionsFile(), |
a0180e76 | 149 | fSaveHistograms(kFALSE), |
2a082c96 | 150 | fMakeSummaries(kFALSE), |
a0180e76 | 151 | fDetectorArray(), |
29b7c86f | 152 | fPulseSize(10), |
153 | fPulseLength(10), | |
154 | fRequiredEvents(0), | |
6cf6e7a0 | 155 | fCurrentEvent(0), |
2a082c96 | 156 | fRunno(0), |
157 | fSummaries(0) | |
c5569fbc | 158 | { |
159 | //Constructor | |
6cf6e7a0 | 160 | fSeenDetectors[0] = fSeenDetectors[1] = fSeenDetectors[2] = kFALSE; |
a0180e76 | 161 | fDetectorArray.SetOwner(); |
6cf6e7a0 | 162 | Rotate("conditions.csv", 3); |
ce5a8b1a | 163 | fConditionsFile.open("conditions.csv"); |
a0180e76 | 164 | } |
165 | //_____________________________________________________________________ | |
166 | AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) : | |
167 | TNamed(baseDA), | |
a7e41e8d | 168 | fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()), |
a0180e76 | 169 | fOutputFile(), |
ce5a8b1a | 170 | fConditionsFile(), |
a0180e76 | 171 | fSaveHistograms(baseDA.fSaveHistograms), |
2a082c96 | 172 | fMakeSummaries(baseDA.fMakeSummaries), |
a0180e76 | 173 | fDetectorArray(baseDA.fDetectorArray), |
427e8f99 | 174 | fPulseSize(baseDA.fPulseSize), |
175 | fPulseLength(baseDA.fPulseLength), | |
a0180e76 | 176 | fRequiredEvents(baseDA.fRequiredEvents), |
6cf6e7a0 | 177 | fCurrentEvent(baseDA.fCurrentEvent), |
2a082c96 | 178 | fRunno(baseDA.fRunno), |
179 | fSummaries(0) | |
a0180e76 | 180 | { |
c5569fbc | 181 | //Copy constructor |
408bf2b4 | 182 | fSeenDetectors[0] = baseDA.fSeenDetectors[0]; |
183 | fSeenDetectors[1] = baseDA.fSeenDetectors[1]; | |
184 | fSeenDetectors[2] = baseDA.fSeenDetectors[2]; | |
185 | ||
a0180e76 | 186 | fDetectorArray.SetOwner(); |
187 | ||
188 | } | |
189 | ||
82d71828 | 190 | |
a0180e76 | 191 | //_____________________________________________________________________ |
e9c06036 | 192 | AliFMDBaseDA::~AliFMDBaseDA() |
193 | { | |
a0180e76 | 194 | //destructor |
a0180e76 | 195 | } |
196 | ||
a31ea3ce | 197 | //_____________________________________________________________________ |
198 | Bool_t AliFMDBaseDA::HaveEnough(Int_t nEvents) const | |
199 | { | |
200 | return nEvents > GetRequiredEvents(); | |
201 | } | |
202 | //_____________________________________________________________________ | |
203 | UShort_t AliFMDBaseDA::GetProgress(Int_t nEvents) const | |
204 | { | |
205 | return UShort_t((nEvents *100)/ GetRequiredEvents()); | |
206 | } | |
207 | ||
a0180e76 | 208 | //_____________________________________________________________________ |
e9c06036 | 209 | void AliFMDBaseDA::Run(AliRawReader* reader) |
210 | { | |
c5569fbc | 211 | //Run the FMD DA |
e9c06036 | 212 | TFile* diagFile = 0; |
a31ea3ce | 213 | // if (fSaveHistograms) |
214 | // diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE"); | |
7bce699b | 215 | |
a0180e76 | 216 | reader->Reset(); |
6cf6e7a0 | 217 | fRunno = reader->GetRunNumber(); |
218 | ||
e9c06036 | 219 | AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0); |
220 | TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0); | |
3effc6e7 | 221 | |
c5569fbc | 222 | Bool_t sodread = kFALSE; |
200d06f9 | 223 | |
224 | for(Int_t i=0;i<3;i++) { | |
56940d2b | 225 | if (!reader->NextEvent()) { |
133f1578 | 226 | // Read Start-of-Run / Start-of-Files event |
227 | AliWarning(Form("Failed to read the %d%s event", | |
228 | i+1, (i == 0 ? "st" : (i == 1 ? "nd" : "rd")))); | |
229 | break; | |
230 | } | |
29b7c86f | 231 | |
200d06f9 | 232 | UInt_t eventType = reader->GetType(); |
233 | if(eventType == AliRawEventHeaderBase::kStartOfData || | |
234 | eventType == AliRawEventHeaderBase::kFormatError) { | |
235 | ||
236 | WriteConditionsData(fmdReader); | |
237 | Init(); | |
c5569fbc | 238 | sodread = kTRUE; |
200d06f9 | 239 | break; |
240 | } | |
29b7c86f | 241 | } |
200d06f9 | 242 | |
7bce699b | 243 | InitContainer(diagFile); |
a31ea3ce | 244 | if (AliLog::GetDebugLevel("FMD","") >= 3) { |
245 | fDetectorArray.ls(); | |
246 | } | |
7bce699b | 247 | |
c5569fbc | 248 | if(!sodread) |
29b7c86f | 249 | AliWarning("No SOD event detected!"); |
3effc6e7 | 250 | |
1656783c | 251 | int lastProgress = 0; |
a0180e76 | 252 | |
a31ea3ce | 253 | for(Int_t i = 0; i< 3;i++) fNEventsPerDetector[i] = 0; |
254 | ||
255 | for(Int_t n = 1; !HaveEnough(n); n++) { | |
256 | if(!reader->NextEvent()) { n--; continue; } | |
3effc6e7 | 257 | SetCurrentEvent(n); |
e9c06036 | 258 | digitArray->Clear(); |
259 | fmdReader->ReadAdcs(digitArray); | |
7bce699b | 260 | |
a31ea3ce | 261 | Bool_t seen[] = { false, false, false }; |
e9c06036 | 262 | for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) { |
263 | AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i)); | |
a31ea3ce | 264 | UShort_t det = digit->Detector(); |
265 | fSeenDetectors[det-1] = true; | |
266 | seen[det-1] = true; | |
e9c06036 | 267 | FillChannels(digit); |
a0180e76 | 268 | } |
e9c06036 | 269 | |
a31ea3ce | 270 | for(Int_t i = 0; i< 3;i++) |
271 | if (seen[i]) (fNEventsPerDetector[i])++; | |
272 | ||
e9c06036 | 273 | FinishEvent(); |
7bce699b | 274 | |
a31ea3ce | 275 | int progress = GetProgress(n); |
e9c06036 | 276 | if (progress <= lastProgress) continue; |
277 | lastProgress = progress; | |
278 | std::cout << "Progress: " << lastProgress << " / 100 " << std::endl; | |
7bce699b | 279 | |
e9c06036 | 280 | } |
7bce699b | 281 | |
a31ea3ce | 282 | AliInfoF("Looped over %d events (%d,%d,%d)",GetCurrentEvent(), |
283 | fNEventsPerDetector[0], | |
284 | fNEventsPerDetector[1], | |
285 | fNEventsPerDetector[2]); | |
a0180e76 | 286 | WriteHeaderToFile(); |
287 | ||
288 | for(UShort_t det=1;det<=3;det++) { | |
408bf2b4 | 289 | if (!fSeenDetectors[det-1]) continue; |
e9c06036 | 290 | std::cout << "FMD" << det << std::endl; |
c5569fbc | 291 | UShort_t firstRing = (det == 1 ? 1 : 0); |
292 | for (UShort_t ir = firstRing; ir < 2; ir++) { | |
a0180e76 | 293 | Char_t ring = (ir == 0 ? 'O' : 'I'); |
294 | UShort_t nsec = (ir == 0 ? 40 : 20); | |
295 | UShort_t nstr = (ir == 0 ? 256 : 512); | |
2a082c96 | 296 | |
297 | if (fMakeSummaries) MakeSummary(det, ring); | |
298 | ||
e9c06036 | 299 | std::cout << " Ring " << ring << ": " << std::flush; |
a0180e76 | 300 | for(UShort_t sec =0; sec < nsec; sec++) { |
301 | for(UShort_t strip = 0; strip < nstr; strip++) { | |
302 | Analyse(det,ring,sec,strip); | |
a0180e76 | 303 | } |
e9c06036 | 304 | std::cout << '.' << std::flush; |
a0180e76 | 305 | } |
a31ea3ce | 306 | // if(fSaveHistograms) |
307 | // diagFile->Flush(); | |
e9c06036 | 308 | std::cout << "done" << std::endl; |
a0180e76 | 309 | } |
310 | } | |
7bce699b | 311 | |
a0180e76 | 312 | if(fOutputFile.is_open()) { |
a0180e76 | 313 | fOutputFile.write("# EOF\n",6); |
314 | fOutputFile.close(); | |
a0180e76 | 315 | } |
316 | ||
7bce699b | 317 | Terminate(diagFile); |
318 | ||
a0180e76 | 319 | if(fSaveHistograms ) { |
a31ea3ce | 320 | diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE"); |
321 | fDetectorArray.Write("FMD", TObject::kSingleKey); | |
322 | fSummaries.Write(); | |
e9c06036 | 323 | AliInfo("Closing diagnostics file - please wait ..."); |
324 | // diagFile->Write(); | |
ce5a8b1a | 325 | diagFile->Close(); |
e9c06036 | 326 | AliInfo("done"); |
7bce699b | 327 | |
a0180e76 | 328 | } |
329 | } | |
330 | //_____________________________________________________________________ | |
331 | ||
e9c06036 | 332 | void AliFMDBaseDA::InitContainer(TDirectory* diagFile) |
333 | { | |
a31ea3ce | 334 | //Prepare container for diagnostics |
e9c06036 | 335 | TDirectory* savDir = gDirectory; |
336 | ||
a0180e76 | 337 | for(UShort_t det=1;det<=3;det++) { |
a31ea3ce | 338 | TObjArray* detArray = new TObjArray(det == 1 ? 1 : 2); |
a0180e76 | 339 | detArray->SetOwner(); |
a31ea3ce | 340 | detArray->SetName(GetDetectorPath(det, false)); |
a0180e76 | 341 | fDetectorArray.AddAtAndExpand(detArray,det); |
e9c06036 | 342 | |
343 | TDirectory* detDir = 0; | |
344 | if (diagFile) { | |
345 | diagFile->cd(); | |
346 | detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE)); | |
347 | } | |
348 | ||
a0180e76 | 349 | UShort_t FirstRing = (det == 1 ? 1 : 0); |
350 | for (UShort_t ir = FirstRing; ir < 2; ir++) { | |
351 | Char_t ring = (ir == 0 ? 'O' : 'I'); | |
352 | UShort_t nsec = (ir == 0 ? 40 : 20); | |
353 | UShort_t nstr = (ir == 0 ? 256 : 512); | |
a31ea3ce | 354 | TObjArray* ringArray = new TObjArray(nsec); |
a0180e76 | 355 | ringArray->SetOwner(); |
a31ea3ce | 356 | ringArray->SetName(GetRingPath(det, ring, false)); |
a0180e76 | 357 | detArray->AddAtAndExpand(ringArray,ir); |
e9c06036 | 358 | |
359 | ||
360 | TDirectory* ringDir = 0; | |
361 | if (detDir) { | |
362 | detDir->cd(); | |
363 | ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE)); | |
364 | } | |
365 | ||
366 | ||
a0180e76 | 367 | for(UShort_t sec =0; sec < nsec; sec++) { |
a31ea3ce | 368 | TObjArray* sectorArray = new TObjArray(nstr); |
a0180e76 | 369 | sectorArray->SetOwner(); |
a31ea3ce | 370 | sectorArray->SetName(GetSectorPath(det, ring, sec, false)); |
a0180e76 | 371 | ringArray->AddAtAndExpand(sectorArray,sec); |
e9c06036 | 372 | |
373 | ||
374 | TDirectory* secDir = 0; | |
375 | if (ringDir) { | |
376 | ringDir->cd(); | |
377 | secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE)); | |
378 | } | |
379 | ||
a0180e76 | 380 | for(UShort_t strip = 0; strip < nstr; strip++) { |
e9c06036 | 381 | if (secDir) { |
382 | secDir->cd(); | |
383 | secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE)); | |
384 | } | |
a31ea3ce | 385 | TObjArray* stripArray = new TObjArray(0); |
386 | stripArray->SetOwner(true); | |
387 | stripArray->SetName(GetStripPath(det, ring, sec, strip, false)); | |
388 | sectorArray->AddAtAndExpand(stripArray, strip); | |
389 | AddChannelContainer(stripArray, det, ring, sec, strip); | |
a0180e76 | 390 | } |
a31ea3ce | 391 | AddSectorSummary(sectorArray, det, ring, sec, nstr); |
a0180e76 | 392 | } |
393 | } | |
394 | } | |
e9c06036 | 395 | savDir->cd(); |
a0180e76 | 396 | } |
ce5a8b1a | 397 | |
398 | //_____________________________________________________________________ | |
3effc6e7 | 399 | void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader) |
e9c06036 | 400 | { |
c5569fbc | 401 | //Write the conditions data to file |
ce5a8b1a | 402 | AliFMDParameters* pars = AliFMDParameters::Instance(); |
403 | fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14); | |
6cf6e7a0 | 404 | TDatime now; |
405 | fConditionsFile << "# This file created from run number " << fRunno | |
406 | << " at " << now.AsString() << std::endl; | |
427e8f99 | 407 | |
3effc6e7 | 408 | AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate(); |
409 | AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange(); | |
427e8f99 | 410 | |
408bf2b4 | 411 | fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength, |
412 | fSeenDetectors); | |
bd727bee | 413 | |
408bf2b4 | 414 | sampleRate->WriteToFile(fConditionsFile, fSeenDetectors); |
415 | stripRange->WriteToFile(fConditionsFile, fSeenDetectors); | |
bd727bee | 416 | |
417 | ||
427e8f99 | 418 | // Zero Suppresion |
419 | ||
420 | // Strip Range | |
421 | ||
29b7c86f | 422 | fConditionsFile.write("# Gain Events \n",15); |
bd727bee | 423 | |
29b7c86f | 424 | for(UShort_t det=1; det<=3;det++) { |
408bf2b4 | 425 | if (!fSeenDetectors[det-1]) { |
426 | continue; | |
427 | } | |
29b7c86f | 428 | UShort_t firstring = (det == 1 ? 1 : 0); |
429 | for(UShort_t iring = firstring; iring <=1;iring++) { | |
430 | Char_t ring = (iring == 1 ? 'I' : 'O'); | |
431 | for(UShort_t board =0 ; board <=1; board++) { | |
432 | ||
433 | Int_t idx = GetHalfringIndex(det,ring,board); | |
434 | ||
435 | fConditionsFile << det << ',' | |
436 | << ring << ',' | |
437 | << board << ',' | |
438 | << fPulseLength.At(idx) << "\n"; | |
439 | ||
440 | } | |
441 | } | |
442 | } | |
bd727bee | 443 | |
29b7c86f | 444 | fConditionsFile.write("# Gain Pulse \n",14); |
bd727bee | 445 | |
29b7c86f | 446 | for(UShort_t det=1; det<=3;det++) { |
408bf2b4 | 447 | if (!fSeenDetectors[det-1]) { |
448 | continue; | |
449 | } | |
29b7c86f | 450 | UShort_t firstring = (det == 1 ? 1 : 0); |
451 | for(UShort_t iring = firstring; iring <=1;iring++) { | |
452 | Char_t ring = (iring == 1 ? 'I' : 'O'); | |
453 | for(UShort_t board =0 ; board <=1; board++) { | |
454 | ||
455 | Int_t idx = GetHalfringIndex(det,ring,board); | |
456 | ||
457 | fConditionsFile << det << ',' | |
458 | << ring << ',' | |
459 | << board << ',' | |
460 | << fPulseSize.At(idx) << "\n"; | |
461 | ||
462 | } | |
463 | } | |
464 | } | |
2d6778fb | 465 | // sampleRate->WriteToFile(std::cout, fSeenDetectors); |
466 | // stripRange->WriteToFile(std::cout, fSeenDetectors); | |
467 | ||
1656783c | 468 | if(fConditionsFile.is_open()) { |
ce5a8b1a | 469 | |
427e8f99 | 470 | fConditionsFile.write("# EOF\n",6); |
1656783c | 471 | fConditionsFile.close(); |
472 | ||
473 | } | |
ce5a8b1a | 474 | |
475 | } | |
427e8f99 | 476 | //_____________________________________________________________________ |
6cf6e7a0 | 477 | Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, |
478 | UShort_t board) const | |
479 | { | |
480 | // Get the index corresponding to a half-ring | |
481 | // | |
482 | // Parameters: | |
483 | // det Detector number | |
484 | // ring Ring identifier | |
485 | // board Board number | |
486 | // | |
487 | // Return | |
488 | // Internal index of the board | |
427e8f99 | 489 | UShort_t iring = (ring == 'I' ? 1 : 0); |
490 | ||
491 | Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0)); | |
492 | ||
29b7c86f | 493 | return index-2; |
427e8f99 | 494 | |
495 | } | |
6cf6e7a0 | 496 | //_____________________________________________________________________ |
497 | void AliFMDBaseDA::Rotate(const char* base, int max) const | |
498 | { | |
499 | // | |
500 | // Rotate a set of files. base is the basic name of the files. | |
501 | // If the file base.max exists it is removed. | |
502 | // If the file base.n exists (where n < max) it is renamed to | |
503 | // base.(n-1). | |
504 | // If the file base exists, it is renamed to base.1 | |
505 | // | |
506 | // Parameters: | |
507 | // base Base name of the files | |
508 | // max Maximum number to keep (minus one for the current). | |
509 | ||
510 | // Note: TSystem::AccessPathName returns false if the condition is | |
511 | // fulfilled! | |
512 | ||
513 | // Check if we have base.max, and if so, remove it. | |
514 | TString testName(Form("%s.%d", base, max)); | |
515 | if (!gSystem->AccessPathName(testName.Data())) | |
516 | gSystem->Unlink(testName.Data()); | |
517 | ||
518 | // Loop down from max-1 to 1 and move files | |
519 | for (int i = max-1; i >= 1; i--) { | |
520 | testName = Form("%s.%d", base, i); | |
521 | if (!gSystem->AccessPathName(testName.Data())) { | |
522 | TString newName(Form("%s.%d", base, i+1)); | |
523 | gSystem->Rename(testName.Data(), newName.Data()); | |
524 | } | |
525 | } | |
526 | ||
527 | // If we have the file base, rename it to base.1 | |
528 | testName = Form("%s", base); | |
529 | if (!gSystem->AccessPathName(testName.Data())){ | |
530 | TString newName(Form("%s.%d", base, 1)); | |
531 | gSystem->Rename(testName.Data(), newName.Data()); | |
532 | } | |
533 | } | |
427e8f99 | 534 | |
2a082c96 | 535 | //_____________________________________________________________________ |
536 | TH2* | |
537 | AliFMDBaseDA::MakeSummaryHistogram(const char* prefix, const char* title, | |
538 | UShort_t d, Char_t r) | |
539 | { | |
09b6c804 | 540 | // |
541 | // Utility function for defining summary histograms | |
542 | // | |
543 | // Parameters: | |
544 | // det Detector | |
545 | // ring Ring identifier | |
546 | // prefix Histogram prefix | |
547 | // title Histogram title | |
548 | // | |
2a082c96 | 549 | Int_t nX = ((d == 1 || r == 'I' || r == 'i') ? 20 : 40); |
550 | Int_t nY = ((d == 1 || r == 'I' || r == 'i') ? 512 : 256); | |
551 | ||
552 | TH2* ret = new TH2F(Form("%sFMD%d%c", prefix, d, r), | |
553 | Form("%s for FMD%d%c", title, d, r), | |
554 | nX, -0.5, nX-0.5, nY, -0.5, nY-0.5); | |
555 | ret->SetXTitle("Sector #"); | |
556 | ret->SetYTitle("Strip #"); | |
a31ea3ce | 557 | ret->SetDirectory(0); |
2a082c96 | 558 | // if (!fSummaries) fSummaries = new TObjArray; |
559 | fSummaries.Add(ret); | |
560 | return ret; | |
561 | } | |
ce5a8b1a | 562 | |
a31ea3ce | 563 | //_____________________________________________________________________ |
564 | TObjArray* | |
565 | AliFMDBaseDA::GetDetectorArray(UShort_t det) | |
566 | { | |
567 | if (det < 1 || det > 3) { | |
568 | AliErrorF("Detector index %d out of bounds", det); | |
569 | return 0; | |
570 | } | |
571 | return static_cast<TObjArray*>(fDetectorArray.At(det)); | |
572 | } | |
573 | //_____________________________________________________________________ | |
574 | TObjArray* | |
575 | AliFMDBaseDA::GetRingArray(UShort_t det, Char_t ring) | |
576 | { | |
577 | Int_t idx = (ring == 'O' || ring == 'o' ? 0 : 1); | |
578 | TObjArray* array = GetDetectorArray(det); | |
579 | if (!array) return 0; | |
580 | array = static_cast<TObjArray*>(array->At(idx)); | |
581 | if (!array) AliErrorF("No ring array for FMD%d%c (%d)", det, ring, idx); | |
582 | return array; | |
583 | } | |
584 | //_____________________________________________________________________ | |
585 | TObjArray* | |
586 | AliFMDBaseDA::GetSectorArray(UShort_t det, Char_t ring, UShort_t sector) | |
587 | { | |
588 | TObjArray* array = GetRingArray(det,ring); | |
589 | if (!array) return 0; | |
590 | array = static_cast<TObjArray*>(array->At(sector)); | |
591 | if (!array) AliErrorF("No sector array for FMD%d%c[%02d]", det, ring, sector); | |
592 | return array; | |
593 | } | |
594 | //_____________________________________________________________________ | |
595 | TObjArray* | |
596 | AliFMDBaseDA::GetStripArray(UShort_t det, Char_t ring, | |
597 | UShort_t sector, UShort_t strip) | |
598 | { | |
599 | TObjArray* array = GetSectorArray(det,ring,sector); | |
600 | if (!array) return 0; | |
601 | array = static_cast<TObjArray*>(array->At(strip)); | |
602 | if (!array) AliErrorF("No strip array for FMD%d%c[%02d,%03d]", | |
603 | det, ring, sector, strip); | |
604 | return array; | |
605 | } | |
606 | ||
607 | //===================================================================== | |
608 | AliFMDBaseDA::Runner::Runner() | |
609 | : fReader(0), | |
610 | fDiagFile(""), | |
611 | fDiag(false) | |
612 | {} | |
613 | ||
614 | //_____________________________________________________________________ | |
615 | void | |
616 | AliFMDBaseDA::Runner::AddHandlers() | |
617 | { | |
618 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
619 | "*", | |
620 | "TStreamerInfo", | |
621 | "RIO", | |
622 | "TStreamerInfo()"); | |
623 | gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit", | |
624 | "TMinuitMinimizer", | |
625 | "Minuit", | |
626 | "TMinuitMinimizer(const char *)"); | |
627 | gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", | |
628 | "GSLMultiMin", | |
629 | "ROOT::Math::GSLMinimizer", | |
630 | "MathMore", | |
631 | "GSLMinimizer(const char *)"); | |
632 | gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", | |
633 | "GSLMultiFit", | |
634 | "ROOT::Math::GSLNLSMinimizer", | |
635 | "MathMore", "GSLNLSMinimizer(int)"); | |
636 | gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", | |
637 | "GSLSimAn", | |
638 | "ROOT::Math::GSLSimAnMinimizer", | |
639 | "MathMore", | |
640 | "GSLSimAnMinimizer(int)"); | |
641 | gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", | |
642 | "Linear", | |
643 | "TLinearMinimizer", | |
644 | "Minuit", | |
645 | "TLinearMinimizer(const char *)"); | |
646 | gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", | |
647 | "Fumili", | |
648 | "TFumiliMinimizer", | |
649 | "Fumili", | |
650 | "TFumiliMinimizer(int)"); | |
651 | } | |
652 | //_____________________________________________________________________ | |
653 | void | |
654 | AliFMDBaseDA::Runner::ShowUsage(std::ostream& o, const char* progname) | |
655 | { | |
656 | o << "Usage: " << progname << " SOURCE [OPTIONS]\n\n" | |
657 | << "Options:\n" | |
658 | << " -h,--help Show this help\n" | |
659 | << " -d,--diagnostics[=FILE] Write diagnostics to file\n" | |
660 | << " -D,--debug=LEVEL Set the debug level\n\n" | |
661 | << "SOURCE is one of\n" | |
662 | << " * FILE.raw Raw data file\n" | |
663 | << " * FILE.root ROOT'ified raw data file\n" | |
664 | << " * collection://FILE.root Event list in a ROOT file\n" | |
665 | << " * collection://FILE File containing list of ROOT files\n" | |
666 | << " * ^FMD Monitor source\n" | |
667 | << "There are other options too. Check the AliRawReader docs\n" | |
668 | << std::endl; | |
669 | } | |
670 | ||
671 | //_____________________________________________________________________ | |
672 | namespace { | |
673 | Bool_t ExtractValue(const TString& arg, TString& val) | |
674 | { | |
675 | val = ""; | |
676 | Int_t eq = arg.Index("="); | |
677 | if (eq == kNPOS) return false; | |
678 | ||
679 | val = arg(eq+1, arg.Length()-eq-1); | |
680 | return true; | |
681 | } | |
682 | } | |
683 | ||
684 | //_____________________________________________________________________ | |
685 | Int_t | |
686 | AliFMDBaseDA::Runner::Init(int argc, char** argv) | |
687 | { | |
688 | AddHandlers(); | |
689 | ||
690 | // --- Process the command line ------------------------------------ | |
691 | TString source; | |
692 | Int_t debugLevel = 0; | |
693 | Bool_t help = false; | |
694 | ||
695 | for (int i = 1; i < argc; i++) { | |
696 | TString arg(argv[i]); | |
697 | Bool_t badOption = false; | |
698 | ||
699 | if (arg[0] == '-') { // It's an option | |
700 | if (arg[1] == '-') { // It's a long option | |
701 | TString val; | |
702 | if (arg.EqualTo("--help")) help = true; | |
703 | else if (arg.BeginsWith("--debug")) { | |
704 | if (ExtractValue(arg, val)) | |
705 | debugLevel = val.Atoi(); | |
706 | } | |
707 | else if (arg.BeginsWith("--diagnostics")) { | |
708 | fDiag = true; | |
709 | if (ExtractValue(arg, val)) | |
710 | fDiagFile = val; | |
711 | } | |
712 | else badOption = true; | |
713 | } | |
714 | else { // Short option | |
715 | TString next(i < argc-1 ? argv[i+1] : ""); | |
716 | switch (arg[1]) { | |
717 | case 'h': help = true; break; | |
718 | case 'd': fDiag = true; | |
719 | if (!next.IsNull() && next[0] != '-') { | |
720 | fDiagFile = next; | |
721 | i++; | |
722 | } | |
723 | break; | |
724 | case 'D': | |
725 | if (!next.IsNull() && next[0] != '-') { | |
726 | debugLevel = next.Atoi(); | |
727 | i++; | |
728 | } | |
729 | break; | |
730 | default: badOption = true; | |
731 | } | |
732 | } // End of options | |
733 | if (badOption) { | |
734 | std::cerr << argv[0] << ": Unknown option " << argv[i] | |
735 | << std::endl; | |
736 | return -1; | |
737 | } | |
738 | } | |
739 | else { // source or compatibility debug level | |
740 | if (source.IsNull()) source = arg; | |
741 | else debugLevel = arg.Atoi(); | |
742 | } | |
743 | } | |
744 | ||
745 | // --- Check if help was requested --------------------------------- | |
746 | if (help) { | |
747 | ShowUsage(std::cout, argv[0]); | |
748 | return 1; | |
749 | } | |
750 | ||
751 | // --- Check if we have a source ----------------------------------- | |
752 | if (source.IsNull()) { | |
753 | std::cerr << "No source given" << std::endl; | |
754 | return -2; | |
755 | } | |
756 | ||
757 | // --- Initialize various things ----------------------------------- | |
758 | AliFMDParameters::Instance()->Init(kFALSE,0); | |
759 | ||
760 | //This will only work for FDR 1 data. When newer data becomes | |
761 | //available the ! must be removed! | |
762 | Bool_t old = kTRUE; | |
763 | AliFMDParameters::Instance()->UseCompleteHeader(old); | |
764 | ||
765 | AliLog::EnableDebug(debugLevel > 0); | |
766 | AliLog::SetModuleDebugLevel("FMD", debugLevel); | |
767 | ||
768 | // --- Make our reader --------------------------------------------- | |
769 | fReader = AliRawReader::Create(source); | |
770 | if (!fReader) { | |
771 | std::cerr << "Failed to make raw reader for source \"" << source | |
772 | << "\"" << std::endl; | |
773 | return -3; | |
774 | } | |
775 | return 0; | |
776 | } | |
777 | ||
778 | //_____________________________________________________________________ | |
779 | Int_t | |
780 | AliFMDBaseDA::Runner::RunNumber() const | |
781 | { | |
782 | if (!fReader) return -1; | |
783 | return fReader->GetRunNumber(); | |
784 | } | |
785 | ||
786 | //_____________________________________________________________________ | |
787 | void | |
788 | AliFMDBaseDA::Runner::Exec(AliFMDBaseDA& da) | |
789 | { | |
790 | TStopwatch timer; | |
791 | timer.Start(); | |
792 | ||
793 | da.SetSaveDiagnostics(fDiag || !fDiagFile.IsNull()); | |
794 | if (!fDiagFile.IsNull()) da.SetDiagnosticsFilename(fDiagFile); | |
795 | ||
796 | da.Run(fReader); | |
797 | ||
798 | timer.Stop(); | |
799 | timer.Print(); | |
800 | ||
801 | #ifdef ALI_AMORE | |
802 | try { | |
803 | amore::da::AmoreDA myAmore(amore::da::AmoreDA::kSender); | |
804 | ||
805 | for (UShort_t det = 1; det <= 3; det++) { | |
806 | if (!da.HasSeenDetector(det)) continue; | |
807 | TObject* runNo = new TObject; | |
808 | runNo->SetUniqueID(fReader->GetRunNumber()); | |
809 | myAmore.Send(Form("gainRunNoFMD%d", det), runNo); | |
810 | } | |
811 | ||
812 | TIter next(&da.GetSummaries()); | |
813 | TObject* obj = 0; | |
814 | while ((obj = next())) | |
815 | myAmore.Send(obj->GetName(), obj); | |
816 | ||
817 | } | |
818 | catch (exception& e) { | |
819 | cerr << "Failed to make AMORE instance: " << e.what() << endl; | |
820 | } | |
821 | ||
822 | #endif | |
823 | } | |
824 | ||
825 | ||
826 | ||
827 | ||
828 | ||
829 | //_____________________________________________________________________ | |
830 | ||
a0180e76 | 831 | //_____________________________________________________________________ |
832 | // | |
833 | // EOF | |
834 | // |