Moving changes in AliTestShuttle.cxx/h in $ALICE_ROOT/SHUTTLE/TestShuttle
[u/mrichter/AliRoot.git] / TRIGGER / AliTRIPreprocessor.cxx
CommitLineData
b48d2542 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$*/
17
18// Trigger preprocessor class.
19// According to the TriggerDetectorMask read from the logbook_trigger_clusters
20// DAQ table, the triggering detectors are identified, and the
21// corresponding procedure is called.
22// Data are stored in the OCDB, in /TRIGGER/<DET>/<level3>, where
23// <DET> correspond to the triggering detector,
24// and <level3> is defined in the detector procedure
25
26#include "AliTRIPreprocessor.h"
27
28#include "AliCDBMetaData.h"
29#include "AliCDBEntry.h"
30#include "AliLog.h"
31#include "AliITSTriggerConditions.h"
32
33#include <TTimeStamp.h>
34#include <TObjString.h>
35#include <TList.h>
36#include <TROOT.h>
37#include <TSystem.h>
38
39ClassImp(AliTRIPreprocessor)
40
41// names of detectors/systems in the DETECTORS_MAP in /date/db/detCodes.h
42const char* AliTRIPreprocessor::fgkDetectorsMapName[AliTRIPreprocessor::kNDetectorsMap] = {"SPD"/*0*/, "SDD"/*1*/, "SSD"/*2*/, "TPC"/*3*/, "TRD"/*4*/,
43 "TOF"/*5*/, "HMP"/*6*/, "PHS"/*7*/, "CPV"/*8*/, "PMD"/*9*/,
44 "MCH"/*10*/,"MTR"/*11*/,"FMD"/*12*/,"T00"/*13*/,"V00"/*14*/,
45 "ZDC"/*15*/,"ACO"/*16*/,"TRI"/*17*/,"EMC"/*18*/,"TST"/*19*/,
46 ""/*20*/, ""/*21*/, ""/*22*/, ""/*23*/, ""/*24*/,
47 ""/*25*/, ""/*26*/, ""/*27*/, ""/*28*/, "GRP"/*29*/,
48 "HLT"/*30*/};
49
50//______________________________________________________________________________________________
51AliTRIPreprocessor::AliTRIPreprocessor(AliShuttleInterface* shuttle) :
52 AliPreprocessor("TRI", shuttle),
53 fShuttle(shuttle)
54
55{
56 //
57 // constructor
58 //
59
60 AddRunType("PHYSICS");
61}
62
63//______________________________________________________________________________________________
64AliTRIPreprocessor::~AliTRIPreprocessor()
65{
66 //
67 // destructor
68 //
69}
70
71//______________________________________________________________________________________________
72void AliTRIPreprocessor::Initialize(Int_t run, UInt_t startTime,
73 UInt_t endTime)
74{
75
76 //
77 // Initialize preprocessor
78 //
79
80 AliPreprocessor::Initialize(run, startTime, endTime);
81
82 Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
83 TTimeStamp(startTime).AsString(),
84 TTimeStamp(endTime).AsString()));
85
86}
87
88//______________________________________________________________________________________________
89Bool_t AliTRIPreprocessor::ProcessDCS()
90{
91 //
92 // DCS data are never needed
93 //
94
95 return kFALSE;
96}
97
98//______________________________________________________________________________________________
99UInt_t AliTRIPreprocessor::Process(TMap* /*dcsAliasMap*/)
100{
101
102 // Procees function:
103 // After reading the TriggerDetectorMask, the
104 // corresponding triggering detector procedures to
105 // process the trigger data are called.
106
107 typedef Short_t (AliTRIPreprocessor::*AliProcessTriggerData)();
108 const AliProcessTriggerData processTriggerDataArray[AliTRIPreprocessor::kNDetectorsMap]= {
109 &AliTRIPreprocessor::ProcessSPDTriggerData,
110 0,
111 0,
112 0,
113 0,
114 &AliTRIPreprocessor::ProcessTOFTriggerData,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
115
116
117 // getting the list of triggering detectors from DAQ logbook
118
119 TString triggerDetectorMask = (TString)GetTriggerDetectorMask();
120 Int_t result=0;
121 if (!triggerDetectorMask.IsNull()){
122 Int_t length = triggerDetectorMask.Length();
123 Log(Form("mask = %s", triggerDetectorMask.Data()));
124 for (Int_t i = 0; i<length; i++){
125 AliDebug(2,Form("%d-th bit = %c in index %d",i,triggerDetectorMask[length-1-i],length-1-i));
126 if (triggerDetectorMask[length-1-i] == '1'){
127 AliInfo(Form("Processing Trigger data for %s",fgkDetectorsMapName[i]));
128 result+=(this->*processTriggerDataArray[i])();
129 }
130 }
131 }
132
133 // result should be 0 to end successfully
134
135 return result;
136
137}
138//______________________________________________________________________________________________
139Short_t AliTRIPreprocessor::ProcessSPDTriggerData()
140{
141 //
142 // Processing SPD Trigger Data
143 //
144
145 Log("************** Processing SPD Trigger data... **************");
146
147 // Read new conditions from dcs fxs
148 AliITSTriggerConditions* newCond = new AliITSTriggerConditions();
149 TString fxsID = "PITConditions";
150 TList* list = GetFileSources(kDCS, fxsID.Data());
151 if (!list) {
152 AliError("FXS file not found.");
153 return 1;
154 }
155 UInt_t nFiles = 0;
156 while (list->At(nFiles)!=NULL) {
157 TObjString* fileNameEntry = (TObjString*) list->At(nFiles);
158 TString fileName = GetFile(kDCS, fxsID.Data(), fileNameEntry->GetString().Data());
159 if (fileName.IsNull()) {
160 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
161 return 1;
162 }
163 if (nFiles==0) newCond->ReadFromTextFile(fileName.Data());
164 nFiles++;
165 }
166 if (nFiles!=1) {
167 AliWarning(Form("Found %d files with id %s (expected exactly 1).",nFiles,fxsID.Data()));
168 }
169
170 // Read old conditions from ocdb
171 AliITSTriggerConditions* oldCond = NULL;
172 AliCDBEntry* pitCond = GetFromOCDB("SPD", "PITConditions");
173 if (pitCond) {
174 oldCond = (AliITSTriggerConditions*) pitCond->GetObject();
175 if (!oldCond) {
176 AliError("AliCDBEntry::GetObject() returned NULL.");
177 return 1;
178 }
179 }
180 else {
181 Log("Old conditions not found in database.");
182 }
183
184 // Do we need to update db?
185 Bool_t doUpdate = kTRUE;
186 if (oldCond) {
187 // compare to see if there were any changes...
188 if (newCond->IsEqualTo(oldCond)) {
189 Log("Old conditions equal to new conditions. Do nothing.");
190 doUpdate = kFALSE;
191 }
192 }
193
194 if (doUpdate) {
195 // store new conditions in ocdb
196 AliCDBMetaData metaData;
197 metaData.SetResponsible("Henrik Tydesjo");
198 metaData.SetComment("Created by Trigger PreProcessor");
199 if (!Store("SPD", "PITConditions", newCond, &metaData, 0, kTRUE)) {
200 Log("Failed to store conditions data.");
201 return 1;
202 }
203 Log("Database updated.");
204 }
205
206 delete newCond;
207
208 Log("************************* ...done.*************************");
209
210 return 0; // 0 means success
211
212}
213//______________________________________________________________________________________________
214Short_t AliTRIPreprocessor::ProcessTOFTriggerData()
215{
216 //
217 // Processing TOF Trigger Data
218 //
219
220 Log("************** Processing TOF Trigger data... **************");
221 Log("************************* ...done.*************************");
222 return 0;
223}
224
225