ROOT logo
/* $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/OCDB/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;
}

 TestPMDPreprocessor.C:1
 TestPMDPreprocessor.C:2
 TestPMDPreprocessor.C:3
 TestPMDPreprocessor.C:4
 TestPMDPreprocessor.C:5
 TestPMDPreprocessor.C:6
 TestPMDPreprocessor.C:7
 TestPMDPreprocessor.C:8
 TestPMDPreprocessor.C:9
 TestPMDPreprocessor.C:10
 TestPMDPreprocessor.C:11
 TestPMDPreprocessor.C:12
 TestPMDPreprocessor.C:13
 TestPMDPreprocessor.C:14
 TestPMDPreprocessor.C:15
 TestPMDPreprocessor.C:16
 TestPMDPreprocessor.C:17
 TestPMDPreprocessor.C:18
 TestPMDPreprocessor.C:19
 TestPMDPreprocessor.C:20
 TestPMDPreprocessor.C:21
 TestPMDPreprocessor.C:22
 TestPMDPreprocessor.C:23
 TestPMDPreprocessor.C:24
 TestPMDPreprocessor.C:25
 TestPMDPreprocessor.C:26
 TestPMDPreprocessor.C:27
 TestPMDPreprocessor.C:28
 TestPMDPreprocessor.C:29
 TestPMDPreprocessor.C:30
 TestPMDPreprocessor.C:31
 TestPMDPreprocessor.C:32
 TestPMDPreprocessor.C:33
 TestPMDPreprocessor.C:34
 TestPMDPreprocessor.C:35
 TestPMDPreprocessor.C:36
 TestPMDPreprocessor.C:37
 TestPMDPreprocessor.C:38
 TestPMDPreprocessor.C:39
 TestPMDPreprocessor.C:40
 TestPMDPreprocessor.C:41
 TestPMDPreprocessor.C:42
 TestPMDPreprocessor.C:43
 TestPMDPreprocessor.C:44
 TestPMDPreprocessor.C:45
 TestPMDPreprocessor.C:46
 TestPMDPreprocessor.C:47
 TestPMDPreprocessor.C:48
 TestPMDPreprocessor.C:49
 TestPMDPreprocessor.C:50
 TestPMDPreprocessor.C:51
 TestPMDPreprocessor.C:52
 TestPMDPreprocessor.C:53
 TestPMDPreprocessor.C:54
 TestPMDPreprocessor.C:55
 TestPMDPreprocessor.C:56
 TestPMDPreprocessor.C:57
 TestPMDPreprocessor.C:58
 TestPMDPreprocessor.C:59
 TestPMDPreprocessor.C:60
 TestPMDPreprocessor.C:61
 TestPMDPreprocessor.C:62
 TestPMDPreprocessor.C:63
 TestPMDPreprocessor.C:64
 TestPMDPreprocessor.C:65
 TestPMDPreprocessor.C:66
 TestPMDPreprocessor.C:67
 TestPMDPreprocessor.C:68
 TestPMDPreprocessor.C:69
 TestPMDPreprocessor.C:70
 TestPMDPreprocessor.C:71
 TestPMDPreprocessor.C:72
 TestPMDPreprocessor.C:73
 TestPMDPreprocessor.C:74
 TestPMDPreprocessor.C:75
 TestPMDPreprocessor.C:76
 TestPMDPreprocessor.C:77
 TestPMDPreprocessor.C:78
 TestPMDPreprocessor.C:79
 TestPMDPreprocessor.C:80
 TestPMDPreprocessor.C:81
 TestPMDPreprocessor.C:82
 TestPMDPreprocessor.C:83
 TestPMDPreprocessor.C:84
 TestPMDPreprocessor.C:85
 TestPMDPreprocessor.C:86
 TestPMDPreprocessor.C:87
 TestPMDPreprocessor.C:88
 TestPMDPreprocessor.C:89
 TestPMDPreprocessor.C:90
 TestPMDPreprocessor.C:91
 TestPMDPreprocessor.C:92
 TestPMDPreprocessor.C:93
 TestPMDPreprocessor.C:94
 TestPMDPreprocessor.C:95
 TestPMDPreprocessor.C:96
 TestPMDPreprocessor.C:97
 TestPMDPreprocessor.C:98
 TestPMDPreprocessor.C:99
 TestPMDPreprocessor.C:100
 TestPMDPreprocessor.C:101
 TestPMDPreprocessor.C:102
 TestPMDPreprocessor.C:103
 TestPMDPreprocessor.C:104
 TestPMDPreprocessor.C:105
 TestPMDPreprocessor.C:106
 TestPMDPreprocessor.C:107
 TestPMDPreprocessor.C:108
 TestPMDPreprocessor.C:109
 TestPMDPreprocessor.C:110
 TestPMDPreprocessor.C:111
 TestPMDPreprocessor.C:112
 TestPMDPreprocessor.C:113
 TestPMDPreprocessor.C:114
 TestPMDPreprocessor.C:115
 TestPMDPreprocessor.C:116
 TestPMDPreprocessor.C:117
 TestPMDPreprocessor.C:118
 TestPMDPreprocessor.C:119
 TestPMDPreprocessor.C:120
 TestPMDPreprocessor.C:121
 TestPMDPreprocessor.C:122
 TestPMDPreprocessor.C:123
 TestPMDPreprocessor.C:124
 TestPMDPreprocessor.C:125
 TestPMDPreprocessor.C:126
 TestPMDPreprocessor.C:127
 TestPMDPreprocessor.C:128
 TestPMDPreprocessor.C:129
 TestPMDPreprocessor.C:130
 TestPMDPreprocessor.C:131
 TestPMDPreprocessor.C:132
 TestPMDPreprocessor.C:133
 TestPMDPreprocessor.C:134
 TestPMDPreprocessor.C:135
 TestPMDPreprocessor.C:136
 TestPMDPreprocessor.C:137
 TestPMDPreprocessor.C:138
 TestPMDPreprocessor.C:139
 TestPMDPreprocessor.C:140
 TestPMDPreprocessor.C:141