]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPreprocessorSPD.cxx
SPD pre-processor update (H. Tydesjo)
[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
54   // *** REFERENCE DATA ***
55
56 // OLD algorithm (commented out)!!!
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   // Store the container files as reference data (one file for each equipment)
76   for (UInt_t eq=0; eq<20; eq++) {
77     Char_t id[20];
78     sprintf(id,"SPD_reference_%d",eq);
79     TList* list = GetFileSources(kDAQ,id); // (the id should be unique, so always 1 file)
80     if (list) {
81       TObjString* fileNameEntry = (TObjString*) list->First();
82       if (fileNameEntry!=NULL) {
83         TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
84         Char_t refCAT[10];
85         sprintf(refCAT,"SPDref_eq_%d.root",eq);
86         if (!StoreReferenceFile(fileName.Data(),refCAT)) {
87           return 1;
88         }
89       }
90     }
91   }
92
93
94   // *** NOISY DATA ***
95
96 // OLD algorithm (commented out)!!!
97 // ***********************************************************
98 //  // Read old calibration
99 //  AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy");
100 //  TObjArray* spdEntry;
101 //  if(cdbEntry) {
102 //    spdEntry = (TObjArray*)cdbEntry->GetObject();
103 //    if(!spdEntry) return 0;
104 //  }
105 //  else {
106 //    Log(Form("Old calibration not found in database. A fresh one will be created."));
107 //    // Create fresh calibration
108 //    spdEntry = new TObjArray(240);
109 //    for(Int_t module=0;module<240;module++){
110 //      AliITSCalibrationSPD* cal = new AliITSCalibrationSPD();
111 //      spdEntry->Add(cal);
112 //    }
113 //    spdEntry->SetOwner(kTRUE);
114 //  }
115 // ***********************************************************
116
117   // Read old calibration
118   AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy");
119   TObjArray* spdEntry;
120   if(cdbEntry) {
121     spdEntry = (TObjArray*)cdbEntry->GetObject();
122     if(!spdEntry) return 1;
123   }
124   else {
125     Log("Old calibration not found in database. This is required for further processing.");
126     return 1;
127   }
128
129   TString pwd = gSystem->pwd();  // remember the working directory, to cd back later
130   TString tempDir = Form("%s",AliShuttleInterface::GetShuttleTempDir());
131
132   // Retrieve and unpack tared calibration files from FXS
133   TList* list = GetFileSources(kDAQ,"SPD_noisy");
134   if (list) {
135     UInt_t index = 0;
136     while (list->At(index)!=NULL) {
137       TObjString* fileNameEntry = (TObjString*) list->At(index);
138       TString fileName = GetFile(kDAQ, "SPD_noisy", fileNameEntry->GetString().Data());
139       gSystem->cd(tempDir.Data());
140       Char_t command[100];
141       sprintf(command,"tar -xf %s",fileName.Data());
142       gSystem->Exec(command);
143       index++;
144     }
145   }
146
147   gSystem->cd(pwd.Data());
148
149   // Update the database entries if needed
150   UInt_t nrUpdatedMods = 0;
151   AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
152   Char_t fileLoc[100];
153   sprintf(fileLoc,"%s",AliShuttleInterface::GetShuttleTempDir());
154   handler->SetFileLocation(fileLoc);
155   for (Int_t module=0; module<240; module++) {
156     handler->SetModuleNr(module);
157     if (handler->ReadFromFile()) {
158       ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrNoisy( handler->GetNrNoisy() );
159       ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNoisyList( handler->GetNoisyArray() );
160       nrUpdatedMods++;
161     }
162   }
163   delete handler;
164   if (nrUpdatedMods>0) {
165     Log(Form("Noisy lists for %d modules will be updated and stored...",nrUpdatedMods));
166     // Store the cdb entry
167     AliCDBMetaData metaData;
168     metaData.SetBeamPeriod(0);
169     metaData.SetResponsible("Henrik Tydesjo");
170     metaData.SetComment("Preprocessor test for SPD.");  
171     if (!Store("Calib", "SPDNoisy", spdEntry, &metaData, 0, kTRUE)) {
172       return 1;
173     }
174     //    delete spdEntry;
175     Log("Database updated.");
176   }
177
178   return 0; // 0 means success
179
180
181
182 }
183