]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/TOFPreprocessor.C
Coding convention violations: suppression
[u/mrichter/AliRoot.git] / TOF / TOFPreprocessor.C
1 /* 
2 $Id$ 
3 */
4
5 // This class runs the test TOF preprocessor
6 // It uses AliTestShuttle to simulate a full Shuttle process
7
8 // The input data is created in the functions
9 //   CreateDCSAliasMap() creates input that would in the same way come from DCS
10 //   ReadDCSAliasMap() reads from a file
11 //   CreateInputFilesMap() creates a list of local files, that can be accessed by the shuttle
12
13 extern TBenchmark *gBenchmark;
14 void TOFPreprocessor(Char_t * RunType="PHYSICS")
15 {
16   gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle.so");
17
18   AliLog::SetClassDebugLevel("AliTOFPreprocessor",2);
19   // initialize location of CDB
20   AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
21   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");
22
23   // create AliTestShuttle instance
24   Int_t nrun = 7;
25   AliTestShuttle* shuttle = new AliTestShuttle(nrun, 30, 980);
26   //setting run type to physiscs
27   shuttle->SetInputRunType(RunType);
28   shuttle->SetTimeCreated(20);
29   shuttle->SetDCSQueryOffset(20);
30
31   // Generation of "fake" input DCS data
32   TMap* dcsAliasMap = CreateDCSAliasMap();  
33
34   // now give the alias map to the shuttle
35   shuttle->SetDCSInput(dcsAliasMap);   
36
37   // processing files. for the time being, the files are local.
38   shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "DELAYS", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Total.root");
39   shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "RUNLevel", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Partial.root");
40   shuttle->AddInputFile(AliTestShuttle::kDCS, "TOF", "TofFeeLightMap", "", "$ALICE_ROOT/TOF/ShuttleInput/TOFFEElight.20090616.102605.8000");
41   shuttle->AddInputFile(AliTestShuttle::kDCS, "TOF", "TofFeeMap", "", "$ALICE_ROOT/TOF/ShuttleInput/TOFFEE.20091217.194708.105517");
42
43   TString filename;
44   TString LDCname;
45   //char filename[100];
46   //char LDCname[5];
47
48   for (Int_t iLDC=0;iLDC<2;iLDC++){
49     filename.Form("$ALICE_ROOT/TOF/ShuttleInput/TOFoutPulserLDC_%02i.root",iLDC*2);
50     LDCname.Form("LDC%i",iLDC*2);
51     shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "PULSER", LDCname, filename);
52     filename.Form("$ALICE_ROOT/TOF/ShuttleInput/TOFoutNoiseLDC_%02i.root",iLDC*2);
53     LDCname.Form("LDC%i",iLDC*2);
54     shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "NOISE", LDCname, filename);
55   }
56   
57
58   // instantiation of the preprocessor
59   AliPreprocessor* pp = new AliTOFPreprocessor(shuttle);
60
61   // preprocessing
62   gBenchmark->Start("process");
63   shuttle->Process();
64   gBenchmark->Stop("process");
65   gBenchmark->Print("process");
66
67   // checking the file which should have been created  
68   AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())->Get("TOF/Calib/ParOnlineDelay", nrun);
69   if (!chkEntry)
70   {
71     printf("The file is not there. Something went wrong.\n");
72     return;
73   }
74
75   AliTOFDataDCS* output = dynamic_cast<AliTOFDataDCS*> (chkEntry->GetObject());
76   // If everything went fine, draw the result
77   if (output)
78     printf("Output found.\n");
79   //    output->Draw();
80   
81 }
82
83 TMap* CreateDCSAliasMap()
84 {
85   // Creates a DCS structure
86   // The structure is the following:
87   //   TMap (key --> value)
88   //     <DCSAlias> --> <valueList>
89   //     <DCSAlias> is a string
90   //     <valueList> is a TObjArray of AliDCSValue
91   //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
92
93   // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
94   // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
95
96   TMap* aliasMap = new TMap;
97   aliasMap->SetOwner(1);
98
99   TRandom random;
100   TDatime *datime = new TDatime();
101   Int_t time = datime->GetTime();
102   Int_t date = datime->GetDate();
103   Int_t pid  = gSystem->GetPid();
104   delete datime;
105   Int_t iseed = TMath::Abs(10000 * pid + time - date); 
106
107   //Float_t thrHVv=7.75, thrHVc=3, thrLVv=2.75, thrLVc=2.5,
108   //thrFEEthr=1.5, thrFEEt=10, thrTemp=35, thrPress=1000;
109   //Float_t tentHVv=6.75, tentHVc=2, tentLVv=1.75, tentLVc=1.5,
110   //  tentFEEthr=0.5, te    result=0;
111   //ntFEEt=20, tentTemp=25, tentPress=900;
112   //Float_t sigmaHVv=1, sigmaHVc=0.25, sigmaLVv=0.25, sigmaLVc=0.25,
113   //  sigmaFEEthr=0.05, sigmaFEEt=5, sigmaTemp=1, sigmaPress=10;
114
115   Float_t tentHVv=6500, tentHVi=80;
116   Float_t sigmaHVv=10, sigmaHVi=10;
117
118   Float_t tent=0, sigma=0, thr=0;
119   // to have all the aliases, decomment the following line:
120   Int_t NAliases=360, NHV=90;
121
122   // if not all the aliases are there, use this:
123   //Int_t NAliases=120, NHV=90;
124
125   for(int nAlias=0;nAlias<NAliases;nAlias++) {
126
127     TObjArray* valueSet = new TObjArray;
128     valueSet->SetOwner(1);
129
130     TString sindex;
131     TString aliasName;
132     if (nAlias<NHV){
133       aliasName = "tof_hv_vp_";
134       sindex.Form("%02i",nAlias);
135       aliasName += sindex;
136       //aliasName += nAlias;
137       tent=tentHVv;
138       sigma=sigmaHVv;
139       //      thr=thrHVv;
140     }
141     else if (nAlias<NHV*2){
142       //      aliasName = "HVvneg";
143       //aliasName += nAlias-NHV;
144       aliasName = "tof_hv_vn_";
145       sindex.Form("%02i",nAlias-NHV);
146       aliasName += sindex;
147       tent=-tentHVv;
148       sigma=-sigmaHVv;
149       //thr=-thrHVv;
150     }
151     else if (nAlias<NHV*3){
152       //      aliasName = "HVcpos";
153       //aliasName += nAlias-2*NHV;
154       aliasName = "tof_hv_ip_";
155       sindex.Form("%02i",nAlias-2*NHV);
156       aliasName += sindex;
157       tent=tentHVi;
158       sigma=sigmaHVi;
159       //thr=thrHVc;
160     }
161     else if (nAlias<NHV*4){
162       //      aliasName = "HVcneg";
163       //aliasName += nAlias-3*NHV;
164       aliasName = "tof_hv_in_";
165       sindex.Form("%02i",nAlias-3*NHV);
166       aliasName += sindex;
167       tent=-tentHVi;
168       sigma=-sigmaHVi;
169       //thr=-thrHVc;
170     }
171     // gauss generation of values 
172     for (int timeStamp=0;timeStamp<1000;timeStamp+=10){
173     //for (int timeStamp=0;timeStamp<1;timeStamp++){
174       Float_t gaussvalue = (Float_t) (random.Gaus(tent,sigma));
175       if (TMath::Abs(gaussvalue-tent)>sigma){
176         AliDCSValue* dcsVal = new AliDCSValue(gaussvalue, timeStamp);
177         valueSet->Add(dcsVal);
178       }
179     }
180
181     aliasMap->Add(new TObjString(aliasName), valueSet);
182   }
183
184   return aliasMap;
185 }
186
187 TMap* ReadDCSAliasMap()
188 {
189   // Open a file that contains DCS input data
190   // The CDB framework is used to open the file, this means the file is located
191   // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
192   // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
193   // An explanation of the structure can be found in CreateDCSAliasMap()
194
195   AliCDBEntry *entry = AliCDBManager::Instance()->Get("TOF/DCS/Data", 0);
196   return dynamic_cast<TMap*> (entry->GetObject());
197 }
198
199 void WriteDCSAliasMap()
200 {
201   // This writes the output from CreateDCSAliasMap to a CDB file
202
203   TMap* dcsAliasMap = CreateDCSAliasMap();
204
205   AliCDBMetaData metaData;
206         metaData.SetBeamPeriod(0);
207         metaData.SetResponsible("Chiara");
208         metaData.SetComment("Test object for TOFPreprocessor.C");
209
210   AliCDBId id("TOF/DCS/Data", 0, 0);
211
212   // initialize location of CDB
213   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
214
215   AliCDBManager::Instance()->Put(dcsAliasMap, id, &metaData);
216 }