1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.14 2007/08/06 12:25:47 acolla
19 Function Bool_t GetHLTStatus added to preprocessor. It returns the status of HLT
20 read from the run logbook.
21 TestShuttle setup updated.
22 TRD data point configuration updated.
24 Revision 1.13 2007/05/30 06:35:21 jgrosseo
25 Adding functionality to the Shuttle/TestShuttle:
26 o) Function to retrieve list of sources from a given system (GetFileSources with id=0)
27 o) Function to retrieve list of IDs for a given source (GetFileIDs)
28 These functions are needed for dealing with the tag files that are saved for the GRP preprocessor
29 Example code has been added to the TestProcessor in TestShuttle
31 Revision 1.12 2007/04/27 07:06:48 jgrosseo
32 GetFileSources returns empty list in case of no files, but successful query
33 No mails sent in testmode
35 Revision 1.11 2007/04/04 10:33:36 jgrosseo
36 1) 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.
37 In case of an error with the Grid, the Shuttle will retry the storing later, the preprocessor does not need to be run again.
39 2) 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.
41 3) New function StoreReferenceFile to _directly_ store a file (without opening it) to the reference storage.
43 4) The memory usage of the preprocessor is monitored. If it exceeds 2 GB it is terminated.
45 5) 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.
46 If you always need DCS data (like before), you do not need to implement it.
48 6) The run type has been added to the monitoring page
50 Revision 1.10 2007/02/28 10:41:01 acolla
51 Run type field added in SHUTTLE framework. Run type is read from "run type" logbook and retrieved by
52 AliPreprocessor::GetRunType() function.
53 Added some ldap definition files.
55 Revision 1.8 2007/02/13 11:22:25 acolla
56 Shuttle getters and setters of main/local OCDB/Reference storages, temp and log
57 folders moved to AliShuttleInterface
59 Revision 1.6 2006/11/06 14:22:47 jgrosseo
60 major update (Alberto)
61 o) reading of run parameters from the logbook
62 o) online offline naming conversion
63 o) standalone DCSclient package
65 Revision 1.5 2006/10/02 12:58:52 jgrosseo
66 Small interface change in StoreReferenceData
68 Revision 1.4 2006/08/08 14:19:07 jgrosseo
69 Update to shuttle classes (Alberto)
71 - Possibility to set the full object's path in the Preprocessor's and
72 Shuttle'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
76 data in a dedicated CDB storage.
78 Revision 1.3 2006/07/11 12:44:32 jgrosseo
79 adding parameters for extended validity range of data produced by preprocessor
81 Revision 1.2 2006/06/06 14:20:05 jgrosseo
82 o) updated test preprocessor (alberto)
83 o) added comments to example macro
84 o) test shuttle implements new interface
86 Revision 1.2 2006/03/07 07:52:34 hristov
87 New version (B.Yordanov)
89 Revision 1.3 2005/11/17 17:47:34 byordano
90 TList changed to TObjArray
92 Revision 1.2 2005/11/17 14:43:22 byordano
95 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
96 Initial import as subdirectory in AliRoot
98 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
101 Revision 1.2 2005/08/29 21:15:47 byordano
107 // test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
109 // reads files from the local disk
110 // stores to local CDB
111 // logs to the screen
114 #include "AliTestShuttle.h"
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 #include "AliLTUConfig.h"
125 #include "AliTriggerInput.h"
129 #include <TObjString.h>
131 #include <TTimeStamp.h>
132 #include <TObjArray.h>
134 ClassImp(AliTestShuttle)
136 //______________________________________________________________________________________________
137 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
139 fStartTime(startTime),
141 fTimeCreated(startTime),
148 fTriggerConfiguration(""),
149 fTriggerDetectorMask(""),
155 fInputFiles = new TMap;
156 fRunParameters = new TMap;
157 fPreprocessors = new TObjArray;
159 fInputFiles->SetOwner(1);
160 fRunParameters->SetOwner(1);
161 fPreprocessors->SetOwner(1);
163 fltuConfig = new TObjArray();
164 fltuConfig->SetOwner(1);
167 //______________________________________________________________________________________________
168 AliTestShuttle::~AliTestShuttle()
175 delete fRunParameters;
178 delete fPreprocessors;
188 //______________________________________________________________________________________________
189 Bool_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
190 Int_t validityStart, Bool_t validityInfinite)
192 // Stores the CDB object
193 // This function should be called at the end of the preprocessor cycle
195 // This implementation just stores it on the local disk, the full AliShuttle
196 // puts it to the Grid FileCatalog
198 Int_t startRun = fRun - validityStart;
200 AliError("First valid run happens to be less than 0! Setting it to 0...");
205 if(validityInfinite) {
206 endRun = AliCDBRunRange::Infinity();
211 AliCDBId id(path, startRun, endRun);
213 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
216 //______________________________________________________________________________________________
217 Bool_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
219 // Stores the object as reference data
220 // This function should be called at the end of the preprocessor cycle
222 // This implementation just stores it on the local disk, the full AliShuttle
223 // puts it to the Grid FileCatalog
225 AliCDBId id(path, fRun, fRun);
227 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
230 //______________________________________________________________________________________________
231 Bool_t AliTestShuttle::StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName)
234 // Stores reference file directly (without opening it).
236 // This implementation just stores it on the local disk, the full AliShuttle
237 // puts it to the Grid FileCatalog
239 AliCDBManager* man = AliCDBManager::Instance();
240 AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage);
242 TString localBaseFolder = sto->GetBaseFolder();
244 TString targetDir = GetRefFilePrefix(localBaseFolder.Data(), detector);
246 return CopyFileLocally(targetDir, localFile, gridFileName);
249 //______________________________________________________________________________________________
250 Bool_t AliTestShuttle::StoreRunMetadataFile(const char* localFile, const char* gridFileName)
253 // Stores Run metadata file to the Grid, in the run folder
255 // Only GRP can call this function.
257 AliCDBManager* man = AliCDBManager::Instance();
258 AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage);
260 TString localBaseFolder = sto->GetBaseFolder();
262 // Build Run level folder
263 // folder = /alice/data/year/lhcPeriod/runNb/Raw
265 TTimeStamp startTime(fStartTime);
267 TString year = Form("%d",startTime.GetDate());
270 TString lhcPeriod = GetRunParameter("LHCperiod");
272 if (lhcPeriod.Length() == 0)
274 Log("SHUTTLE","StoreRunMetaDataFile - LHCPeriod not found in logbook!");
278 // TODO: currently SHUTTLE cannot write in /alice/data/ !!!!!
279 //TString targetDir = Form("%s/GRP/RunMetadata/alice/data/%s/%s/%d/Raw",
280 // localBaseFolder.Data(), year.Data(),
281 // lhcPeriod.Data(), fRun);
283 TString targetDir = Form("%s/GRP/RunMetadata/alice/simulation/%s/%s/%d/Raw",
284 localBaseFolder.Data(), year.Data(),
285 lhcPeriod.Data(), fRun);
287 return CopyFileLocally(targetDir, localFile, gridFileName);
290 //______________________________________________________________________________________________
291 Bool_t AliTestShuttle::CopyFileLocally(TString& targetDir, const char* localFile, const char* gridFileName)
294 // Stores file locally. Called by StoreReferenceFile and StoreRunMetadataFile
297 //try to open folder, if it does not exist
298 void* dir = gSystem->OpenDirectory(targetDir.Data());
300 if (gSystem->mkdir(targetDir.Data(), kTRUE)) {
301 Log("SHUTTLE", Form("StoreFileLocally - Can't open directory <%s>", targetDir.Data()));
306 gSystem->FreeDirectory(dir);
309 TString target = Form("%s/%s", targetDir.Data(), gridFileName);
311 Int_t result = gSystem->GetPathInfo(localFile, 0, (Long64_t*) 0, 0, 0);
314 Log("SHUTTLE", Form("StoreFileLocally - %s does not exist", localFile));
318 result = gSystem->CopyFile(localFile, target);
322 Log("SHUTTLE", Form("StoreFileLocally - File %s stored locally to %s", localFile, target.Data()));
327 Log("SHUTTLE", Form("StoreFileLocally - Could not store file %s to %s!. Error code = %d",
328 localFile, target.Data(), result));
336 //______________________________________________________________________________________________
337 const char* AliTestShuttle::GetRefFilePrefix(const char* base, const char* detector)
340 // Get folder name of reference files
343 TString offDetStr(GetOfflineDetName(detector));
345 if (offDetStr == "ITS" || offDetStr == "MUON" || offDetStr == "PHOS")
347 dir.Form("%s/%s/%s", base, offDetStr.Data(), detector);
349 dir.Form("%s/%s", base, offDetStr.Data());
355 //______________________________________________________________________________________________
356 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
358 // This function retrieves a file from the given system (kDAQ, kDCS, kHLT, kDQM) with the given file id
359 // and from the given source in the system.
360 // The function returnes the path to the local file.
362 // test implementation of GetFile
363 // takes files from the local disks, files are passen in a TMap in the constructor
366 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
367 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
368 TMap* sourceList = 0;
370 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
373 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
377 TObjString* fileName = 0;
378 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
380 fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
383 AliError(Form("Could not find files from source %s in %s with id %s",
384 source, fkSystemNames[system], id));
388 return fileName->String().Data();
391 //______________________________________________________________________________________________
392 TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
394 // Returns a list of sources in a given system that saved a file with the given id
396 // test implementation of GetFileSources
397 // takes files from the local disks, files are passen in a TMap in the constructor
401 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
403 key.Form("%s-%s", fkSystemNames[system], detector);
405 TList* list = new TList;
407 TIterator* iter = fInputFiles->MakeIterator();
409 while ((obj = iter->Next()))
411 TObjString* objStr = dynamic_cast<TObjString*> (obj);
414 Bool_t found = kFALSE;
417 found = (objStr->String().CompareTo(key) == 0);
420 found = objStr->String().BeginsWith(key);
424 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
425 TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
427 TIterator* iter2 = sourceList->GetTable()->MakeIterator();
429 while ((obj2 = iter2->Next()))
431 TPair* pair = dynamic_cast<TPair*> (obj2);
434 if (!list->FindObject(pair->Key()))
435 list->Add(new TObjString(pair->Key()->GetName()));
444 if (list->GetEntries() == 0)
445 AliInfo(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
450 //______________________________________________________________________________________________
451 TList* AliTestShuttle::GetFileIDs(Int_t system, const char* detector, const char* source)
453 // Returns a list of ids in a given system that saved a file with the given source
455 // test implementation of GetFileSources
456 // takes files from the local disks, files are passen in a TMap in the constructor
460 key.Form("%s-%s", fkSystemNames[system], detector);
462 TList* list = new TList;
464 TIterator* iter = fInputFiles->MakeIterator();
466 while ((obj = iter->Next()))
468 TObjString* objStr = dynamic_cast<TObjString*> (obj);
471 if (objStr->String().BeginsWith(key))
473 Bool_t found = kFALSE;
475 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
476 TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
478 TIterator* iter2 = sourceList->GetTable()->MakeIterator();
480 while ((obj2 = iter2->Next()))
482 TPair* pair = dynamic_cast<TPair*> (obj2);
485 if (strcmp(pair->Key()->GetName(), source) == 0)
494 TObjArray* tokens = objStr->String().Tokenize("-");
495 if (tokens->GetEntries() == 3)
497 TObjString* id = dynamic_cast<TObjString*> (tokens->At(2));
498 if (id && !list->FindObject(id->String()))
499 list->Add(new TObjString(id->String()));
509 if (list->GetEntries() == 0)
510 AliInfo(Form("Could not find any file in %s with source %s (%s)", fkSystemNames[system], source, key.Data()));
515 //______________________________________________________________________________________________
516 void AliTestShuttle::Log(const char* detector, const char* message, UInt_t level)
518 // test implementation of Log
519 // just prints to the screen
521 TString fullMessage = detector;
522 fullMessage.Append(Form(": %s",message));
523 AliLog::Message(level, fullMessage, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);
526 //______________________________________________________________________________________________
527 void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
530 // This function adds a file to the list of input files
531 // the list is stored in fInputFiles
532 // fInputFiles: TMap (key -> value)
533 // <system>-<detector>-<id> -> TMap (key -> value)
534 // <source> -> <filename>
538 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
539 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
540 TMap* sourceList = 0;
542 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
545 sourceList = new TMap;
546 fInputFiles->Add(new TObjString(key), sourceList);
549 sourceList->Add(new TObjString(source), new TObjString(fileName));
552 //______________________________________________________________________________________________
553 Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
555 // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
557 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
560 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
564 return sto->Put(entry);
567 //______________________________________________________________________________________________
568 AliCDBEntry* AliTestShuttle::GetFromOCDB(const char* detector, const AliCDBPath& path)
570 // returns obiect from OCDB valid for current run
572 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
575 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
579 return (AliCDBEntry*) sto->Get(path, fRun);
582 //______________________________________________________________________________________________
583 void AliTestShuttle::Process()
585 // This function tests all preprocessors that are registered to it
586 // All preprocessors get the same dcs alias map and have access to the same list of files.
588 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
590 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
593 if (preprocessor->ProcessRunType())
595 preprocessor->Initialize(fRun, fStartTime, fEndTime);
596 preprocessor->Process(fDcsAliasMap);
603 //______________________________________________________________________________________________
604 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
606 // registers a preprocessor
608 const char* detName = preprocessor->GetName();
609 if(strcmp("DET", detName) != 0) {
610 if(GetDetPos(detName) < 0)
611 AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
614 fPreprocessors->Add(preprocessor);
617 //______________________________________________________________________________________________
618 void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
619 // set a run parameter (in reality it will be read from the DAQ logbook)
621 TObjString* keyObj = new TObjString(key);
622 if (fRunParameters->Contains(key)) {
623 AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
624 delete fRunParameters->Remove(keyObj);
627 fRunParameters->Add(keyObj, new TObjString(value));
628 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
632 //______________________________________________________________________________________________
633 const char* AliTestShuttle::GetRunType()
636 // get a run parameter
639 return fRunType.Data();
642 //______________________________________________________________________________________________
643 const char* AliTestShuttle::GetRunParameter(const char* key){
644 // get a run parameter
646 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
648 AliError(Form("No such parameter: %s", key));
651 return value->GetName();
654 //______________________________________________________________________________________________
655 void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
657 // sets Shuttle temp directory
659 fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
662 //______________________________________________________________________________________________
663 void AliTestShuttle::SetShuttleLogDir(const char* logDir)
665 // sets Shuttle log directory
667 fgkShuttleLogDir = gSystem->ExpandPathName(logDir);
670 //______________________________________________________________________________________________
671 const char* AliTestShuttle::GetTriggerConfiguration()
673 //returns trigger configuration
674 if (fTriggerConfiguration.Length()>0){
675 return fTriggerConfiguration;
679 //______________________________________________________________________________________________
680 const char* AliTestShuttle::GetCTPTimeParams()
682 //returns trigger configuration
683 if (fCTPtiming.Length()>0){
688 //______________________________________________________________________________________________
689 const char* AliTestShuttle::GetTriggerDetectorMask()
691 //returns trigger detector mask
692 if (fTriggerDetectorMask.Length()>0){
693 return fTriggerDetectorMask;
697 //______________________________________________________________________________________________
698 UInt_t AliTestShuttle::GetStartTimeDCSQuery()
700 // Return Start Time for the DCS query
702 // The call is delegated to AliShuttleInterface
704 return fTimeCreated-fDCSQueryOffset;
706 //______________________________________________________________________________________________
707 UInt_t AliTestShuttle::GetEndTimeDCSQuery()
709 // Return End Time for the DCS query
711 // The call is delegated to AliShuttleInterface
713 return fEndTime+fDCSQueryOffset;
715 //______________________________________________________________________________________________
716 void AliTestShuttle::SendMLFromDet(const char* value)
719 // Sending an information coming from the current detector to ML
722 Printf("%s will be sent to monalisa in the $currentdetector_RunCondition tag",value);
725 //______________________________________________________________________________________________
726 void AliTestShuttle::SetLTUConfig(TString* ltuConfig, const char* det){
729 // Setting LTU configuration for detector det
732 AliInfo(Form("LTU Config will be added for detector %s",det));
733 AliInfo(Form("First element of the array of strings will correspond to LTUFineDelay1 --> %s",ltuConfig[0].Data()));
734 AliInfo(Form("Second element of the array of strings will correspond to LTUFineDelay2 --> %s",ltuConfig[1].Data()));
735 AliInfo(Form("Third element of the array of strings will correspond to LTUBCDelayAdd --> %s",ltuConfig[2].Data()));
736 Float_t ltuFineDelay1 = ltuConfig[0].Atof();
737 Float_t ltuFineDelay2 = ltuConfig[1].Atof();
738 Float_t ltuBCDelayAdd = ltuConfig[2].Atof();
739 AliLTUConfig* ltu = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(det),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
740 Int_t idet = AliDAQ::DetectorID(det);
741 fltuConfig->AddAtAndExpand(ltu,idet);
744 //______________________________________________________________________________________________
745 TString* AliTestShuttle::GetLTUConfig(const char* det){
748 // Getting LTU configuration for detector det
751 TString* ltuConfigString = new TString[3];
753 for (Int_t index = 0; index < AliDAQ::kNDetectors; index++){
754 AliDebug(3,Form("index = %d, det = %s, CTP name = %s",index,det,AliTriggerInput::fgkCTPDetectorName[index]));
755 if (strcmp(det,AliTriggerInput::fgkCTPDetectorName[index]) == 0){
756 AliInfo(Form("Getting LTU configuration for detector %s",AliTriggerInput::fgkCTPDetectorName[index]));
762 AliLTUConfig* ltu = (AliLTUConfig*)fltuConfig->At(idet);
764 AliInfo(Form("ltu for detector %s not added in the simulated run, returning a null pointer",det));
768 ltuConfigString[0]=Form("%f",ltu->GetFineDelay1());
769 ltuConfigString[1]=Form("%f",ltu->GetFineDelay2());
770 ltuConfigString[0]=Form("%f",ltu->GetBCDelayAdd());
774 AliError(Form("Detector %s not found in the list of CTP detector names",det));
776 return ltuConfigString;