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