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