]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDPreprocessor.cxx
Fixes from P2. Allow pre-setting cuts and factor in display.
[u/mrichter/AliRoot.git] / FMD / AliFMDPreprocessor.cxx
index 32374dd26de10440df0dc54e78ccf956fd6679d0..57fc71fedd3e7cd3407258e1c4e96295789064fc 100644 (file)
@@ -58,7 +58,7 @@
 // Latest changes by Christian Holm Christensen
 //
 
-// #include <iostream>
+ #include <iostream>
 
 #include <fstream>
 #include "AliFMDPreprocessor.h"
@@ -83,6 +83,18 @@ ClassImp(AliFMDPreprocessor)
 ;
 #endif 
 
+
+//____________________________________________________
+AliFMDPreprocessor::AliFMDPreprocessor(AliShuttleInterface* shuttle)
+  : AliPreprocessor("FMD", shuttle)
+{
+  AddRunType("PHYSICS");
+  AddRunType("STANDALONE");
+  AddRunType("PEDESTAL");
+  AddRunType("GAIN");
+}
+
+
 //____________________________________________________
 Bool_t AliFMDPreprocessor::GetAndCheckFileSources(TList*&     list,
                                                  Int_t       system, 
@@ -130,44 +142,52 @@ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
   Bool_t resultRange = kTRUE;
   Bool_t resultRate  = kTRUE;
   Bool_t resultZero  = kTRUE;
-
+  Bool_t infoCalib   = kTRUE;
   // Do we need this ?
   // if(!dcsAliasMap) return 1;
   // 
   // Invoking the cdb manager and the FMD parameters class
   // AliCDBManager* cdb   = AliCDBManager::Instance();
-  // cdb->SetDefaultStorage("local://$ALICE_ROOT");
+  // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
   // cdb->SetRun(0);
   AliFMDParameters* pars = AliFMDParameters::Instance();
   pars->Init(this, false, AliFMDParameters::kAltroMap);
-
   // This is if the SOR contains Fee parameters, and we run a DA to
   // extract these parameters.   The same code could work if we get
   // the information from DCS via the FXS 
   TList* files = 0;
-  // GetAndCheckFileSources(files, kDAQ,"info");
-  // if (!files) return 1;
   AliFMDCalibSampleRate*      calibRate  = 0;
   AliFMDCalibStripRange*      calibRange = 0;
   AliFMDCalibZeroSuppression* calibZero  = 0;
-  GetInfoCalibration(files, calibRate, calibRange, calibZero);
-  // Disabled for now. 
-  // resultRate  = (!calibRate  ? kFALSE : kTRUE);
-  // resultRange = (!calibRange ? kFALSE : kTRUE);
-  // resultZero  = (!calibZero  ? kFALSE : kTRUE);
+  
+  if (GetAndCheckFileSources(files, kDAQ,pars->GetConditionsShuttleID()))
+    infoCalib = GetInfoCalibration(files, calibRate, calibRange, calibZero);
+  resultRate  = (!calibRate  ? kFALSE : kTRUE);
+  resultRange = (!calibRange ? kFALSE : kTRUE);
+  resultZero  = (!calibZero  ? kFALSE : kTRUE);
+  
 
-  // Gt the run type 
+  // Get the run type 
   TString runType(GetRunType()); 
 
   //Creating calibration objects
   AliFMDCalibPedestal* calibPed  = 0;
   AliFMDCalibGain*     calibGain = 0;
-  if (runType.Contains("PEDESTAL", TString::kIgnoreCase) && 
-      GetAndCheckFileSources(files, kDAQ, "pedestal"))  
-    resultPed = (!(calibPed = GetPedestalCalibration(files)) ? kFALSE : kTRUE);
-  if (runType.Contains("PULSER", TString::kIgnoreCase) && 
-      GetAndCheckFileSources(files, kDAQ, "gain"))
-    resultGain = (!(calibGain = GetGainCalibration(files)) ? kFALSE : kTRUE);
+  if (runType.Contains("PEDESTAL", TString::kIgnoreCase)) { 
+    if (GetAndCheckFileSources(files, kDAQ, pars->GetPedestalShuttleID())) {
+      if(files->GetSize())
+       calibPed = GetPedestalCalibration(files);
+    }
+    resultPed = (calibPed ? kTRUE : kFALSE);
+  }
+  if (runType.Contains("GAIN", TString::kIgnoreCase)) {
+    if (GetAndCheckFileSources(files, kDAQ, pars->GetGainShuttleID())) {
+      if(files->GetSize())
+       calibGain = GetGainCalibration(files);
+    }
+    resultGain = (calibGain ? kTRUE : kFALSE);
+  }
   
   //Storing Calibration objects  
   AliCDBMetaData metaData;
@@ -192,16 +212,13 @@ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
     delete calibRate;
   }
   if(calibZero) { 
-    resultZero = Store("Calib","ZeroSuppression", calibZero, &metaData,0,kTRUE);
+    resultZero = Store("Calib","ZeroSuppression", calibZero,&metaData,0,kTRUE);
     delete calibZero;
   }
 
-#if 0
-  // Disabled until we implement GetInfoCalibration properly
   Bool_t success = (resultPed && resultGain  && resultRange && 
-                   resultRate  && resultZero);
-#endif
-  Bool_t success = resultPed && resultGain;
+                   resultRate  && resultZero && infoCalib);
+  
   Log(Form("FMD preprocessor was %s", (success ? "successful" : "failed")));
   return (success ? 0 : 1);
 }
@@ -221,24 +238,26 @@ AliFMDPreprocessor::GetInfoCalibration(TList* files,
   //     z     On return, newly allocated object 
   // Return: 
   //     kTRUE on success
-  if (!files) return kTRUE; // Should really be false
-  if (files->GetEntries() <= 0) return kTRUE;
+  if (!files) return kFALSE; // Should really be false
+  if (files->GetEntries() <= 0) return kFALSE;
   
   s = new AliFMDCalibSampleRate();
   r = new AliFMDCalibStripRange();
   z = new AliFMDCalibZeroSuppression();
   
-  // AliFMDParameters*    pars     = AliFMDParameters::Instance();
+  AliFMDParameters*    pars     = AliFMDParameters::Instance();
   TIter                iter(files);
   TObjString*          fileSource;
 
   while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
-    const Char_t* filename = GetFile(kDAQ, "info", fileSource->GetName());
+    const Char_t* filename = GetFile(kDAQ, pars->GetConditionsShuttleID(), fileSource->GetName());
     std::ifstream in(filename);
     if(!in) {
       Log(Form("File %s not found!", filename));
       continue;
     }
+    s->ReadFromFile(in);
+    r->ReadFromFile(in);
   }
   return kTRUE;
 }
@@ -263,7 +282,7 @@ AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
   TObjString*          fileSource;
   
   while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
-    const Char_t* filename = GetFile(kDAQ, "pedestal", fileSource->GetName());
+    const Char_t* filename = GetFile(kDAQ, pars->GetPedestalShuttleID(), fileSource->GetName());
     std::ifstream in(filename);
     if(!in) {
       Log(Form("File %s not found!", filename));
@@ -274,7 +293,7 @@ AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
     TString header;
     header.ReadLine(in);
     header.ToLower();
-    if(!header.Contains("pedestal")) {
+    if(!header.Contains(pars->GetPedestalShuttleID())) {
       Log("File header is not from pedestal!");
       continue;
     }
@@ -285,37 +304,41 @@ AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
     header.ReadLine(in);
     
     // Loop until EOF
-    while(!in.eof()) {
+    while(in.peek()!=EOF) {
       if(in.bad()) { 
        Log(Form("Bad read at line %d in %s", lineno, filename));
        break;
       }
-      UInt_t ddl=2, board, chip, channel, strip, tb;
+      UShort_t det, sec, strip;
+      Char_t ring;
       Float_t ped, noise, mu, sigma, chi2ndf;
-      Char_t c[10];
+      Char_t c[8];
          
-      in // >> ddl      >> c[0] 
-        >> board    >> c[1]
-        >> chip     >> c[2]
-        >> channel  >> c[3]
-        >> strip    >> c[4]
-        >> tb       >> c[5]
-        >> ped      >> c[6]
-        >> noise    >> c[7]
-        >> mu       >> c[8]
-        >> sigma    >> c[9]
+      in >> det      >> c[0] 
+        >> ring     >> c[1]
+        >> sec      >> c[2]
+        >> strip    >> c[3]
+        >> ped      >> c[4]
+        >> noise    >> c[5]
+        >> mu       >> c[6]
+        >> sigma    >> c[7]
         >> chi2ndf;
       lineno++;
+      
       // Ignore trailing garbage 
-      if (strip > 127) continue;
+      // if (strip > 127) continue;
       
+      //Setting DDL to comply with the FMD in DAQ
+      // UInt_t FmdDDLBase = 3072; 
+      // ddl = ddl - FmdDDLBase;
       //Setting the pedestals via the hardware address
-      UShort_t det, sec, str;
-      Char_t ring;
-         
-      pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
-      strip += str;
+      
+      
+      // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
+      // strip += str;
+     
       calibPed->Set(det,ring,sec,strip,ped,noise);
+     
     }
   }
   return calibPed;
@@ -339,7 +362,7 @@ AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
   TIter             iter(gainFiles);
   TObjString*       fileSource;
   while((fileSource = dynamic_cast<TObjString *>(iter.Next()))) {
-    const Char_t* filename = GetFile(kDAQ, "gain", fileSource->GetName());
+    const Char_t* filename = GetFile(kDAQ, pars->GetGainShuttleID(), fileSource->GetName());
     std::ifstream in(filename);
     if(!in) {
       Log(Form("File %s not found!", filename));
@@ -350,7 +373,7 @@ AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
     TString header;
     header.ReadLine(in);
     header.ToLower();
-    if(!header.Contains("gain")) {
+    if(!header.Contains(pars->GetGainShuttleID())) {
       Log("File header is not from gain!");
       continue;
     }
@@ -361,33 +384,35 @@ AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
 
     int lineno  = 2;
     // Read until EOF 
-    while(!in.eof()) {
+    while(in.peek()!=EOF) {
       if(in.bad()) { 
        Log(Form("Bad read at line %d in %s", lineno, filename));
        break;
       }
-      UInt_t ddl=2, board, chip, channel, strip;
+      UShort_t det, sec, strip;
+      Char_t ring;
+      
       Float_t gain,error,  chi2ndf;
-      Char_t c[7];
-             
-      in // >> ddl      >> c[0] 
-        >> board    >> c[1]
-        >> chip     >> c[2]
-        >> channel  >> c[3]
-        >> strip    >> c[4]
-        >> gain     >> c[5]
-        >> error    >> c[6]
+      Char_t c[6];
+      
+      in >> det      >> c[0] 
+        >> ring     >> c[1]
+        >> sec      >> c[2]
+        >> strip    >> c[3]
+        >> gain     >> c[4]
+        >> error    >> c[5]
         >> chi2ndf;
       lineno++;
       // Ignore trailing garbage
-      if(strip > 127) continue;
+      //if(strip > 127) continue;
       
+      //Setting DDL to comply with the FMD in DAQ
+      // UInt_t FmdDDLBase = 3072; 
+      // ddl = ddl - FmdDDLBase;
       //Setting the pedestals via the hardware address
-      UShort_t det, sec, str;
-      Char_t ring;
-      pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
+      //   pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
 
-      strip += str;
+      // strip += str;
       calibGain->Set(det,ring,sec,strip,gain);
     }
   }