]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPreprocessorSPD.cxx
Speed improvements of 3D e Z SPD vertexers. Protection needed for Pb-Pb events added...
[u/mrichter/AliRoot.git] / ITS / AliITSPreprocessorSPD.cxx
1 ///////////////////////////////////////////////
2 //  Author: Henrik Tydesjo                   //
3 //  Preprocessor Class for the SPD           //
4 //                                           //
5 ///////////////////////////////////////////////
6
7 #include "AliITSPreprocessorSPD.h"
8 #include "AliITSCalibrationSPD.h"
9 #include "AliITSOnlineCalibrationSPD.h"
10 #include "AliITSOnlineCalibrationSPDhandler.h"
11 #include "AliCDBManager.h"
12 #include "AliCDBStorage.h"
13 #include "AliCDBEntry.h"
14 #include "AliCDBMetaData.h"
15 #include "AliShuttleInterface.h"
16 #include "AliLog.h"
17 #include <TTimeStamp.h>
18 #include <TObjString.h>
19 #include <TSystem.h>
20
21 ClassImp(AliITSPreprocessorSPD)
22
23 //______________________________________________________________________________________________
24 AliITSPreprocessorSPD::AliITSPreprocessorSPD(AliShuttleInterface* shuttle) :
25   AliPreprocessor("SPD", shuttle)
26 {
27   // constructor
28 }
29
30 //______________________________________________________________________________________________
31 AliITSPreprocessorSPD::~AliITSPreprocessorSPD()
32 {
33   // destructor
34 }
35
36 //______________________________________________________________________________________________
37 void AliITSPreprocessorSPD::Initialize(Int_t run, UInt_t startTime,
38         UInt_t endTime)
39 {
40   // initialize
41   AliPreprocessor::Initialize(run, startTime, endTime);
42
43   AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
44                TTimeStamp(startTime).AsString(),
45                TTimeStamp(endTime).AsString()));
46 }
47
48 //______________________________________________________________________________________________
49 UInt_t AliITSPreprocessorSPD::Process(TMap* dcsAliasMap)
50 {
51   // Do the actual preprocessing
52
53   UInt_t result = 1;
54
55
56 //  // *** REFERENCE DATA ***
57
58 //  // Store the container files as reference data (one for each equipment)
59 //  for (UInt_t eq=0; eq<20; eq++) {
60 //    Char_t id[20];
61 //    sprintf(id,"SPDref%d",eq);
62 //    TList* list = GetFileSources(kDAQ,id); // (the id is actually unique, so always 1 file)
63 //    if (list) {
64 //      TObjString* fileNameEntry = (TObjString*) list->First();
65 //      Char_t* fileName = (Char_t*) GetFile(kDAQ, id, fileNameEntry->GetString().Data());
66 //      AliITSOnlineSPDscan *scan = new AliITSOnlineSPDscan((Char_t*)fileName);
67 //      TObjArray* arr = scan->GetAsTObjArray();
68 //      Char_t refCAT[10];
69 //      sprintf(refCAT,"Ref%d",eq);
70 //      StoreReferenceData("SHUTTLE", refCAT, arr, &metaData, 0, 0);
71 //    }
72 //  }
73
74
75
76   // *** NOISY DATA ***
77
78   // Read old calibration
79   TString runStr = GetRunParameter("run");
80   Int_t run = atoi(runStr);
81   AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB());
82   if(!storage) return 0;
83   AliCDBEntry* cdbEntry = storage->Get("ITS/Calib/SPDNoisy", run);
84   TObjArray* spdEntry;
85   if(cdbEntry) {
86     spdEntry = (TObjArray*)cdbEntry->GetObject();
87     if(!spdEntry) return 0;
88   }
89   else {
90     Log(Form("Old calibration not found in database. A fresh one will be created."));
91     // Create fresh calibration
92     spdEntry = new TObjArray(240);
93     for(Int_t module=0;module<240;module++){
94       AliITSCalibrationSPD* cal = new AliITSCalibrationSPD();
95       spdEntry->Add(cal);
96     }
97     spdEntry->SetOwner(kTRUE);
98   }
99
100
101   TString pwd = gSystem->pwd();  // remember the working directory, to cd back later
102   TString tempDir = Form("%s",AliShuttleInterface::GetShuttleTempDir());
103
104   // Retrieve and unpack tared calibration files from FXS
105   TList* list = GetFileSources(kDAQ,"SPD_noisy");
106   if (list) {
107     UInt_t index = 0;
108     while (list->At(index)!=NULL) {
109       TObjString* fileNameEntry = (TObjString*) list->At(index);
110       TString fileName = GetFile(kDAQ, "SPD_noisy", fileNameEntry->GetString().Data());
111       gSystem->cd(tempDir.Data());
112       Char_t command[100];
113       sprintf(command,"tar -xf %s",fileName.Data());
114       gSystem->Exec(command);
115       index++;
116     }
117   }
118
119   gSystem->cd(pwd.Data());
120
121
122   // Update the database entries
123   UInt_t nrUpdatedMods = 0;
124   AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
125   Char_t fileLoc[100];
126   sprintf(fileLoc,"%s",AliShuttleInterface::GetShuttleTempDir());
127   handler->SetFileLocation(fileLoc);
128   for (Int_t module=0; module<240; module++) {
129     handler->SetModuleNr(module);
130     if (handler->ReadFromFile()) {
131       ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrNoisy( handler->GetNrNoisy() );
132       ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNoisyList( handler->GetNoisyArray() );
133       nrUpdatedMods++;
134     }
135   }
136   delete handler;
137
138   if (nrUpdatedMods>0) {
139     Log(Form("Noisy lists for %d modules updated.",nrUpdatedMods));
140
141     // Store the cdb entry
142     AliCDBMetaData metaData;
143     metaData.SetBeamPeriod(0);
144     metaData.SetResponsible("Henrik Tydesjo");
145     metaData.SetComment("Preprocessor test for SPD.");  
146     result = Store("Calib", "SPDNoisy", spdEntry, &metaData, 0, kTRUE);
147     delete spdEntry;
148     Log("Database updated.");
149   }
150
151   return result;
152
153
154
155 }
156