]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPreprocessorSPD.cxx
DIPO 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
54   // *** CHECK RUN TYPE ***
55
56   TString runType = GetRunType();
57   if(runType != "SPD_STANDALONE_CALIBRATION") {
58     Log("Nothing to do");
59     return 0;
60   }
61
62
63   // *** REFERENCE DATA ***
64
65   // Store the container files as reference data (one file for each equipment)
66   for (UInt_t eq=0; eq<20; eq++) {
67     Char_t id[20];
68     sprintf(id,"SPD_reference_%d",eq);
69     TList* list = GetFileSources(kDAQ,id); // (the id should be unique, so always 1 file)
70     if (list) {
71       TObjString* fileNameEntry = (TObjString*) list->First();
72       if (fileNameEntry!=NULL) {
73         TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
74         Char_t refCAT[10];
75         sprintf(refCAT,"SPDref_eq_%d.root",eq);
76         if (!StoreReferenceFile(fileName.Data(),refCAT)) {
77           return 1;
78         }
79       }
80     }
81   }
82
83
84   // *** NOISY DATA ***
85
86   // Read old calibration
87   AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "CalibSPD");
88   TObjArray* spdEntry;
89   if(cdbEntry) {
90     spdEntry = (TObjArray*)cdbEntry->GetObject();
91     if(!spdEntry) return 1;
92   }
93   else {
94     Log("Old calibration not found in database. This is required for further processing.");
95     return 1;
96   }
97
98   TString pwd = gSystem->pwd();  // remember the working directory, to cd back later
99   TString tempDir = Form("%s",AliShuttleInterface::GetShuttleTempDir());
100
101   // Retrieve and unpack tared calibration files from FXS
102   TList* list = GetFileSources(kDAQ,"SPD_noisy");
103   if (list) {
104     UInt_t index = 0;
105     while (list->At(index)!=NULL) {
106       TObjString* fileNameEntry = (TObjString*) list->At(index);
107       TString fileName = GetFile(kDAQ, "SPD_noisy", fileNameEntry->GetString().Data());
108       gSystem->cd(tempDir.Data());
109       Char_t command[100];
110       sprintf(command,"tar -xf %s",fileName.Data());
111       gSystem->Exec(command);
112       index++;
113     }
114   }
115
116   gSystem->cd(pwd.Data());
117
118   // Update the database entries if needed
119   UInt_t nrUpdatedMods = 0;
120   AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
121   Char_t fileLoc[100];
122   sprintf(fileLoc,"%s",AliShuttleInterface::GetShuttleTempDir());
123   handler->SetFileLocation(fileLoc);
124   for (Int_t module=0; module<240; module++) {
125     handler->SetModuleNr(module);
126     if (handler->ReadFromFile()) {
127       ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrNoisy( handler->GetNrNoisy() );
128       ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNoisyList( handler->GetNoisyArray() );
129       nrUpdatedMods++;
130     }
131   }
132   delete handler;
133   if (nrUpdatedMods>0) {
134     Log(Form("Noisy lists for %d modules will be updated and stored...",nrUpdatedMods));
135     // Store the cdb entry
136     AliCDBMetaData metaData;
137     metaData.SetBeamPeriod(0);
138     metaData.SetResponsible("Henrik Tydesjo");
139     metaData.SetComment("Preprocessor test for SPD.");  
140     if (!Store("Calib", "CalibSPD", spdEntry, &metaData, 0, kTRUE)) {
141       return 1;
142     }
143     //    delete spdEntry;
144     Log("Database updated.");
145   }
146
147   return 0; // 0 means success
148
149
150
151 }
152