new classes for TRD trending and alarm management
authorabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 Jul 2010 08:00:51 +0000 (08:00 +0000)
committerabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 Jul 2010 08:00:51 +0000 (08:00 +0000)
PWG1/PWG1LinkDef.h
PWG1/TRD/info/AliTRDtrendValue.cxx [new file with mode: 0644]
PWG1/TRD/info/AliTRDtrendValue.h [new file with mode: 0644]
PWG1/TRD/info/AliTRDtrendingManager.cxx [new file with mode: 0644]
PWG1/TRD/info/AliTRDtrendingManager.h [new file with mode: 0644]
PWG1/TRD/macros/AliTRDmakeTrendDB.C [new file with mode: 0644]

index 6834d07..08a2f38 100644 (file)
@@ -82,6 +82,8 @@
 
 // TRD performance classes
 #pragma link C++ class  AliTenderSupplyTRD+;
+#pragma link C++ class  AliTRDtrendValue+;
+#pragma link C++ class  AliTRDtrendingManager+;
 #pragma link C++ class  AliTRDclusterInfo+;
 #pragma link C++ class  AliTRDv0Info+;
 #pragma link C++ class  AliTRDtrackInfo+;
diff --git a/PWG1/TRD/info/AliTRDtrendValue.cxx b/PWG1/TRD/info/AliTRDtrendValue.cxx
new file mode 100644 (file)
index 0000000..d61c025
--- /dev/null
@@ -0,0 +1,151 @@
+#include "TString.h"
+#include "TObjString.h"
+#include "TObjArray.h"
+
+#include "AliLog.h"
+#include "AliTRDtrendValue.h"
+
+ClassImp(AliTRDtrendValue)
+
+
+//____________________________________________
+AliTRDtrendValue::AliTRDtrendValue() 
+  : TNamed("none", "none")
+  ,fAlarmLevel(0)
+  ,fValue(0.)
+  ,fResponsible()
+  ,fNnotifiable(0)
+{
+  memset(fLimits, 0, 2*(kNlevels+1)*sizeof(Double_t));
+  for(Int_t ilevel(kNlevels); ilevel--; ) sprintf(fAlarmMessage[ilevel], " ");
+}
+
+//____________________________________________
+AliTRDtrendValue::AliTRDtrendValue(Char_t *n, Char_t *t) 
+  : TNamed("none", t)
+  ,fAlarmLevel(0)
+  ,fValue(0.)
+  ,fResponsible()
+  ,fNnotifiable(0)
+{
+  TString s(n);
+  TObjArray *names(s.Tokenize("_"));
+  if(names->GetEntriesFast()!=2){
+    AliError(Form("Wrong trend value name format. Trend value name should be of the form \"trendClass_trendValue\" with only one \"_\" character."));
+  } else SetName(n);
+
+  memset(fLimits, 0, 2*(kNlevels+1)*sizeof(Double_t));
+  for(Int_t ilevel(kNlevels); ilevel--; ) sprintf(fAlarmMessage[ilevel], " ");
+}
+
+//____________________________________________
+Int_t AliTRDtrendValue::GetAlarmLevel()
+{
+  // check value against limits and do some more work
+  fAlarmLevel=kNlevels-1;
+  for(Int_t ilevel(0); ilevel<kNlevels+1; ilevel++)
+    if(fValue<fLimits[2*ilevel+1] &&
+       fValue>=fLimits[2*ilevel]){ 
+      fAlarmLevel = ilevel;
+      break;
+    }
+
+  return fAlarmLevel;
+}
+
+//____________________________________________
+const char* AliTRDtrendValue::GetAlarmMessage() const
+{
+  if(!fAlarmLevel) return "OK";
+  else return fAlarmMessage[fAlarmLevel-1];
+}
+
+//____________________________________________
+const char* AliTRDtrendValue::GetClassName() const
+{
+  TString s(TNamed::GetName());
+  TObjArray *names(s.Tokenize("_"));
+  if(names->GetEntriesFast()!=2){
+    AliError(Form("Wrong trend value name format."));
+    return NULL;
+  }
+
+  return ((TObjString*)names->At(0))->String().Data();
+}
+
+//____________________________________________
+const char* AliTRDtrendValue::GetValueName() const
+{
+  TString s(TNamed::GetName());
+  TObjArray *names(s.Tokenize("_"));
+  if(names->GetEntriesFast()!=2){
+    AliError(Form("Wrong trend value name format."));
+    return NULL;
+  }
+  return ((TObjString*)names->At(1))->String().Data();
+}
+
+//____________________________________________
+const char* AliTRDtrendValue::GetResponsible(Char_t *n, Char_t *mail) const
+{
+  if(n) sprintf(n, "%s", fResponsible.name);
+  if(mail) sprintf(mail, "%s", fResponsible.mail);
+  return Form("%s <%s>", fResponsible.name, fResponsible.mail);
+}
+
+//____________________________________________
+const char* AliTRDtrendValue::GetNotifiable(Int_t in, Char_t *n, Char_t *mail) const
+{
+  if(in<0||in>=fNnotifiable) return NULL;
+  if(n) sprintf(n, "%s", fNotifiable[in].name);
+  if(mail) sprintf(mail, "%s", fNotifiable[in].mail);
+  return Form("%s <%s>", fNotifiable[in].name, fNotifiable[in].mail);
+}
+
+//____________________________________________
+void AliTRDtrendValue::SetNotifiable(const Char_t *name, const Char_t *mail)
+{
+  if(fNnotifiable==kNnotifiable){
+    AliWarning(Form("Could not add %s for notification. Only %d persons can be registered for notification.", name, kNnotifiable));
+    return;
+  }
+  sprintf(fNotifiable[fNnotifiable].name, "%s", name);
+  sprintf(fNotifiable[fNnotifiable].mail, "%s", mail);
+  fNnotifiable++;
+}
+
+//____________________________________________
+void AliTRDtrendValue::SetResponsible(const Char_t *name, const Char_t *mail) 
+{
+  sprintf(fResponsible.name, "%s", name);
+  sprintf(fResponsible.mail, "%s", mail);
+}
+
+//____________________________________________
+void AliTRDtrendValue::Print(Option_t */*o*/) const
+{
+//   name - title
+//   value - limits
+//   alarm level, message
+//   responsible
+
+  printf("    %s [%s] - %s\n", GetValueName(), GetClassName(), GetTitle());
+  printf("*** %f limits[%f %f]\n", fValue, fLimits[0], fLimits[1]);
+  if(fAlarmLevel){
+    printf("*** Alarm level   : %d limits[%f %f]\n", fAlarmLevel, fLimits[2*fAlarmLevel], fLimits[2*fAlarmLevel+1]);
+    printf("*** Alarm message : %s\n", GetAlarmMessage());
+  }
+  printf("*** Responsible %s <%s>\n", fResponsible.name, fResponsible.mail);
+  if(fNnotifiable){
+    printf("*** Notifiable person(s) ***\n");
+    for(Int_t i(0); i<fNnotifiable; i++)
+      printf("        %s <%s>\n", fNotifiable[i].name, fNotifiable[i].mail);
+  }
+}
+
+//____________________________________________
+AliTRDtrendValue::AliTRDtrendValueResponsible::AliTRDtrendValueResponsible(Char_t *n, Char_t *m) 
+{
+  if(n) sprintf(name, "%s", n); else sprintf(name, " ");
+  if(m) sprintf(mail, "%s", m); else sprintf(mail, " ");
+}
diff --git a/PWG1/TRD/info/AliTRDtrendValue.h b/PWG1/TRD/info/AliTRDtrendValue.h
new file mode 100644 (file)
index 0000000..72d5be4
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef ALITRDTRENDVALUE_H
+#define ALITRDTRENDVALUE_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+#ifndef ROOT_TNamed
+#include "TNamed.h"
+#endif
+
+class AliTRDtrendValue : public TNamed
+{
+public:
+  friend class AliTRDtrendingManager;
+  
+  enum ETRDtrendValue{
+    kNlevels = 4
+   ,kNnotifiable = 10 
+  };
+  AliTRDtrendValue();
+  AliTRDtrendValue(Char_t *n, Char_t *t);
+
+  Double_t    Get() const { return fValue;}
+  Int_t       GetAlarmLevel();
+  const char* GetAlarmMessage() const;
+  const char* GetClassName() const;
+  const char* GetValueName() const;
+  const char* GetResponsible(Char_t *n=NULL, Char_t *mail=NULL) const;
+  const char* GetNotifiable(Int_t in, Char_t *n=NULL, Char_t *mail=NULL) const;
+  Bool_t      IsAlarm() const { return fAlarmLevel>0;}
+  void        Print(Option_t *o="") const;
+  void        Set(Double_t v) { fValue=v; GetAlarmLevel();}
+
+protected: // only manager can fill these info !! 
+  void        SetAlarm(Int_t level, Char_t *m) {memcpy(fAlarmMessage[level], m, 1024*sizeof(Char_t));}
+  void        SetLimits(Double_t l[2*(kNlevels+1)]) {memcpy(fLimits, l, 2*(kNlevels+1)*sizeof(Double_t));}
+  void        SetResponsible(const Char_t *name, const Char_t *mail);
+  void        SetNotifiable(const Char_t *name, const Char_t *mail);
+
+private:
+  UChar_t       fAlarmLevel;// alarm level
+  Double_t      fValue;     // current value
+  Double_t      fLimits[2*(kNlevels+1)];// limits
+  Char_t        fAlarmMessage[kNlevels][1024]; // 
+
+  struct AliTRDtrendValueResponsible{
+    AliTRDtrendValueResponsible(Char_t *name=NULL, Char_t *mail=NULL);
+    Char_t name[100];
+    Char_t mail[200];
+  };
+  AliTRDtrendValueResponsible fResponsible; // responsible person
+  Int_t                       fNnotifiable; // number of persons to be notify
+  AliTRDtrendValueResponsible fNotifiable[kNnotifiable]; // 
+
+  ClassDef(AliTRDtrendValue, 0) // TRD trending value representation
+};
+
+#endif
+
diff --git a/PWG1/TRD/info/AliTRDtrendingManager.cxx b/PWG1/TRD/info/AliTRDtrendingManager.cxx
new file mode 100644 (file)
index 0000000..7897aad
--- /dev/null
@@ -0,0 +1,246 @@
+#include "TObjArray.h"
+#include "AliLog.h"
+#include "AliCDBRunRange.h"
+#include "AliCDBManager.h"
+#include "AliCDBMetaData.h"
+#include "AliCDBStorage.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDtrendingManager.h"
+
+ClassImp(AliTRDtrendingManager)
+
+AliTRDtrendingManager* AliTRDtrendingManager::fgInstance=NULL;
+Bool_t AliTRDtrendingManager::fgTerminated = kFALSE;
+
+//____________________________________________
+AliTRDtrendingManager* AliTRDtrendingManager::Instance()
+{
+  //
+  // Singleton implementation
+  // Returns an instance of this class, it is created if neccessary
+  //
+  if (fgTerminated != kFALSE) return NULL;
+
+  if (!fgInstance) {
+    fgInstance = new AliTRDtrendingManager();
+    AliTRDcalibDB *trd(AliTRDcalibDB::Instance());
+    if(!trd){ 
+      AliWarningGeneral("AliTRDtrendingManager", "TRD OCDB manager not initialized. No trending DB available.");
+    } else {
+      const TObjArray *trendMap(trd->GetTrendMap());
+      if(!trendMap){
+        AliWarningGeneral("AliTRDtrendingManager", "No TRD trending DB available  for TRD.");
+      } else fgInstance->fEntries=(TObjArray*)trendMap->Clone();
+    }
+  }
+
+  return fgInstance;
+}
+
+//____________________________________________
+void AliTRDtrendingManager::Terminate()
+{
+  //
+  // Singleton implementation
+  // Deletes the instance of this class and sets the terminated flag,
+  // instances cannot be requested anymore
+  // This function can be called several times.
+  //
+  
+  fgTerminated = kTRUE;
+  
+  if (fgInstance != NULL) {
+    delete fgInstance;
+    fgInstance = NULL;
+  }
+}
+
+//____________________________________________
+AliTRDtrendingManager::AliTRDtrendingManager() 
+  : TObject()
+  ,fEntries(NULL)
+  ,fValue(NULL)
+{
+  fRunRange[0] = 0; fRunRange[1] = AliCDBRunRange::Infinity();
+}
+
+//____________________________________________
+AliTRDtrendingManager::~AliTRDtrendingManager()
+{
+  if(fValue) delete fValue;
+  if(fEntries) delete fEntries;
+}
+
+//____________________________________________
+void AliTRDtrendingManager::AddValue(
+  Char_t *class_name
+  ,Char_t *name
+  ,Char_t *title
+  ,Double_t limits[2*(AliTRDtrendValue::kNlevels+1)]
+  ,Char_t *messages[AliTRDtrendValue::kNlevels]
+  ,Char_t *responsible
+  ,Char_t *notifiables
+  )
+{
+// Expert Function !!!
+// Add a trend value to the map already loaded
+// If no map loaded create a new one from scratch
+//
+// class_name : name of the performance task 
+// name       : name of the value to be trended
+// title      : description of the value to be trended
+// limits     : array of acceptance limits for this value. The array is organized as follows : 
+//               - field 0 and 1 normal limits
+//               - field 2 and 3 first level of alarm
+//               - ....
+//               - field 8 and 9 fourth level of alarm
+// messages   : array of alarm messages for each alarm level
+// responsible: name and email of the responsible person. Format "name/email"
+// notifiables: name and email of the notifiable persons. Format "name1/email1, name2/email2, etc"
+//
+  AliWarning("*** EXPERT FUNCTION *** This function is adding one trending value to the current DB. Continue if you know what yout do!");
+
+  // create new trending value`
+  if(!fValue) fValue = new AliTRDtrendValue(Form("%s_%s", class_name, name), title);
+  else new(fValue) AliTRDtrendValue(Form("%s_%s", class_name, name), title);
+  fValue->SetLimits(limits);
+  for(Int_t ilevel(AliTRDtrendValue::kNlevels); ilevel--;) fValue->SetAlarm(ilevel, messages[ilevel]);
+  TString s(responsible);
+  TObjArray *r=s.Tokenize("/");
+  if(r->GetEntriesFast()!=2){ 
+    AliWarning("Responsible name/email incorrectly formated.");
+  } else { 
+    fValue->SetResponsible(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data());
+  }
+  if(notifiables){
+    s=notifiables;
+    TObjArray *n=s.Tokenize(",");
+    for(Int_t in(0); in<TMath::Min(AliTRDtrendValue::kNnotifiable, n->GetEntriesFast()); in++){
+      TString ss(((TObjString*)n->At(in))->String());
+      r=ss.Tokenize("/");
+      if(r->GetEntriesFast()!=2){ 
+        AliWarning(Form("Notifiable person name/email incorrectly formated for [%s].", ss.Data()));
+      } else { 
+        fValue->SetNotifiable(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data());
+      }
+    }
+  }
+  // if no trending map defined create one
+  if(!fEntries){
+    AliInfo("No trending map loaded. Create one from scratch.");
+    fEntries = new TObjArray(50);
+    fEntries->SetOwner();
+  }
+
+  fEntries->AddLast(new AliTRDtrendValue(*fValue));
+}
+
+//____________________________________________
+AliTRDtrendValue* AliTRDtrendingManager::GetValue(Char_t *class_name, Char_t *value_name)
+{
+  if(!fEntries){
+    AliError("No trending map defined.");
+    return NULL;
+  }
+  AliTRDtrendValue *val((AliTRDtrendValue*)fEntries->FindObject(Form("%s_%s", class_name, value_name)));
+  if(!val){ 
+    AliError(Form("Missing trending value %s [%s]", value_name, class_name));
+    fEntries->ls();
+  }
+  return val;
+}
+
+//____________________________________________
+Bool_t AliTRDtrendingManager::ModifyValue(
+  Char_t *class_name
+  ,Char_t *name
+  ,Char_t *title
+  ,Double_t *limits
+  ,Char_t **messages
+  ,Char_t *responsible
+  ,Char_t *notifiables
+  )
+{
+// Expert Function !!!
+// Modify a trend value in the map already loaded
+// see function AddValue() for explanation of input format. 
+
+  if(!fEntries){
+    AliError("No trending map loaded.");
+    return kFALSE;
+  }
+  AliWarning("*** EXPERT FUNCTION *** This function is modifying one trending value to the current DB. Continue if you know what yout do!");
+
+  AliTRDtrendValue *val((AliTRDtrendValue*)fEntries->FindObject(Form("%s_%s", class_name, name)));
+  if(!val){ 
+    AliError(Form("Missing trending value %s [%s]", name, class_name));
+    return kFALSE;
+  }  
+  
+  val->SetTitle(title);
+  if(limits) val->SetLimits(limits);
+  if(messages){ 
+    for(Int_t ilevel(AliTRDtrendValue::kNlevels); ilevel--;) val->SetAlarm(ilevel, messages[ilevel]);
+  }
+  TString s;
+  TObjArray *r(NULL);
+  if(responsible){ 
+    s=responsible;
+    r=s.Tokenize("/");
+    if(r->GetEntriesFast()!=2){ 
+      AliWarning("Responsible name/email incorrectly formated.");
+    } else { 
+      val->SetResponsible(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data());
+    }
+  }
+  if(notifiables){
+    s=notifiables;
+    TObjArray *n=s.Tokenize(",");
+    for(Int_t in(0); in<TMath::Min(AliTRDtrendValue::kNnotifiable, n->GetEntriesFast()); in++){
+      TString ss(((TObjString*)n->At(in))->String());
+      r=ss.Tokenize("/");
+      if(r->GetEntriesFast()!=2){ 
+        AliWarning(Form("Notifiable person name/email incorrectly formated for [%s].", ss.Data()));
+      } else { 
+        val->SetNotifiable(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data());
+      }
+    }
+  }
+  return kTRUE;
+}
+
+//____________________________________________
+void AliTRDtrendingManager::Print(Option_t *o) const
+{
+  if(!fEntries){
+    AliError("No trending map available.");
+    return;
+  }
+
+  for(Int_t iv(0); iv<fEntries->GetEntriesFast(); iv++){
+    ((AliTRDtrendValue*)fEntries->At(iv))->Print(o);
+  }
+}
+
+//____________________________________________
+void AliTRDtrendingManager::Save()
+{
+// Saving TRD trending DB to $ALICE_ROOT/OCDB.
+
+  AliWarning("Saving TRD trending DB to $ALICE_ROOT/OCDB.");
+
+  AliCDBMetaData *metaData= new AliCDBMetaData(); 
+  metaData->SetObjectClassName("TObjArray");
+  metaData->SetResponsible("Alexander Wilk");
+  metaData->SetBeamPeriod(1);
+  metaData->SetAliRootVersion("05-21-01"); //root version
+  metaData->SetComment("TRD trending ");
+  
+  AliCDBId id("TRD/Calib/Trend", fRunRange[0], fRunRange[1]); 
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBStorage *gStorLoc = man->GetStorage("local://$ALICE_ROOT/OCDB");
+  if (!gStorLoc) {
+    return;
+  }
+  gStorLoc->Put(fEntries, id, metaData); 
+}
diff --git a/PWG1/TRD/info/AliTRDtrendingManager.h b/PWG1/TRD/info/AliTRDtrendingManager.h
new file mode 100644 (file)
index 0000000..e47f2ce
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef ALITRDTRENDINGMANAGER_H
+#define ALITRDTRENDINGMANAGER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+#ifndef ROOT_TObject
+#include "TObject.h"
+#endif
+
+#ifndef ALITRDTRENDVALUE_H
+#include "AliTRDtrendValue.h"
+#endif
+
+class TObjArray;
+class AliTRDtrendingManager : public TObject
+{
+public:
+  virtual ~AliTRDtrendingManager();
+  void              AddValue(Char_t *class_name
+                            ,Char_t *value_name
+                            ,Char_t *value_title
+                            ,Double_t limits[2*(AliTRDtrendValue::kNlevels+1)]
+                            ,Char_t *messages[AliTRDtrendValue::kNlevels]
+                            ,Char_t *responsible
+                            ,Char_t *notifiables=NULL
+                            );
+  AliTRDtrendValue* GetValue(Char_t *class_name, Char_t *value_name);
+  static AliTRDtrendingManager*        Instance();
+  Bool_t            ModifyValue(Char_t *class_name
+                            ,Char_t *value_name
+                            ,Char_t *value_title
+                            ,Double_t *limits=NULL
+                            ,Char_t **messages=NULL
+                            ,Char_t *responsible=NULL
+                            ,Char_t *notifiables=NULL
+                            );
+  void              Print(Option_t *o="") const;
+  void              Save();
+  void              ResetRunRange(Int_t runStart, Int_t runStop) {fRunRange[0]=runStart; fRunRange[1]=runStop;}
+  void              Terminate();
+
+protected:
+  AliTRDtrendingManager();
+  AliTRDtrendingManager(const AliTRDtrendingManager& ref);
+  AliTRDtrendingManager& operator=(const AliTRDtrendingManager& ref);
+
+private:
+  static Bool_t                        fgTerminated; // instance terminate flag
+       static AliTRDtrendingManager*   fgInstance;       // instance
+  TObjArray        *fEntries;    // list of trending values
+  AliTRDtrendValue *fValue;      // current loaded trend value
+  Int_t             fRunRange[2];// valability range
+
+  ClassDef(AliTRDtrendingManager, 0) // TRD trending Manager
+};
+
+#endif
diff --git a/PWG1/TRD/macros/AliTRDmakeTrendDB.C b/PWG1/TRD/macros/AliTRDmakeTrendDB.C
new file mode 100644 (file)
index 0000000..e5b95f1
--- /dev/null
@@ -0,0 +1,43 @@
+const Char_t *name[]={
+  "clResY", "clPullY", 
+  "trkltResY", "trkltPullY", "trkltResZ", "trkltPullZ", "trkltResPhi"
+};
+const Char_t *title[]={
+  "cluster resolution r-phi"
+ ,"cluster pulls r-phi"
+ ,"tracklet resolution r-phi"
+ ,"tracklet pulls r-phi"
+ ,"tracklet resolution z"
+ ,"tracklet pulls z"
+ ,"tracklet resolution phi"
+};
+void AliTRDmakeTrendDB()
+{
+  gSystem->Load("libANALYSIS.so");
+  gSystem->Load("libANALYSISalice.so");
+  gSystem->Load("libTENDER.so");
+  gSystem->Load("libPWG1.so");
+
+
+/*  AliCDBManager *cdb(AliCDBManager::Instance());
+  cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  cdb->SetRun(0);*/
+  AliTRDtrendingManager *tm(AliTRDtrendingManager::Instance());
+  AliTRDtrendValue *val(NULL);
+
+  for(Int_t iv(0); iv<7; iv++){
+    Double_t limits[]={-1., 1., -2., 2., -3., 3., -4., 4., -5., 5.};
+    char *messages[]={
+      "acceptable"
+     ,"worrisome"
+     ,"far from normal"
+     ,"off the limits"
+     ,"totally off"
+    };
+    tm->AddValue("resolution", name[iv], title[iv], limits, messages, "Alex Bercuci/a.bercuci@gsi.de", "Markus Fasel/m.fasel@gsi.de,Ionut Arsene/I.C.Arsene@gsi.de,Christoph Blume/blume@ikf.uni-frankfurt.de");
+    val=tm->GetValue("resolution", name[iv]);
+    val->Set(0.5+iv);
+  }
+  tm->Print();
+  //tm->Save();
+}
\ No newline at end of file