#include "AliFMDBaseDA.h"
#include "iostream"
-
#include "AliFMDRawReader.h"
#include "AliFMDCalibSampleRate.h"
+#include "AliFMDCalibStripRange.h"
#include "AliLog.h"
+#include "AliRawEventHeaderBase.h"
+#include <TDatime.h>
+#include <TSystem.h>
+
//_____________________________________________________________________
ClassImp(AliFMDBaseDA)
#if 0
UShort_t str,
Bool_t full) const
{
+ // Get the strip path
+ //
+ // Parameters
+ // det Detector number
+ // ring Ring identifier
+ // sec Sector number
+ // str Strip number
+ // full If true, return full path
+ //
+ // Return
+ // The path
return Form("%s%sFMD%d%c[%02d,%03d]",
(full ? GetSectorPath(det, ring, sec, full) : ""),
(full ? "/" : ""), det, ring, sec, str);
UShort_t sec,
Bool_t full) const
{
+ // Get the strip path
+ //
+ // Parameters
+ // det Detector number
+ // ring Ring identifier
+ // sec Sector number
+ // str Strip number
+ // full If true, return full path
+ //
+ // Return
+ // The path
return Form("%s%sFMD%d%c[%02d]",
(full ? GetRingPath(det, ring, full) : ""),
(full ? "/" : ""), det, ring, sec);
Char_t ring,
Bool_t full) const
{
+ // Get the strip path
+ //
+ // Parameters
+ // det Detector number
+ // ring Ring identifier
+ // sec Sector number
+ // str Strip number
+ // full If true, return full path
+ //
+ // Return
+ // The path
return Form("%s%sFMD%d%c",
(full ? GetDetectorPath(det, full) : ""),
(full ? "/" : ""), det, ring);
AliFMDBaseDA::GetDetectorPath(UShort_t det,
Bool_t full) const
{
+ // Get the strip path
+ //
+ // Parameters
+ // det Detector number
+ // ring Ring identifier
+ // sec Sector number
+ // str Strip number
+ // full If true, return full path
+ //
+ // Return
+ // The path
return Form("%s%sFMD%d",
(full ? fDiagnosticsFilename.Data() : ""),
(full ? ":/" : ""), det);
fConditionsFile(),
fSaveHistograms(kFALSE),
fDetectorArray(),
- fPulseSize(16),
- fPulseLength(16),
+ fPulseSize(10),
+ fPulseLength(10),
fRequiredEvents(0),
- fCurrentEvent(0)
- {
+ fCurrentEvent(0),
+ fRunno(0)
+{
+ //Constructor
+ fSeenDetectors[0] = fSeenDetectors[1] = fSeenDetectors[2] = kFALSE;
fDetectorArray.SetOwner();
+ Rotate("conditions.csv", 3);
fConditionsFile.open("conditions.csv");
}
//_____________________________________________________________________
fPulseSize(baseDA.fPulseSize),
fPulseLength(baseDA.fPulseLength),
fRequiredEvents(baseDA.fRequiredEvents),
- fCurrentEvent(baseDA.fCurrentEvent)
+ fCurrentEvent(baseDA.fCurrentEvent),
+ fRunno(baseDA.fRunno)
{
+ //Copy constructor
+ fSeenDetectors[0] = baseDA.fSeenDetectors[0];
+ fSeenDetectors[1] = baseDA.fSeenDetectors[1];
+ fSeenDetectors[2] = baseDA.fSeenDetectors[2];
+
fDetectorArray.SetOwner();
}
//_____________________________________________________________________
void AliFMDBaseDA::Run(AliRawReader* reader)
{
+ //Run the FMD DA
TFile* diagFile = 0;
if (fSaveHistograms)
diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
- WriteConditionsData();
- InitContainer(diagFile);
- Init();
-
-
- reader->Reset();
+
+ reader->Reset();
+ fRunno = reader->GetRunNumber();
+
AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
+
+ Bool_t sodread = kFALSE;
+
+ for(Int_t i=0;i<3;i++) {
+ reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
- reader->NextEvent(); // Read Start-of-Run event
- reader->NextEvent(); // Read Start-of-Files event
+ UInt_t eventType = reader->GetType();
+ if(eventType == AliRawEventHeaderBase::kStartOfData ||
+ eventType == AliRawEventHeaderBase::kFormatError) {
+
+ WriteConditionsData(fmdReader);
+ Init();
+ sodread = kTRUE;
+ break;
+ }
+ }
+
+ InitContainer(diagFile);
+
+ if(!sodread)
+ AliWarning("No SOD event detected!");
+
int lastProgress = 0;
+
+
for(Int_t n =1;n <= GetRequiredEvents(); n++) {
if(!reader->NextEvent()) continue;
-
- SetCurrentEvent(*(reader->GetEventId()));
-
+ SetCurrentEvent(n);
digitArray->Clear();
fmdReader->ReadAdcs(digitArray);
- AliDebug(5, Form("In event # %d with %d entries",
- *(reader->GetEventId()), digitArray->GetEntriesFast()));
-
for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
+ fSeenDetectors[digit->Detector()-1] = kTRUE;
FillChannels(digit);
}
+
FinishEvent();
+
int progress = int((n *100)/ GetRequiredEvents()) ;
if (progress <= lastProgress) continue;
lastProgress = progress;
std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
+
}
-
+
AliInfo(Form("Looped over %d events",GetCurrentEvent()));
WriteHeaderToFile();
for(UShort_t det=1;det<=3;det++) {
+ if (!fSeenDetectors[det-1]) continue;
std::cout << "FMD" << det << std::endl;
- UShort_t FirstRing = (det == 1 ? 1 : 0);
- for (UShort_t ir = FirstRing; ir < 2; ir++) {
+ UShort_t firstRing = (det == 1 ? 1 : 0);
+ for (UShort_t ir = firstRing; ir < 2; ir++) {
Char_t ring = (ir == 0 ? 'O' : 'I');
UShort_t nsec = (ir == 0 ? 40 : 20);
UShort_t nstr = (ir == 0 ? 256 : 512);
std::cout << '.' << std::flush;
}
if(fSaveHistograms)
- diagFile->Flush();
+ diagFile->Flush();
std::cout << "done" << std::endl;
}
}
-
+
if(fOutputFile.is_open()) {
fOutputFile.write("# EOF\n",6);
fOutputFile.close();
}
+ Terminate(diagFile);
+
if(fSaveHistograms ) {
+
AliInfo("Closing diagnostics file - please wait ...");
// diagFile->Write();
diagFile->Close();
AliInfo("done");
+
}
}
//_____________________________________________________________________
void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
{
+ //Prepare container for diagnostics
TObjArray* detArray;
TObjArray* ringArray;
TObjArray* sectorArray;
}
//_____________________________________________________________________
-void AliFMDBaseDA::WriteConditionsData()
+void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
{
+ //Write the conditions data to file
AliFMDParameters* pars = AliFMDParameters::Instance();
fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
+ TDatime now;
+ fConditionsFile << "# This file created from run number " << fRunno
+ << " at " << now.AsString() << std::endl;
- // fConditionsFile.write("# Sample Rate, timebins \n",25);
-
- // Sample Rate
-
- UInt_t defSampleRate = 4;
- UInt_t sampleRateFromSOD;
- //UInt_t timebins = 544;
AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
- for(UShort_t det=1;det<=3;det++) {
- UShort_t FirstRing = (det == 1 ? 1 : 0);
- for (UShort_t ir = FirstRing; ir < 2; ir++) {
- Char_t ring = (ir == 0 ? 'O' : 'I');
- UShort_t nsec = (ir == 0 ? 40 : 20);
- UShort_t nstr = (ir == 0 ? 256 : 512);
- for(UShort_t sec =0; sec < nsec; sec++) {
- for(UShort_t strip = 0; strip < nstr; strip++) {
- sampleRateFromSOD = defSampleRate;
- sampleRate->Set(det,ring,sec,strip,sampleRateFromSOD);
- fConditionsFile << det << ','
- << ring << ','
- << sec << ','
- << strip << ','
- << "samplerate" << ','
- << sampleRateFromSOD << "\n";
- }
- }
- }
- }
-
- pars->SetSampleRate(sampleRate);
+ AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
+ fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
+ fSeenDetectors);
+
+ sampleRate->WriteToFile(fConditionsFile, fSeenDetectors);
+ stripRange->WriteToFile(fConditionsFile, fSeenDetectors);
+
+
// Zero Suppresion
// Strip Range
- // Gain Relevant stuff
-
- UShort_t defPulseSize = 32 ;
- UShort_t defPulseLength = 100 ;
- UShort_t pulseSizeFromSOD;
- UShort_t pulseLengthFromSOD;
+ fConditionsFile.write("# Gain Events \n",15);
- fPulseSize.Reset(defPulseSize);
- fPulseLength.Reset(defPulseLength);
-
- for(UShort_t det=1;det<=3;det++)
- for(UShort_t iring=0;iring<=1;iring++)
- for(UShort_t board=0;board<=1;board++) {
- pulseSizeFromSOD = defPulseSize;
- pulseLengthFromSOD = defPulseLength;
-
- fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
- fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
+ for(UShort_t det=1; det<=3;det++) {
+ if (!fSeenDetectors[det-1]) {
+ continue;
+ }
+ UShort_t firstring = (det == 1 ? 1 : 0);
+ for(UShort_t iring = firstring; iring <=1;iring++) {
+ Char_t ring = (iring == 1 ? 'I' : 'O');
+ for(UShort_t board =0 ; board <=1; board++) {
+
+ Int_t idx = GetHalfringIndex(det,ring,board);
+
+ fConditionsFile << det << ','
+ << ring << ','
+ << board << ','
+ << fPulseLength.At(idx) << "\n";
+
}
-
+ }
+ }
- // fConditionsFile << defSampleRate << ','
- // << timebins <<"\n";
+ fConditionsFile.write("# Gain Pulse \n",14);
+ for(UShort_t det=1; det<=3;det++) {
+ if (!fSeenDetectors[det-1]) {
+ continue;
+ }
+ UShort_t firstring = (det == 1 ? 1 : 0);
+ for(UShort_t iring = firstring; iring <=1;iring++) {
+ Char_t ring = (iring == 1 ? 'I' : 'O');
+ for(UShort_t board =0 ; board <=1; board++) {
+
+ Int_t idx = GetHalfringIndex(det,ring,board);
+
+ fConditionsFile << det << ','
+ << ring << ','
+ << board << ','
+ << fPulseSize.At(idx) << "\n";
+
+ }
+ }
+ }
if(fConditionsFile.is_open()) {
fConditionsFile.write("# EOF\n",6);
}
//_____________________________________________________________________
-Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
-
+Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring,
+ UShort_t board) const
+{
+ // Get the index corresponding to a half-ring
+ //
+ // Parameters:
+ // det Detector number
+ // ring Ring identifier
+ // board Board number
+ //
+ // Return
+ // Internal index of the board
UShort_t iring = (ring == 'I' ? 1 : 0);
Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
- return index;
+ return index-2;
}
+//_____________________________________________________________________
+void AliFMDBaseDA::Rotate(const char* base, int max) const
+{
+ //
+ // Rotate a set of files. base is the basic name of the files.
+ // If the file base.max exists it is removed.
+ // If the file base.n exists (where n < max) it is renamed to
+ // base.(n-1).
+ // If the file base exists, it is renamed to base.1
+ //
+ // Parameters:
+ // base Base name of the files
+ // max Maximum number to keep (minus one for the current).
+
+ // Note: TSystem::AccessPathName returns false if the condition is
+ // fulfilled!
+
+ // Check if we have base.max, and if so, remove it.
+ TString testName(Form("%s.%d", base, max));
+ if (!gSystem->AccessPathName(testName.Data()))
+ gSystem->Unlink(testName.Data());
+
+ // Loop down from max-1 to 1 and move files
+ for (int i = max-1; i >= 1; i--) {
+ testName = Form("%s.%d", base, i);
+ if (!gSystem->AccessPathName(testName.Data())) {
+ TString newName(Form("%s.%d", base, i+1));
+ gSystem->Rename(testName.Data(), newName.Data());
+ }
+ }
+
+ // If we have the file base, rename it to base.1
+ testName = Form("%s", base);
+ if (!gSystem->AccessPathName(testName.Data())){
+ TString newName(Form("%s.%d", base, 1));
+ gSystem->Rename(testName.Data(), newName.Data());
+ }
+}
//_____________________________________________________________________