ROOT logo
/* 
$Id$ 
*/

// This class runs the test TOF 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

extern TBenchmark *gBenchmark;
void TOFPreprocessorFDR()
{
  gSystem->Load("$ALICE/SHUTTLE/TestShuttle/libTestShuttle.so");

  AliLog::SetClassDebugLevel("AliTOFPreprocessorFDR",1);
  // initialize location of CDB
  AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
  AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");

  // create AliTestShuttle instance
  AliTestShuttle* shuttle = new AliTestShuttle(0, 0, 1000);

  // Generation of "fake" input DCS data
  TMap* dcsAliasMap = CreateDCSAliasMap();  

  // now give the alias map to the shuttle
  shuttle->SetDCSInput(dcsAliasMap);   

  // instantiation of the preprocessor
  AliPreprocessor* pp = new AliTOFPreprocessorFDR(shuttle);

  // preprocessing
  gBenchmark->Start("process");
  shuttle->Process();
  gBenchmark->Stop("process");
  gBenchmark->Print("process");

  // checking the file which should have been created  
  AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())->Get("TOF/Calib/DCSData", 0);
  if (!chkEntry)
  {
    printf("The file is not there. Something went wrong.\n");
    return;
  }

  AliTOFDataDCS* output = dynamic_cast<AliTOFDataDCS*> (chkEntry->GetObject());
  // If everything went fine, draw the result
  if (output)
    printf("Output found.\n");
  //    output->Draw();
  
}

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;
  TDatime *datime = new TDatime();
  Int_t time = datime->GetTime();
  Int_t date = datime->GetDate();
  Int_t pid  = gSystem->GetPid();
  delete datime;
  Int_t iseed = TMath::Abs(10000 * pid + time - date); 

  Float_t tentLVv33=3.3, tentLVv48=48, tentLVi33=100, tentLVi48=10;
  Float_t sigmaLVv33=0.1, sigmaLVv48=1, sigmaLVi33=10, sigmaLVi48=2;

  Float_t tent=0, sigma=0, thr=0;
  Int_t NAliases=4;

  for(int nAlias=0;nAlias<NAliases;nAlias++) {
    
    TObjArray* valueSet = new TObjArray;
    valueSet->SetOwner(1);
    
    TString sindex;
    TString aliasName;
    if (nAlias==0){
      aliasName = "tof_lv_i48_02";
      tent=tentLVi48;
      sigma=sigmaLVi48;
    }
    else if (nAlias==1){
      aliasName = "tof_lv_v48_02";
      tent=tentLVv48;
      sigma=sigmaLVv48;
    }
    else if (nAlias==2){
      aliasName = "tof_lv_i33_02";
      tent=tentLVi33;
      sigma=sigmaLVi33;
    }
    else if (nAlias==3){
      aliasName = "tof_lv_v33_02";
      tent=tentLVv33;
      sigma=sigmaLVv33;
    }
    
    // gauss generation of values 
    for (int timeStamp=0;timeStamp<1000;timeStamp+=10){
      Float_t gaussvalue = (Float_t) (random.Gaus(tent,sigma));
      if (TMath::Abs(gaussvalue-tent)>sigma){
	AliDCSValue* dcsVal = new AliDCSValue(gaussvalue, timeStamp);
	valueSet->Add(dcsVal);
      }
    }
    
    aliasMap->Add(new TObjString(aliasName), valueSet);
  }
  return aliasMap;

}

TMap* ReadDCSAliasMap()
{
  // Open a file that contains DCS input data
  // The CDB framework is used to open the file, this means the file is located
  // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
  // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
  // An explanation of the structure can be found in CreateDCSAliasMap()

  AliCDBEntry *entry = AliCDBManager::Instance()->Get("TOF/DCS/Data", 0);
  return dynamic_cast<TMap*> (entry->GetObject());
}

void WriteDCSAliasMap()
{
  // This writes the output from CreateDCSAliasMap to a CDB file

  TMap* dcsAliasMap = CreateDCSAliasMap();

  AliCDBMetaData metaData;
	metaData.SetBeamPeriod(0);
	metaData.SetResponsible("Chiara");
	metaData.SetComment("Test object for TOFPreprocessorDCS.C");

  AliCDBId id("TOF/DCS/Data", 0, 0);

  // initialize location of CDB
  AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");

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