]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - SHUTTLE/TestShuttle/AliTestShuttle.cxx
Printout fixed.
[u/mrichter/AliRoot.git] / SHUTTLE / TestShuttle / AliTestShuttle.cxx
... / ...
CommitLineData
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/*
17$Log$
18Revision 1.14 2007/08/06 12:25:47 acolla
19Function Bool_t GetHLTStatus added to preprocessor. It returns the status of HLT
20read from the run logbook.
21TestShuttle setup updated.
22TRD data point configuration updated.
23
24Revision 1.13 2007/05/30 06:35:21 jgrosseo
25Adding functionality to the Shuttle/TestShuttle:
26o) Function to retrieve list of sources from a given system (GetFileSources with id=0)
27o) Function to retrieve list of IDs for a given source (GetFileIDs)
28These functions are needed for dealing with the tag files that are saved for the GRP preprocessor
29Example code has been added to the TestProcessor in TestShuttle
30
31Revision 1.12 2007/04/27 07:06:48 jgrosseo
32GetFileSources returns empty list in case of no files, but successful query
33No mails sent in testmode
34
35Revision 1.11 2007/04/04 10:33:36 jgrosseo
361) Storing of files to the Grid is now done _after_ your preprocessors succeeded. This is transparent, which means that you can still use the same functions (Store, StoreReferenceData) to store files to the Grid. However, the Shuttle first stores them locally and transfers them after the preprocessor finished. The return code of these two functions has changed from UInt_t to Bool_t which gives you the success of the storing.
37In case of an error with the Grid, the Shuttle will retry the storing later, the preprocessor does not need to be run again.
38
392) The meaning of the return code of the preprocessor has changed. 0 is now success and any other value means failure. This value is stored in the log and you can use it to keep details about the error condition.
40
413) New function StoreReferenceFile to _directly_ store a file (without opening it) to the reference storage.
42
434) The memory usage of the preprocessor is monitored. If it exceeds 2 GB it is terminated.
44
455) New function AliPreprocessor::ProcessDCS(). If you do not need to have DCS data in all cases, you can skip the processing by implemting this function and returning kFALSE under certain conditions. E.g. if there is a certain run type.
46If you always need DCS data (like before), you do not need to implement it.
47
486) The run type has been added to the monitoring page
49
50Revision 1.10 2007/02/28 10:41:01 acolla
51Run type field added in SHUTTLE framework. Run type is read from "run type" logbook and retrieved by
52AliPreprocessor::GetRunType() function.
53Added some ldap definition files.
54
55Revision 1.8 2007/02/13 11:22:25 acolla
56Shuttle getters and setters of main/local OCDB/Reference storages, temp and log
57folders moved to AliShuttleInterface
58
59Revision 1.6 2006/11/06 14:22:47 jgrosseo
60major update (Alberto)
61o) reading of run parameters from the logbook
62o) online offline naming conversion
63o) standalone DCSclient package
64
65Revision 1.5 2006/10/02 12:58:52 jgrosseo
66Small interface change in StoreReferenceData
67
68Revision 1.4 2006/08/08 14:19:07 jgrosseo
69Update to shuttle classes (Alberto)
70
71- Possibility to set the full object's path in the Preprocessor's and
72Shuttle's Store functions
73- Possibility to extend the object's run validity in the same classes
74("startValidity" and "validityInfinite" parameters)
75- Implementation of the StoreReferenceData function to store reference
76data in a dedicated CDB storage.
77
78Revision 1.3 2006/07/11 12:44:32 jgrosseo
79adding parameters for extended validity range of data produced by preprocessor
80
81Revision 1.2 2006/06/06 14:20:05 jgrosseo
82o) updated test preprocessor (alberto)
83o) added comments to example macro
84o) test shuttle implements new interface
85
86Revision 1.2 2006/03/07 07:52:34 hristov
87New version (B.Yordanov)
88
89Revision 1.3 2005/11/17 17:47:34 byordano
90TList changed to TObjArray
91
92Revision 1.2 2005/11/17 14:43:22 byordano
93import to local CVS
94
95Revision 1.1.1.1 2005/10/28 07:33:58 hristov
96Initial import as subdirectory in AliRoot
97
98Revision 1.1.1.1 2005/09/12 22:11:40 byordano
99SHUTTLE package
100
101Revision 1.2 2005/08/29 21:15:47 byordano
102some docs added
103
104*/
105
106//
107// test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
108//
109// reads files from the local disk
110// stores to local CDB
111// logs to the screen
112//
113
114#include "AliTestShuttle.h"
115#include "AliLog.h"
116
117#include "AliCDBManager.h"
118#include "AliCDBStorage.h"
119#include "AliCDBMetaData.h"
120#include "AliCDBPath.h"
121#include "AliCDBId.h"
122#include "AliPreprocessor.h"
123
124#include <TMap.h>
125#include <TList.h>
126#include <TObjString.h>
127#include <TSystem.h>
128#include <TTimeStamp.h>
129
130ClassImp(AliTestShuttle)
131
132//______________________________________________________________________________________________
133AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
134 fRun(run),
135 fStartTime(startTime),
136 fEndTime(endTime),
137 fTimeCreated(startTime),
138 fDCSQueryOffset(0),
139 fInputFiles(0),
140 fRunParameters(0),
141 fRunType(),
142 fPreprocessors(0),
143 fDcsAliasMap(0)
144{
145 // constructor
146
147 fInputFiles = new TMap;
148 fRunParameters = new TMap;
149 fPreprocessors = new TObjArray;
150
151 fInputFiles->SetOwner(1);
152 fRunParameters->SetOwner(1);
153 fPreprocessors->SetOwner(1);
154}
155
156//______________________________________________________________________________________________
157AliTestShuttle::~AliTestShuttle()
158{
159 // destructor
160
161 delete fInputFiles;
162 fInputFiles = 0;
163
164 delete fRunParameters;
165 fRunParameters = 0;
166
167 delete fPreprocessors;
168 fPreprocessors = 0;
169
170 delete fDcsAliasMap;
171 fDcsAliasMap = 0;
172}
173
174//______________________________________________________________________________________________
175Bool_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
176 Int_t validityStart, Bool_t validityInfinite)
177{
178 // Stores the CDB object
179 // This function should be called at the end of the preprocessor cycle
180 //
181 // This implementation just stores it on the local disk, the full AliShuttle
182 // puts it to the Grid FileCatalog
183
184 Int_t startRun = fRun - validityStart;
185 if(startRun < 0) {
186 AliError("First valid run happens to be less than 0! Setting it to 0...");
187 startRun=0;
188 }
189
190 Int_t endRun = -1;
191 if(validityInfinite) {
192 endRun = AliCDBRunRange::Infinity();
193 } else {
194 endRun = fRun;
195 }
196
197 AliCDBId id(path, startRun, endRun);
198
199 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
200}
201
202//______________________________________________________________________________________________
203Bool_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
204{
205 // Stores the object as reference data
206 // This function should be called at the end of the preprocessor cycle
207 //
208 // This implementation just stores it on the local disk, the full AliShuttle
209 // puts it to the Grid FileCatalog
210
211 AliCDBId id(path, fRun, fRun);
212
213 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
214}
215
216//______________________________________________________________________________________________
217Bool_t AliTestShuttle::StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName)
218{
219 //
220 // Stores reference file directly (without opening it).
221 //
222 // This implementation just stores it on the local disk, the full AliShuttle
223 // puts it to the Grid FileCatalog
224
225 AliCDBManager* man = AliCDBManager::Instance();
226 AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage);
227
228 TString localBaseFolder = sto->GetBaseFolder();
229
230 TString targetDir = GetRefFilePrefix(localBaseFolder.Data(), detector);
231
232 return CopyFileLocally(targetDir, localFile, gridFileName);
233}
234
235//______________________________________________________________________________________________
236Bool_t AliTestShuttle::StoreRunMetadataFile(const char* localFile, const char* gridFileName)
237{
238 //
239 // Stores Run metadata file to the Grid, in the run folder
240 //
241 // Only GRP can call this function.
242
243 AliCDBManager* man = AliCDBManager::Instance();
244 AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage);
245
246 TString localBaseFolder = sto->GetBaseFolder();
247
248 // Build Run level folder
249 // folder = /alice/data/year/lhcPeriod/runNb/Raw
250
251 TTimeStamp startTime(fStartTime);
252
253 TString year = Form("%d",startTime.GetDate());
254 year = year(0,4);
255
256 TString lhcPeriod = GetRunParameter("LHCperiod");
257
258 if (lhcPeriod.Length() == 0)
259 {
260 Log("SHUTTLE","StoreRunMetaDataFile - LHCPeriod not found in logbook!");
261 return 0;
262 }
263
264 // TODO: currently SHUTTLE cannot write in /alice/data/ !!!!!
265 //TString targetDir = Form("%s/GRP/RunMetadata/alice/data/%s/%s/%d/Raw",
266 // localBaseFolder.Data(), year.Data(),
267 // lhcPeriod.Data(), fRun);
268
269 TString targetDir = Form("%s/GRP/RunMetadata/alice/simulation/%s/%s/%d/Raw",
270 localBaseFolder.Data(), year.Data(),
271 lhcPeriod.Data(), fRun);
272
273 return CopyFileLocally(targetDir, localFile, gridFileName);
274}
275
276//______________________________________________________________________________________________
277Bool_t AliTestShuttle::CopyFileLocally(TString& targetDir, const char* localFile, const char* gridFileName)
278{
279 //
280 // Stores file locally. Called by StoreReferenceFile and StoreRunMetadataFile
281 //
282
283 //try to open folder, if it does not exist
284 void* dir = gSystem->OpenDirectory(targetDir.Data());
285 if (dir == NULL) {
286 if (gSystem->mkdir(targetDir.Data(), kTRUE)) {
287 Log("SHUTTLE", Form("StoreFileLocally - Can't open directory <%s>", targetDir.Data()));
288 return kFALSE;
289 }
290
291 } else {
292 gSystem->FreeDirectory(dir);
293 }
294
295 TString target = Form("%s/%s", targetDir.Data(), gridFileName);
296
297 Int_t result = gSystem->GetPathInfo(localFile, 0, (Long64_t*) 0, 0, 0);
298 if (result)
299 {
300 Log("SHUTTLE", Form("StoreFileLocally - %s does not exist", localFile));
301 return kFALSE;
302 }
303
304 result = gSystem->CopyFile(localFile, target);
305
306 if (result == 0)
307 {
308 Log("SHUTTLE", Form("StoreFileLocally - File %s stored locally to %s", localFile, target.Data()));
309 return kTRUE;
310 }
311 else
312 {
313 Log("SHUTTLE", Form("StoreFileLocally - Could not store file %s to %s!. Error code = %d",
314 localFile, target.Data(), result));
315 return kFALSE;
316 }
317
318
319
320}
321
322//______________________________________________________________________________________________
323const char* AliTestShuttle::GetRefFilePrefix(const char* base, const char* detector)
324{
325 //
326 // Get folder name of reference files
327 //
328
329 TString offDetStr(GetOfflineDetName(detector));
330 static TString dir;
331 if (offDetStr == "ITS" || offDetStr == "MUON" || offDetStr == "PHOS")
332 {
333 dir.Form("%s/%s/%s", base, offDetStr.Data(), detector);
334 } else {
335 dir.Form("%s/%s", base, offDetStr.Data());
336 }
337
338 return dir.Data();
339}
340
341//______________________________________________________________________________________________
342const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
343{
344 // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id
345 // and from the given source in the system.
346 // The function returnes the path to the local file.
347 //
348 // test implementation of GetFile
349 // takes files from the local disks, files are passen in a TMap in the constructor
350
351 TString key;
352 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
353 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
354 TMap* sourceList = 0;
355 if (sourceListPair)
356 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
357 if (!sourceList)
358 {
359 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
360 return 0;
361 }
362
363 TObjString* fileName = 0;
364 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
365 if (fileNamePair)
366 fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
367 if (!fileName)
368 {
369 AliError(Form("Could not find files from source %s in %s with id %s",
370 source, fkSystemNames[system], id));
371 return 0;
372 }
373
374 return fileName->GetString().Data();
375}
376
377//______________________________________________________________________________________________
378TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
379{
380 // Returns a list of sources in a given system that saved a file with the given id
381 //
382 // test implementation of GetFileSources
383 // takes files from the local disks, files are passen in a TMap in the constructor
384
385 TString key;
386 if (id)
387 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
388 else
389 key.Form("%s-%s", fkSystemNames[system], detector);
390
391 TList* list = new TList;
392
393 TIterator* iter = fInputFiles->MakeIterator();
394 TObject* obj = 0;
395 while ((obj = iter->Next()))
396 {
397 TObjString* objStr = dynamic_cast<TObjString*> (obj);
398 if (objStr)
399 {
400 Bool_t found = kFALSE;
401 if (id)
402 {
403 found = (objStr->String().CompareTo(key) == 0);
404 }
405 else
406 found = objStr->String().BeginsWith(key);
407
408 if (found)
409 {
410 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
411 TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
412
413 TIterator* iter2 = sourceList->GetTable()->MakeIterator();
414 TObject* obj2 = 0;
415 while ((obj2 = iter2->Next()))
416 {
417 TPair* pair = dynamic_cast<TPair*> (obj2);
418 if (pair)
419 {
420 if (!list->FindObject(pair->Key()))
421 list->Add(new TObjString(pair->Key()->GetName()));
422 }
423 }
424
425 delete iter2;
426 }
427 }
428 }
429
430 if (list->GetEntries() == 0)
431 AliInfo(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
432
433 return list;
434}
435
436//______________________________________________________________________________________________
437TList* AliTestShuttle::GetFileIDs(Int_t system, const char* detector, const char* source)
438{
439 // Returns a list of ids in a given system that saved a file with the given source
440 //
441 // test implementation of GetFileSources
442 // takes files from the local disks, files are passen in a TMap in the constructor
443
444
445 TString key;
446 key.Form("%s-%s", fkSystemNames[system], detector);
447
448 TList* list = new TList;
449
450 TIterator* iter = fInputFiles->MakeIterator();
451 TObject* obj = 0;
452 while ((obj = iter->Next()))
453 {
454 TObjString* objStr = dynamic_cast<TObjString*> (obj);
455 if (objStr)
456 {
457 if (objStr->String().BeginsWith(key))
458 {
459 Bool_t found = kFALSE;
460
461 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
462 TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
463
464 TIterator* iter2 = sourceList->GetTable()->MakeIterator();
465 TObject* obj2 = 0;
466 while ((obj2 = iter2->Next()))
467 {
468 TPair* pair = dynamic_cast<TPair*> (obj2);
469 if (pair)
470 {
471 if (strcmp(pair->Key()->GetName(), source) == 0)
472 found = kTRUE;
473 }
474 }
475
476 delete iter2;
477
478 if (found)
479 {
480 TObjArray* tokens = objStr->String().Tokenize("-");
481 if (tokens->GetEntries() == 3)
482 {
483 TObjString* id = dynamic_cast<TObjString*> (tokens->At(2));
484 if (id && !list->FindObject(id->String()))
485 list->Add(new TObjString(id->String()));
486 }
487
488 delete tokens;
489
490 }
491 }
492 }
493 }
494
495 if (list->GetEntries() == 0)
496 AliInfo(Form("Could not find any file in %s with source %s (%s)", fkSystemNames[system], source, key.Data()));
497
498 return list;
499}
500
501//______________________________________________________________________________________________
502void AliTestShuttle::Log(const char* detector, const char* message)
503{
504 // test implementation of Log
505 // just prints to the screen
506
507 AliInfo(Form("%s: %s", detector, message));
508}
509
510//______________________________________________________________________________________________
511void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
512{
513 //
514 // This function adds a file to the list of input files
515 // the list is stored in fInputFiles
516 // fInputFiles: TMap (key -> value)
517 // <system>-<detector>-<id> -> TMap (key -> value)
518 // <source> -> <filename>
519 //
520
521 TString key;
522 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
523 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
524 TMap* sourceList = 0;
525 if (sourceListPair)
526 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
527 if (!sourceList)
528 {
529 sourceList = new TMap;
530 fInputFiles->Add(new TObjString(key), sourceList);
531 }
532
533 sourceList->Add(new TObjString(source), new TObjString(fileName));
534}
535
536//______________________________________________________________________________________________
537Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
538{
539 // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
540
541 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
542 if (!sto)
543 {
544 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
545 return 0;
546 }
547
548 return sto->Put(entry);
549}
550
551//______________________________________________________________________________________________
552AliCDBEntry* AliTestShuttle::GetFromOCDB(const char* detector, const AliCDBPath& path)
553{
554// returns obiect from OCDB valid for current run
555
556 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
557 if (!sto)
558 {
559 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
560 return 0;
561 }
562
563 return (AliCDBEntry*) sto->Get(path, fRun);
564}
565
566//______________________________________________________________________________________________
567void AliTestShuttle::Process()
568{
569 // This function tests all preprocessors that are registered to it
570 // All preprocessors get the same dcs alias map and have access to the same list of files.
571
572 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
573 {
574 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
575 if (preprocessor)
576 {
577 if (preprocessor->ProcessRunType())
578 {
579 preprocessor->Initialize(fRun, fStartTime, fEndTime);
580 preprocessor->Process(fDcsAliasMap);
581 }
582
583 }
584 }
585}
586
587//______________________________________________________________________________________________
588void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
589{
590 // registers a preprocessor
591
592 const char* detName = preprocessor->GetName();
593 if(strcmp("DET", detName) != 0) {
594 if(GetDetPos(detName) < 0)
595 AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
596 }
597
598 fPreprocessors->Add(preprocessor);
599}
600
601//______________________________________________________________________________________________
602void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
603// set a run parameter (in reality it will be read from the DAQ logbook)
604
605 TObjString* keyObj = new TObjString(key);
606 if (fRunParameters->Contains(key)) {
607 AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
608 delete fRunParameters->Remove(keyObj);
609
610 }
611 fRunParameters->Add(keyObj, new TObjString(value));
612 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
613 GetEntries()));
614}
615
616//______________________________________________________________________________________________
617const char* AliTestShuttle::GetRunType()
618{
619 //
620 // get a run parameter
621 //
622
623 return fRunType.Data();
624}
625
626//______________________________________________________________________________________________
627const char* AliTestShuttle::GetRunParameter(const char* key){
628// get a run parameter
629
630 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
631 if(!value) {
632 AliError(Form("No such parameter: %s", key));
633 return 0;
634 }
635 return value->GetName();
636}
637
638//______________________________________________________________________________________________
639void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
640{
641// sets Shuttle temp directory
642
643 fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
644}
645
646//______________________________________________________________________________________________
647void AliTestShuttle::SetShuttleLogDir(const char* logDir)
648{
649// sets Shuttle log directory
650
651 fgkShuttleLogDir = gSystem->ExpandPathName(logDir);
652}
653
654//______________________________________________________________________________________________
655const char* AliTestShuttle::GetTriggerConfiguration()
656{
657 //returns trigger configuration
658 if (fTriggerConfiguration.Length()>0){
659 return fTriggerConfiguration;
660 }
661 return NULL;
662}
663//______________________________________________________________________________________________
664const char* AliTestShuttle::GetTriggerDetectorMask()
665{
666 //returns trigger detector mask
667 if (fTriggerDetectorMask.Length()>0){
668 return fTriggerDetectorMask;
669 }
670 return NULL;
671}
672//______________________________________________________________________________________________
673UInt_t AliTestShuttle::GetStartTimeDCSQuery()
674{
675 // Return Start Time for the DCS query
676 //
677 // The call is delegated to AliShuttleInterface
678
679 return fTimeCreated-fDCSQueryOffset;
680}
681//______________________________________________________________________________________________
682UInt_t AliTestShuttle::GetEndTimeDCSQuery()
683{
684 // Return End Time for the DCS query
685 //
686 // The call is delegated to AliShuttleInterface
687
688 return fEndTime+fDCSQueryOffset;
689}