--- /dev/null
+// --- ROOT system
+#include <TFile.h>
+#include <TTimeStamp.h>
+
+#include "AliPMDPreprocessor.h"
+#include "AliPMDCalibData.h"
+#include "AliLog.h"
+#include "AliShuttleInterface.h"
+#include "AliCDBMetaData.h"
+#include <TTimeStamp.h>
+#include <TObjString.h>
+#include <TTree.h>
+#include <TSystem.h>
+
+
+ClassImp(AliPMDPreprocessor)
+
+//______________________________________________________________________________________________
+AliPMDPreprocessor::AliPMDPreprocessor(const char* detector, AliShuttleInterface* shuttle) :
+ AliPreprocessor(detector, shuttle)
+{
+ // constructor
+}
+
+//______________________________________________________________________________________________
+AliPMDPreprocessor::~AliPMDPreprocessor()
+{
+ // destructor
+}
+
+//______________________________________________________________________________________________
+void AliPMDPreprocessor::Initialize(Int_t run, UInt_t startTime,
+ UInt_t endTime)
+{
+ // Creates AliPMDDataDAQ object
+
+ AliPreprocessor::Initialize(run, startTime, endTime);
+
+ AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
+ TTimeStamp(startTime).AsString(),
+ TTimeStamp(endTime).AsString()));
+
+ fRun = run;
+ fStartTime = startTime;
+ fEndTime = endTime;
+
+}
+
+//______________________________________________________________________________________________
+UInt_t AliPMDPreprocessor::Process(TMap* pdaqAliasMap)
+{
+
+ if(!pdaqAliasMap) return 0;
+
+ AliPMDCalibData *calibda = new AliPMDCalibData();
+
+ TList* filesources = GetFileSources(kDAQ, "PMDGAINS");
+
+ if(!filesources) {
+ AliError(Form("No sources found for PMDGAINS for run %d !", fRun));
+ return 0;
+ }
+
+ AliInfo("Here's the list of sources for PMDGAINS");
+ filesources->Print();
+
+ TIter iter(filesources);
+ TObjString* source;
+ int i=0;
+ UInt_t result = 0;
+ TString filename;
+ while((source=dynamic_cast<TObjString*> (iter.Next()))){
+ AliInfo(Form("\n\n Getting file #%d\n",++i));
+ filename = GetFile(kDAQ, "PMDGAINS", source->GetName());
+ if(!filename.Data()) {
+ AliError(Form("Error retrieving file from source %s failed!", source->GetName()));
+ delete filesources;
+ return 0;
+ }
+
+ Int_t DET,SM,ROW,COL;
+ Float_t GAIN;
+ TFile *f= new TFile(filename.Data());
+ TTree *tree = (TTree*)f->Get("ic");
+ tree->SetBranchAddress("DET", &DET);
+ tree->SetBranchAddress("SM", &SM);
+ tree->SetBranchAddress("ROW", &ROW);
+ tree->SetBranchAddress("COL", &COL);
+ tree->SetBranchAddress("GAIN", &GAIN);
+ Int_t nEntries = (Int_t) tree->GetEntries();
+ for(Int_t i = 0; i < nEntries; i++)
+ {
+ tree->GetEntry(i);
+// if(DET>1 || SM>23 || ROW>95 || COL>95) {
+// printf("Error! gain[%d,%d,%d,%d] = %f\n",DET,SM,ROW,COL,GAIN);
+// continue;
+ // }
+ calibda->SetGainFact(DET,SM,ROW,COL,GAIN);
+ }
+ f->Close();
+ delete f;
+ }
+
+ //Now we have to store the final CDB file
+ AliCDBMetaData metaData;
+ metaData.SetBeamPeriod(0);
+ metaData.SetComment("test PMD preprocessor");
+
+ result = Store("Calib","Data", calibda, &metaData);
+
+ delete calibda;
+ return result;
+}
+
--- /dev/null
+/* $Id$ */
+
+// 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 TestPMDPreprocessor()
+{
+ // load library
+ gSystem->Load("libTestShuttle.so");
+
+ // TODO if needed, change location of OCDB and Reference test folders
+ // by default they are set to $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB and TestReference
+
+ AliTestShuttle::SetOCDBStorage("local://TestCDB");
+ // AliTestShuttle::SetReferenceStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
+
+ printf("Test OCDB storage Uri: %s\n", AliTestShuttle::GetOCDBStorage().Data());
+
+ // create AliTestShuttle instance
+ // The parameters are run, startTime, endTime
+ AliTestShuttle* shuttle = new AliTestShuttle(7, 0, 1);
+
+ // TODO(1)
+ //
+ // The shuttle can read DCS data, if the preprocessor should be tested to process DCS data,
+ // some fake data has to be created.
+ //
+ // The "fake" input data can be taken using either (a) or (b):
+ // (a) data from a file: Use ReadDCSAliasMap()
+ // the format of the file is explained in ReadDCSAliasMap()
+ // To use it uncomment the following line:
+ //
+ //TMap* dcsAliasMap = ReadDCSAliasMap();
+ //
+ // (b) generated in this macro: Use CreateDCSAliasMap() and its documentation
+ // To use it uncomment the following line:
+ //
+ TMap* dcsAliasMap = CreateDCSAliasMap();
+
+ // now give the alias map to the shuttle
+ shuttle->SetDCSInput(dcsAliasMap);
+
+ // TODO(2)
+ //
+ // The shuttle can also process files that originate from DCS, DAQ and HLT.
+ // To test it, we provide some local files and locations where these would be found when
+ // the online machinery would be there.
+ // In real life this functions would be produces by the sub-detectors
+ // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
+ //
+ // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
+ // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
+ // In this example we add a file originating from the GDC with the id PEDESTALS
+ // Three files originating from different LDCs but with the same id are also added
+
+ shuttle->AddInputFile(AliShuttleInterface::kDAQ, "PMD", "PMDGAINS", "LDC1", "xy.root");
+
+
+ // TODO(4)
+ // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
+
+ AliPreprocessor* test = new AliPMDPreprocessor("PMD", shuttle);
+
+ printf("Starting SHUTTLE!\n");
+
+ // Test the preprocessor
+ shuttle->Process();
+
+ printf("SHUTTLE done!\n");
+
+ delete shuttle;
+
+ // TODO(5)
+ // In the preprocessor AliShuttleInterface::Store should be called to put the final
+ // data to the CDB.
+ //
+ // Check the file which should have been created
+ AliCDBEntry* entry = AliCDBManager::Instance()->GetStorage(AliTestShuttle::GetOCDBStorage())
+ ->Get("PMD/Calib/Data", 7);
+ if (!entry)
+ {
+ printf("The file is not there. Something went wrong.\n");
+ return;
+ }
+
+ AliPMDCalibData* output = dynamic_cast<AliPMDCalibData*> (entry->GetObject());
+
+ // If everything went fine, print the result
+ if (output)
+ printf("Gain of det=1, smn=2, row=3, col=4: %f\n", output->GetGainFact(1,2,3,4));
+
+ AliCDBManager::Instance()->Destroy();
+
+ printf("DONE!\n");
+}
+
+TMap* CreateDCSAliasMap()
+{
+ // Creates a DCS structure
+ // The structure is the following:
+ // TMap (key --> value)
+ // <DCSAlias> --> <valueList>
+ // <DCSAlias> is a string
+ // <valueList> is a TObjArray of AliDCSValue
+ // An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
+
+ // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
+ // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
+
+ TMap* aliasMap = new TMap;
+ aliasMap->SetOwner(1);
+
+ TRandom random;
+
+ for(int nAlias=0;nAlias<6;nAlias++)
+ {
+ TObjArray* valueSet = new TObjArray;
+ valueSet->SetOwner(1);
+
+ TString aliasName="DCSAlias";
+ aliasName += nAlias;
+ //printf("\n\n alias: %s\n\n",aliasName.Data());
+
+ for (int timeStamp=0;timeStamp<1000;timeStamp+=10)
+ {
+ AliDCSValue* dcsVal = new AliDCSValue((Float_t) (random.Gaus()+5*nAlias), timeStamp);
+ //printf("%s\n",dcsVal->ToString().Data());
+ valueSet->Add(dcsVal);
+ }
+ aliasMap->Add(new TObjString(aliasName), valueSet);
+ }
+
+ return aliasMap;
+}
+