From: jgrosseo Date: Fri, 2 Jun 2006 14:19:18 +0000 (+0000) Subject: adding TestShuttle program X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=5c6b40ae3d0555f7aa4a3e0b9584226ec805805a;hp=574593065679acf55a498b1e3c371966a8e9df6b;ds=sidebyside adding TestShuttle program --- diff --git a/SHUTTLE/TestShuttle/AliTestDataDCS.cxx b/SHUTTLE/TestShuttle/AliTestDataDCS.cxx new file mode 100644 index 00000000000..689ef4fe1d6 --- /dev/null +++ b/SHUTTLE/TestShuttle/AliTestDataDCS.cxx @@ -0,0 +1,195 @@ +#include "AliTestDataDCS.h" + +#include "AliCDBMetaData.h" +#include "AliDCSValue.h" +#include "AliLog.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +ClassImp(AliTestDataDCS) + +//--------------------------------------------------------------- +AliTestDataDCS::AliTestDataDCS(): + TObject(), + fRun(0), + fStartTime(0), + fEndTime(0), + fGraphs("TGraph",kNGraphs), + fIsProcessed(kFALSE) +{ + for(int i=0;iGetEntries()<2){ + AliError(Form("Alias %s has just %d entries!", + fAliasNames[j].Data(),aliasArr->GetEntries())); + continue; + } + + TIter iterarray(aliasArr); + + Double_t *time = new Double_t[aliasArr->GetEntries()]; + Double_t *val = new Double_t[aliasArr->GetEntries()]; + + UInt_t ne=0; + while ((aValue = (AliDCSValue*) iterarray.Next())) { + val[ne] = aValue->GetSimpleValue().GetFloat(); + time[ne] = (Double_t) (aValue->GetTimeStamp()); + // fill histos (alias 0-2) + if(j < 3) fHv[j]->Fill(val[ne]); + ne++; + } + // fill graphs (alias 3-5) + if(j >= 3) CreateGraph(j, aliasArr->GetEntries(), time, val); + delete[] val; + delete[] time; + } + + // calculate mean and rms of the first two histos + for(int i=0;iGetMean(); + fWidth[i] = fHv[i]->GetRMS(); + } + + // pol1 fit of the first graph + if(fGraphs.GetEntries() > 0){ + ((TGraph*) fGraphs.UncheckedAt(0))->Fit("pol1"); + fFunc = ((TGraph*) fGraphs.UncheckedAt(0))->GetFunction("pol1"); + } + + fIsProcessed=kTRUE; + + +} + +//--------------------------------------------------------------- +void AliTestDataDCS::Init(){ + + TH1::AddDirectory(kFALSE); + + fGraphs.SetOwner(1); + + for(int i=0;iGetXaxis()->SetTitle("Hv"); + } +} + +//--------------------------------------------------------------- +void AliTestDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr){ + + int entries=aliasArr->GetEntries(); + AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data())); + AliInfo(Form(" %d DP values collected",entries)); + +} + +//--------------------------------------------------------------- +void AliTestDataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y) +{ + + TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y); + + gr->GetXaxis()->SetTimeDisplay(1); + gr->SetTitle(fAliasNames[i].Data()); + + AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast())); + + +} + +//--------------------------------------------------------------- +void AliTestDataDCS::Draw(const Option_t* /*option*/) +{ +// Draw all histos and graphs + + if(!fIsProcessed) return; + + TCanvas *ch; + TString canvasHistoName="Histos"; + ch=new TCanvas(canvasHistoName,canvasHistoName,20,20,600,600); + ch->Divide(2,2); + ch->cd(1); + fHv[0]->Draw(); + ch->cd(2); + fHv[1]->Draw(); + ch->cd(3); + fHv[2]->Draw(); + + + if(fGraphs.GetEntries() == 0) return; + + TCanvas *cg; + TString canvasGraphName="Graphs"; + cg=new TCanvas(canvasGraphName,canvasGraphName,40,40,600,600); + cg->Divide(2,2); + cg->cd(1); + ((TGraph*) fGraphs.UncheckedAt(0))->Draw("alp"); + + cg->cd(2); + ((TGraph*) fGraphs.UncheckedAt(1))->Draw("alp"); + cg->cd(3); + ((TGraph*) fGraphs.UncheckedAt(2))->Draw("alp"); + + if(fFunc){ + cg->cd(4); + fFunc->Draw("l"); + } + +} + diff --git a/SHUTTLE/TestShuttle/AliTestDataDCS.h b/SHUTTLE/TestShuttle/AliTestDataDCS.h new file mode 100644 index 00000000000..decc61fcbc1 --- /dev/null +++ b/SHUTTLE/TestShuttle/AliTestDataDCS.h @@ -0,0 +1,69 @@ +#ifndef AliTestDataDCS_H +#define AliTestDataDCS_H + +#include +#include +#include +#include +#include + +class AliTestDataDCS : public TObject { +public: + enum {kNAliases=6, kNHistos=3, kNGraphs=3, kNFunctions=2}; + enum {kHvMin=0, kHvMax=500}; + + AliTestDataDCS(); + AliTestDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime); + ~AliTestDataDCS(); + + void SetRun(Int_t run) {fRun = run;} + void SetStartTime(Int_t startTime) {fStartTime = startTime;} + void SetEndTime(Int_t endTime) {fEndTime = endTime;} + Int_t GetRun() {return fRun;} + Int_t GetStartTime() {return fStartTime;} + Int_t GetEndTime() {return fEndTime;} + + void ProcessData(TMap& aliasMap); + + const char* GetAliasName(UInt_t pos) + {return posEval(time) : -1;} + + void Draw(const Option_t* option); + + +private: + void Init(); + void Introduce(UInt_t numAlias, const TObjArray* aliasArr); + void CreateGraph(int i, int dim, const Double_t *x, const Double_t *y); + + Int_t fRun; + UInt_t fStartTime; + UInt_t fEndTime; + + Float_t fMean[kNHistos]; + Float_t fWidth[kNHistos]; + + TString fAliasNames[kNAliases]; + TH1F *fHv[kNHistos]; + TClonesArray fGraphs; + TF1 *fFunc; + + Bool_t fIsProcessed; + + ClassDef(AliTestDataDCS, 2); +}; + +#endif diff --git a/SHUTTLE/TestShuttle/AliTestPreprocessor.cxx b/SHUTTLE/TestShuttle/AliTestPreprocessor.cxx new file mode 100644 index 00000000000..1d3f3b130eb --- /dev/null +++ b/SHUTTLE/TestShuttle/AliTestPreprocessor.cxx @@ -0,0 +1,69 @@ +#include "AliTestPreprocessor.h" + +#include "AliCDBMetaData.h" +#include "AliDCSValue.h" +#include "AliLog.h" +#include "AliTestDataDCS.h" + +#include + +// +// This class is an example for a simple preprocessor. +// It takes data from DCS and passes it to the class AliTestDataDCS, which +// reformats its. This class is then written to the CDB. +// + +ClassImp(AliTestPreprocessor) + +AliTestPreprocessor::AliTestPreprocessor(const char* detector, AliShuttleInterface* shuttle) : + AliPreprocessor(detector, shuttle), + fData(0) +{ + // constructor +} + +AliTestPreprocessor::~AliTestPreprocessor() +{ + // destructor +} + +void AliTestPreprocessor::Initialize(Int_t run, UInt_t startTime, + UInt_t endTime) +{ + // Creates AliTestDataDCS object + + AliPreprocessor::Initialize(run, startTime, endTime); + + AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, + TTimeStamp(startTime).AsString(), + TTimeStamp(endTime).AsString())); + + fData = new AliTestDataDCS(fRun, fStartTime, fEndTime); +} + +Int_t AliTestPreprocessor::Process(TMap* dcsAliasMap) +{ + // Fills data into a AliTestDataDCS object + + if (!dcsAliasMap) + return -1; + + fData->ProcessData(*dcsAliasMap); + + const char* fileName = GetFile(kDAQ, "PEDESTALS", "GDC"); + if (fileName) + AliInfo(Form("Got the file %s, now we can extract some values.", fileName)); + // open file, extract some values, write them to fData + + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Alberto Colla"); + metaData.SetComment("This preprocessor fills an AliTestDataDCS object."); + + Store(fData, &metaData); + delete fData; + fData = 0; + + return 0; +} + diff --git a/SHUTTLE/TestShuttle/AliTestPreprocessor.h b/SHUTTLE/TestShuttle/AliTestPreprocessor.h new file mode 100644 index 00000000000..5c57439d69e --- /dev/null +++ b/SHUTTLE/TestShuttle/AliTestPreprocessor.h @@ -0,0 +1,26 @@ +#ifndef ALI_TEST_PREPROCESSOR_H +#define ALI_TEST_PREPROCESSOR_H + +#include "AliPreprocessor.h" + +// test preprocessor that writes data to AliTestDataDCS + +class AliTestDataDCS; + +class AliTestPreprocessor : public AliPreprocessor +{ + public: + AliTestPreprocessor(const char* detector, AliShuttleInterface* shuttle); + virtual ~AliTestPreprocessor(); + + protected: + virtual void Initialize(Int_t run, UInt_t startTime, UInt_t endTime); + virtual Int_t Process(TMap* dcsAliasMap); + + private: + AliTestDataDCS *fData; // CDB class that stores the data + + ClassDef(AliTestPreprocessor, 0); +}; + +#endif diff --git a/SHUTTLE/TestShuttle/AliTestShuttle.cxx b/SHUTTLE/TestShuttle/AliTestShuttle.cxx new file mode 100644 index 00000000000..6f2e95eb0f2 --- /dev/null +++ b/SHUTTLE/TestShuttle/AliTestShuttle.cxx @@ -0,0 +1,160 @@ +/************************************************************************** + * 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. * + **************************************************************************/ + +/* +$Log$ +Revision 1.2 2006/03/07 07:52:34 hristov +New version (B.Yordanov) + +Revision 1.3 2005/11/17 17:47:34 byordano +TList changed to TObjArray + +Revision 1.2 2005/11/17 14:43:22 byordano +import to local CVS + +Revision 1.1.1.1 2005/10/28 07:33:58 hristov +Initial import as subdirectory in AliRoot + +Revision 1.1.1.1 2005/09/12 22:11:40 byordano +SHUTTLE package + +Revision 1.2 2005/08/29 21:15:47 byordano +some docs added + +*/ + +// +// test implementation of the AliShuttleInterface, to be used for local tests of preprocessors +// +// reads files from the local disk +// stores to local CDB +// logs to the screen +// + +#include "AliTestShuttle.h" +#include "AliLog.h" + +#include "AliCDBManager.h" +#include "AliCDBMetaData.h" +#include "AliCDBId.h" + +#include +#include +#include +#include + +ClassImp(AliTestShuttle) + +AliTestShuttle::AliTestShuttle(TMap* inputFiles) : fInputFiles(inputFiles) +{ + // constructor + // inputFiles contains the map of local files that can be retrieved by the preprocessor + // check TestPreprocessor.C for an example of its structure +} + +AliTestShuttle::~AliTestShuttle() +{ + // destructor +} + +Int_t AliTestShuttle::Store(const char* detector, TObject* object, AliCDBMetaData* metaData) +{ + // Stores the CDB object + // This function should be called at the end of the preprocessor cycle + // + // This implementation just stores it on the local disk, the full AliShuttle + // puts it to the Grid FileCatalog + + AliCDBId id(Form("%s/SHUTTLE/Data", detector), 0, 0); + + AliCDBManager::Instance()->Put(object, id, metaData); + + return -1; +} + +const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source) +{ + // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id + // and from the given source in the system. + // The function returnes the path to the local file. + // + // test implementation of GetFile + // takes files from the local disks, files are passen in a TMap in the constructor + + TString key; + key.Form("%s-%s-%s", fkSystemNames[system], detector, id); + TPair* sourceListPair = dynamic_cast (fInputFiles->FindObject(key.Data())); + TMap* sourceList = 0; + if (sourceListPair) + sourceList = dynamic_cast (sourceListPair->Value()); + if (!sourceList) + { + AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data())); + return 0; + } + + TPair* fileNamePair = dynamic_cast (sourceList->FindObject(source)); + TObjString* fileName = dynamic_cast (fileNamePair->Value()); + if (!fileName) + { + AliError(Form("Could not find files from source %s in %s with id %s", source, fkSystemNames[system], id)); + return 0; + } + + return fileName->GetString().Data(); +} + +TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id) +{ + // Returns a list of sources in a given system that saved a file with the given id + // + // test implementation of GetFileSources + // takes files from the local disks, files are passen in a TMap in the constructor + + TString key; + key.Form("%s-%s-%s", fkSystemNames[system], detector, id); + TPair* sourceListPair = dynamic_cast (fInputFiles->FindObject(key.Data())); + TMap* sourceList = 0; + if (sourceListPair) + sourceList = dynamic_cast (sourceListPair->Value()); + if (!sourceList) + { + AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data())); + return 0; + } + + TIterator* iter = sourceList->GetTable()->MakeIterator(); + TObject* obj = 0; + TList* list = new TList; + while ((obj = iter->Next())) + { + TPair* pair = dynamic_cast (obj); + if (pair) + list->Add(pair->Key()); + } + + delete iter; + + return list; +} + +void AliTestShuttle::Log(const char* detector, const char* message) +{ + // test implementation of Log + // just prints to the screen + + AliInfo(Form("%s: %s", detector, message)); +} + diff --git a/SHUTTLE/TestShuttle/AliTestShuttle.h b/SHUTTLE/TestShuttle/AliTestShuttle.h new file mode 100644 index 00000000000..b51567dbdfb --- /dev/null +++ b/SHUTTLE/TestShuttle/AliTestShuttle.h @@ -0,0 +1,37 @@ +#ifndef ALI_TEST_SHUTTLE_H +#define ALI_TEST_SHUTTLE_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +// +// test implementation of the AliShuttleInterface, to be used for local tests of preprocessors +// + +#include + +class TMap; +class TList; +class AliCDBMetaData; + +class AliTestShuttle : public AliShuttleInterface +{ + public: + AliTestShuttle(TMap* inputFiles); + virtual ~AliTestShuttle(); + + virtual Int_t Store(const char* detector, TObject* object, AliCDBMetaData* metaData); + virtual const char* GetFile(Int_t system, const char* detector, const char* id, const char* source); + virtual TList* GetFileSources(Int_t system, const char* detector, const char* id); + virtual void Log(const char* detector, const char* message); + + protected: + TMap* fInputFiles; // files for GetFile, GetFileSources + + private: + ClassDef(AliTestShuttle, 0); +}; + +#endif diff --git a/SHUTTLE/TestShuttle/Makefile b/SHUTTLE/TestShuttle/Makefile new file mode 100644 index 00000000000..3ad46c197cf --- /dev/null +++ b/SHUTTLE/TestShuttle/Makefile @@ -0,0 +1,38 @@ +# $Id$ + +PACKAGE = TestShuttle + +include $(ROOTSYS)/test/Makefile.arch +include lib$(PACKAGE).pkg + +ALICEINC = -I. + +ifneq ($(ALICE_ROOT),) + ALICEINC += -I$(ALICE_ROOT)/include +endif + +CXXFLAGS += $(ALICEINC) +SRCS += dict.cxx +OBJS = $(SRCS:.cxx=.o) + +lib$(PACKAGE).so: $(OBJS) + @echo "Linking" $@ ... + @/bin/rm -f $@ +ifeq ($(PLATFORM),macosx) + @$(LD) -bundle -undefined $(UNDEFOPT) $(LDFLAGS) $^ -o $@ +else + @$(LD) $(SOFLAGS) $(LDFLAGS) $(OBJS) -o $@ +endif + @chmod a+x $@ + @echo "done" + +%.o: %.cxx %.h + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + @rm -f $(OBJS) core *~ *.so dict.* $(PARFILE) + +dict.cxx dict.h: $(HDRS) $(DHDR) + @echo "Generating dictionary ..." + @[ -f dict ] || rm -f $@ + rootcint -f $@ -c $(ALICEINC) $^ diff --git a/SHUTTLE/TestShuttle/TestCDB/TPC/DCS/Data/Run21200_21200_v0_s0.root b/SHUTTLE/TestShuttle/TestCDB/TPC/DCS/Data/Run21200_21200_v0_s0.root new file mode 100644 index 00000000000..50a0cd282c2 Binary files /dev/null and b/SHUTTLE/TestShuttle/TestCDB/TPC/DCS/Data/Run21200_21200_v0_s0.root differ diff --git a/SHUTTLE/TestShuttle/TestPreprocessor.C b/SHUTTLE/TestShuttle/TestPreprocessor.C new file mode 100644 index 00000000000..23065fa9756 --- /dev/null +++ b/SHUTTLE/TestShuttle/TestPreprocessor.C @@ -0,0 +1,92 @@ +// This class runs the test preprocessor +// It uses AliTestShuttle to simulate a full Shuttle process + +// The input data is created in the functions +// CreateDCSAliasMap() creates input that would in the same way come from DCS +// ReadDCSAliasMap() reads from a file +// CreateInputFilesMap() creates a list of local files, that can be accessed by the shuttle + +void TestPreprocessor() +{ + gSystem->Load("libTestShuttle"); + + // initialize location of CDB + AliCDBManager *man = AliCDBManager::Instance(); + man->SetDefaultStorage("local://TestCDB"); + + // TODO decide where to read the data + TMap* dcsAliasMap = 0; + //dcsAliasMap = CreateDCSAliasMap(); + dcsAliasMap = ReadDCSAliasMap(); + + // create TMap of available files + TMap* inputFiles = CreateInputFilesMap(); + + // create AliTestShuttle instance + AliTestShuttle* shuttle = new AliTestShuttle(inputFiles); + TestShuttle(shuttle); + + // create preprocessor + AliPreprocessor* pp = new AliTestPreprocessor("TPC", shuttle); + + // call preprocessor + pp->Initialize(0, 0, 1); + pp->Process(dcsAliasMap); +} + +TMap* CreateDCSAliasMap() +{ + // fill fake DCS object + + TObjArray* valueSet1 = new TObjArray; + + + valueSet1->Add(); + + TObjArray* valueSet2 = new TObjArray; + valueSet2->Add(); + + TMap* aliasMap = new TMap; + aliasMap->Add(new TObjString("DCSAlias1"), valueSet1); + aliasMap->Add(new TObjString("DCSAlias2"), valueSet2); + + return aliasMap; +} + +TMap* ReadDCSAliasMap() +{ + // open the file + AliCDBEntry *entry = AliCDBManager::Instance()->Get("TPC/DCS/Data",21200); + return dynamic_cast (entry->GetObject()); +} + +TMap* CreateInputFilesMap() +{ + // create a list of files which will be available from the AliTestShuttle + + inputFile1 = new TMap; + inputFile1->Add(new TObjString("GDC"), new TObjString("file1.root")); + + inputFile2 = new TMap; + inputFile2->Add(new TObjString("LDC0"), new TObjString("file2a.root")); + inputFile2->Add(new TObjString("LDC1"), new TObjString("file2b.root")); + inputFile2->Add(new TObjString("LDC2"), new TObjString("file2c.root")); + + TMap* inputFiles = new TMap; + inputFiles->Add(new TObjString("DAQ-TPC-PEDESTALS"), inputFile1); + inputFiles->Add(new TObjString("DAQ-TPC-DRIFTVELOCITY"), inputFile2); + + return inputFiles; +} + +void TestShuttle(AliShuttleInterface* shuttle) +{ + const char* file = shuttle->GetFile(AliShuttleInterface::kDAQ, "TPC", "PEDESTALS", "GDC"); + cout << "GetFile: " << file << endl; + cout << "GetFileSources: " << endl; + shuttle->GetFileSources(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY")->Print(); + + shuttle->Log("TPC", "Log test"); + + //shuttle->Store(); +} diff --git a/SHUTTLE/TestShuttle/TestShuttleLinkDef.h b/SHUTTLE/TestShuttle/TestShuttleLinkDef.h new file mode 100644 index 00000000000..d25e4e689e7 --- /dev/null +++ b/SHUTTLE/TestShuttle/TestShuttleLinkDef.h @@ -0,0 +1,15 @@ +#ifdef __CINT__ +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ class AliTestDataDCS+; +#pragma link C++ class AliTestPreprocessor+; +#pragma link C++ class AliTestShuttle; + +#endif diff --git a/SHUTTLE/TestShuttle/libTestShuttle.pkg b/SHUTTLE/TestShuttle/libTestShuttle.pkg new file mode 100644 index 00000000000..676639d9606 --- /dev/null +++ b/SHUTTLE/TestShuttle/libTestShuttle.pkg @@ -0,0 +1,11 @@ +# $Id$ + +HDRS = AliTestDataDCS.h \ +AliTestPreprocessor.h \ +AliTestShuttle.h + +SRCS = $(HDRS:.h=.cxx) + +DHDR= TestShuttleLinkDef.h + +EINCLUDE=