o) Function to retrieve list of sources from a given system (GetFileSources with id=0)
o) Function to retrieve list of IDs for a given source (GetFileIDs)
These functions are needed for dealing with the tag files that are saved for the GRP preprocessor
Example code has been added to the TestProcessor in TestShuttle
/*
$Log$
+Revision 1.44 2007/05/11 16:09:32 acolla
+Reference files for ITS, MUON and PHOS are now stored in OfflineDetName/OnlineDetName/run_...
+example: ITS/SPD/100_filename.root
+
Revision 1.43 2007/05/10 09:59:51 acolla
Various bug fixes in StoreRefFilesToGrid; Cleaning of reference storage before processing detector (CleanReferenceStorage)
{
//
// Get sources producing the condition file Id from file exchange servers
+ // if id is NULL all sources are returned (distinct)
//
// check if test mode should simulate a FXS error
// check connection, in case connect
if (!Connect(system))
{
- Log(detector, Form("GetFile - Couldn't connect to %s FXS database", GetSystemName(system)));
+ Log(detector, Form("GetFileSources - Couldn't connect to %s FXS database", GetSystemName(system)));
return NULL;
}
sourceName = "DDLnumbers";
}
- TString sqlQueryStart = Form("select %s from %s where", sourceName.Data(), fConfig->GetFXSdbTable(system));
- TString whereClause = Form("run=%d and detector=\"%s\" and fileId=\"%s\"",
- GetCurrentRun(), detector, id);
+ TString sqlQueryStart = Form("select distinct %s from %s where", sourceName.Data(), fConfig->GetFXSdbTable(system));
+ TString whereClause = Form("run=%d and detector=\"%s\"",
+ GetCurrentRun(), detector);
+ if (id)
+ whereClause += Form(" and fileId=\"%s\"", id);
TString sqlQuery = Form("%s %s", sqlQueryStart.Data(), whereClause.Data());
AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data()));
return list;
}
+//______________________________________________________________________________________________
+TList* AliShuttle::GetFileIDs(Int_t system, const char* detector, const char* source)
+{
+ //
+ // Get all ids of condition files produced by a given source from file exchange servers
+ //
+
+ // check if test mode should simulate a FXS error
+ if (fTestMode & kErrorFXSSources)
+ {
+ Log(detector, Form("GetFileIDs - In TESTMODE - Simulating error while connecting to %s FXS", GetSystemName(system)));
+ return 0;
+ }
+
+ // check connection, in case connect
+ if (!Connect(system))
+ {
+ Log(detector, Form("GetFileIDs - Couldn't connect to %s FXS database", GetSystemName(system)));
+ return NULL;
+ }
+
+ TString sourceName = 0;
+ if (system == kDAQ)
+ {
+ sourceName = "DAQsource";
+ } else if (system == kHLT)
+ {
+ sourceName = "DDLnumbers";
+ }
+
+ TString sqlQueryStart = Form("select fileId from %s where", fConfig->GetFXSdbTable(system));
+ TString whereClause = Form("run=%d and detector=\"%s\"",
+ GetCurrentRun(), detector);
+ if (sourceName.Length() > 0 && source)
+ whereClause += Form(" and %s=\"%s\"", sourceName.Data(), source);
+ TString sqlQuery = Form("%s %s", sqlQueryStart.Data(), whereClause.Data());
+
+ AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data()));
+
+ // Query execution
+ TSQLResult* aResult;
+ aResult = fServer[system]->Query(sqlQuery);
+ if (!aResult) {
+ Log(detector, Form("GetFileIDs - Can't execute SQL query to %s database for source: %s",
+ GetSystemName(system), source));
+ return 0;
+ }
+
+ TList *list = new TList();
+ list->SetOwner(1);
+
+ if (aResult->GetRowCount() == 0)
+ {
+ Log(detector,
+ Form("GetFileIDs - No entry in %s FXS table for source: %s", GetSystemName(system), source));
+ delete aResult;
+ return list;
+ }
+
+ TSQLRow* aRow;
+
+ while ((aRow = aResult->Next()))
+ {
+
+ TString id(aRow->GetField(0), aRow->GetFieldLength(0));
+ AliDebug(2, Form("fileId = %s", id.Data()));
+ list->Add(new TObjString(id));
+ delete aRow;
+ }
+
+ delete aResult;
+
+ return list;
+}
+
//______________________________________________________________________________________________
Bool_t AliShuttle::Connect(Int_t system)
{
virtual Bool_t StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName);
virtual const char* GetFile(Int_t system, const char* detector,
const char* id, const char* source);
- virtual TList* GetFileSources(Int_t system, const char* detector, const char* id);
+ virtual TList* GetFileSources(Int_t system, const char* detector, const char* id = 0);
+ virtual TList* GetFileIDs(Int_t system, const char* detector, const char* source);
virtual const char* GetRunParameter(const char* lbEntry);
virtual AliCDBEntry* GetFromOCDB(const char* detector, const AliCDBPath& path);
virtual const char* GetRunType();
// Now we will loop on the list and we'll query the files one by one.
Log("The following sources produced files with the id DRIFTVELOCITY");
sourceList->Print();
-
+
TIter iter(sourceList);
TObjString *source = 0;
while((source=dynamic_cast<TObjString*> (iter.Next()))){
delete sourceList;
+ // Example of how to retrieve the list of sources that produced files
+ sourceList = GetFileSources(kDAQ);
+ if (!sourceList)
+ {
+ Log("Error: No sources found!");
+ return 1;
+ }
+
+ Log("The following sources produced files");
+ sourceList->Print();
+ delete sourceList;
+
+ // Example of how to retrieve the list of ids from a given source
+ TList* idList = GetFileIDs(kDAQ, "LDC0");
+ if (!idList)
+ {
+ Log("Error: No IDs found!");
+ return 1;
+ }
+
+ Log("The following ids are available");
+ idList->Print();
+ delete idList;
+
// Example to store a file directly to the reference storage
// Suppose we have queried the file from the FXS. Now the file is available locally and is called "file1.root".
const char* refFileName="file1.root";
/*
$Log$
+Revision 1.12 2007/04/27 07:06:48 jgrosseo
+GetFileSources returns empty list in case of no files, but successful query
+No mails sent in testmode
+
Revision 1.11 2007/04/04 10:33:36 jgrosseo
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.
In case of an error with the Grid, the Shuttle will retry the storing later, the preprocessor does not need to be run again.
return 0;
}
+ TObjString* fileName = 0;
TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
- TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
+ if (fileNamePair)
+ fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
if (!fileName)
{
AliError(Form("Could not find files from source %s in %s with id %s",
// takes files from the local disks, files are passen in a TMap in the constructor
TString key;
- key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
- TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
- TMap* sourceList = 0;
- if (sourceListPair)
- sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
- if (!sourceList)
+ if (id)
+ key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
+ else
+ key.Form("%s-%s", fkSystemNames[system], detector);
+
+ TList* list = new TList;
+
+ TIterator* iter = fInputFiles->MakeIterator();
+ TObject* obj = 0;
+ while ((obj = iter->Next()))
{
- AliInfo(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
- return new TList;
+ TObjString* objStr = dynamic_cast<TObjString*> (obj);
+ if (objStr)
+ {
+ Bool_t found = kFALSE;
+ if (id)
+ {
+ found = (objStr->String().CompareTo(key) == 0);
+ }
+ else
+ found = objStr->String().BeginsWith(key);
+
+ if (found)
+ {
+ TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
+ TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
+
+ TIterator* iter2 = sourceList->GetTable()->MakeIterator();
+ TObject* obj2 = 0;
+ while ((obj2 = iter2->Next()))
+ {
+ TPair* pair = dynamic_cast<TPair*> (obj2);
+ if (pair)
+ {
+ if (!list->FindObject(pair->Key()))
+ list->Add(new TObjString(pair->Key()->GetName()));
+ }
+ }
+
+ delete iter2;
+ }
+ }
}
+
+ if (list->GetEntries() == 0)
+ AliInfo(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
+
+ return list;
+}
- TIterator* iter = sourceList->GetTable()->MakeIterator();
- TObject* obj = 0;
+//______________________________________________________________________________________________
+TList* AliTestShuttle::GetFileIDs(Int_t system, const char* detector, const char* source)
+{
+ // Returns a list of ids in a given system that saved a file with the given source
+ //
+ // test implementation of GetFileSources
+ // takes files from the local disks, files are passen in a TMap in the constructor
+
+
+ TString key;
+ key.Form("%s-%s", fkSystemNames[system], detector);
+
TList* list = new TList;
+
+ TIterator* iter = fInputFiles->MakeIterator();
+ TObject* obj = 0;
while ((obj = iter->Next()))
{
- TPair* pair = dynamic_cast<TPair*> (obj);
- if (pair)
- list->Add(pair->Key());
+ TObjString* objStr = dynamic_cast<TObjString*> (obj);
+ if (objStr)
+ {
+ if (objStr->String().BeginsWith(key))
+ {
+ Bool_t found = kFALSE;
+
+ TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
+ TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
+
+ TIterator* iter2 = sourceList->GetTable()->MakeIterator();
+ TObject* obj2 = 0;
+ while ((obj2 = iter2->Next()))
+ {
+ TPair* pair = dynamic_cast<TPair*> (obj2);
+ if (pair)
+ {
+ if (strcmp(pair->Key()->GetName(), source) == 0)
+ found = kTRUE;
+ }
+ }
+
+ delete iter2;
+
+ if (found)
+ {
+ TObjArray* tokens = objStr->String().Tokenize("-");
+ if (tokens->GetEntries() == 3)
+ {
+ TObjString* id = dynamic_cast<TObjString*> (tokens->At(2));
+ if (id && !list->FindObject(id->String()))
+ list->Add(new TObjString(id->String()));
+ }
+
+ delete tokens;
+
+ }
+ }
+ }
}
-
- delete iter;
-
+
+ if (list->GetEntries() == 0)
+ AliInfo(Form("Could not find any file in %s with source %s (%s)", fkSystemNames[system], source, key.Data()));
+
return list;
}
//______________________________________________________________________________________________
void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
{
+ //
// This function adds a file to the list of input files
-
+ // the list is stored in fInputFiles
+ // fInputFiles: TMap (key -> value)
+ // <system>-<detector>-<id> -> TMap (key -> value)
+ // <source> -> <filename>
+ //
+
TString key;
key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
virtual Bool_t StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData);
virtual Bool_t StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName);
virtual const char* GetFile(Int_t system, const char* detector, const char* id, const char* source);
- virtual TList* GetFileSources(Int_t system, const char* detector, const char* id);
+ virtual TList* GetFileSources(Int_t system, const char* detector, const char* id = 0);
+ virtual TList* GetFileIDs(Int_t system, const char* detector, const char* source);
virtual const char* GetRunParameter(const char* key);
virtual AliCDBEntry* GetFromOCDB(const char* detector, const AliCDBPath& path);
virtual const char* GetRunType();
// Three files originating from different LDCs but with the same id are also added
// Note that the test preprocessor name is TPC. The name of the detector's preprocessor must follow
// the "online" naming convention ALICE-INT-2003-039.
+ shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "PEDESTALS", "GDC0", "file1.root");
shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC0", "file2a.root");
shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC1", "file2b.root");
shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC2", "file2c.root");
const char* detectorMask = GetRunParameter("detectorMask");
const char* lhcPeriod = GetRunParameter("LHCperiod");
+ TList* list = GetFileSources(kDAQ);
+ TIterator* iter = list->MakeIterator();
+ TObject* obj = 0;
+ while ((obj = iter->Next()))
+ {
+ TObjString* objStr = dynamic_cast<TObjString*> (obj);
+ if (objStr)
+ {
+ Log(Form("Found source %s", objStr->String().Data()));
+ TList* list2 = GetFileIDs(kDAQ, objStr->String());
+ list2->Print();
+ delete list2;
+ }
+ }
+ delete iter;
+ delete list;
+
//===========//
//DCS data points
//===========//
/*
$Log$
+Revision 1.13 2007/04/12 08:26:33 jgrosseo
+updated commment
+
Revision 1.12 2007/04/05 08:05:55 acolla
Conversion from online to offline detector name in StoreReferenceFile
TList* AliPreprocessor::GetFileSources(Int_t system, const char* id)
{
// Returns a list of sources in a given system that saved a file with the given id
+ // if id is not given all sources are returned
//
// The call is delegated to AliShuttleInterface
return fShuttle->GetFileSources(system, GetName(), id);
}
+//______________________________________________________________________________________________
+TList* AliPreprocessor::GetFileIDs(Int_t system, const char* source)
+{
+ // Returns a list of ids in a given system that saved a file with the given source
+ //
+ // The call is delegated to AliShuttleInterface
+
+ return fShuttle->GetFileIDs(system, GetName(), source);
+}
+
//______________________________________________________________________________________________
void AliPreprocessor::Log(const char* message)
{
Bool_t StoreReferenceFile(const char* localFile, const char* gridFileName);
const char* GetFile(Int_t system, const char* id, const char* source);
- TList* GetFileSources(Int_t system, const char* id);
+ TList* GetFileSources(Int_t system, const char* id = 0);
+ TList* GetFileIDs(Int_t system, const char* source);
const char* GetRunParameter(const char* param);
AliCDBEntry* GetFromOCDB(const char* pathLevel2, const char* pathLevel3);
const char* GetRunType();
Int_t validityStart = 0, Bool_t validityInfinite = kFALSE) = 0;
virtual Bool_t StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData) = 0;
virtual Bool_t StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName) = 0;
+
virtual const char* GetFile(Int_t system, const char* detector, const char* id, const char* source) = 0;
- virtual TList* GetFileSources(Int_t system, const char* detector, const char* id) = 0;
+
+ virtual TList* GetFileSources(Int_t system, const char* detector, const char* id = 0) = 0;
+ virtual TList* GetFileIDs(Int_t system, const char* detector, const char* source) = 0;
+
virtual const char* GetRunParameter(const char* lbEntry) = 0;
- virtual AliCDBEntry* GetFromOCDB(const char* detector, const AliCDBPath& path) = 0;
virtual const char* GetRunType() = 0;
+
+ virtual AliCDBEntry* GetFromOCDB(const char* detector, const AliCDBPath& path) = 0;
+
virtual void Log(const char* detector, const char* message) = 0;
virtual void RegisterPreprocessor(AliPreprocessor* preprocessor) = 0;