]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/TestPreprocessor.C
PMD DA informations : satya
[u/mrichter/AliRoot.git] / PMD / TestPreprocessor.C
1 /* $Id$ */
2
3 // This class runs the test preprocessor
4 // It uses AliTestShuttle to simulate a full Shuttle process
5
6 // The input data is created in the functions
7 // CreateDCSAliasMap() creates input that would in the same way come from DCS
8 // ReadDCSAliasMap() reads from a file
9 // CreateInputFilesMap() creates a list of local files,
10 // that can be accessed by the shuttle
11
12 void TestPreprocessor()
13 {
14     // load library
15     gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle.so");
16
17     // create AliTestShuttle instance
18     // The parameters are run, startTime, endTime
19     AliTestShuttle* shuttle = new AliTestShuttle(0, 0, 1);
20
21
22 //    printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
23
24     // TODO if needed, change location of OCDB and Reference test folders
25     // by default they are set to $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB
26     // and TestReference
27
28     AliTestShuttle::SetMainCDB("local://TestCDB");
29     AliTestShuttle::SetMainRefStorage("local://TestReference");
30     
31     printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
32     printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
33     
34     
35     // TODO(1)
36     //
37     // The shuttle can read DCS data, if the preprocessor should be
38     // tested to process DCS data,
39     // some fake data has to be created.
40     //
41     // The "fake" input data can be taken using either (a) or (b):
42     // (a) data from a file: Use ReadDCSAliasMap()
43     //     the format of the file is explained in ReadDCSAliasMap()
44     //     To use it uncomment the following line:
45     //
46     // TMap* dcsAliasMap = ReadDCSAliasMap();
47     //
48     // (b) generated in this macro: Use CreateDCSAliasMap() and
49     //     its documentation
50     //     To use it uncomment the following line:
51     //
52
53     TMap* dcsAliasMap = CreateDCSAliasMap();
54
55     // now give the alias map to the shuttle
56
57     shuttle->SetDCSInput(dcsAliasMap);
58
59     // TODO(2)
60     //
61     // The shuttle can also process files that originate from DCS, DAQ and HLT.
62     // To test it, we provide some local files and locations where these would
63     // be found when
64     // the online machinery would be there.
65     // In real life this functions would be produces by the sub-detectors
66     // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
67     //
68     // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
69     // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
70     // In this example we add a file originating from the GDC with the id PEDESTALS
71     // Three files originating from different LDCs but with the same id are also added
72     // Note that the test preprocessor name is TPC. The name of the detector's preprocessor must follow
73     // the "online" naming convention ALICE-INT-2003-039.
74     
75     shuttle->AddInputFile(AliShuttleInterface::kDAQ, "PMD", "PMD_PED.root", "GDC0", "PMD_PED.root");
76     shuttle->AddInputFile(AliShuttleInterface::kDAQ, "PMD", "PMDGAINS.root", "GDC0", "PMDGAINS.root");
77     shuttle->AddInputFile(AliShuttleInterface::kDAQ, "PMD", "PMD_HOT.root", "GDC0", "PMD_HOT.root");
78     
79     // TODO(3)
80     //
81     // The shuttle can read run type stored in the DAQ logbook.
82     // To test it, we must provide the run type manually. They will be retrieved in the preprocessor
83     // using GetRunType function.
84
85     shuttle->SetInputRunType("PHYSICS");
86
87     // TODO(4)
88     //
89     // The shuttle can read run parameters stored in the DAQ run logbook.
90     // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
91     // using GetRunParameter function.
92
93     shuttle->AddInputRunParameter("totalEvents", "30000");
94     shuttle->AddInputRunParameter("NumberOfGDCs", "15");
95
96     // TODO(5)
97     //
98     // The shuttle can query condition parameters valid from the current run from the OCDB
99     // To test it, we must first store the object into the OCDB. It will be retrieved in the preprocessor
100     // using GetFromOCDB function.
101     
102     TObjString obj("This is a condition parameter stored in OCDB");
103     AliCDBId id("PMD/Calib/Hot", 0, AliCDBRunRange::Infinity());
104     AliCDBMetaData md;
105     AliCDBEntry entry(&obj, id, &md);
106
107     shuttle->AddInputCDBEntry(&entry);
108
109     
110     // TODO(6)
111     // Create the preprocessor that should be tested, it registers
112     // itself automatically to the shuttle
113     // AliPreprocessor* test = new AliTestPreprocessor(shuttle);
114     AliPMDPreprocessor* test = new AliPMDPreprocessor(shuttle);
115
116     // Test the preprocessor
117     shuttle->Process();
118     
119     // TODO(7)
120     // In the preprocessor AliShuttleInterface::Store should be called to put the final
121     // data to the CDB. To check if all went fine have a look at the files produced in
122     // $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/SHUTTLE/Data
123     //
124     // Check the file which should have been created
125     AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
126         ->Get("PMD/Calib/Hot", 7);
127     if (!chkEntry)
128     {
129         printf("The file is not there. Something went wrong.\n");
130         return;
131     }
132     
133     AliPMDHotData* output = dynamic_cast<AliPMDHotData*> (chkEntry->GetObject());
134     // If everything went fine, draw the result
135     if (output)
136         output->Print();
137 }
138
139 TMap* CreateDCSAliasMap()
140 {
141     // Creates a DCS structure
142     // The structure is the following:
143     // TMap (key --> value)
144     //     <DCSAlias> --> <valueList>
145     //     <DCSAlias> is a string
146     //     <valueList> is a TObjArray of AliDCSValue
147     //     An AliDCSValue consists of timestamp and a value in form
148     //     of a AliSimpleValue
149     
150     // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
151     // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
152
153     TMap* aliasMap = new TMap;
154     aliasMap->SetOwner(1);
155     
156     TRandom random;
157
158     for(int nAlias=0;nAlias<6;nAlias++)
159     {
160         TObjArray* valueSet = new TObjArray;
161         valueSet->SetOwner(1);
162         
163         TString aliasName="DCSAlias";
164         aliasName += nAlias;
165         //printf("\n\n alias: %s\n\n",aliasName.Data());
166         
167         for (int timeStamp=0;timeStamp<1000;timeStamp+=10)
168         {
169             AliDCSValue* dcsVal = new AliDCSValue((Float_t) (random.Gaus()+5*nAlias), timeStamp);
170             //printf("%s\n",dcsVal->ToString().Data());
171             valueSet->Add(dcsVal);
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()->GetStorage(AliShuttleInterface::GetMainCDB())
188         ->Get("DET/DCS/Data", 0);
189     return dynamic_cast<TMap*> (entry->GetObject());
190 }
191
192 void WriteDCSAliasMap()
193 {
194     // This writes the output from CreateDCSAliasMap to a CDB file
195     
196     TMap* dcsAliasMap = CreateDCSAliasMap();
197     
198     AliCDBMetaData metaData;
199     metaData.SetBeamPeriod(0);
200     metaData.SetResponsible("Responsible person");
201     metaData.SetComment("Test object for TestPreprocessor.C");
202
203     AliCDBId id("DET/DCS/Data", 0, 0);
204     
205     // look into AliTestShuttle's CDB main folder
206     
207     AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
208         ->Put(dcsAliasMap, id, &metaData);
209 }