/*
$Log$
+Revision 1.5 2006/08/15 10:50:00 jgrosseo
+effc++ corrections (alberto)
+
Revision 1.4 2006/07/04 14:59:57 jgrosseo
revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
//______________________________________________________________________
Int_t AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
- const char* reqString, UInt_t startTime, UInt_t endTime, TObjArray& result)
+ const char* reqString, UInt_t startTime, UInt_t endTime, TObjArray* result)
{
// get array of DCS values from the DCS server
// reqString: alias name
Int_t sResult;
AliDCSMessage requestMessage;
- requestMessage.CreateRequestMessage(reqType, startTime, endTime,
+ requestMessage.CreateRequestMessage(reqType, startTime, endTime,
reqString);
if ((sResult = SendMessage(requestMessage)) < 0) {
GetErrorString(sResult)));
Close();
return sResult;
- }
-
+ }
+
sResult = ReceiveValueSet(result);
-
+
Close();
return sResult;
//______________________________________________________________________
Int_t AliDCSClient::GetValues(AliDCSMessage::RequestType reqType,
- UInt_t startTime, UInt_t endTime, TMap& result)
+ UInt_t startTime, UInt_t endTime, TMap& result)
{
// get array of DCS values from the DCS server
// startTime, endTime: start time and end time of the query
if (!IsConnected()) {
AliError("Not connected!");
return AliDCSClient::fgkBadState;
- }
+ }
AliDCSMessage multiRequestMessage;
- multiRequestMessage.CreateMultiRequestMessage(reqType,
+ multiRequestMessage.CreateMultiRequestMessage(reqType,
startTime, endTime);
TObjArray requests;
-
+
TIter iter(&result);
TObjString* aRequest;
-
+
// copy request strings to temporary TObjArray because
// TMap doesn't guarantee the order of elements!!!
while ((aRequest = (TObjString*) iter.Next())) {
TObjArray* resultSet = new TObjArray();
resultSet->SetOwner(1);
- if ((sResult = ReceiveValueSet(*resultSet)) < 0) {
+ if ((sResult = ReceiveValueSet(resultSet)) < 0) {
AliError(Form("Can't get values for %s!" ,
aRequest->String().Data()));
}
//______________________________________________________________________
-Int_t AliDCSClient::ReceiveValueSet(TObjArray& result)
+Int_t AliDCSClient::ReceiveValueSet(TObjArray* result)
{
// receive set of values
return AliDCSClient::fgkBadMessage;
}
}
-
+
receivedValues += message.GetValues(result);
if (receivedValues > valueCount) {
//______________________________________________________________________
Int_t AliDCSClient::GetDPValues(const char* dpName, UInt_t startTime,
- UInt_t endTime, TObjArray& result)
+ UInt_t endTime, TObjArray* result)
{
//
// Reads a values from the server which correspond to this
//______________________________________________________________________
Int_t AliDCSClient::GetAliasValues(const char* alias, UInt_t startTime,
- UInt_t endTime, TObjArray& result)
+ UInt_t endTime, TObjArray* result)
{
//
// Reads a values from the server which correspond to this
//______________________________________________________________________
Int_t AliDCSClient::GetAliasValues(UInt_t startTime, UInt_t endTime,
- TMap& result)
+ TMap& result)
{
//
// For every key of 'result' (which must be TObjString)
class AliDCSClient: public TObject {
public:
-
+
friend class AliShuttle;
-
+
AliDCSClient(const char* host, Int_t port, UInt_t timeout = 5000,
Int_t retries = 5);
virtual ~AliDCSClient();
Int_t GetDPValues(const char* dpName, UInt_t startTime, UInt_t endTime,
- TObjArray& result);
+ TObjArray* result);
Int_t GetAliasValues(const char* alias, UInt_t startTime,
- UInt_t endTime, TObjArray& result);
+ UInt_t endTime, TObjArray* result);
Int_t GetDPValues(UInt_t startTime, UInt_t endTime, TMap& result);
static const char* fgkCommErrorString; // Communication error string
static const char* fgkServerErrorString; // Server error string
- AliDCSClient(const AliDCSClient& other);
- AliDCSClient& operator= (const AliDCSClient& other);
+ AliDCSClient(const AliDCSClient& other);
+ AliDCSClient& operator= (const AliDCSClient& other);
TSocket* fSocket; // Pointer to the TCP socket client
-
+
UInt_t fTimeout; // timeout parameter
Int_t fRetries; // number of retries
-
+
AliDCSMessage::ErrorCode fServerErrorCode; // error code
-
+
TString fServerError; // server error string
Int_t SendMessage(AliDCSMessage& message);
- Int_t ReceiveMessage(AliDCSMessage& message);
+ Int_t ReceiveMessage(AliDCSMessage& message);
Int_t GetValues(AliDCSMessage::RequestType requestType,
const char* requestString, UInt_t startTime, UInt_t endTime,
- TObjArray& result);
-
+ TObjArray* result);
+
Int_t GetValues(AliDCSMessage::RequestType requestType,
UInt_t startTime, UInt_t endTime, TMap& result);
- Int_t ReceiveValueSet(TObjArray& result);
+ Int_t ReceiveValueSet(TObjArray* result);
ClassDef(AliDCSClient, 0);
/*
$Log$
+Revision 1.6 2006/08/15 10:50:00 jgrosseo
+effc++ corrections (alberto)
+
Revision 1.5 2006/07/20 09:54:40 jgrosseo
introducing status management: The processing per subdetector is divided into several steps,
after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
fMessage(NULL), fMessageSize(0), fType(kInvalid),
fStartTime(0), fEndTime(0),
fRequestString(""), fCount(0),
- fValueType(AliDCSValue::kInvalid), fValues(),
+ fValueType(AliDCSValue::kInvalid),
fErrorCode(kNoneError), fErrorString(""),
fRequestStrings()
{
// default constructor
+ fValues = new TObjArray();
+ fValues->SetOwner(0);
}
fMessageSize(size), fType(kInvalid),
fStartTime(0), fEndTime(0),
fRequestString(""), fCount(0),
- fValueType(AliDCSValue::kInvalid), fValues(),
+ fValueType(AliDCSValue::kInvalid),
fErrorCode(kNoneError), fErrorString(""),
fRequestStrings()
{
fMessage = new char[size];
memcpy(fMessage, message, size);
+ fValues = new TObjArray();
+ fValues->SetOwner(0);
}
//______________________________________________________________________
TObject(), fMessage(NULL), fMessageSize(0), fType(kInvalid),
fStartTime(0), fEndTime(0),
fRequestString(""), fCount(0),
- fValueType(AliDCSValue::kInvalid), fValues(),
+ fValueType(AliDCSValue::kInvalid),
fErrorCode(kNoneError), fErrorString(""),
fRequestStrings()
{
DestroyMessage();
DestroyBuffer();
+ if(fValues) delete fValues; fValues=0;
}
//______________________________________________________________________
-void AliDCSMessage::CreateRequestMessage(RequestType type,
+void AliDCSMessage::CreateRequestMessage(RequestType type,
UInt_t startTime, UInt_t endTime, const char* request)
{
// Create request message
}
//______________________________________________________________________
-void AliDCSMessage::SetUByte(char* buf, UChar_t val)
+void AliDCSMessage::SetUByte(char* buf, UChar_t val)
{
// Set ubyte value to buf
{
// store result set message
- TIter iter(&fValues);
+ TIter iter(fValues);
AliDCSValue* aValue;
UInt_t valueDataSize = 0;
cursor += 1;
UInt_t timeStamp = GetUInt(fMessage + cursor);
cursor += sizeof(UInt_t);
- fValues.Add(new AliDCSValue(aBool, timeStamp));
+ fValues->Add(new AliDCSValue(aBool, timeStamp));
}
} else if (fValueType == AliDCSValue::kChar) {
if (VALUES_OFFSET + count + count * sizeof(UInt_t) >
cursor += sizeof(Char_t);
UInt_t timeStamp = GetUInt(fMessage + cursor);
cursor += sizeof(UInt_t);
- fValues.Add(new AliDCSValue(aByte, timeStamp));
+ fValues->Add(new AliDCSValue(aByte, timeStamp));
}
} else if (fValueType == AliDCSValue::kInt) {
if (VALUES_OFFSET + count * sizeof(Int_t) +
cursor += sizeof(Int_t);
UInt_t timeStamp = GetUInt(fMessage + cursor);
cursor += sizeof(UInt_t);
- fValues.Add(new AliDCSValue(aInt, timeStamp));
+ fValues->Add(new AliDCSValue(aInt, timeStamp));
}
} else if (fValueType == AliDCSValue::kUInt) {
cursor += sizeof(UInt_t);
UInt_t timeStamp = GetUInt(fMessage + cursor);
cursor += sizeof(UInt_t);
- fValues.Add(new AliDCSValue(aUInt, timeStamp));
+ fValues->Add(new AliDCSValue(aUInt, timeStamp));
}
} else if (fValueType == AliDCSValue::kFloat) {
if (VALUES_OFFSET + count * sizeof(Float_t) +
cursor += sizeof(Float_t);
UInt_t timeStamp = GetUInt(fMessage + cursor);
cursor += sizeof(UInt_t);
- fValues.Add(new AliDCSValue(aFloat, timeStamp));
+ fValues->Add(new AliDCSValue(aFloat, timeStamp));
}
} else {
}
//______________________________________________________________________
-void AliDCSMessage::LoadErrorMessage()
+void AliDCSMessage::LoadErrorMessage()
{
// load error message
}
//______________________________________________________________________
-void AliDCSMessage::LoadFromBuffer()
+void AliDCSMessage::LoadFromBuffer()
{
// Reads the underlying message buffer and if it's valid message
// creates the corresponding message.
fMessageSize = HEADER_SIZE + bodySize;
Type aType = (Type) GetUByte(fMessage + TYPE_OFFSET);
-
+
switch (aType) {
case kRequest:
LoadRequestMessage();
}
//______________________________________________________________________
-Bool_t AliDCSMessage::AddRequestString(const char* request)
+Bool_t AliDCSMessage::AddRequestString(const char* request)
{
// MultRequest.
// Add a request to the request set.
}
//______________________________________________________________________
-void AliDCSMessage::ClearRequestStrings()
+void AliDCSMessage::ClearRequestStrings()
{
// MultRequest.
// Clears the request set.
}
//______________________________________________________________________
-void AliDCSMessage::GetRequestStrings(TObjArray& result) const
+void AliDCSMessage::GetRequestStrings(TObjArray& result) const
{
// MultRequest.
// Returns all request strings in this message.
}
//______________________________________________________________________
-UInt_t AliDCSMessage::GetValueCount() const
+UInt_t AliDCSMessage::GetValueCount() const
{
// ResultSet.
// Returns the count of values in this ResultSet.
return 0;
}
- return fValues.GetEntriesFast();
+ return fValues->GetEntriesFast();
}
//______________________________________________________________________
-UInt_t AliDCSMessage::GetValues(TObjArray& result) const
+UInt_t AliDCSMessage::GetValues(TObjArray* result) const
{
// ResultSet.
// Returns the number of values got from the message.
// result: used to return the values. Collection of AliDCSValue.
+ // result must be owner of the AliDCSValues because fVaule is not!
+ // creator of the result array and used GetValues to fill it must delete object by himself!
- // TODO do not copy
+ // TODO do not copy -> corrected?
if (fType != kResultSet) {
AliError("Invalid AliDCSMessage type!");
return 0;
}
- TIter iter(&fValues);
+ TIter iter(fValues);
AliDCSValue* aValue;
while ((aValue = (AliDCSValue*) iter.Next())) {
- result.AddLast(new AliDCSValue(*aValue));
+ result->AddLast(aValue);
}
- return fValues.GetEntriesFast();
+ return fValues->GetEntriesFast();
}
+
//______________________________________________________________________
-Bool_t AliDCSMessage::AddValue(const AliDCSValue& value)
+Bool_t AliDCSMessage::AddValue(AliDCSValue& value)
{
// Adds value to the ResultSet value list.
// Returns kFALSE in case of error.
return kFALSE;
}
- fValues.Add(new AliDCSValue(value));
+ fValues->Add(&value);
return kTRUE;
}
+
//______________________________________________________________________
-void AliDCSMessage::ClearValues()
+void AliDCSMessage::ClearValues()
{
// clear values array
- fValues.Delete();
+ if(fValues) fValues->Clear();
}
//______________________________________________________________________
UInt_t GetValueCount() const;
- UInt_t GetValues(TObjArray& result) const;
+ UInt_t GetValues(TObjArray* result) const;
- Bool_t AddValue(const AliDCSValue& value);
+ Bool_t AddValue(AliDCSValue& value);
void ClearValues();
//ResultSet message fields
AliDCSValue::Type fValueType; // Simple value type
- // TODO this has to be a pointer
- TObjArray fValues; // array of received values
-
+ TObjArray* fValues; // array of received values
+
//Error message fields
ErrorCode fErrorCode; // error code
/*
$Log$
+Revision 1.14 2006/08/29 09:16:05 jgrosseo
+small update
+
Revision 1.13 2006/08/15 10:50:00 jgrosseo
effc++ corrections (alberto)
#include "AliLog.h"
#include "AliPreprocessor.h"
#include "AliShuttleStatus.h"
+#include "AliShuttleLogbookEntry.h"
#include <TSystem.h>
#include <TObject.h>
ClassImp(AliShuttle)
-TString AliShuttle::fgkMainCDB("alien://DBFolder=ShuttleCDB");
+TString AliShuttle::fgkMainCDB("alien://folder=ShuttleCDB");
TString AliShuttle::fgkLocalCDB("local://LocalShuttleCDB");
-TString AliShuttle::fgkMainRefStorage("alien://DBFolder=ShuttleReference");
+TString AliShuttle::fgkMainRefStorage("alien://folder=ShuttleReference");
TString AliShuttle::fgkLocalRefStorage("local://LocalReferenceStorage");
Bool_t AliShuttle::fgkProcessDCS(kTRUE);
const char* AliShuttle::fgkShuttleTempDir = gSystem->ExpandPathName("$ALICE_ROOT/SHUTTLE/temp");
const char* AliShuttle::fgkShuttleLogDir = gSystem->ExpandPathName("$ALICE_ROOT/SHUTTLE/log");
-const char* AliShuttle::fgkDetectorName[AliShuttle::fgkNDetectors] = {"SPD", "SDD", "SSD", "TPC", "TRD", "TOF",
+const char* AliShuttle::fgkDetectorName[AliShuttle::kNDetectors] = {"SPD", "SDD", "SSD", "TPC", "TRD", "TOF",
"PHOS", "CPV", "RICH", "EMCAL", "MUON_TRK", "MUON_TRG", "FMD", "ZDC", "PMD", "START", "VZERO"};
-const char* AliShuttle::fgkDetectorCode[AliShuttle::fgkNDetectors] = {"SPD", "SDD", "SSD", "TPC", "TRD", "TOF",
+const char* AliShuttle::fgkDetectorCode[AliShuttle::kNDetectors] = {"SPD", "SDD", "SSD", "TPC", "TRD", "TOF",
"PHS", "CPV", "HMP", "EMC", "MCH", "MTR", "FMD", "ZDC", "PMD", "T00", "V00"};
//______________________________________________________________________________________________
fConfig(config),
fTimeout(timeout), fRetries(retries),
fPreprocessorMap(),
-fCurrentRun(-1),
-fCurrentStartTime(0), fCurrentEndTime(0),
+fLogbookEntry(0),
fCurrentDetector(""),
fStatusEntry(0),
fGridError(kFALSE)
fServer[iSys]=0;
fFESlist[iSys].SetOwner(kTRUE);
}
+ fPreprocessorMap.SetOwner(kTRUE);
}
//______________________________________________________________________
fConfig(0),
fTimeout(0), fRetries(0),
fPreprocessorMap(),
-fCurrentRun(-1),
-fCurrentStartTime(0), fCurrentEndTime(0),
+fLogbookEntry(0),
fCurrentDetector(""),
fStatusEntry(0),
fGridError(kFALSE)
fServer[iSys]->Close();
delete fServer[iSys];
}
+
+ if (fStatusEntry){
+ delete fStatusEntry;
+ fStatusEntry = 0;
+ }
}
//______________________________________________________________________________________________
fPreprocessorMap.Add(new TObjString(preprocessor->GetName()), preprocessor);
}
-
//______________________________________________________________________________________________
UInt_t AliShuttle::Store(const AliCDBPath& path, TObject* object,
AliCDBMetaData* metaData, Int_t validityStart, Bool_t validityInfinite)
// 2 if stored in backup (Local) storage
const char* cdbType = (mainUri == fgkMainCDB) ? "CDB" : "Reference";
-
+
Int_t firstRun = GetCurrentRun() - validityStart;
if(firstRun < 0) {
- AliError("First valid run happens to be less than 0! Setting it to 0...");
+ AliError("First valid run happens to be less than 0! Setting it to 0.");
firstRun=0;
}
lastRun = GetCurrentRun();
}
- AliCDBId id(path, firstRun, lastRun);
+ AliCDBId id(path, firstRun, lastRun, -1, -1);
+
+ if(! dynamic_cast<TObjString*> (metaData->GetProperty("RunUsed(TObjString)"))){
+ TObjString runUsed = Form("%d", GetCurrentRun());
+ metaData->SetProperty("RunUsed(TObjString)",&runUsed);
+ }
UInt_t result = 0;
if (!(AliCDBManager::Instance()->GetStorage(mainUri))) {
- Log(fCurrentDetector, Form("Cannot activate main %s storage!", cdbType));
+ AliError(Form("WriteToCDB - Cannot activate main %s storage", cdbType));
} else {
result = (UInt_t) AliCDBManager::Instance()->GetStorage(mainUri)
->Put(object, id, metaData);
if(!result) {
Log(fCurrentDetector,
- Form("Problem with main %s storage. Object will go to local storage!", cdbType));
+ Form("WriteToCDB - Problem with main %s storage. Putting <%s> into backup storage",
+ cdbType, path.GetPath().Data()));
+
+ // Set Grid version to current run number, to ease retrieval later
+ id.SetVersion(GetCurrentRun());
result = AliCDBManager::Instance()->GetStorage(localUri)
->Put(object, id, metaData);
result = 2;
fGridError = kTRUE;
}else{
- Log(fCurrentDetector, "Can't store data!");
+ Log(fCurrentDetector, "WriteToCDB - Can't store data!");
}
}
+
return result;
}
//______________________________________________________________________________________________
AliShuttleStatus* AliShuttle::ReadShuttleStatus()
{
- // Reads the AliShuttleStatus from the CDB
+// Reads the AliShuttleStatus from the CDB
- if (fStatusEntry)
- {
- delete fStatusEntry;
- fStatusEntry = 0;
- }
+ if (fStatusEntry){
+ delete fStatusEntry;
+ fStatusEntry = 0;
+ }
- fStatusEntry = AliCDBManager::Instance()->GetStorage(AliShuttle::GetLocalCDB())
- ->Get(Form("/SHUTTLE/STATUS/%s", fCurrentDetector.Data()), fCurrentRun);
+ fStatusEntry = AliCDBManager::Instance()->GetStorage(AliShuttle::GetLocalCDB())
+ ->Get(Form("/SHUTTLE/STATUS/%s", fCurrentDetector.Data()), GetCurrentRun());
- if (!fStatusEntry)
- return 0;
+ if (!fStatusEntry) return 0;
+ fStatusEntry->SetOwner(1);
- TObject* anObject = fStatusEntry->GetObject();
- if (anObject == NULL || anObject->IsA() != AliShuttleStatus::Class())
- {
- AliError("Invalid object stored to CDB!");
- return 0;
- }
+ AliShuttleStatus* status = dynamic_cast<AliShuttleStatus*> (fStatusEntry->GetObject());
+ if (!status) {
+ AliError("Invalid object stored to CDB!");
+ return 0;
+ }
- AliShuttleStatus* status = dynamic_cast<AliShuttleStatus*> (anObject);
- return status;
+ return status;
}
//______________________________________________________________________________________________
Bool_t AliShuttle::WriteShuttleStatus(AliShuttleStatus* status)
{
- // writes the status for one subdetector
+// writes the status for one subdetector
+
+ if (fStatusEntry){
+ delete fStatusEntry;
+ fStatusEntry = 0;
+ }
- if (fStatusEntry)
- {
- delete fStatusEntry;
- fStatusEntry = 0;
- }
+ Int_t run = GetCurrentRun();
- AliCDBId id(AliCDBPath("SHUTTLE", "STATUS", fCurrentDetector), fCurrentRun, fCurrentRun);
+ AliCDBId id(AliCDBPath("SHUTTLE", "STATUS", fCurrentDetector), run, run);
- fStatusEntry = new AliCDBEntry(status, id, new AliCDBMetaData);
+ fStatusEntry = new AliCDBEntry(status, id, new AliCDBMetaData);
+ fStatusEntry->SetOwner(1);
- UInt_t result = AliCDBManager::Instance()->GetStorage(fgkLocalCDB)->Put(fStatusEntry);
+ UInt_t result = AliCDBManager::Instance()->GetStorage(fgkLocalCDB)->Put(fStatusEntry);
- if (!result)
- {
- AliError(Form("WriteShuttleStatus for %s, run %d failed", fCurrentDetector.Data(), fCurrentRun));
- return kFALSE;
- }
+ if (!result) {
+ AliError(Form("WriteShuttleStatus for %s, run %d failed", fCurrentDetector.Data(), run));
+ return kFALSE;
+ }
- return kTRUE;
+ return kTRUE;
}
//______________________________________________________________________________________________
{
// changes the AliShuttleStatus for the given detector and run to the given status
- if (!fStatusEntry)
- {
- AliError("UNEXPECTED: fStatusEntry empty");
- return;
- }
+ if (!fStatusEntry){
+ AliError("UNEXPECTED: fStatusEntry empty");
+ return;
+ }
- TObject* anObject = fStatusEntry->GetObject();
- AliShuttleStatus* status = dynamic_cast<AliShuttleStatus*> (anObject);
+ AliShuttleStatus* status = dynamic_cast<AliShuttleStatus*> (fStatusEntry->GetObject());
- if (!status)
- {
- AliError("UNEXPECTED: status could not be read from current CDB entry");
- return;
- }
+ if (!status){
+ AliError("UNEXPECTED: status could not be read from current CDB entry");
+ return;
+ }
- Log("SHUTTLE", Form("%s: Changing state from %s to %s", fCurrentDetector.Data(),
- status->GetStatusName(), status->GetStatusName(newStatus)));
+ Log("SHUTTLE", Form("UpdateShuttleStatus - %s: Changing state from %s to %s", fCurrentDetector.Data(),
+ status->GetStatusName(), status->GetStatusName(newStatus)));
- status->SetStatus(newStatus);
- if (increaseCount)
- status->IncreaseCount();
+ status->SetStatus(newStatus);
+ if (increaseCount) status->IncreaseCount();
- AliCDBManager::Instance()->GetStorage(fgkLocalCDB)->Put(fStatusEntry);
+ AliCDBManager::Instance()->GetStorage(fgkLocalCDB)->Put(fStatusEntry);
}
-
//______________________________________________________________________________________________
Bool_t AliShuttle::ContinueProcessing()
{
- // this function reads the AliShuttleStatus information from CDB and
- // checks if the processing should be continued
- // if yes it returns kTRUE and updates the AliShuttleStatus with nextStatus
-
- AliShuttleStatus* status = ReadShuttleStatus();
- if (!status)
- {
- // first time
-
- Log("SHUTTLE", Form("%s: Processing first time.", fCurrentDetector.Data()));
- status = new AliShuttleStatus(AliShuttleStatus::kStarted);
- return WriteShuttleStatus(status);
- }
-
- if (status->GetStatus() == AliShuttleStatus::kDone)
- {
- Log("SHUTTLE", Form("%s already done for run %d", fCurrentDetector.Data(), fCurrentRun));
- return kFALSE;
- }
-
- if (status->GetStatus() == AliShuttleStatus::kFailed)
- {
- Log("SHUTTLE", Form("%s already in failed state for run %d", fCurrentDetector.Data(), fCurrentRun));
- return kFALSE;
- }
-
- // TODO what to do in case of storage error? currently it does not do anything
- if (status->GetStatus() == AliShuttleStatus::kStoreFailed)
- {
- Log("SHUTTLE", Form("%s: Grid storage failed at least once for run %d", fCurrentDetector.Data(), fCurrentRun));
- return kFALSE;
- }
-
- // if we get here, there is a restart
-
- // abort conditions
- if (status->GetStatus() == AliShuttleStatus::kPPStarted && status->GetCount() >= fConfig->GetMaxPPRetries() ||
- status->GetCount() >= fConfig->GetMaxRetries())
- {
- Log("SHUTTLE", Form("%s, run %d failed too often, %d times, status %s. Skipping processing.",
- fCurrentDetector.Data(), fCurrentRun, status->GetCount(), status->GetStatusName()));
-
- return kFALSE;
- }
-
- Log("SHUTTLE", Form("Restart of %s, run %d. Got stuck before in %s, count %d",
- fCurrentDetector.Data(), fCurrentRun, status->GetStatusName(), status->GetCount()));
-
- UpdateShuttleStatus(AliShuttleStatus::kStarted, kTRUE);
-
- return kTRUE;
+// this function reads the AliShuttleStatus information from CDB and
+// checks if the processing should be continued
+// if yes it returns kTRUE and updates the AliShuttleStatus with nextStatus
+
+ if(!GetDetCode(fCurrentDetector)) {
+ Log("SHUTTLE", Form("ContinueProcessing - %s: unknown detector",
+ fCurrentDetector.Data()));
+ return kFALSE;
+ }
+
+ AliShuttleLogbookEntry::Status entryStatus =
+ fLogbookEntry->GetDetectorStatus(GetDetCode(fCurrentDetector));
+
+ if(entryStatus != AliShuttleLogbookEntry::kUnprocessed) {
+ Log("SHUTTLE", Form("ContinueProcessing - %s is already %s",
+ fCurrentDetector.Data(),
+ fLogbookEntry->GetDetectorStatusName(entryStatus)));
+ return kFALSE;
+ }
+
+ // if we get here, according to Shuttle logbook subdetector is in UNPROCESSED state
+ AliShuttleStatus* status = ReadShuttleStatus();
+ if (!status) {
+ // first time
+ Log("SHUTTLE", Form("ContinueProcessing - %s: Processing first time",
+ fCurrentDetector.Data()));
+ status = new AliShuttleStatus(AliShuttleStatus::kStarted);
+ return WriteShuttleStatus(status);
+ }
+
+ // The following two cases shouldn't happen if Shuttle Logbook was correctly updated.
+ // If it happens it may mean Logbook updating failed... let's do it now!
+ if (status->GetStatus() == AliShuttleStatus::kDone ||
+ status->GetStatus() == AliShuttleStatus::kFailed){
+ Log("SHUTTLE", Form("ContinueProcessing - %s is already %s. Updating Shuttle Logbook",
+ fCurrentDetector.Data(),
+ status->GetStatusName(status->GetStatus())));
+ UpdateShuttleLogbook(fCurrentDetector.Data(),
+ status->GetStatusName(status->GetStatus()));
+ return kFALSE;
+ }
+
+ if (status->GetStatus() == AliShuttleStatus::kStoreFailed) {
+ Log("SHUTTLE",
+ Form("ContinueProcessing - %s: Grid storage of one or more objects failed. Trying again now",
+ fCurrentDetector.Data()));
+ if(TryToStoreAgain()){
+ Log(fCurrentDetector.Data(), "ContinueProcessing - All objects successfully stored into OCDB");
+ UpdateShuttleStatus(AliShuttleStatus::kDone);
+ UpdateShuttleLogbook(fCurrentDetector.Data(), "DONE");
+ } else {
+ Log("SHUTTLE",
+ Form("ContinueProcessing - %s: Grid storage failed again",
+ fCurrentDetector.Data()));
+ }
+ return kFALSE;
+ }
+
+ // if we get here, there is a restart
+
+ // abort conditions
+ // TODO we should add two counters, one for PP and one for DCS!
+ if ((status->GetStatus() == AliShuttleStatus::kPPStarted ||
+ status->GetStatus() == AliShuttleStatus::kPPError) &&
+ (status->GetCount() >= fConfig->GetMaxPPRetries() ||
+ status->GetCount() >= fConfig->GetMaxRetries())) {
+ Log("SHUTTLE",
+ Form("ContinueProcessing - %s failed %d times in status %s - Updating Shuttle Logbook",
+ fCurrentDetector.Data(),
+ status->GetCount(), status->GetStatusName()));
+ UpdateShuttleLogbook(fCurrentDetector.Data(), "FAILED");
+ return kFALSE;
+ }
+
+ Log("SHUTTLE", Form("ContinueProcessing - %s: restarting. Got stuck before in %s. Retry number %d.",
+ fCurrentDetector.Data(),
+ status->GetStatusName(), status->GetCount()));
+
+ UpdateShuttleStatus(AliShuttleStatus::kStarted);
+
+ return kTRUE;
}
//______________________________________________________________________________________________
-Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
+Bool_t AliShuttle::Process(AliShuttleLogbookEntry* entry)
{
//
// Makes data retrieval for all detectors in the configuration.
- // run: is the run number used
- // startTime: is the run start time
- // endTime: is the run end time
+ // entry: Shuttle logbook entry, contains run paramenters and status of detectors
+ // (Unprocessed, Inactive, Failed or Done).
// Returns kFALSE in case of error occured and kTRUE otherwise
//
- AliInfo(Form("\n\n \t\t\t^*^*^*^*^*^*^*^*^*^*^*^* run %d: START ^*^*^*^*^*^*^*^*^*^*^*^* \n", run));
+ if(!entry) return kFALSE;
+
+ fLogbookEntry = entry;
+
+ if(fLogbookEntry->IsDone()){
+ Log("SHUTTLE","Process - Shuttle is already DONE. Updating logbook");
+ UpdateShuttleLogbook("shuttle_done");
+ fLogbookEntry = 0;
+ return kTRUE;
+ }
+
+
+ AliInfo(Form("\n\n \t\t\t^*^*^*^*^*^*^*^*^*^*^*^* run %d: START ^*^*^*^*^*^*^*^*^*^*^*^* \n",
+ GetCurrentRun()));
+
+ fLogbookEntry->Print("");
// Initialization
Bool_t hasError = kFALSE;
for(Int_t iSys=0;iSys<3;iSys++) fFESCalled[iSys]=kFALSE;
- fCurrentRun = run;
- fCurrentStartTime = startTime;
- fCurrentEndTime = endTime;
+ AliCDBStorage *mainCDBSto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
+ if(mainCDBSto) mainCDBSto->QueryCDB(GetCurrentRun());
+ AliCDBStorage *mainRefSto = AliCDBManager::Instance()->GetStorage(fgkMainRefStorage);
+ if(mainRefSto) mainRefSto->QueryCDB(GetCurrentRun());
// Loop on detectors in the configuration
TIter iter(fConfig->GetDetectors());
- TObjString* aDetector;
+ TObjString* aDetector = 0;
while ((aDetector = (TObjString*) iter.Next())) {
fCurrentDetector = aDetector->String();
- Bool_t detectorError=kFALSE;
if (!fConfig->HostProcessDetector(fCurrentDetector)) continue;
+ AliPreprocessor* aPreprocessor =
+ dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(fCurrentDetector));
+ if(!aPreprocessor){
+ Log("SHUTTLE",Form("Process - %s: no preprocessor registered. Skipping"));
+ continue;
+ }
+
if (ContinueProcessing() == kFALSE) continue;
- AliInfo(Form("\n\n \t\t\t****** %s: START ******", aDetector->GetName()));
+ AliInfo(Form("\n\n \t\t\t****** run %d - %s: START ******",
+ GetCurrentRun(), aDetector->GetName()));
+
+ UInt_t result = ProcessCurrentDetector();
- if(!Process()) {
+ if(!result) {
hasError = kTRUE;
- detectorError=kTRUE;
+ AliInfo(Form("\n \t\t\t****** run %d - %s: PREPROCESSOR ERROR ****** \n\n",
+ GetCurrentRun(), aDetector->GetName()));
continue;
}
- AliInfo(Form("\n \t\t\t****** %s: FINISH ****** \n\n", aDetector->GetName()));
+
+ if(result == 2) {
+ AliInfo(Form("\n \t\t\t****** run %d - %s: STORAGE ERROR ****** \n\n",
+ GetCurrentRun(), aDetector->GetName()));
+ } else {
+ AliInfo(Form("\n \t\t\t****** run %d - %s: DONE ****** \n\n",
+ GetCurrentRun(), aDetector->GetName()));
+ }
// Process successful: Update time_processed field in FES logbooks!
if(fFESCalled[kDAQ]) {
// fFESlist[kHLT].Clear();
//}
- // UpdateShuttleStatus(AliShuttleStatus::kDone);
}
- fCurrentRun = -1;
- fCurrentStartTime = 0;
- fCurrentEndTime = 0;
+ AliInfo(Form("\n\n \t\t\t^*^*^*^*^*^*^*^*^*^*^*^* run %d: FINISH ^*^*^*^*^*^*^*^*^*^*^*^* \n",
+ GetCurrentRun()));
+
+ //check if shuttle is done for this run, if so update logbook
+ TObjArray checkEntryArray;
+ checkEntryArray.SetOwner(1);
+ TString whereClause = Form("where run=%d",GetCurrentRun());
+ if(QueryShuttleLogbook(whereClause.Data(), checkEntryArray)) {
- AliInfo(Form("\n\n \t\t\t^*^*^*^*^*^*^*^*^*^*^*^* run %d: FINISH ^*^*^*^*^*^*^*^*^*^*^*^* \n", run));
+ AliShuttleLogbookEntry* checkEntry = dynamic_cast<AliShuttleLogbookEntry*>
+ (checkEntryArray.At(0));
+
+ if(checkEntry && checkEntry->IsDone()){
+ Log("SHUTTLE","Process - Shuttle is DONE. Updating logbook");
+ UpdateShuttleLogbook("shuttle_done");
+ }
+ }
+
+ fLogbookEntry = 0;
return hasError == kFALSE;
}
//______________________________________________________________________________________________
-Bool_t AliShuttle::Process()
+UInt_t AliShuttle::ProcessCurrentDetector()
{
//
- // Makes data retrieval just for one specific detector.
+ // Makes data retrieval just for a specific detector (fCurrentDetector).
// Threre should be a configuration for this detector.
- // run: is the run number used
- // startTime: is the run start time
- // endTime: is the run end time
- // detector: detector for which the retrieval will be made
- // Returns kFALSE in case of error occured and kTRUE otherwise
- //
-
- AliInfo(Form("Retrieving values for %s, run %d", fCurrentDetector.Data(), fCurrentRun));
- if (!fConfig->HasDetector(fCurrentDetector)) {
- Log(fCurrentDetector, "There isn't any configuration for %s !");
- UpdateShuttleStatus(AliShuttleStatus::kFailed);
- return kFALSE;
- }
+ AliInfo(Form("Retrieving values for %s, run %d", fCurrentDetector.Data(), GetCurrentRun()));
UpdateShuttleStatus(AliShuttleStatus::kDCSStarted);
TIter iter(fConfig->GetDCSAliases(fCurrentDetector));
TObjString* anAlias;
TMap aliasMap;
+ aliasMap.SetOwner(1);
Bool_t aDCSError = kFALSE;
fGridError = kFALSE;
- UInt_t aPPResult;
while ((anAlias = (TObjString*) iter.Next())) {
- TObjArray valueSet;
+ TObjArray *valueSet = new TObjArray();
+ valueSet->SetOwner(1);
// TODO Test only... I've added a flag that allows to
// exclude DCS archive DB query
if(fgkProcessDCS){
aDCSError = kFALSE;
}
if(!aDCSError) {
- aliasMap.Add(anAlias->Clone(), valueSet.Clone());
+ aliasMap.Add(anAlias->Clone(), valueSet);
}else{
- TString message = Form("Error while retrieving alias %s !",
- anAlias->GetName());
- Log(fCurrentDetector, message.Data());
- aDCSError = kTRUE;
- break;
+ Log(fCurrentDetector, Form("ProcessCurrentDetector - Error while retrieving alias %s",
+ anAlias->GetName()));
+ UpdateShuttleStatus(AliShuttleStatus::kDCSError, kTRUE);
+ aliasMap.DeleteAll();
+ return 0;
}
}
- if (aDCSError)
- {
- UpdateShuttleStatus(AliShuttleStatus::kDCSError);
- return kFALSE;
- }
-
+ // DCS Archive DB processing successful. Call Preprocessor!
UpdateShuttleStatus(AliShuttleStatus::kPPStarted);
AliPreprocessor* aPreprocessor =
dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(fCurrentDetector));
- if(aPreprocessor)
- {
- aPreprocessor->Initialize(fCurrentRun, fCurrentStartTime, fCurrentEndTime);
- aPPResult = aPreprocessor->Process(&aliasMap);
- }else{
- // TODO default behaviour?
- AliInfo(Form("No Preprocessor for %s: storing TMap of DP arrays into CDB!", fCurrentDetector.Data()));
- AliCDBMetaData metaData;
- AliDCSValue dcsValue(fCurrentStartTime, fCurrentEndTime);
- metaData.SetResponsible(Form("Duck, Donald"));
- metaData.SetProperty("StartEndTime", &dcsValue);
- metaData.SetComment("Automatically stored by Shuttle!");
- AliCDBPath path(fCurrentDetector,"DCS","Data");
- aPPResult = Store(path, &aliasMap, &metaData);
- }
+ aPreprocessor->Initialize(GetCurrentRun(), GetCurrentStartTime(), GetCurrentEndTime());
+
+ UInt_t aPPResult = aPreprocessor->Process(&aliasMap);
+
+ UInt_t returnValue = 0;
if (aPPResult == 0) { // Preprocessor error
- UpdateShuttleStatus(AliShuttleStatus::kPPError);
+ UpdateShuttleStatus(AliShuttleStatus::kPPError, kTRUE);
+ returnValue = 0;
} else if (fGridError == kFALSE) { // process and Grid storage ok!
UpdateShuttleStatus(AliShuttleStatus::kDone);
+ UpdateShuttleLogbook(fCurrentDetector, "DONE");
+ Log(fCurrentDetector.Data(),
+ "ProcessCurrentDetector - Preprocessor and Grid storage ended successfully");
+ returnValue = 1;
} else { // Grid storage error (process ok, but object put in local storage)
UpdateShuttleStatus(AliShuttleStatus::kStoreFailed);
+ returnValue = 2;
}
- aliasMap.Delete();
+ aliasMap.DeleteAll();
- return (aPPResult > 0);
+ return returnValue;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::QueryShuttleLogbook(const char* whereClause,
+ TObjArray& entries)
+{
+// Query DAQ's Shuttle logbook and fills detector status object.
+// Call QueryRunParameters to query DAQ logbook for run parameters.
+
+ // check connection, in case connect
+ if(!Connect(kDAQ)) return kFALSE;
+
+ TString sqlQuery;
+ sqlQuery = Form("select * from logbook_shuttle %s order by run", whereClause);
+
+ TSQLResult* aResult = fServer[kDAQ]->Query(sqlQuery);
+ if (!aResult) {
+ AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
+ return kFALSE;
+ }
+
+ if(aResult->GetRowCount() == 0) {
+ if(sqlQuery.Contains("where shuttle_done=0")){
+ Log("SHUTTLE", "QueryShuttleLogbook - All runs in Shuttle Logbook are already DONE");
+ delete aResult;
+ return kTRUE;
+ } else {
+ AliError("No entries in Shuttle Logbook match request");
+ delete aResult;
+ return kFALSE;
+ }
+ }
+
+ // TODO Check field count!
+ const UInt_t nCols = 24;
+ if (aResult->GetFieldCount() != (Int_t) nCols) {
+ AliError("Invalid SQL result field number!");
+ delete aResult;
+ return kFALSE;
+ }
+
+ entries.SetOwner(1);
+
+ TSQLRow* aRow;
+ while ((aRow = aResult->Next())) {
+ TString runString(aRow->GetField(0), aRow->GetFieldLength(0));
+ Int_t run = runString.Atoi();
+
+ UInt_t startTime, endTime;
+ if(!QueryRunParameters(run, startTime, endTime)) continue;
+
+ const UInt_t nDet = AliShuttle::kNDetectors;
+ AliShuttleLogbookEntry::Status detStatus[nDet];
+
+ // loop on detectors
+ for(UInt_t ii = 0; ii < nCols; ii++){
+ TString detCode(aResult->GetFieldName(ii));
+ Int_t detPos = AliShuttle::GetDetPos(detCode.Data());
+ if(detPos < 0) continue;
+ TString statusString(aRow->GetField(ii), aRow->GetFieldLength(ii));
+ if(statusString == "UNPROCESSED"){
+ detStatus[detPos] = AliShuttleLogbookEntry::kUnprocessed;
+ } else if (statusString == "INACTIVE") {
+ detStatus[detPos] = AliShuttleLogbookEntry::kInactive;
+ } else if (statusString == "FAILED") {
+ detStatus[detPos] = AliShuttleLogbookEntry::kFailed;
+ } else if (statusString == "DONE") {
+ detStatus[detPos] = AliShuttleLogbookEntry::kDone;
+ }
+ }
+
+ entries.AddLast(new AliShuttleLogbookEntry(run, startTime, endTime, detStatus));
+ delete aRow;
+ }
+
+ if(sqlQuery.Contains("where shuttle_done=0"))
+ Log("SHUTTLE", Form("QueryShuttleLogbook - Found %d unprocessed runs in Shuttle Logbook",
+ entries.GetEntriesFast()));
+ delete aResult;
+ return kTRUE;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::QueryRunParameters(Int_t& run, UInt_t& startTime, UInt_t& endTime)
+{
+// Retrieve start time and end time for run in the DAQ logbook
+
+ // check connection, in case connect
+ if(!Connect(kDAQ)) return kFALSE;
+
+ TString sqlQuery;
+ sqlQuery = Form("select time_start, time_end from logbook where run=%d", run);
+
+ TSQLResult* aResult = fServer[kDAQ]->Query(sqlQuery);
+ if (!aResult) {
+ AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
+ return kFALSE;
+ }
+
+ if(aResult->GetRowCount() == 0) {
+ Log("SHUTTLE", Form("QueryRunParameters - No entry in DAQ Logbook for run %d. Skipping", run));
+ delete aResult;
+ return kFALSE;
+ }
+
+ if(aResult->GetRowCount() > 1) {
+ AliError(Form("More than one entry in DAQ Logbook for run %d. Skipping", run));
+ delete aResult;
+ return kFALSE;
+ }
+
+ TSQLRow* aRow;
+ while ((aRow = aResult->Next())) {
+
+ TString startTimeString(aRow->GetField(0),
+ aRow->GetFieldLength(0));
+ startTime = startTimeString.Atoi();
+ TString endTimeString(aRow->GetField(1),
+ aRow->GetFieldLength(1));
+ endTime = endTimeString.Atoi();
+
+ if (!startTime || !endTime || startTime > endTime) {
+ Log("SHUTTLE",
+ Form("QueryRunParameters - Invalid parameters for Run %d: startTime = %d, endTime = %d",
+ run, startTime, endTime));
+ delete aRow;
+ delete aResult;
+ return kFALSE;
+ }
+
+ delete aRow;
+ }
+
+ delete aResult;
+ return kTRUE;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::TryToStoreAgain()
+{
+ // Called in case the detector failed to store the object in Grid OCDB
+ // It tries to store the object again, if it does not find more recent and overlapping objects
+ // Calls underlying TryToStoreAgain(const char*) function twice, for OCDB and Reference storage.
+
+ AliInfo("Trying to store OCDB data again...");
+ Bool_t resultCDB = TryToStoreAgain(fgkMainCDB);
+
+ AliInfo("Trying to store reference data again...");
+ Bool_t resultRef = TryToStoreAgain(fgkMainRefStorage);
+
+ return resultCDB && resultRef;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::TryToStoreAgain(TString& gridURI)
+{
+ // Called by TryToStoreAgain(), performs actual storage retry
+
+ TList* gridIds=0;
+
+ Bool_t result = kTRUE;
+
+ const char* type = 0;
+ TString backupURI;
+ if(gridURI == fgkMainCDB) {
+ type = "OCDB";
+ backupURI = fgkLocalCDB;
+ } else if(gridURI == fgkMainRefStorage) {
+ type = "reference";
+ backupURI = fgkLocalRefStorage;
+ } else {
+ AliError(Form("Invalid storage URI: %s", gridURI.Data()));
+ return kFALSE;
+ }
+
+ AliCDBManager* man = AliCDBManager::Instance();
+
+ AliCDBStorage *gridSto = man->GetStorage(gridURI);
+ if(!gridSto) {
+ Log(fCurrentDetector.Data(),
+ Form("TryToStoreAgain - cannot activate main %s storage", type));
+ return kFALSE;
+ }
+
+ gridIds = gridSto->GetQueryCDBList();
+
+ // get objects previously stored in local CDB
+ AliCDBStorage *backupSto = man->GetStorage(backupURI);
+ AliCDBPath aPath(fCurrentDetector,"*","*");
+ // Local objects were stored with current run as Grid version!
+ TList* localEntries = backupSto->GetAll(aPath.GetPath(), GetCurrentRun(), GetCurrentRun());
+ localEntries->SetOwner(1);
+
+ // loop on local stored objects
+ TIter localIter(localEntries);
+ AliCDBEntry *aLocEntry = 0;
+ while((aLocEntry = dynamic_cast<AliCDBEntry*> (localIter.Next()))){
+ aLocEntry->SetOwner(1);
+ AliCDBId aLocId = aLocEntry->GetId();
+ aLocEntry->SetVersion(-1);
+ aLocEntry->SetSubVersion(-1);
+
+ // loop on Grid valid Id's
+ Bool_t store = kTRUE;
+ TIter gridIter(gridIds);
+ AliCDBId* aGridId = 0;
+ while((aGridId = dynamic_cast<AliCDBId*> (gridIter.Next()))){
+ // If local object is valid up to infinity we store it anyway
+ // TODO This does not work! It may hide more recent objects...
+ if(aLocId.GetLastRun() == AliCDBRunRange::Infinity()) {
+ // TODO Check that it won't hide more recent files! how????
+ break;
+ }
+ if(aGridId->GetPath() != aLocId.GetPath()) continue;
+ // skip all objects valid up to infinity
+ if(aGridId->GetLastRun() == AliCDBRunRange::Infinity()) continue;
+ // if we get here, it means there's already some more recent object stored on Grid!
+ store = kFALSE;
+ break;
+ }
+
+ if(!store){
+ Log(fCurrentDetector.Data(),
+ Form("TryToStoreAgain - A more recent object already exists in %s storage: <%s>",
+ type, aGridId->ToString().Data()));
+ // removing local filename...
+ // TODO maybe it's better not to remove it, it was not copied to the Grid!
+ TString filename;
+ backupSto->IdToFilename(aLocId, filename);
+ AliInfo(Form("Removing local file %s", filename.Data()));
+ gSystem->Exec(Form("rm %s",filename.Data()));
+ continue;
+ }
+
+ // If we get here, the file can be stored!
+ Bool_t storeOk = gridSto->Put(aLocEntry);
+ if(storeOk){
+ Log(fCurrentDetector.Data(),
+ Form("TryToStoreAgain - Object <%s> successfully put into %s storage",
+ aLocId.ToString().Data(), type));
+
+ // removing local filename...
+ TString filename;
+ backupSto->IdToFilename(aLocId, filename);
+ AliInfo(Form("Removing local file %s", filename.Data()));
+ gSystem->Exec(Form("rm %s", filename.Data()));
+ continue;
+ } else {
+ Log(fCurrentDetector.Data(),
+ Form("TryToStoreAgain - Grid %s storage of object <%s> failed again",
+ type, aLocId.ToString().Data()));
+ result = kFALSE;
+ }
+ }
+ localEntries->Clear();
+
+ return result;
}
//______________________________________________________________________________________________
Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
- TObjArray& valueSet)
+ TObjArray* valueSet)
{
// Retrieve all "alias" data points from the DCS server
// host, port: TSocket connection parameters
// alias: name of the alias
-// valueSet: array of retrieved AliDCSValue's
+// valueSet: array of retrieved AliDCSValue's
AliDCSClient client(host, port, fTimeout, fRetries);
if (!client.IsConnected()) {
GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
if (result < 0) {
- AliError(Form("Can't get '%s'! Reason: %s",
+ Log(fCurrentDetector.Data(), Form("GetValueSet - Can't get '%s'! Reason: %s",
alias, AliDCSClient::GetErrorString(result)));
if (result == AliDCSClient::fgkServerError) {
- AliError(Form("Server error: %s",
+ Log(fCurrentDetector.Data(), Form("GetValueSet - Server error: %s",
client.GetServerError().Data()));
}
}
//______________________________________________________________________________________________
-Bool_t AliShuttle::Connect(Int_t system){
+Bool_t AliShuttle::Connect(Int_t system)
+{
// Connect to MySQL Server of the system's FES logbook
+// DAQ Logbook, Shuttle Logbook and DAQ FES Logbook are on the same host
// check connection: if already connected return
if(fServer[system] && fServer[system]->IsConnected()) return kTRUE;
fConfig->GetFESlbUser(system),
fConfig->GetFESlbPass(system));
if (!fServer[system] || !fServer[system]->IsConnected()) {
- AliError(Form("Can't establish connection to FES logbook for %s !",fkSystemNames[system]));
+ AliError(Form("Can't establish connection to FES logbook for %s",fkSystemNames[system]));
+ if(fServer[system]) delete fServer[system];
return kFALSE;
}
// Get tables
// TODO in the configuration should the table name be there too?
+ TSQLResult* aResult=0;
switch(system){
case kDAQ:
- fServer[kDAQ]->GetTables("REFSYSLOG");
+ aResult = fServer[kDAQ]->GetTables("REFSYSLOG");
break;
case kDCS:
- //fServer[kDCS]->GetTables("REFSYSLOG");
+ //aResult = fServer[kDCS]->GetTables("REFSYSLOG");
break;
case kHLT:
- //fServer[kHLT]->GetTables("REFSYSLOG");
+ //aResult = fServer[kHLT]->GetTables("REFSYSLOG");
break;
default:
break;
}
+ delete aResult;
return kTRUE;
}
//______________________________________________________________________________________________
-const char* AliShuttle::GetDAQFileName(const char* detector, const char* id, const char* source){
+const char* AliShuttle::GetDAQFileName(const char* detector, const char* id, const char* source)
+{
// Retrieves a file from the DAQ FES.
// First queris the DAQ logbook_fs for the DAQ file name, using the run, detector, id and source info
// then calls RetrieveDAQFile(DAQfilename) for actual copy to local disk
-// run: current run being processed (fCurrentRun)
+// run: current run being processed (given by Logbook entry fLogbookEntry)
// detector: comes from the Preprocessor name (must be converted into detector code with GetDetCode)
// id: provided as a parameter by the Preprocessor
// source: provided by the Preprocessor through GetFileSources function
// check connection, in case connect
if(!Connect(kDAQ)){
- Log(detector, "GetDAQFileName: Couldn't connect to DAQ Logbook !");
+ Log(detector, "GetDAQFileName - Couldn't connect to DAQ Logbook");
return 0;
}
// Query preparation
TString sqlQueryStart = "select filePath from logbook_fs where";
TString whereClause = Form("run=%d and detector=\"%s\" and fileId=\"%s\" and DAQsource=\"%s\"",
- fCurrentRun, GetDetCode(detector), id, source);
+ GetCurrentRun(), GetDetCode(detector), id, 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[kDAQ]->Query(sqlQuery);
+ TSQLResult* aResult = 0;
+ aResult = dynamic_cast<TSQLResult*> (fServer[kDAQ]->Query(sqlQuery));
if (!aResult) {
- Log(detector, Form("Can't execute query <%s>!", sqlQuery.Data()));
+ Log(detector, Form("GetDAQFileName - Can't execute SQL query for: id = %s, source = %s",
+ id, source));
return 0;
}
if (aResult->GetRowCount() == 0) {
Log(detector,
- Form("GetDAQFileName: No result from SQL query <%s>!", sqlQuery.Data()));
+ Form("GetDAQFileName - No entry in FES table for: id = %s, source = %s",
+ id, source));
delete aResult;
return 0;
}
if (aResult->GetRowCount() >1) {
Log(detector,
- Form("GetDAQFileName: More than one row resulting from SQL query <%s>!", sqlQuery.Data()));
+ Form("GetDAQFileName - More than one entry in FES table for: id = %s, source = %s",
+ id, source));
delete aResult;
return 0;
}
- TSQLRow* aRow = aResult->Next();
+ TSQLRow* aRow = dynamic_cast<TSQLRow*> (aResult->Next());
if(!aRow){
- Log(detector, Form("GetDAQFileName: Empty set result from query <%s>!", sqlQuery.Data()));
+ Log(detector, Form("GetDAQFileName - Empty set result from query: id = %s, source = %s",
+ id, source));
delete aResult;
return 0;
}
TString filePath(aRow->GetField(0), aRow->GetFieldLength(0));
delete aResult;
+ delete aRow;
AliDebug(2, Form("filePath = %s",filePath.Data()));
// retrieved file is renamed to make it unique
TString localFileName = Form("%s_%d_%s_%s.shuttle",
- detector, fCurrentRun, id, source);
+ detector, GetCurrentRun(), id, source);
// file retrieval from DAQ FES
Bool_t result = RetrieveDAQFile(filePath.Data(), localFileName.Data());
if(!result) {
- Log(detector, Form("copying file %s from DAQ FES failed!", filePath.Data()));
+ Log(detector, Form("GetDAQFileName - Copy of file %s from DAQ FES failed", filePath.Data()));
return 0;
} else {
- AliInfo(Form("File %s copied from DAQ FES into %s/%s !",
+ AliInfo(Form("File %s copied from DAQ FES into %s/%s",
filePath.Data(), fgkShuttleTempDir, localFileName.Data()));
}
}
//______________________________________________________________________________________________
-Bool_t AliShuttle::RetrieveDAQFile(const char* daqFileName, const char* localFileName){
+Bool_t AliShuttle::RetrieveDAQFile(const char* daqFileName, const char* localFileName)
+{
// check temp directory: trying to cd to temp; if it does not exist, create it
AliDebug(2, Form("Copy file %s from DAQ FES into folder %s and rename it as %s",
void* dir = gSystem->OpenDirectory(fgkShuttleTempDir);
if (dir == NULL) {
if (gSystem->mkdir(fgkShuttleTempDir, kTRUE)) {
- AliError(Form("Can't open directory <%s>!", fgkShuttleTempDir));
+ AliError(Form("Can't open directory <%s>", fgkShuttleTempDir));
return kFALSE;
}
}
//______________________________________________________________________________________________
-TList* AliShuttle::GetDAQFileSources(const char* detector, const char* id){
+TList* AliShuttle::GetDAQFileSources(const char* detector, const char* id)
+{
// Retrieves a file from the DCS FES.
// check connection, in case connect
if(!Connect(kDAQ)){
- Log(detector, "GetDAQFileName: Couldn't connect to DAQ Logbook !");
+ Log(detector, "GetDAQFileSources - Couldn't connect to DAQ Logbook");
return 0;
}
// Query preparation
TString sqlQueryStart = "select DAQsource from logbook_fs where";
TString whereClause = Form("run=%d and detector=\"%s\" and fileId=\"%s\"",
- fCurrentRun, GetDetCode(detector), id);
+ GetCurrentRun(), GetDetCode(detector), id);
TString sqlQuery = Form("%s %s", sqlQueryStart.Data(), whereClause.Data());
AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data()));
TSQLResult* aResult;
aResult = fServer[kDAQ]->Query(sqlQuery);
if (!aResult) {
- Log(detector, Form("GetDAQFileSources: Can't execute query <%s>!", sqlQuery.Data()));
+ Log(detector, Form("GetDAQFileSources - Can't execute SQL query for id: %s", id));
return 0;
}
if (aResult->GetRowCount() == 0) {
Log(detector,
- Form("GetDAQFileSources: No result from SQL query <%s>!", sqlQuery.Data()));
+ Form("GetDAQFileSources - No entry in FES table for id: %s", id));
delete aResult;
return 0;
}
TString daqSource(aRow->GetField(0), aRow->GetFieldLength(0));
AliDebug(2, Form("daqSource = %s", daqSource.Data()));
list->Add(new TObjString(daqSource));
+ delete aRow;
}
delete aResult;
}
//______________________________________________________________________________________________
-Bool_t AliShuttle::UpdateDAQTable(){
+const char* AliShuttle::GetDCSFileName(const char* /*detector*/, const char* /*id*/, const char* /*source*/){
+// Retrieves a file from the DCS FES.
+
+return "You're in DCS";
+
+}
+
+//______________________________________________________________________________________________
+TList* AliShuttle::GetDCSFileSources(const char* /*detector*/, const char* /*id*/){
+// Retrieves a file from the DCS FES.
+
+return NULL;
+
+}
+
+//______________________________________________________________________________________________
+const char* AliShuttle::GetHLTFileName(const char* /*detector*/, const char* /*id*/, const char* /*source*/){
+// Retrieves a file from the HLT FES.
+
+return "You're in HLT";
+
+}
+
+//______________________________________________________________________________________________
+TList* AliShuttle::GetHLTFileSources(const char* /*detector*/, const char* /*id*/){
+// Retrieves a file from the HLT FES.
+
+return NULL;
+
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::UpdateDAQTable()
+{
// Update DAQ table filling time_processed field in all rows corresponding to current run and detector
// check connection, in case connect
if(!Connect(kDAQ)){
- Log(fCurrentDetector, "UpdateDAQTable: Couldn't connect to DAQ Logbook !");
+ Log(fCurrentDetector, "UpdateDAQTable - Couldn't connect to DAQ Logbook");
return kFALSE;
}
TString aFESentrystr = aFESentry->String();
TObjArray *aFESarray = aFESentrystr.Tokenize("_!?!_");
if(!aFESarray || aFESarray->GetEntries() != 2 ) {
- Log(fCurrentDetector,Form("UpdateDAQTable: error updating FES entry! string = %s",
+ Log(fCurrentDetector, Form("UpdateDAQTable - error updating FES entry. Check string: <%s>",
aFESentrystr.Data()));
if(aFESarray) delete aFESarray;
return kFALSE;
const char* fileId = ((TObjString*) aFESarray->At(0))->GetName();
const char* daqSource = ((TObjString*) aFESarray->At(1))->GetName();
TString whereClause = Form("where run=%d and detector=\"%s\" and fileId=\"%s\" and DAQsource=\"%s\";",
- fCurrentRun,GetDetCode(fCurrentDetector), fileId, daqSource);
+ GetCurrentRun(), GetDetCode(fCurrentDetector), fileId, daqSource);
delete aFESarray;
TSQLResult* aResult;
aResult = dynamic_cast<TSQLResult*> (fServer[kDAQ]->Query(sqlQuery));
if (!aResult) {
- Log(fCurrentDetector, Form("UpdateDAQTable: Can't execute query <%s>!", sqlQuery.Data()));
+ Log(fCurrentDetector, Form("UpdateDAQTable - Can't execute SQL query <%s>", sqlQuery.Data()));
return kFALSE;
}
delete aResult;
+ }
- // check result - TODO Is it necessary?
- sqlQuery = Form("select time_processed from logbook_fs %s", whereClause.Data());
- AliDebug(2, Form(" CHECK - SQL query: \n%s",sqlQuery.Data()));
+ return kTRUE;
+}
- aResult = dynamic_cast<TSQLResult*> (fServer[kDAQ]->Query(sqlQuery));
- if (!aResult) {
- AliWarning("Can't check result!");
- continue;
- }
- if (aResult->GetRowCount() == 0) {
- Log(fCurrentDetector,
- Form("GetDAQFileName: No result from SQL query <%s>!", sqlQuery.Data()));
- delete aResult;
- //return 0;
- }
+//______________________________________________________________________________________________
+Bool_t AliShuttle::UpdateShuttleLogbook(const char* detector, const char* status)
+{
+// Update Shuttle logbook filling detector or shuttle_done column
+// ex. of usage: UpdateShuttleLogbook("PHOS", "DONE") or UpdateShuttleLogbook("shuttle_done")
- if (aResult->GetRowCount() >1) {
- Log(fCurrentDetector,
- Form("GetDAQFileName: More than one row resulting from SQL query <%s>!", sqlQuery.Data()));
- delete aResult;
- //return 0;
+ // check connection, in case connect
+ if(!Connect(kDAQ)){
+ Log("SHUTTLE", "UpdateShuttleLogbook - Couldn't connect to DAQ Logbook.");
+ return kFALSE;
}
- TSQLRow *row = dynamic_cast<TSQLRow*> (aResult->Next());
- TString processedTimeString(row->GetField(0), row->GetFieldLength(0));
- Int_t processedTime = processedTimeString.Atoi();
- if(processedTime != now.GetSec()){
- Log(fCurrentDetector, Form("UpdateDAQTable: Update table error: processed_time=%d, now=%d !",
- processedTime, now.GetSec()));
- delete aResult;
+ TString detName(detector);
+ TString setClause;
+ if(detName == "shuttle_done") {
+ setClause = "set shuttle_done=1";
+ } else {
+ TString detCode = GetDetCode(detector);
+ if(detCode.IsNull()) {
+ Log("SHUTTLE", Form("UpdateShuttleLogbook - Unknown detector %s", detector));
return kFALSE;
}
+ TString statusStr(status);
+ if(statusStr.Contains("done", TString::kIgnoreCase) ||
+ statusStr.Contains("failed", TString::kIgnoreCase)){
+ setClause = Form("set %s=\"%s\"", detCode.Data(), status);
+ } else {
+ Log("SHUTTLE",
+ Form("UpdateShuttleLogbook - Invalid status <%s> for detector %s",
+ status, detector));
+ return kFALSE;
+ }
+ }
- delete aResult;
+ TString whereClause = Form("where run=%d", GetCurrentRun());
+
+ TString sqlQuery = Form("update logbook_shuttle %s %s",
+ setClause.Data(), whereClause.Data());
+ AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data()));
+
+ // Query execution
+ TSQLResult* aResult;
+ aResult = dynamic_cast<TSQLResult*> (fServer[kDAQ]->Query(sqlQuery));
+ if (!aResult) {
+ Log("SHUTTLE", Form("UpdateShuttleLogbook - Can't execute query <%s>", sqlQuery.Data()));
+ return kFALSE;
}
+ delete aResult;
return kTRUE;
}
//______________________________________________________________________________________________
-const char* AliShuttle::GetDCSFileName(const char* /*detector*/, const char* /*id*/, const char* /*source*/){
-// Retrieves a file from the DCS FES.
-
-return "You're in DCS";
+Int_t AliShuttle::GetCurrentRun() const
+{
+// Get current run from logbook entry
+ return fLogbookEntry ? fLogbookEntry->GetRun() : -1;
}
//______________________________________________________________________________________________
-TList* AliShuttle::GetDCSFileSources(const char* /*detector*/, const char* /*id*/){
-// Retrieves a file from the DCS FES.
-
-return NULL;
+UInt_t AliShuttle::GetCurrentStartTime() const
+{
+// get current start time
+ return fLogbookEntry ? fLogbookEntry->GetStartTime() : 0;
}
//______________________________________________________________________________________________
-const char* AliShuttle::GetHLTFileName(const char* /*detector*/, const char* /*id*/, const char* /*source*/){
-// Retrieves a file from the HLT FES.
-
-return "You're in HLT";
+UInt_t AliShuttle::GetCurrentEndTime() const
+{
+// get current end time from logbook entry
+ return fLogbookEntry ? fLogbookEntry->GetEndTime() : 0;
}
//______________________________________________________________________________________________
-TList* AliShuttle::GetHLTFileSources(const char* /*detector*/, const char* /*id*/){
-// Retrieves a file from the HLT FES.
+const char* AliShuttle::GetDetCode(const char* detector){
+// Return detector code
-return NULL;
+ for(UInt_t iDet=0; iDet < kNDetectors; iDet++){
+ if(!strcmp(fgkDetectorName[iDet], detector)) return fgkDetectorCode[iDet];
+ }
+ AliErrorClass(Form("Unknown detector: %s",detector));
+ return 0;
}
//______________________________________________________________________________________________
-const char* AliShuttle::GetDetCode(const char* detector){
+const char* AliShuttle::GetDetCode(UInt_t detPos){
// Return detector code
- for(int iDet=0; iDet < fgkNDetectors; iDet++){
- if(!strcmp(fgkDetectorName[iDet], detector)) return fgkDetectorCode[iDet];
+ if( detPos >= kNDetectors) {
+ AliErrorClass(Form("Invalid parameter: %d", detPos));
+ return 0;
}
+ return fgkDetectorCode[detPos];
+}
- return 0;
+//______________________________________________________________________________________________
+const Int_t AliShuttle::GetDetPos(const char* detCode){
+// Return detector position in the detector code array
+
+ for(UInt_t iDet=0; iDet < kNDetectors; iDet++){
+ if(!strcmp(fgkDetectorCode[iDet], detCode)) return iDet;
+ }
+ return -1;
}
//______________________________________________________________________________________________
void* dir = gSystem->OpenDirectory(fgkShuttleLogDir);
if (dir == NULL) {
if (gSystem->mkdir(fgkShuttleLogDir, kTRUE)) {
- AliError(Form("Can't open directory <%s>!", fgkShuttleTempDir));
+ AliError(Form("Can't open directory <%s>", fgkShuttleTempDir));
return;
}
gSystem->FreeDirectory(dir);
}
- TString toLog = Form("%s: %s, run %d - %s", TTimeStamp(time(0)).AsString("s"),
- detector, GetCurrentRun(), message);
+ TString toLog = Form("%s: %s - ", TTimeStamp(time(0)).AsString("s"), detector);
+ if(GetCurrentRun()>=0 ) toLog += Form("run %d - ", GetCurrentRun());
+ toLog += Form("%s", message);
+
AliInfo(toLog.Data());
TString fileName;
logFile.close();
}
+
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::Collect(Int_t run)
+{
+ //
+ // Collects conditions data for the given run.
+ //
+
+ AliInfo(Form("Collecting conditions data for run %d", run));
+
+ TString whereClause("where run=");
+ whereClause += run;
+
+ TObjArray dateEntries;
+ if (!QueryShuttleLogbook(whereClause, dateEntries)) {
+ AliError("Can't retrieve entries from Shuttle logbook!");
+ return kFALSE;
+ }
+
+ if (!dateEntries.GetEntriesFast()) {
+ AliError(Form("Retrieval of parameters for run %d failed!", run));
+ return kFALSE;
+ }
+
+ if (dateEntries.GetEntriesFast() > 1) {
+ AliError(Form("There is more than one entry for run <%d> in Shuttle logbook!", run));
+ return kFALSE;
+ }
+
+ if (!RetrieveConditionsData(dateEntries)) {
+ AliError("An error occured during conditions data retrieval!");
+ return kFALSE;
+ }
+
+ return kTRUE;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::CollectNew()
+{
+ //
+ // Collects conditions data for all UNPROCESSED run written to DAQ LogBook.
+ // In operational mode, this is the Shuttle function triggered by the EOR signal.
+ //
+
+ Log("SHUTTLE","CollectNew - Shuttle called. Collecting conditions data for unprocessed runs");
+
+ TString whereClause("where shuttle_done=0");
+
+ TObjArray shuttleLogbookEntries;
+ if (!QueryShuttleLogbook(whereClause, shuttleLogbookEntries)) {
+ Log("SHUTTLE", "CollectNew - Can't retrieve entries from Shuttle logbook");
+ return kFALSE;
+ }
+
+ if (!RetrieveConditionsData(shuttleLogbookEntries)) {
+ Log("SHUTTLE", "CollectNew - Process of at least one run failed");
+ return kFALSE;
+ }
+
+ return kTRUE;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::CollectAll()
+{
+ //
+ // Collects conditions data for all runs (even if they're already done!) written in Shuttle LogBook.
+ //
+
+ AliInfo("Collecting conditions data for all runs ...");
+
+ TObjArray dateEntries;
+ if (!QueryShuttleLogbook("", dateEntries)) {
+ AliError("Can't retrieve entries from Shuttle logbook");
+ return kFALSE;
+ }
+
+ if (!RetrieveConditionsData(dateEntries)) {
+ AliError("An error occured during conditions data retrieval!");
+ return kFALSE;
+ }
+
+ return kTRUE;
+}
+
+
+//______________________________________________________________________________________________
+Bool_t AliShuttle::RetrieveConditionsData(const TObjArray& dateEntries)
+{
+// Retrieve conditions data for all runs that aren't processed yet
+
+ Bool_t hasError = kFALSE;
+
+ TIter iter(&dateEntries);
+ AliShuttleLogbookEntry* anEntry;
+
+ while ((anEntry = (AliShuttleLogbookEntry*) iter.Next())){
+ if (!Process(anEntry)){
+ hasError = kTRUE;
+ }
+ }
+
+ return hasError == kFALSE;
+}
class TObject;
class AliShuttleConfig;
+class AliShuttleLogbookEntry;
class AliPreprocessor;
class AliCDBMetaData;
class TSQLServer;
class AliShuttle: public AliShuttleInterface {
public:
+ enum { kNDetectors=17 }; // number of subdetectors in ALICE
+
AliShuttle(const AliShuttleConfig* config, UInt_t timeout = 5000, Int_t retries = 5);
virtual ~AliShuttle();
virtual void RegisterPreprocessor(AliPreprocessor* preprocessor);
- Bool_t Process(Int_t run, UInt_t startTime, UInt_t endTime);
- Bool_t Process();
+ Bool_t Collect(Int_t run);
+ Bool_t CollectNew();
+ Bool_t CollectAll();
+
+ Bool_t Process(AliShuttleLogbookEntry* entry);
- Int_t GetCurrentRun() const {return fCurrentRun;};
- UInt_t GetCurrentStartTime() const {return fCurrentStartTime;};
- UInt_t GetCurrentEndTime() const {return fCurrentEndTime;};
+ Int_t GetCurrentRun() const;
+ UInt_t GetCurrentStartTime() const;
+ UInt_t GetCurrentEndTime() const;
virtual UInt_t Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
Int_t validityStart = 0, Bool_t validityInfinite = kFALSE);
static TString GetLocalRefStorage() {return fgkLocalRefStorage;}
static void SetLocalRefStorage (TString localRefStorage) {fgkLocalRefStorage = localRefStorage;}
- // TODO Test only, remove later!
- void SetCurrentRun(int run) {fCurrentRun=run;}
//TODO Test only, remove later !
- void SetProcessDCS(Bool_t process) {fgkProcessDCS = process;}
+ void SetProcessDCS(Bool_t process) {fgkProcessDCS = process;}
static const char* GetDetCode(const char* detector);
+ static const char* GetDetCode(UInt_t detPos);
+ static const Int_t GetDetPos(const char* detCode);
+ static const UInt_t NDetectors() {return kNDetectors;}
static const char* GetShuttleTempDir() {return fgkShuttleTempDir;}
Bool_t Connect(Int_t system);
-
private:
AliShuttle(const AliShuttle& other);
AliShuttle& operator= (const AliShuttle& other);
- Bool_t GetValueSet(const char* host, Int_t port, const char* alias,
- TObjArray& result);
+ UInt_t ProcessCurrentDetector();
+
+ Bool_t QueryRunParameters(Int_t& run, UInt_t& startTime, UInt_t& endTime);
+ Bool_t QueryShuttleLogbook(const char* whereClause, TObjArray& entries);
+ Bool_t RetrieveConditionsData(const TObjArray& shuttleLogbookEntries);
+
+ Bool_t GetValueSet(const char* host, Int_t port, const char* alias, TObjArray* result);
const char* GetDAQFileName(const char* detector, const char* id, const char* source);
Bool_t RetrieveDAQFile(const char* daqFileName, const char* localFileName);
const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
Int_t validityStart = 0, Bool_t validityInfinite = kFALSE);
+ Bool_t TryToStoreAgain();
+ Bool_t TryToStoreAgain(TString& storageType);
+
AliShuttleStatus* ReadShuttleStatus();
Bool_t WriteShuttleStatus(AliShuttleStatus* status);
Bool_t ContinueProcessing();
void UpdateShuttleStatus(AliShuttleStatus::Status newStatus, Bool_t increaseCount = kFALSE);
+ Bool_t UpdateShuttleLogbook(const char* detector, const char* status=0);
- const AliShuttleConfig* fConfig; //! pointer to configuration object
-
- static const Int_t fgkNDetectors = 17; //! number of detectors
- static const char* fgkDetectorName[fgkNDetectors]; //! names of detectors
- static const char* fgkDetectorCode[fgkNDetectors]; //! codes of detectors
- static TString fgkMainCDB; //! URI of the main (Grid) CDB storage
- static TString fgkLocalCDB; //! URI of the local backup CDB storage
- static TString fgkMainRefStorage; //! URI of the main (Grid) REFERENCE storage
- static TString fgkLocalRefStorage; //! URI of the local REFERENCE storage
- static const char* fgkShuttleTempDir; //! base path of SHUTTLE temp folder
- static const char* fgkShuttleLogDir; //! path of SHUTTLE log folder
-
- UInt_t fTimeout; //! DCS server connection timeout parameter
- Int_t fRetries; //! Number of DCS server connection retries
-
- TMap fPreprocessorMap; //! list of detector Preprocessors ("DET", "Preprocessor")
+ const AliShuttleConfig* fConfig; // pointer to configuration object
- Int_t fCurrentRun; //! run currenty processed
- UInt_t fCurrentStartTime; //! Run Start time
- UInt_t fCurrentEndTime; //! Run end time
+// static const UInt_t fgkNDetectors = 17; //! number of detectors
+ static const char* fgkDetectorName[kNDetectors]; //! names of detectors
+ static const char* fgkDetectorCode[kNDetectors]; //! codes of detectors
+ static TString fgkMainCDB; // URI of the main (Grid) CDB storage
+ static TString fgkLocalCDB; //! URI of the local backup CDB storage
+ static TString fgkMainRefStorage; // URI of the main (Grid) REFERENCE storage
+ static TString fgkLocalRefStorage; // URI of the local REFERENCE storage
+ static const char* fgkShuttleTempDir; // base path of SHUTTLE temp folder
+ static const char* fgkShuttleLogDir; // path of SHUTTLE log folder
- TString fCurrentDetector; // current detector
+ UInt_t fTimeout; // DCS server connection timeout parameter
+ Int_t fRetries; // Number of DCS server connection retries
- TSQLServer *fServer[3]; //! pointer to the three FS logbook servers
+ TMap fPreprocessorMap; // list of detector Preprocessors ("DET", "Preprocessor")
- Bool_t fFESCalled[3]; //! FES call status
- TList fFESlist[3]; //! List of files retrieved from each FES
+ AliShuttleLogbookEntry* fLogbookEntry; //! current Shuttle logbook entry
+ TString fCurrentDetector; // current detector
- AliCDBEntry* fStatusEntry; //! last CDB entry containing a AliShuttleStatus retrieved
+ TSQLServer *fServer[3]; // pointer to the three FS logbook servers
+ Bool_t fFESCalled[3]; // FES call status
+ TList fFESlist[3]; // List of files retrieved from each FES
- Bool_t fGridError; // determines if at least one storage to the Grid OCDB failed for the current sub detector and the file was stored on the local disk
+ AliCDBEntry* fStatusEntry; // last CDB entry containing a AliShuttleStatus retrieved
+ Bool_t fGridError; // Grid storage error flag
//TODO Test only, remove later !
static Bool_t fgkProcessDCS; // flag to enable DCS archive data processing
/*
$Log$
+Revision 1.8 2006/08/15 10:50:00 jgrosseo
+effc++ corrections (alberto)
+
Revision 1.7 2006/07/20 09:54:40 jgrosseo
introducing status management: The processing per subdetector is divided into several steps,
after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
fDetector(""),
fDCSHost(""),
fDCSPort(0),
-fDCSAliases(),
fIsValid(kFALSE),
fSkipDCSQuery(kFALSE)
{
// constructor of the shuttle configuration holder
TLDAPAttribute* anAttribute;
+ fDCSAliases = new TObjArray();
+ fDCSAliases->SetOwner(1);
anAttribute = entry->GetAttribute("det"); // MUST
fDetector = anAttribute->GetValue();
const char* anAlias;
while ((anAlias = anAttribute->GetValue())) {
- fDCSAliases.AddLast(new TObjString(anAlias));
+ fDCSAliases->AddLast(new TObjString(anAlias));
}
fIsValid = kTRUE;
{
// destructor of the shuttle configuration holder
- fDCSAliases.Delete();
+ delete fDCSAliases;
}
ClassImp(AliShuttleConfig)
const char* binddn, const char* password, const char* basedn):
fIsValid(kFALSE),
fDAQlbHost(""), fDAQlbUser(""), fDAQlbPass(""),
- fMaxPPRetries(0), fMaxRetries(0),
- fDetectorMap(), fDetectorList(),
- fShuttleInstanceHost(""), fProcessedDetectors(),
- fProcessAll(kFALSE)
+ fMaxPPRetries(0), fMaxRetries(0), fDetectorMap(), fDetectorList(),
+ fShuttleInstanceHost(""), fProcessedDetectors(), fProcessAll(kFALSE)
{
//
// host: ldap server host
// (objectClass=shuttleConfig) will be used as detector configurations.
//
+ fDetectorMap.SetOwner();
+ fDetectorList.SetOwner(0); //fDetectorList and fDetectorMap share the same object!
+ fProcessedDetectors.SetOwner();
+
TLDAPServer aServer(host, port, binddn, password, 3);
if (!aServer.IsConnected()) {
- AliError(Form("Can't connect to ldap server %s:%d",
+ AliError(Form("Can't connect to ldap server %s:%d",
host, port));
return;
}
// reads configuration for the shuttle running on this machine
-
+
fShuttleInstanceHost = gSystem->HostName();
- TString queryFilter = "(ShuttleHost=";
- queryFilter += fShuttleInstanceHost;
- queryFilter += ")";
-
- TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
- queryFilter.Data());
+ TString queryFilter = Form("(ShuttleHost=%s)", fShuttleInstanceHost.Data());
+
+ TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, queryFilter.Data());
if (!aResult) {
AliError(Form("Can't find configuration with base DN: %s",
if (aResult->GetCount() > 1) {
AliError(Form("More than one Shuttle instance for host %s!",
fShuttleInstanceHost.Data()));
+ delete aResult;
return;
}
- TLDAPEntry* anEntry;
- TLDAPAttribute* anAttribute;
+ TLDAPEntry* anEntry = 0;
+ TLDAPAttribute* anAttribute = 0;
if(!fProcessAll){
anEntry = aResult->GetNext();
}
}
+ delete anEntry; delete aResult;
+
// Detector configuration (DCS Archive DB settings)
- aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
- "(objectClass=AliShuttleDetector)");
+ aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, "(objectClass=AliShuttleDetector)");
if (!aResult) {
- AliError(Form("Can't find configuration with base DN: %s",
- basedn));
+ AliError(Form("Can't find configuration with base DN: %s", basedn));
return;
}
if (!aHolder->IsValid()) {
AliError("Detector configuration error!");
delete aHolder;
+ delete aResult;
return;
}
if (aResult->GetCount() == 0) {
AliError("Can't find DAQ logbook configuration!");
+ delete aResult;
return;
}
if (aResult->GetCount() > 1) {
AliError("More than one DAQ logbook configuration found!");
+ delete aResult;
return;
}
anAttribute = anEntry->GetAttribute("DAQLogbookHost");
if (!anAttribute) {
AliError("Can't find DAQLogbookHost attribute!");
+ delete anEntry; delete aResult;
return;
}
fDAQlbHost = anAttribute->GetValue();
anAttribute = anEntry->GetAttribute("DAQLogbookUser");
if (!anAttribute) {
AliError("Can't find DAQLogbookUser attribute!");
+ delete aResult; delete anEntry;
return;
}
fDAQlbUser = anAttribute->GetValue();
anAttribute = anEntry->GetAttribute("DAQLogbookPassword");
if (!anAttribute) {
AliError("Can't find DAQLogbookPassword attribute!");
+ delete aResult; delete anEntry;
return;
}
fDAQlbPass = anAttribute->GetValue();
anAttribute = anEntry->GetAttribute("MaxPPRetries");
if (!anAttribute) {
AliError("Can't find MaxPPRetries attribute!");
+ delete aResult; delete anEntry;
return;
}
TString tmpStr = anAttribute->GetValue();
- fMaxPPRetries = tmpStr.Atoi();
+ fMaxPPRetries = tmpStr.Atoi();
anAttribute = anEntry->GetAttribute("MaxRetries");
if (!anAttribute) {
AliError("Can't find MaxRetries attribute!");
+ delete aResult; delete anEntry;
return;
}
tmpStr = anAttribute->GetValue();
- fMaxRetries = tmpStr.Atoi();
+ fMaxRetries = tmpStr.Atoi();
- delete anEntry;
- delete aResult;
+ delete aResult; delete anEntry;
// FES configuration (FES logbook and hosts)
-
for(int iSys=0;iSys<3;iSys++){
queryFilter = Form("(system=%s)", AliShuttleInterface::fkSystemNames[iSys]);
aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, queryFilter.Data());
if (aResult->GetCount() != 1 ) {
AliError("Error in FES configuration!");
+ delete aResult;
return;
}
if (!anAttribute) {
AliError(Form ("Can't find LogbookHost attribute for %s!!",
AliShuttleInterface::fkSystemNames[iSys]));
+ delete aResult; delete anEntry;
return;
}
fFESlbHost[iSys] = anAttribute->GetValue();
if (!anAttribute) {
AliError(Form ("Can't find LogbookUser attribute for %s!!",
AliShuttleInterface::fkSystemNames[iSys]));
+ delete aResult; delete anEntry;
return;
}
fFESlbUser[iSys] = anAttribute->GetValue();
if (!anAttribute) {
AliError(Form ("Can't find LogbookPassword attribute for %s!!",
AliShuttleInterface::fkSystemNames[iSys]));
+ delete aResult; delete anEntry;
return;
}
fFESlbPass[iSys] = anAttribute->GetValue();
if (!anAttribute) {
AliError(Form ("Can't find FSHost attribute for %s!!",
AliShuttleInterface::fkSystemNames[iSys]));
+ delete aResult; delete anEntry;
return;
}
fFESHost[iSys] = anAttribute->GetValue();
if (!anAttribute) {
AliError(Form ("Can't find FSUser attribute for %s!!",
AliShuttleInterface::fkSystemNames[iSys]));
+ delete aResult; delete anEntry;
return;
}
fFESUser[iSys] = anAttribute->GetValue();
anAttribute = anEntry->GetAttribute("FSPassword");
if (anAttribute) fFESPass[iSys] = anAttribute->GetValue();
- delete anEntry;
- delete aResult;
+ delete aResult; delete anEntry;
}
fIsValid = kTRUE;
// destructor
fDetectorMap.DeleteAll();
+ fDetectorList.Clear();
+ fProcessedDetectors.Delete();
}
//______________________________________________________________________________________________
result += "\n\n";
}
+ result += Form("Max PP retries = %d - Max total retries = %d\n\n", fMaxPPRetries, fMaxRetries);
+
result += Form("DAQ Logbook Configuration \n \tHost: %s - User: %s - ",
fDAQlbHost.Data(), fDAQlbUser.Data());
const char* GetFESlbUser(Int_t system) const {return fFESlbUser[system].Data();}
const char* GetFESlbPass(Int_t system) const {return fFESlbPass[system].Data();}
- Int_t GetMaxPPRetries() const { return fMaxPPRetries; }
- Int_t GetMaxRetries() const { return fMaxRetries; }
+ Int_t GetMaxPPRetries() const { return fMaxPPRetries; }
+ Int_t GetMaxRetries() const { return fMaxRetries; }
const TObjArray* GetDetectors() const;
const char* GetDetector() const {return fDetector.Data();}
const char* GetDCSHost() const {return fDCSHost.Data();}
Int_t GetDCSPort() const {return fDCSPort;}
- const TObjArray* GetDCSAliases() const {return &fDCSAliases;}
+ const TObjArray* GetDCSAliases() const {return fDCSAliases;}
Bool_t IsValid() const {return fIsValid;}
Bool_t SkipDCSQuery() const {return fSkipDCSQuery;}
TString fDetector; // Detector name
TString fDCSHost; // Host name of the DCS server
Int_t fDCSPort; // port of the DCS server
- TObjArray fDCSAliases; // List of DCS aliases to be retrieved
+ TObjArray* fDCSAliases; // List of DCS aliases to be retrieved
Bool_t fIsValid; // flag for the validity of the configuration
Bool_t fSkipDCSQuery; // flag - if TRUE (-> DCS config empty) skip DCS archive data query
TString fFESlbUser[3]; //! username of the [DAQ, DCS, HLT] FES logbook
TString fFESlbPass[3]; //! password of the [DAQ, DCS, HLT] FES logbook
- Int_t fMaxPPRetries; // number of retries of a crashed preprocessor
- Int_t fMaxRetries; // number of retries for all other failures
+ Int_t fMaxPPRetries; // number of retries of a crashed preprocessor
+ Int_t fMaxRetries; // number of retries for all other failures
TMap fDetectorMap; //! Map of the detector-by-detector configuration
TObjArray fDetectorList; //! List of detectors with valid configuration
--- /dev/null
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * *
+ * Author: The ALICE Off-line Project. *
+ * Contributors are mentioned in the code where appropriate. *
+ * *
+ * Permission to use, copy, modify and distribute this software and its *
+ * documentation strictly for non-commercial purposes is hereby granted *
+ * without fee, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission notice *
+ * appear in the supporting documentation. The authors make no claims *
+ * about the suitability of this software for any purpose. It is *
+ * provided "as is" without express or implied warranty. *
+ **************************************************************************/
+
+//
+// This class is a container for the data queried from DAQ's logbook and logbook_shuttle tables.
+// It holds the run number, the start time and end time of the run,
+// and the array of the detectors' status (Unprocessed, Inactive, Failed, Done)
+
+#include "AliShuttleLogbookEntry.h"
+#include "AliLog.h"
+#include "TTimeStamp.h"
+
+// TODO test only!
+#include <TSQLServer.h>
+#include <TSQLResult.h>
+#include <TSQLRow.h>
+#include <TObjArray.h>
+
+ClassImp(AliShuttleLogbookEntry)
+
+//______________________________________________________________________________________________
+AliShuttleLogbookEntry::AliShuttleLogbookEntry() :
+TObject(),
+fRun(-1),
+fStartTime(0),
+fEndTime(0),
+//fDetectorStatus(0),
+fServer(0)
+{
+ // default constructor
+
+ const UInt_t nDet = AliShuttle::NDetectors();
+// fDetectorStatus = new Status[nDet];
+ memset(fDetectorStatus, kUnprocessed, nDet*sizeof(Status));
+}
+
+//______________________________________________________________________________________________
+AliShuttleLogbookEntry::AliShuttleLogbookEntry(Int_t run, UInt_t startTime, UInt_t endTime, Status* status) :
+TObject(),
+fRun(run),
+fStartTime(startTime),
+fEndTime(endTime),
+//fDetectorStatus(0),
+fServer(0)
+{
+ // default constructor
+
+ const UInt_t nDet = AliShuttle::NDetectors();
+// fDetectorStatus = new Status[nDet];
+ memset(fDetectorStatus, kUnprocessed, nDet*sizeof(Status));
+ if(status) SetDetectorStatus(status);
+}
+
+//______________________________________________________________________________________________
+AliShuttleLogbookEntry::~AliShuttleLogbookEntry() {
+// destructor
+
+ if(fServer){
+ if(fServer->IsConnected()) fServer->Close();
+ delete fServer;
+ }
+// if(fDetectorStatus) delete[] fDetectorStatus; fDetectorStatus=0;
+}
+
+//______________________________________________________________________________________________
+AliShuttleLogbookEntry::AliShuttleLogbookEntry(const AliShuttleLogbookEntry &c) :
+TObject(),
+fRun(c.fRun),
+fStartTime(c.fStartTime),
+fEndTime(c.fEndTime),
+fServer(0)
+{
+ // copy constructor
+
+ SetDetectorStatus(c.GetDetectorStatus());
+}
+
+//______________________________________________________________________________________________
+AliShuttleLogbookEntry &AliShuttleLogbookEntry::operator=(const AliShuttleLogbookEntry &c)
+{
+ // assigment operator
+
+ if (this != &c)
+ ((AliShuttleLogbookEntry &) c).Copy(*this);
+ return *this;
+}
+
+//______________________________________________________________________________________________
+void AliShuttleLogbookEntry::Copy(TObject& c) const
+{
+ // copy function
+
+ AliShuttleLogbookEntry& target = (AliShuttleLogbookEntry &) c;
+
+ target.fRun = fRun;
+ target.fStartTime = fStartTime;
+ target.fEndTime = fEndTime;
+
+ target.SetDetectorStatus(GetDetectorStatus());
+}
+
+//______________________________________________________________________________________________
+AliShuttleLogbookEntry::Status AliShuttleLogbookEntry::GetDetectorStatus(const char* detCode) const
+{
+// get detector status from detector code
+
+ return GetDetectorStatus(AliShuttle::GetDetPos(detCode));
+}
+
+//______________________________________________________________________________________________
+AliShuttleLogbookEntry::Status AliShuttleLogbookEntry::GetDetectorStatus(Int_t detPos) const
+{
+// get detector status from detector code
+
+ if(detPos < 0 || detPos >= (Int_t) AliShuttle::NDetectors()) {
+ AliError(Form("Invalid parameter: %d", detPos));
+ return kUnprocessed;
+ }
+ return fDetectorStatus[detPos];
+}
+
+//______________________________________________________________________________________________
+void AliShuttleLogbookEntry::SetDetectorStatus(const char* detCode, Status status)
+{
+// set detector status from detector code
+
+ Int_t detPos = AliShuttle::GetDetPos(detCode);
+ if(detPos<0) return;
+ SetDetectorStatus(detPos, status);
+}
+
+//______________________________________________________________________________________________
+void AliShuttleLogbookEntry::SetDetectorStatus(Status* status)
+{
+// set detector status from detector code
+
+ for(UInt_t i=0; i < AliShuttle::NDetectors(); i++){
+ fDetectorStatus[i] = status[i];
+ }
+}
+
+//______________________________________________________________________________________________
+void AliShuttleLogbookEntry::SetDetectorStatus(UInt_t detPos, Status status)
+{
+// set detector status from detector code
+
+ if(detPos >= AliShuttle::NDetectors()) {
+ AliError(Form("Shuttle has only %d subdetectors!", AliShuttle::NDetectors()));
+ return;
+ }
+ fDetectorStatus[detPos] = status;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttleLogbookEntry::IsDone() const{
+// return TRUE if all subdetectors are in status DONE, FAILED or INACTIVE
+
+ for(UInt_t i=0; i < AliShuttle::NDetectors(); i++){
+ if(fDetectorStatus[i] == kUnprocessed) return kFALSE;
+ }
+ return kTRUE;
+}
+
+//______________________________________________________________________________________________
+const char* AliShuttleLogbookEntry::GetDetectorStatusName(Status status)
+{
+ // returns a name (string) of the detector status
+
+ switch (status){
+ case kUnprocessed: return "UNPROCESSED";
+ case kInactive: return "INACTIVE";
+ case kFailed: return "FAILED";
+ case kDone: return "DONE";
+ }
+ return 0;
+}
+
+//______________________________________________________________________________________________
+void AliShuttleLogbookEntry::Print(Option_t* /*option*/) const
+{
+ // print current shuttle logbook entry
+
+ TString message = "\n*** Run parameters ***\n";
+ TTimeStamp startTimeStamp(fStartTime);
+ TTimeStamp endTimeStamp(fEndTime);
+ message += Form("\tRun \t\t%d\n", fRun);
+ message += Form("\tStarted \t%s\n", startTimeStamp.AsString("s"));
+ message += Form("\tFinished \t%s\n", endTimeStamp.AsString("s"));
+ message += "\n*** Detector status ***\n";
+
+ for(UInt_t i=0; i < AliShuttle::NDetectors(); i++)
+ message += Form("\t%2d - %s: %s\n", i, AliShuttle::GetDetCode(i),
+ GetDetectorStatusName(fDetectorStatus[i]));
+
+ AliInfo(Form("%s",message.Data()));
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttleLogbookEntry::Connect(){
+// Connect to MySQL Server of the DAQ logbook
+
+ // check connection: if already connected return
+ if(fServer && fServer->IsConnected()) return kTRUE;
+
+ fServer = TSQLServer::Connect("mysql://pcald30.cern.ch","offline","alice");
+
+ if (!fServer || !fServer->IsConnected()) {
+ AliError("Can't establish connection to DAQ log book DB!");
+ if(fServer) delete fServer;
+ return kFALSE;
+ }
+
+ // Get table
+ TSQLResult* aResult=0;
+ aResult = fServer->GetTables("REFSYSLOG");
+ delete aResult;
+ return kTRUE;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttleLogbookEntry::QueryShuttleLogbook(Int_t runNumber)
+{
+// Query DAQ's Shuttle logbook and fills detector status array
+
+ Int_t run;
+ if(runNumber < 0) {
+ run = GetRun();
+ } else{
+ run = runNumber;
+ }
+
+ // check connection, in case connect
+ if(!Connect()) return kFALSE;
+
+ TString sqlQuery;
+ sqlQuery = Form("select * from logbook_shuttle where run = %d", run);
+
+ TSQLResult* aResult = fServer->Query(sqlQuery);
+ if (!aResult) {
+ AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
+ return kFALSE;
+ }
+
+ // TODO Check field count!
+ if (aResult->GetFieldCount() != 24) {
+ AliError("Invalid SQL result field number!");
+ delete aResult;
+ return kFALSE;
+ }
+
+ TSQLRow* aRow;
+ while ((aRow = aResult->Next())) {
+ TString runString(aRow->GetField(0), aRow->GetFieldLength(0));
+ Int_t run = runString.Atoi();
+
+ Status detStatus[24];
+
+ // loop on detectors
+ for(UInt_t ii = 0; ii < 24; ii++){
+ TString detCode(aResult->GetFieldName(ii));
+ Int_t detPos = AliShuttle::GetDetPos(detCode.Data());
+ if(detPos < 0) continue;
+ TString statusString(aRow->GetField(ii), aRow->GetFieldLength(ii));
+ if(statusString == "UNPROCESSED"){
+ detStatus[detPos] = AliShuttleLogbookEntry::kUnprocessed;
+ } else if (statusString == "INACTIVE") {
+ detStatus[detPos] = AliShuttleLogbookEntry::kInactive;
+ } else if (statusString == "FAILED") {
+ detStatus[detPos] = AliShuttleLogbookEntry::kFailed;
+ } else if (statusString == "DONE") {
+ detStatus[detPos] = AliShuttleLogbookEntry::kDone;
+ }
+ }
+
+ SetRun(run);
+ SetDetectorStatus(detStatus);
+ delete aRow;
+ }
+
+ Print("");
+
+ delete aResult;
+ return kTRUE;
+}
+//______________________________________________________________________________________________
+Bool_t AliShuttleLogbookEntry::UpdateShuttleLogbook()
+{
+ // Update Shuttle logbook table - TEST ONLY, USE WITH CARE!
+
+
+ if(!Connect()) return kFALSE;
+
+ TString sqlQuery("update logbook_shuttle set ");
+
+ for(UInt_t i=0; i < AliShuttle::NDetectors(); i++){
+ sqlQuery += Form("%s=\"%s\"", AliShuttle::GetDetCode(i), GetDetectorStatusName(fDetectorStatus[i]));
+ if(i < AliShuttle::NDetectors()-1) sqlQuery += ", ";
+ }
+
+ sqlQuery += Form(" where run=%d;",GetRun());
+
+ AliInfo(Form("sqlQuery: %s", sqlQuery.Data()));
+
+ TSQLResult* aResult;
+ aResult = fServer->Query(sqlQuery);
+ if (!aResult) {
+ AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
+ return kFALSE;
+ }
+
+ delete aResult;
+
+ return kTRUE;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttleLogbookEntry::UpdateShuttleLogbook(const char* detCode, Status status)
+{
+ // Update Shuttle logbook table - TEST ONLY, USE WITH CARE!
+
+
+ if(AliShuttle::GetDetPos(detCode) < 0) return kFALSE;
+ SetDetectorStatus(detCode, status);
+ if(!Connect()) return kFALSE;
+
+ TString sqlQuery("update logbook_shuttle set ");
+
+
+ sqlQuery += Form("%s=\"%s\" ", detCode, GetDetectorStatusName(status));
+
+ sqlQuery += Form("where run=%d;",GetRun());
+
+ AliInfo(Form("sqlQuery: %s", sqlQuery.Data()));
+
+ TSQLResult* aResult;
+ aResult = fServer->Query(sqlQuery);
+ if (!aResult) {
+ AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
+ return kFALSE;
+ }
+
+ delete aResult;
+
+ return kTRUE;
+}
+
+//______________________________________________________________________________________________
+Bool_t AliShuttleLogbookEntry::InsertNewRun(Int_t runNumber)
+{
+ // Update Shuttle logbook table - TEST ONLY, USE WITH CARE!
+
+ if(runNumber<=0 && GetRun()<=0) return kFALSE;
+ if(runNumber>0) SetRun(runNumber);
+ if(!Connect()) return kFALSE;
+
+ TString sqlQuery = Form("insert into logbook_shuttle (run) values (%d);", GetRun());
+
+ AliInfo(Form("sqlQuery: %s", sqlQuery.Data()));
+
+ TSQLResult* aResult;
+ aResult = fServer->Query(sqlQuery);
+ if (!aResult) {
+ AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
+ return kFALSE;
+ }
+
+ delete aResult;
+
+ UpdateShuttleLogbook();
+
+ return kTRUE;
+}
--- /dev/null
+#ifndef ALI_SHUTTLE_LOGBOOK_ENTRY_H
+#define ALI_SHUTTLE_LOGBOOK_ENTRY_H
+
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+
+/* $Id$ */
+
+//
+// This class is a container for the data queried from DAQ's logbook and logbook_shuttle tables.
+//
+
+#include <TObject.h>
+#include "AliShuttle.h"
+
+class TSQLServer;
+
+class AliShuttleLogbookEntry: public TObject {
+
+public:
+ enum Status {
+ kUnprocessed = 0,
+ kInactive,
+ kFailed, // final
+ kDone // final
+ };
+
+ AliShuttleLogbookEntry();
+ AliShuttleLogbookEntry(Int_t run, UInt_t startTime, UInt_t endTime, Status* status=0);
+ ~AliShuttleLogbookEntry();
+
+ AliShuttleLogbookEntry& operator=(const AliShuttleLogbookEntry& c);
+ AliShuttleLogbookEntry(const AliShuttleLogbookEntry& c);
+ virtual void Copy(TObject& c) const;
+
+ Int_t GetRun() const {return fRun;}
+ UInt_t GetStartTime() const {return fStartTime;}
+ UInt_t GetEndTime() const {return fEndTime;}
+
+ void SetRun(Int_t run) {fRun=run;}
+ void SetStartTime(UInt_t startTime) {fStartTime=startTime;}
+ void SetEndTime(UInt_t endTime) {fEndTime=endTime;}
+
+ Status GetDetectorStatus(const char* detCode) const;
+ Status GetDetectorStatus(Int_t detPos) const;
+ Status* GetDetectorStatus() const {return (Status*) fDetectorStatus;}
+
+ void SetDetectorStatus(const char* detCode, Status status);
+ void SetDetectorStatus(Status* status);
+ void SetDetectorStatus(UInt_t detPos, Status status);
+
+ Bool_t IsDone() const;
+
+ static const char* GetDetectorStatusName(Status status);
+ void Print(Option_t *option) const;
+
+ // TODO Test only, remove later!
+ Bool_t Connect();
+ Bool_t QueryShuttleLogbook(Int_t runNumber=-1);
+ Bool_t UpdateShuttleLogbook();
+ Bool_t UpdateShuttleLogbook(const char* detCode, Status status);
+ Bool_t InsertNewRun(Int_t runNumber=-1);
+
+
+private:
+
+ Int_t fRun; // Run number
+ UInt_t fStartTime; // Run start time
+ UInt_t fEndTime; // Run end time
+ Status fDetectorStatus[AliShuttle::kNDetectors]; // Detector status array
+
+ // TODO Test only, remove later!
+ TSQLServer* fServer; // pointer to the MySQLServer which handles the DAQ logbook
+
+ ClassDef(AliShuttleLogbookEntry, 0)
+};
+
+#endif
+
/*
$Log$
+Revision 1.3 2006/08/29 09:16:05 jgrosseo
+small update
+
Revision 1.2 2006/08/15 10:50:00 jgrosseo
effc++ corrections (alberto)
ClassImp(AliShuttleStatus)
+//______________________________________________________________________________________________
AliShuttleStatus::AliShuttleStatus() : TObject(),
fTimeStamp(0),
fStatus(kInvalid),
// default constructor
}
+//______________________________________________________________________________________________
AliShuttleStatus::AliShuttleStatus(Status status) : TObject(),
fTimeStamp(0),
fStatus(status),
fTimeStamp = time(0);
}
+//______________________________________________________________________________________________
AliShuttleStatus::AliShuttleStatus(const AliShuttleStatus& c) :
TObject(c), fTimeStamp(0),
fStatus(kInvalid),
((AliShuttleStatus &)c).Copy(*this);
}
+//______________________________________________________________________________________________
AliShuttleStatus::~AliShuttleStatus()
{
// destructor
}
+//______________________________________________________________________________________________
AliShuttleStatus &AliShuttleStatus::operator=(const AliShuttleStatus &c)
{
// assigment operator
return *this;
}
+//______________________________________________________________________________________________
void AliShuttleStatus::Copy(TObject& c) const
{
// copy function
target.fCount = fCount;
}
+//______________________________________________________________________________________________
void AliShuttleStatus::SetStatus(Status status)
{
// sets a new status, add the same time the timestamp is set to now
fTimeStamp = time(0);
}
+//______________________________________________________________________________________________
const char* AliShuttleStatus::GetStatusName(Status status)
{
// returns a name (string) of the status
kPPError,
kDone, // final
kFailed, // final
- kStoreFailed // TODO in case Grid storage failed and object is in local CDB.
+ kStoreFailed
};
AliShuttleStatus();
/*
$Log$
+ Revision 1.10 2006/08/15 10:50:00 jgrosseo
+ effc++ corrections (alberto)
+
Revision 1.9 2006/08/08 14:19:29 jgrosseo
Update to shuttle classes (Alberto)
#include "AliShuttleTrigger.h"
-#include <TSQLServer.h>
-#include <TSQLResult.h>
-#include <TSQLRow.h>
-#include <TObjArray.h>
#include <TSystem.h>
-
#include "AliLog.h"
-#include "AliCDBManager.h"
-#include "AliCDBStorage.h"
-#include "AliCDBEntry.h"
-
-#include "AliDCSValue.h"
#include "AliShuttleConfig.h"
#include "AliShuttle.h"
#include "DATENotifier.h"
AliShuttleTrigger::AliShuttleTrigger(const AliShuttleConfig* config,
UInt_t timeout, Int_t retries):
fConfig(config), fShuttle(NULL),
- fNotified(kFALSE), fTerminate(kFALSE), fLastRun(0),
+ fNotified(kFALSE), fTerminate(kFALSE),
fMutex(), fCondition(&fMutex),
fQuitSignalHandler(this, kSigQuit),
fInterruptSignalHandler(this, kSigInterrupt)
gSystem->AddSignalHandler(&fQuitSignalHandler);
gSystem->AddSignalHandler(&fInterruptSignalHandler);
+
}
//______________________________________________________________________
AliShuttleTrigger::AliShuttleTrigger(const AliShuttleTrigger& /*other*/):
TObject(), fConfig(), fShuttle(NULL),
- fNotified(kFALSE), fTerminate(kFALSE), fLastRun(0),
+ fNotified(kFALSE), fTerminate(kFALSE),
fMutex(), fCondition(&fMutex),
fQuitSignalHandler(this, kSigQuit),
fInterruptSignalHandler(this, kSigInterrupt)
delete notifier;
}
-//______________________________________________________________________________________________
-Bool_t AliShuttleTrigger::RetrieveDATEEntries(const char* whereClause,
- TObjArray& entries)
-{
-// Retrieve start time and end time for all runs in the DAQ logbook
-// that aren't processed yet
-
- TString sqlQuery;
- sqlQuery = Form("select run, time_start, time_end from logbook %s order by run",
- whereClause);
-
- TSQLServer* aServer;
- TString logbookHost=Form("mysql://%s", fConfig->GetDAQlbHost());
-
- aServer = TSQLServer::Connect(logbookHost,
- fConfig->GetDAQlbUser(),
- fConfig->GetDAQlbPass());
- if (!aServer) {
- AliError("Can't establish connection to DAQ log book DB!");
- return kFALSE;
- }
-
- aServer->GetTables("REFSYSLOG");
-
- TSQLResult* aResult;
- aResult = aServer->Query(sqlQuery);
- if (!aResult) {
- AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
- delete aServer;
- return kFALSE;
- }
-
- if (aResult->GetFieldCount() != 3) {
- AliError("Invalid SQL result field number!");
- delete aResult;
- delete aServer;
- return kFALSE;
- }
-
- TSQLRow* aRow;
- while ((aRow = aResult->Next())) {
- TString runString(aRow->GetField(0), aRow->GetFieldLength(0));
- Int_t run = runString.Atoi();
-
- TString startTimeString(aRow->GetField(1),
- aRow->GetFieldLength(1));
- Int_t startTime = startTimeString.Atoi();
- if (!startTime) {
- AliWarning(Form("Zero StartTime for run <%d>!", run));
- AliWarning("Going to skip this run!");
- continue;
- }
-
- TString endTimeString(aRow->GetField(2),
- aRow->GetFieldLength(2));
- Int_t endTime = endTimeString.Atoi();
- if (!endTime) {
- AliWarning(Form("Zero EndTime for run <%d>!", run));
- AliWarning("Going to skip this run!");
- continue;
- }
-
- if (startTime > endTime) {
- AliWarning(Form("StartTime bigger than EndTime for run <%d>", run));
- AliWarning("Going to skip this run!");
- continue;
- }
-
- entries.AddLast(new AliShuttleTriggerDATEEntry(run, startTime, endTime));
- delete aRow;
- }
-
- delete aResult;
-
- aServer->Close();
- delete aServer;
-
- entries.SetOwner(1);
-
- return kTRUE;
-}
-
-//______________________________________________________________________________________________
-Bool_t AliShuttleTrigger::RetrieveConditionsData(const TObjArray& dateEntries, Bool_t updateLastRun)
-{
- // Retrieve conditions data for all runs that aren't processed yet
-
- Bool_t hasError = kFALSE;
-
- TIter iter(&dateEntries);
- AliShuttleTriggerDATEEntry* anEntry;
-
- while ((anEntry = (AliShuttleTriggerDATEEntry*) iter.Next()))
- {
- if (!fShuttle->Process(anEntry->GetRun(),
- anEntry->GetStartTime(),
- anEntry->GetEndTime()))
- {
- hasError = kTRUE;
- }
-
- if (!hasError && updateLastRun && fLastRun < anEntry->GetRun())
- {
- fLastRun = anEntry->GetRun();
- WriteLastRun();
- }
- }
-
- return hasError == kFALSE;
-}
-
-//______________________________________________________________________________________________
-Bool_t AliShuttleTrigger::ReadLastRun()
-{
- // reads the last processed run from local CDB
-
- AliCDBEntry* cdbEntry = AliCDBManager::Instance()->GetStorage(AliShuttle::GetLocalCDB())
- ->Get("/SHUTTLE/SYSTEM/LASTRUN", 0);
-
- if (cdbEntry)
- {
- TObject* anObject = cdbEntry->GetObject();
- if (anObject == NULL || anObject->IsA() != AliDCSValue::Class())
- {
- AliError("Invalid last run object stored to CDB!");
- return kFALSE;
- }
- AliDCSValue* dcsValue = (AliDCSValue*) anObject;
- fLastRun = dcsValue->GetInt();
-
- delete cdbEntry;
- }
- else
- {
- AliFatal("No last run number stored. Please set first. Aborting");
- return kFALSE;
- }
-
- AliInfo(Form("Last run number <%d>", fLastRun));
-
- return kTRUE;
-}
-
-//______________________________________________________________________________________________
-Bool_t AliShuttleTrigger::WriteLastRun()
-{
- // writes the last succesfully processed run to local CDB
-
- AliDCSValue lastRunObj(fLastRun, 0);
- AliCDBMetaData metaData;
- AliCDBId cdbID(AliCDBPath("SHUTTLE", "SYSTEM", "LASTRUN"), 0, 0);
-
- UInt_t result = AliCDBManager::Instance()->GetStorage(AliShuttle::GetLocalCDB())
- ->Put(&lastRunObj, cdbID, &metaData);
-
- if (!result) {
- AliError("Can't store last run to CDB!");
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//______________________________________________________________________________________________
-Bool_t AliShuttleTrigger::SetNewLastRun(Int_t run)
-{
- // sets a new run manually, use with caution!
-
- fShuttle->Log("SHUTTLE", Form("Setting last run manually to %d", run));
-
- fLastRun = run;
- return WriteLastRun();
-}
-
//______________________________________________________________________________________________
Bool_t AliShuttleTrigger::Collect(Int_t run)
{
//
- // Collects conditions date for the given run.
+ // Collects conditions data for the given run.
//
- AliInfo(Form("Collecting conditions data for run <%d> ...", run));
-
- TString whereClause("where run = ");
- whereClause += run;
-
- TObjArray dateEntries;
- if (!RetrieveDATEEntries(whereClause, dateEntries)) {
- AliError("Can't retrieve entries from DAQ log book.");
- return kFALSE;
- }
-
- if (!dateEntries.GetEntriesFast()) {
- AliError(Form("There isn't entry for run <%d> in DAQ log book!",
- run));
- return kFALSE;
- }
-
- if (dateEntries.GetEntriesFast() > 1) {
- AliError(Form("There is more than one entry for run <%d> in DAQ log book", run));
- return kFALSE;
- }
-
- if (!RetrieveConditionsData(dateEntries, kFALSE)) {
- AliError("An error occured during conditions data retrieval!");
- return kFALSE;
- }
-
- return kTRUE;
+ return fShuttle->Collect(run);
}
//______________________________________________________________________________________________
Bool_t AliShuttleTrigger::CollectNew()
{
//
- // Collects conditions data for all new run written to DAQ LogBook.
+ // Collects conditions data for all UNPROCESSED run written to DAQ LogBook.
//
- AliInfo("Collecting conditions data for new runs ...");
-
- if (!ReadLastRun())
- {
- AliError("Retrieving of last run failed");
- return kFALSE;
- }
-
- TString whereClause("where run > ");
- whereClause += fLastRun;
-
- TObjArray dateEntries;
- if (!RetrieveDATEEntries(whereClause, dateEntries)) {
- AliError("Can't retrieve entries from DAQ log book.");
- return kFALSE;
- }
-
- if (!RetrieveConditionsData(dateEntries, kTRUE)) {
- AliError("Process of at least one run failed!");
- // return kFALSE;
- }
-
- return kTRUE;
+ return fShuttle->CollectNew();
}
//______________________________________________________________________________________________
Bool_t AliShuttleTrigger::CollectAll()
{
//
- // Collects conditions data for all run written in DAQ LogBook.
+ // Collects conditions data for all runs (even if they're already done!) written in Shuttle LogBook.
//
- if (!ReadLastRun())
- {
- AliError("Retrieving of last run failed");
- return kFALSE;
- }
-
- AliInfo("Collecting conditions data for all runs ...");
-
- TObjArray dateEntries;
- if (!RetrieveDATEEntries("", dateEntries)) {
- AliError("Can't retrieve entries from DAQ log book.");
- return kFALSE;
- }
-
- if (!RetrieveConditionsData(dateEntries, kTRUE)) {
- AliError("An error occured during conditions data retrieval!");
- return kFALSE;
- }
-
- return kTRUE;
+ return fShuttle->CollectAll();
}
#include <TCondition.h>
-class AliCDBStorage;
class AliShuttle;
class AliShuttleConfig;
};
class AliShuttleTrigger: public TObject {
+
public:
AliShuttleTrigger(const AliShuttleConfig* config, UInt_t timeout = 5000, Int_t retries = 5);
~AliShuttleTrigger();
Bool_t CollectNew();
Bool_t CollectAll();
- Bool_t SetNewLastRun(Int_t run);
-
virtual Bool_t Notify();
void Terminate();
void Run();
private:
-
AliShuttleTrigger(const AliShuttleTrigger& other);
AliShuttleTrigger& operator= (const AliShuttleTrigger& other);
- class AliShuttleTriggerDATEEntry: public TObject {
- public:
- AliShuttleTriggerDATEEntry(Int_t run, UInt_t startTime, UInt_t endTime):
- fRun(run), fStartTime(startTime), fEndTime(endTime) {}
-
- Int_t GetRun() const {return fRun;}
- UInt_t GetStartTime() const {return fStartTime;}
- UInt_t GetEndTime() const {return fEndTime;}
-
- private:
- Int_t fRun; // Run number
- UInt_t fStartTime; // Run start time
- UInt_t fEndTime; // Run end time
- ClassDef(AliShuttleTriggerDATEEntry, 0)
- };
-
- Bool_t RetrieveDATEEntries(const char* whereClause, TObjArray& entries);
- Bool_t RetrieveConditionsData(const TObjArray& dateEntries, Bool_t updateLastRun);
-
- Bool_t ReadLastRun();
- Bool_t WriteLastRun();
-
const AliShuttleConfig* fConfig;
- //AliCDBStorage* fLocalStorage;
AliShuttle* fShuttle; // Pointer to the actual Shuttle instance
Bool_t fNotified; // Notified flag
Bool_t fTerminate; // Terminate flag
- Int_t fLastRun; // last sucessfully processed run
-
TMutex fMutex; // Mutex
TCondition fCondition; // Condition
#pragma link C++ class AliShuttle;
#pragma link C++ class AliShuttleTrigger;
#pragma link C++ class TerminateSignalHandler;
-#pragma link C++ class AliShuttleTrigger::AliShuttleTriggerDATEEntry;
#pragma link C++ class AliShuttleStatus;
+#pragma link C++ class AliShuttleLogbookEntry;
#endif
// AliLog::SetGlobalDebugLevel(1);
// Setting local CDB and reference storage locations
- AliShuttle::SetMainCDB("alien://DBFolder=ShuttleCDB");
+ AliShuttle::SetMainCDB("alien://user=aliprod?folder=colla/GridShuttleCDB");
+ AliShuttle::SetMainRefStorage("alien://user=aliprod?folder=colla/GridShuttleRefStorage");
+
+// AliShuttle::SetMainCDB("local://testLeakCDB");
+// AliShuttle::SetMainRefStorage("local://testLeakRef");
+
AliShuttle::SetLocalCDB("local://LocalShuttleCDB");
- AliShuttle::SetMainRefStorage("alien://DBFolder=GridReferenceStorage");
- AliShuttle::SetLocalRefStorage("local://LocalReferenceStorage");
+ AliShuttle::SetLocalRefStorage("local://LocalShuttleRefStorage");
- AliShuttle::SetProcessDCS(kTRUE);
+ AliShuttle::SetProcessDCS(kFALSE);
// AliCDBManager *man = AliCDBManager::Instance();
SRCS = AliDCSMessage.cxx\
AliDCSClient.cxx AliShuttle.cxx AliShuttleConfig.cxx\
- AliShuttleTrigger.cxx AliShuttleStatus.cxx
+ AliShuttleTrigger.cxx AliShuttleStatus.cxx AliShuttleLogbookEntry.cxx
CINTHDRS:= $(patsubst %,$(MODDIR)/%,$(SRCS:.cxx=.h))
{
// default constructor
- for(int i=0;i<kNHistos;i++) fHv[i]=0x0;
- fFunc = 0;
+ for(int i=0;i<kNHistos;i++) fHv[i]=0;
+ fFunc=0;
}
//---------------------------------------------------------------
TTimeStamp(startTime).AsString(),
TTimeStamp(endTime).AsString()));
- fFunc = 0;
- Init();
+ for(int i=0;i<kNHistos;i++) fHv[i]=0;
+ fFunc=0;
}
{
// destructor
- for(int i=0;i<kNHistos;i++) {delete fHv[i]; fHv[i]=0;}
+ Clean();
+}
+
+//---------------------------------------------------------------
+void AliTPCDataDCS::Clean()
+{
+// destructor
+
+ for(int i=0;i<kNHistos;i++) {
+ if(fHv[i]) delete fHv[i];
+ fHv[i]=0;
+ }
fGraphs.Clear("C");
+ if(fFunc) delete fFunc;
fFunc=0;
}
+//---------------------------------------------------------------
+void AliTPCDataDCS::Init()
+{
+// Init alias names and histos
+
+ TH1::AddDirectory(kFALSE);
+
+ fGraphs.SetOwner(1);
+
+ for(int i=0;i<kNAliases;i++){
+ fAliasNames[i] = "TpcHvSect0";
+ fAliasNames[i] += i;
+ fAliasNames[i] += ".FloatValue";
+ }
+
+ for(int i=0;i<kNHistos;i++){
+ fHv[i] = new TH1F(fAliasNames[i].Data(),fAliasNames[i].Data(), 20, kHvMin, kHvMax);
+ fHv[i]->GetXaxis()->SetTitle("Hv");
+ }
+}
+
//---------------------------------------------------------------
void AliTPCDataDCS::ProcessData(TMap& aliasMap)
{
// process TMap of alias values retrieved from the DCS archive DB
- if(!(fHv[0])) Init();
+ Clean();
+ Init();
TObjArray *aliasArr;
AliDCSValue* aValue;
}
// pol1 fit of the first graph
- if(fGraphs.GetEntries() > 0){
- ((TGraph*) fGraphs.UncheckedAt(0))->Fit("pol1");
- fFunc = ((TGraph*) fGraphs.UncheckedAt(0))->GetFunction("pol1");
- }
+// if(fGraphs.GetEntries() > 0){
+// ((TGraph*) fGraphs.UncheckedAt(0))->Fit("pol1");
+// fFunc = ((TGraph*) fGraphs.UncheckedAt(0))->GetFunction("pol1");
+// }
fIsProcessed=kTRUE;
}
-//---------------------------------------------------------------
-void AliTPCDataDCS::Init()
-{
-// Init alias names and histos
-
- TH1::AddDirectory(kFALSE);
-
- fGraphs.SetOwner(1);
-
- for(int i=0;i<kNAliases;i++){
- fAliasNames[i] = "TpcHvSect0";
- fAliasNames[i] += i;
- fAliasNames[i] += ".FloatValue";
- }
-
- for(int i=0;i<kNHistos;i++){
- fHv[i] = new TH1F(fAliasNames[i].Data(),fAliasNames[i].Data(), 20, kHvMin, kHvMax);
- fHv[i]->GetXaxis()->SetTitle("Hv");
- }
-}
-
//---------------------------------------------------------------
void AliTPCDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr)
{
void Draw(const Option_t* option);
+ void Clean();
+
private:
void Init();
values.Add(new TObjString(request), valueSet);
result = client.GetAliasValues(request, startTime,
- endTime, *valueSet);
+ endTime, valueSet);
}
if (result < 0) {
while((source=dynamic_cast<TObjString*> (iter.Next()))){
printf("\n\n Getting file #%d\n",++i);
//if(i==1) continue;
- const char* filename = GetFile(AliShuttleInterface::kDAQ, "thresholds.txt", source->GetName());
- if(!filename) {
+ TString filename = GetFile(AliShuttleInterface::kDAQ, "thresholds.txt", source->GetName());
+ if(!filename.Data()) {
AliError(Form("Error retrieving file from source %d failed!", source->GetName()));
delete filesources;
return 0;
}
- TString command = Form("more $ALICE_ROOT/SHUTTLE/temp/%s",filename);
+ TString command = Form("more $ALICE_ROOT/SHUTTLE/temp/%s",filename.Data());
gSystem->Exec(command.Data());
// STORAGE! The First file name will be stored into CDB, the second into reference storage