end-of-line normalization
[u/mrichter/AliRoot.git] / TRD / AliTRDSaxHandler.cxx
index 30acf53..f397c94 100644 (file)
-/*************************************************************************\r
- * * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *\r
- * *                                                                        *\r
- * * Author: The ALICE Off-line Project.                                    *\r
- * * Contributors are mentioned in the code where appropriate.              *\r
- * *                                                                        *\r
- * * Permission to use, copy, modify and distribute this software and its   *\r
- * * documentation strictly for non-commercial purposes is hereby granted   *\r
- * * without fee, provided that the above copyright notice appears in all   *\r
- * * copies and that both the copyright notice and this permission notice   *\r
- * * appear in the supporting documentation. The authors make no claims     *\r
- * * about the suitability of this software for any purpose. It is          *\r
- * * provided "as is" without express or implied warranty.                  *\r
- * **************************************************************************/\r
-\r
-/* $Id: AliTRDSaxHandler.cxx 26327 2008-06-02 15:36:18Z cblume $ */\r
-\r
-////////////////////////////////////////////////////////////////////////////\r
-//                                                                        //\r
-//  The SAX XML file handler used in the TRD preprocessor                 //\r
-//                                                                        //\r
-//  Authors:                                                              //\r
-//    Frederick Kramer (kramer@ikf.uni-frankfurt.de)                      //\r
-//    Thomas Bird      (thomas@thomasbird.com)                            //\r
-//                                                                        //\r
-////////////////////////////////////////////////////////////////////////////\r
-\r
-\r
-#include <TList.h>\r
-#include <TMath.h>\r
-#include "AliLog.h"\r
-#include "Cal/AliTRDCalDCSGTUTgu.h"\r
-#include "Cal/AliTRDCalDCSPTR.h"\r
-\r
-#include <TXMLAttr.h>\r
-#include <TObjArray.h>\r
-#include "AliTRDSaxHandler.h"\r
-#include "AliTRDgeometry.h"\r
-#include "AliTRDcalibDB.h"\r
-#include "Cal/AliTRDCalDCSv2.h"\r
-#include "Cal/AliTRDCalDCSFEEv2.h"\r
-#include "Cal/AliTRDCalDCSGTU.h"\r
-\r
-ClassImp(AliTRDSaxHandler)\r
-  \r
-//_____________________________________________________________________________\r
-AliTRDSaxHandler::AliTRDSaxHandler()\r
-  :TObject()\r
-  ,fHandlerStatus(0)\r
-  ,fNDCSPTR(0)\r
-  ,fNDCSGTU(0)\r
-  ,fFEEArr(new TObjArray(540))\r
-  ,fPTRArr(new TObjArray(6))\r
-  ,fSystem(0)\r
-  ,fInsideRstate(0)\r
-  ,fCurrentSM(0)\r
-  ,fCurrentStack(0)\r
-  ,fCurrentROB(-1)\r
-  ,fCurrentMCM(-1)\r
-  ,fCurrentADC(-1)\r
-  ,fContent(0)\r
-  ,fDCSFEEObj(0)\r
-  ,fDCSPTRObj(0)\r
-  ,fDCSGTUObj(0)\r
-  ,fCalDCSObj(new AliTRDCalDCSv2())\r
-  ,fLevel1Tag(-2)\r
-  ,fLevel2Tag(-2)\r
-  ,fInsideBoardInfo(false)\r
-  ,fTmu(0)\r
-  ,fCtpOpc(0)\r
-  ,fSegment(0)\r
-  ,fBoardInfo(0)\r
-{\r
-  // AliTRDSaxHandler default constructor\r
-  fFEEArr->SetOwner();\r
-  fPTRArr->SetOwner();\r
-}\r
-\r
-//_____________________________________________________________________________\r
-AliTRDSaxHandler::AliTRDSaxHandler(const AliTRDSaxHandler &sh)\r
-  :TObject(sh)\r
-  ,fHandlerStatus(0)\r
-  ,fNDCSPTR(0)\r
-  ,fNDCSGTU(0)\r
-  ,fFEEArr(0)\r
-  ,fPTRArr(0)\r
-  ,fSystem(0)\r
-  ,fInsideRstate(0)\r
-  ,fCurrentSM(0)\r
-  ,fCurrentStack(0)\r
-  ,fCurrentROB(-1)\r
-  ,fCurrentMCM(-1)\r
-  ,fCurrentADC(-1)\r
-  ,fContent(0)\r
-  ,fDCSFEEObj(0)\r
-  ,fDCSPTRObj(0)\r
-  ,fDCSGTUObj(0)\r
-  ,fCalDCSObj(0)\r
-  ,fLevel1Tag(-2)\r
-  ,fLevel2Tag(-2)\r
-  ,fInsideBoardInfo(false)\r
-  ,fTmu(0)\r
-  ,fCtpOpc(0)\r
-  ,fSegment(0)\r
-  ,fBoardInfo(0)\r
-{\r
-  // AliTRDSaxHandler copy constructor\r
-}\r
-\r
-//_____________________________________________________________________________\r
-AliTRDSaxHandler &AliTRDSaxHandler::operator=(const AliTRDSaxHandler &sh)\r
-{\r
-  // Assignment operator\r
-  if (&sh == this) return *this;\r
-  new (this) AliTRDSaxHandler(sh);\r
-  return *this;\r
-}\r
-\r
-//_____________________________________________________________________________\r
-AliTRDSaxHandler::~AliTRDSaxHandler()\r
-{\r
-  // AliTRDSaxHandler destructor\r
-  if (fFEEArr) {\r
-    delete fFEEArr;\r
-    fFEEArr    = 0x0;\r
-  }\r
-  if (fPTRArr) {\r
-    delete fPTRArr;\r
-    fPTRArr    = 0x0;\r
-  }\r
-  if (fDCSGTUObj) {\r
-    delete fDCSGTUObj;\r
-    fDCSGTUObj    = 0x0;\r
-  }\r
-  if (fCalDCSObj) {\r
-    delete fCalDCSObj;\r
-    fCalDCSObj = 0x0;\r
-  }\r
-}\r
-\r
-//_____________________________________________________________________________\r
-AliTRDCalDCSv2* AliTRDSaxHandler::GetCalDCSObj()\r
-{\r
-  // put the arrays in the global calibration object and return this\r
-\r
-  fCalDCSObj->SetFEEArr(fFEEArr);\r
-  fCalDCSObj->SetPTRArr(fPTRArr);\r
-  fCalDCSObj->SetGTUObj(fDCSGTUObj);\r
-  return fCalDCSObj;\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::ParseConfigName(TString cfgname) const\r
-{\r
-  // Evaluate the config name and set the individual parameters\r
-\r
-  // protect\r
-  if (!AliTRDcalibDB::Instance()) {\r
-    AliError("Could not create an instance of AliTRDcalibDB!");\r
-    return;\r
-  }\r
-\r
-  TString cfg = "", par = "", pars = "";\r
-  Int_t nPar = AliTRDcalibDB::Instance()->GetNumberOfParsDCS(cfgname);\r
-  if (nPar == 0) return;\r
-\r
-  for (Int_t i=1; i<=nPar; i++) {\r
-    // Get the configuration parameter\r
-    AliTRDcalibDB::Instance()->GetDCSConfigParOption(cfgname, i, 0, cfg);\r
-\r
-    // Set Parameters accordingly\r
-    if (i == AliTRDcalibDB::kFltrSet) fDCSFEEObj->SetFilterType(cfg);\r
-    if (i == AliTRDcalibDB::kTrigSet) fDCSFEEObj->SetTriggerSetup(cfg);\r
-    if (i == AliTRDcalibDB::kAddOpti) fDCSFEEObj->SetAddOptions(cfg);\r
-    if (i == AliTRDcalibDB::kTimebin) fDCSFEEObj->SetNumberOfTimeBins(AliTRDcalibDB::Instance()->ExtractTimeBinsFromString(cfg));\r
-    if (i == AliTRDcalibDB::kReadout) fDCSFEEObj->SetReadoutParam(cfg);\r
-    if (i == AliTRDcalibDB::kTrkMode) fDCSFEEObj->SetTrackletMode(cfg);\r
-\r
-    // Set options of parameters accordingly\r
-    Int_t nOpt = AliTRDcalibDB::Instance()->GetNumberOfOptsDCS(cfgname, i);\r
-    if (nOpt == 0) continue;\r
-\r
-    for (Int_t j=1; j<=nOpt; j++) {\r
-      // Get the parameter option\r
-      AliTRDcalibDB::Instance()->GetDCSConfigParOption(cfgname, i, j, par);\r
-\r
-      if (i == AliTRDcalibDB::kReadout) {\r
-       if (par.EqualTo("stat")) fDCSFEEObj->SetFastStatNoise(1);\r
-      }\r
-      if (i == AliTRDcalibDB::kTrkMode) {\r
-       if ((j > 1) && (par.Length() != 0)) pars += "-";\r
-       pars += par;\r
-      }\r
-      // SetTCFilterWeight, SetTCFilterShortDecPar, SetTCFilterLongDecPar might be filled here, too\r
-      // SetSingleHitThres, SetThreePadClustThres, SetSelectiveNoZS, SetTestPattern might be filled here, too\r
-    }\r
-\r
-    fDCSFEEObj->SetTrackletDef(pars);\r
-  }\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnStartDocument() const\r
-{\r
-  // if something should happen right at the beginning of the\r
-  // XML document, this must happen here\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnEndDocument() const\r
-{\r
-  // if something should happen at the end of the XML document\r
-  // this must be done here\r
-}\r
-\r
-//_____________________________________________________________________________\r
-bool AliTRDSaxHandler::CompareString(TString str, const char *str2)\r
-{\r
-  // compre strings, ignoring case\r
-  // returns true if they are the same, else false\r
-  return !(bool)str.CompareTo(str2,str.kIgnoreCase);\r
-}\r
-\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnStartElement(const char *name, const TList *attributes)\r
-{\r
-  // when a new XML element is found, it is processed here\r
-  fContent    = ""; // Technically <p> This <em>is</em> ok but would be a problem here</p>\r
-  Int_t dcsId = 0;\r
-  TString tagName  = name;\r
-  TString dcsTitle = "";\r
-\r
-  // set the current system if necessary\r
-  if (CompareString(tagName, "FEE")) fSystem = kInsideFEE;\r
-  if (CompareString(tagName, "PTR")) fSystem = kInsidePTR;\r
-  if (CompareString(tagName, "GTU")) {\r
-    fSystem = kInsideGTU;\r
-    fDCSGTUObj = new AliTRDCalDCSGTU(tagName,tagName);\r
-  }\r
-\r
-  if (fSystem == kInsideGTU) {\r
-    if (CompareString(tagName, "tgu")) fLevel1Tag = kInsideTgu;\r
-    if (CompareString(tagName, "board_info")) {\r
-      fInsideBoardInfo = true;\r
-      fBoardInfo = new AliTRDCalDCSGTUBoardInfo(tagName,tagName);\r
-    }\r
-    if (CompareString(tagName(0,tagName.Length()-3), "segment")) { \r
-      fSegment = new AliTRDCalDCSGTUSegment(tagName,tagName);\r
-      fSegment->SetId(TString(tagName(8,2)).Atoi());\r
-      fLevel1Tag = kInsideSegment;\r
-    }\r
-    if (fLevel1Tag == kInsideTgu) {\r
-      if (CompareString(tagName, "ctp_opc"))   fCtpOpc = new AliTRDCalDCSGTUCtpOpc(tagName,tagName);\r
-    } else if (fLevel1Tag == kInsideSegment) {\r
-      if (CompareString(tagName, "smu")) {\r
-       fLevel2Tag = kInsideSmu;\r
-      }\r
-      if (CompareString(tagName(0,3), "tmu")) {\r
-       fTmu = new AliTRDCalDCSGTUTmu(tagName,tagName);\r
-       fTmu->SetId(TString(tagName(4,2)).Atoi());\r
-       fLevel2Tag = kInsideTmu;\r
-      }\r
-    }\r
-  } else if (fSystem == kInsideFEE) {\r
-    if (CompareString(tagName, "gaintbl")) fLevel1Tag = kInsideGainTable;\r
-  }\r
-\r
-  // set if we are inside rstate \r
-  // (in principle not necessary - just to be more safe against stupid tags)\r
-  if (CompareString(tagName, "rstate")) fInsideRstate = 1;\r
-\r
-  // get the attributes of the element\r
-  TXMLAttr *attr;\r
-  TIter next(attributes);\r
-  while ((attr = (TXMLAttr*) next())) {\r
-    TString attribName = attr->GetName();\r
-    TString attribValue = attr->GetValue();\r
-    if (fSystem == kInsideFEE && fLevel1Tag == kInsideNone) {\r
-      if (CompareString(attribName, "id") && CompareString(tagName, "DCS")) {\r
-       dcsTitle = name;\r
-       dcsId = atoi(attr->GetValue());\r
-      }\r
-      if (CompareString(attribName, "roc") && CompareString(tagName, "ack")) {\r
-       if (attribValue.Atoi() != fDCSFEEObj->GetDCSid())\r
-         fDCSFEEObj->SetStatusBit(4); // consistency check\r
-      }\r
-      if (CompareString(attribName, "rob") && CompareString(tagName, "ro-board") && (fInsideRstate == 1)) {\r
-       fCurrentROB = attribValue.Atoi();\r
-      }\r
-      if (CompareString(attribName, "mcm") && CompareString(tagName, "m") && (fInsideRstate == 1)) {\r
-       fCurrentMCM = attribValue.Atoi();\r
-      }\r
-      if (CompareString(attribName, "sm") && CompareString(tagName, "DCS")) {\r
-       fCurrentSM = attribValue.Atoi(); // only for GTU/PTR\r
-      }\r
-      if (CompareString(attribName, "id") && CompareString(tagName, "STACK")) {// hmmmm not exist?\r
-       fCurrentStack = attribValue.Atoi(); // only for GTU/PTR\r
-      }\r
-    } else if (fSystem == kInsideFEE && fLevel1Tag == kInsideGainTable) {\r
-      if (CompareString(tagName, "roc") && CompareString(attribName, "type"))    fDCSFEEObj->SetGainTableRocType(attribValue);\r
-      if (CompareString(tagName, "roc") && CompareString(attribName, "serial"))  fDCSFEEObj->SetGainTableRocSerial(attribValue.Atoi());\r
-      if (CompareString(tagName, "mcm") && CompareString(attribName, "rob"))     fCurrentROB = attribValue.Atoi();\r
-      if (CompareString(tagName, "mcm") && CompareString(attribName, "pos"))     fCurrentMCM = attribValue.Atoi();\r
-      if (CompareString(tagName, "adc") && CompareString(attribName, "id"))      fCurrentADC = attribValue.Atoi();\r
-      \r
-    } else if (fSystem == kInsideGTU && fLevel1Tag == kInsideNone) {\r
-      if (CompareString(tagName, "publisher")) {\r
-       if (CompareString(attribName, "at"))         fDCSGTUObj->SetSORFlag(attribValue.Atoi());\r
-       if (CompareString(attribName, "serial"))     fDCSGTUObj->SetSerial(attribValue.Atoi());\r
-       if (CompareString(attribName, "runnr"))      fDCSGTUObj->SetRunNumber(attribValue.Atoi());\r
-      }\r
-    } else if (fSystem == kInsideGTU && fLevel1Tag == kInsideTgu) {\r
-      if (CompareString(tagName, "from")) {\r
-       if (CompareString(attribName, "at"))         fDCSGTUObj->GetTgu()->SetFromSORFlag(attribValue.Atoi());\r
-       if (CompareString(attribName, "runnr"))      fDCSGTUObj->GetTgu()->SetFromRunNumber(attribValue.Atoi());\r
-       if (CompareString(attribName, "child"))      fDCSGTUObj->GetTgu()->SetFromChild(attribValue.Atoi());\r
-      }\r
-      if (CompareString(tagName, "segmentmask") && CompareString(attribName, "value"))  fDCSGTUObj->GetTgu()->SetSegmentMask(attribValue);\r
-      if (CompareString(tagName, "busymask") && CompareString(attribName, "value"))     fDCSGTUObj->GetTgu()->SetBusyMask(attribValue);\r
-      if (CompareString(tagName, "contribmask") && CompareString(attribName, "value"))  fDCSGTUObj->GetTgu()->SetContribMask(attribValue);\r
-      \r
-      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "id"))         fCtpOpc->SetId(attribValue.Atoi());\r
-      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "opcode"))     fCtpOpc->SetOpcode(attribValue.Atoi());\r
-      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "direction"))  fCtpOpc->SetDirection(attribValue.Atoi());\r
-      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "inverted"))   fCtpOpc->SetInverted(attribValue.Atoi());\r
-      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "delay"))      fCtpOpc->SetDelay(attribValue.Atoi());\r
-      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "connected"))  fCtpOpc->SetConnected(attribValue.Atoi());\r
-      \r
-    } else if (fSystem == kInsideGTU && fLevel1Tag == kInsideSegment) {\r
-      if (CompareString(tagName, "from")) {\r
-       if (CompareString(attribName, "at"))         fSegment->SetFromSORFlag(attribValue.Atoi());\r
-       if (CompareString(attribName, "runnr"))      fSegment->SetFromRunNumber(attribValue.Atoi());\r
-       if (CompareString(attribName, "child"))      fSegment->SetFromChild(attribValue.Atoi());\r
-      }\r
-      if (fLevel2Tag == kInsideSmu) {\r
-       if (CompareString(tagName, "stackmask") && CompareString(attribName, "value"))     fSegment->SetSmuStackMask(attribValue);\r
-       if (CompareString(tagName, "tracklets") && CompareString(attribName, "send"))      fSegment->SetSmuTracklets(attribValue.Atoi());\r
-       if (CompareString(tagName, "tracks") && CompareString(attribName, "send"))         fSegment->SetSmuTracks(attribValue.Atoi());\r
-       if (CompareString(tagName, "idelay") && CompareString(attribName, "value"))        fSegment->SetSmuIdelay(attribValue.Atoi());\r
-       if (CompareString(tagName, "ttc_emulator") && CompareString(attribName, "enable")) fSegment->SetSmuTtcEmulatorEnable(attribValue.Atoi());\r
-       \r
-       if (CompareString(tagName, "trigger_window") && CompareString(attribName, "l1_low"))  \r
-         fSegment->SetSmuTriggerWindowL1Low(attribValue.Atoi());\r
-       if (CompareString(tagName, "trigger_window") && CompareString(attribName, "l1_high"))  \r
-         fSegment->SetSmuTriggerWindowL1High(attribValue.Atoi());\r
-       if (CompareString(tagName, "trigger_window") && CompareString(attribName, "l2_low"))  \r
-         fSegment->SetSmuTriggerWindowL2Low(attribValue.Atoi());\r
-       if (CompareString(tagName, "trigger_window") && CompareString(attribName, "l2_high"))  \r
-         fSegment->SetSmuTriggerWindowL2High(attribValue.Atoi());\r
-       \r
-      } else if (fLevel2Tag == kInsideTmu) {\r
-       if (CompareString(tagName, "linkmask") && CompareString(attribName, "value"))      fTmu->SetLinkMask(attribValue);\r
-       if (CompareString(tagName, "pattern_generator") && CompareString(attribName, "enable")) \r
-         fTmu->SetPatternGeneratorEnable(attribValue.Atoi());\r
-       if (CompareString(tagName, "pattern_generator") && CompareString(attribName, "datawords")) \r
-         fTmu->SetPatternGeneratorDataWords(attribValue.Atoi());\r
-       if (CompareString(tagName, "pattern_generator") && CompareString(attribName, "trackletwords")) \r
-         fTmu->SetPatternGeneratorTrackletWords(attribValue.Atoi());\r
-      }\r
-    }\r
-    \r
-    if (fInsideBoardInfo) {\r
-      if (CompareString(tagName, "board_info") && CompareString(attribName, "board_id"))    fBoardInfo->SetId(attribValue);\r
-      if (CompareString(tagName, "board_info") && CompareString(attribName, "design_type")) fBoardInfo->SetType(attribValue.Atoi());\r
-      if (CompareString(tagName, "board_info") && CompareString(attribName, "pci_ga"))      fBoardInfo->SetPciGa(attribValue.Atoi());\r
-      if (CompareString(tagName, "hardware") && CompareString(attribName, "date"))          fBoardInfo->SetHwDate(attribValue);\r
-      if (CompareString(tagName, "hardware") && CompareString(attribName, "rev"))           fBoardInfo->SetHwRev(attribValue.Atoi());\r
-      if (CompareString(tagName, "hardware") && CompareString(attribName, "clean"))         fBoardInfo->SetHwClean(attribValue.Atoi());\r
-      if (CompareString(tagName, "software") && CompareString(attribName, "date"))          fBoardInfo->SetSwDate(attribValue);\r
-      if (CompareString(tagName, "software") && CompareString(attribName, "rev"))           fBoardInfo->SetSwRev(attribValue.Atoi());\r
-      if (CompareString(tagName, "software") && CompareString(attribName, "clean"))         fBoardInfo->SetSwClean(attribValue.Atoi());\r
-    }\r
-  }\r
-\r
-  // if there is a new DCS element put it in the correct array\r
-  if (CompareString(tagName, "DCS")) {\r
-    if (fSystem == kInsideFEE) {\r
-      fDCSFEEObj = new AliTRDCalDCSFEEv2();\r
-      fDCSFEEObj->SetDCSid(dcsId);\r
-    }\r
-    if (fSystem == kInsidePTR) {\r
-//       fDCSPTRObj = new AliTRDCalDCSPTR(name,dcsTitle);\r
-//       fDCSPTRObj->SetDCSid(dcsId);\r
-    }\r
-    if (fSystem == kInsideGTU) {\r
-//       fDCSGTUObj = new AliTRDCalDCSGTU(name,dcsTitle);\r
-//       fDCSGTUObj->SetDCSid(dcsId);\r
-    }\r
-  }\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnEndElement(const char *name)\r
-{\r
-  // do everything that needs to be done when an end tag of an element is found\r
-  TString tagName = name;\r
-  \r
-  // if done with this DCS board, put it in the correct array\r
-  // no check for </ack> necessary since this check is done during XML validation\r
-  if (CompareString(tagName, "DCS")) {\r
-    if (fSystem == kInsideFEE) {\r
-      Int_t detID = 0;\r
-      if (fDCSFEEObj->GetStatusBit() == 0) {\r
-       // if there were no errors (StatusBit==0) the following should match\r
-        detID = fDCSFEEObj->GetDCSid();\r
-        AliTRDgeometry aliGeo;\r
-        Int_t calDetID = aliGeo.GetDetector(fDCSFEEObj->GetLayer(),\r
-                                           fDCSFEEObj->GetStack(),\r
-                                           fDCSFEEObj->GetSM());\r
-       if (detID != calDetID) fDCSFEEObj->SetStatusBit(4);\r
-      } else {\r
-       // if the dcs board didn't properly respond, don't compare\r
-        detID = fDCSFEEObj->GetDCSid();\r
-      }\r
-      fFEEArr->AddAt(fDCSFEEObj,detID);\r
-    }\r
-    if (fSystem == kInsidePTR) {\r
-      fPTRArr->AddAt(fDCSPTRObj,fNDCSPTR);\r
-      fNDCSPTR++;\r
-    }\r
-//     if (fSystem == kInsideGTU) {\r
-//       fGTUArr->AddAt(fDCSGTUObj,fNDCSGTU);\r
-//       fNDCSGTU++;\r
-//     }\r
-    fCurrentSM = 99; // 99 for no SM set\r
-    fDCSFEEObj = 0;  // just to be sure\r
-    return;\r
-  }\r
-\r
-  // done with this stack? \r
-  if (CompareString(tagName, "STACK")) {// TODO: errrrm ???? always 99?\r
-    fCurrentStack = 99; // 99 for no stack set\r
-  }\r
-\r
-  // outside of rstate again?\r
-  if (CompareString(tagName, "rstate")) {\r
-    fInsideRstate = 0;\r
-    fCurrentROB   = -1;\r
-    fCurrentMCM   = -1;\r
-  }\r
-  if (CompareString(tagName, "ro-board")) fCurrentROB = -1;\r
-  \r
-  // store informations of the FEE DCS-Board\r
-  if (fSystem == kInsideFEE) {\r
-    if (CompareString(tagName, "DNR"))            fDCSFEEObj->SetStatusBit(fContent.Atoi());\r
-    if (CompareString(tagName, "CFGTAG"))         fDCSFEEObj->SetConfigTag(fContent.Atoi());\r
-    if (CompareString(tagName, "CFGVRSN"))        fDCSFEEObj->SetConfigVersion(fContent);\r
-    if (CompareString(tagName, "SM-ID"))          fDCSFEEObj->SetSM(fContent.Atoi());\r
-    if (CompareString(tagName, "STACK-ID"))       fDCSFEEObj->SetStack(fContent.Atoi());\r
-    if (CompareString(tagName, "LAYER-ID"))       fDCSFEEObj->SetLayer(fContent.Atoi());\r
-    if (CompareString(tagName, "CFGNME")) {\r
-      fDCSFEEObj->SetConfigName(fContent);\r
-      ParseConfigName(fContent);\r
-    }\r
-    if (CompareString(tagName, "gaintbl")) {\r
-      fLevel1Tag = kInsideNone;\r
-      fCurrentROB = -1;\r
-      fCurrentMCM = -1;\r
-      fCurrentADC = -1;\r
-    }\r
-    if (fLevel1Tag == kInsideGainTable) {\r
-      if (CompareString(tagName, "name"))   fDCSFEEObj->SetGainTableName(fContent);\r
-      if (CompareString(tagName, "desc"))   fDCSFEEObj->SetGainTableDesc(fContent);\r
-      if (fCurrentROB>=0 && fCurrentMCM>=0) {\r
-       if (CompareString(tagName, "adcdac")) fDCSFEEObj->SetGainTableAdcdac(fCurrentROB, fCurrentMCM, fContent.Atoi());\r
-       if (fCurrentADC>=0) {\r
-         if (CompareString(tagName, "fgfn"))   fDCSFEEObj->SetGainTableFgfn(fCurrentROB, fCurrentMCM, fCurrentADC, fContent.Atoi());\r
-         if (CompareString(tagName, "fgan"))   fDCSFEEObj->SetGainTableFgan(fCurrentROB, fCurrentMCM, fCurrentADC, fContent.Atoi());\r
-       }\r
-      }\r
-    }\r
-    if (fInsideRstate == 1) {\r
-      if (fCurrentROB>=0 && fCurrentMCM>=0) {\r
-       if (CompareString(tagName, "gsm")) fDCSFEEObj->SetMCMGlobalState(fCurrentROB, fCurrentMCM, fContent.Atoi());\r
-        if (CompareString(tagName, "ni")) fDCSFEEObj->SetMCMStateNI(fCurrentROB, fCurrentMCM, fContent.Atoi());\r
-       if (CompareString(tagName, "ev")) fDCSFEEObj->SetMCMEventCnt(fCurrentROB, fCurrentMCM, fContent.Atoi());\r
-       if (CompareString(tagName, "ptrg")) fDCSFEEObj->SetMCMPtCnt(fCurrentROB, fCurrentMCM, fContent.Atoi());\r
-      }\r
-    }\r
-  }\r
-\r
-  if (fSystem == kInsideGTU) {\r
-//     if (CompareString(tagName, "run")) { \r
-//       fDCSGTUObj->SetSORFlag(TString(fContent(fContent.Length()-1,1)).Atoi());\r
-//       fDCSGTUObj->SetRunNumber(TString(fContent(0,fContent.Length()-2)).Atoi());\r
-//     }\r
-//     if (CompareString(tagName, "serial"))         fDCSGTUObj->SetSerial(fContent.Atoi());\r
-    if (CompareString(tagName, "board_info")) {\r
-      fInsideBoardInfo = false;\r
-      if (fLevel1Tag == kInsideTgu)                                  fDCSGTUObj->GetTgu()->SetBoardInfo(fBoardInfo);\r
-      if (fLevel1Tag == kInsideSegment && fLevel2Tag == kInsideSmu)  fSegment->SetSmuBoardInfo(fBoardInfo);\r
-      if (fLevel1Tag == kInsideSegment && fLevel2Tag == kInsideTmu)  fTmu->SetBoardInfo(fBoardInfo);\r
-    }\r
-    if (CompareString(tagName, "dnr"))            fDCSGTUObj->SetDNR(fContent.Atoi());\r
-    if (CompareString(tagName, "tgu"))            fLevel1Tag = kInsideNone;\r
-    if (CompareString(tagName(0,tagName.Length()-3), "segment")) { \r
-      fDCSGTUObj->GetSegmentArray()->Add(fSegment);\r
-      fLevel1Tag = kInsideNone;\r
-    }\r
-    if (fLevel1Tag == kInsideTgu) {\r
-      if (CompareString(tagName, "ctp_opc"))        fDCSGTUObj->GetTgu()->GetCtpOpcArray()->Add(fCtpOpc);\r
-    } else if (fLevel1Tag == kInsideSegment) {\r
-      if (CompareString(tagName, "smu"))          fLevel2Tag = kInsideNone;\r
-      if (CompareString(tagName(0,3), "tmu")) {\r
-       fSegment->GetTmuArray()->Add(fTmu);\r
-       fLevel2Tag = kInsideNone;\r
-      }\r
-    }\r
-  }\r
-\r
-  \r
-  // store pretrigger informations\r
-  if (fSystem == kInsidePTR) {\r
-    // no informations available yet\r
-  }\r
-//   // store GTU informations\r
-//   if (fSystem == kInsideGTU) {\r
-//     if (CompareString(tagName, "SMMASK"))\r
-//       fHandlerStatus = fDCSGTUObj->SetSMMask(fContent);\r
-//     if (CompareString(tagName, "LINKMASK")) \r
-//       fHandlerStatus = fDCSGTUObj->SetLinkMask(fCurrentSM, fCurrentStack, fContent);\r
-//     if (CompareString(tagName, "STMASK"))\r
-//       fDCSGTUObj->SetStackMaskBit(fCurrentSM, fCurrentStack, fContent.Atoi());\r
-//   }\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnCharacters(const char *characters)\r
-{\r
-  // copy the the text content of an XML element\r
-  fContent = characters;\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnComment(const char* /*text*/) const\r
-{\r
-  // comments within the XML file are ignored\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnWarning(const char *text)\r
-{\r
-  // process warnings here\r
-  AliInfo(Form("Warning: %s",text));\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnError(const char *text)\r
-{\r
-  // process errors here\r
-  AliError(Form("Error: %s",text));\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnFatalError(const char *text)\r
-{\r
-  // process fatal errors here\r
-  AliError(Form("Fatal error: %s",text)); // use AliFatal?\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliTRDSaxHandler::OnCdataBlock(const char* /*text*/, Int_t /*len*/) const\r
-{\r
-  // process character data blocks here\r
-  // not implemented and should not be used here\r
-}\r
-\r
+/*************************************************************************
+ * * Copyright(c) 1998-2008, 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.                  *
+ * **************************************************************************/
+
+/* $Id: AliTRDSaxHandler.cxx 26327 2008-06-02 15:36:18Z cblume $ */
+
+////////////////////////////////////////////////////////////////////////////
+//                                                                        //
+//  The SAX XML file handler used in the TRD preprocessor                 //
+//                                                                        //
+//  Authors:                                                              //
+//    Frederick Kramer (kramer@ikf.uni-frankfurt.de)                      //
+//    Thomas Bird      (thomas@thomasbird.com)                            //
+//                                                                        //
+////////////////////////////////////////////////////////////////////////////
+
+
+#include <TList.h>
+#include <TMath.h>
+#include "AliLog.h"
+#include "Cal/AliTRDCalDCSGTUTgu.h"
+#include "Cal/AliTRDCalDCSPTR.h"
+
+#include <TXMLAttr.h>
+#include <TObjArray.h>
+#include "AliTRDSaxHandler.h"
+#include "AliTRDgeometry.h"
+#include "AliTRDcalibDB.h"
+#include "Cal/AliTRDCalDCSv2.h"
+#include "Cal/AliTRDCalDCSFEEv2.h"
+#include "Cal/AliTRDCalDCSGTU.h"
+
+ClassImp(AliTRDSaxHandler)
+  
+//_____________________________________________________________________________
+AliTRDSaxHandler::AliTRDSaxHandler()
+  :TObject()
+  ,fHandlerStatus(0)
+  ,fNDCSPTR(0)
+  ,fNDCSGTU(0)
+  ,fFEEArr(new TObjArray(540))
+  ,fPTRArr(new TObjArray(6))
+  ,fSystem(0)
+  ,fInsideRstate(0)
+  ,fCurrentSM(0)
+  ,fCurrentStack(0)
+  ,fCurrentROB(-1)
+  ,fCurrentMCM(-1)
+  ,fCurrentADC(-1)
+  ,fContent(0)
+  ,fDCSFEEObj(0)
+  ,fDCSPTRObj(0)
+  ,fDCSGTUObj(0)
+  ,fCalDCSObj(new AliTRDCalDCSv2())
+  ,fLevel1Tag(-2)
+  ,fLevel2Tag(-2)
+  ,fInsideBoardInfo(false)
+  ,fTmu(0)
+  ,fCtpOpc(0)
+  ,fSegment(0)
+  ,fBoardInfo(0)
+{
+  // AliTRDSaxHandler default constructor
+  fFEEArr->SetOwner();
+  fPTRArr->SetOwner();
+}
+
+//_____________________________________________________________________________
+AliTRDSaxHandler::AliTRDSaxHandler(const AliTRDSaxHandler &sh)
+  :TObject(sh)
+  ,fHandlerStatus(0)
+  ,fNDCSPTR(0)
+  ,fNDCSGTU(0)
+  ,fFEEArr(0)
+  ,fPTRArr(0)
+  ,fSystem(0)
+  ,fInsideRstate(0)
+  ,fCurrentSM(0)
+  ,fCurrentStack(0)
+  ,fCurrentROB(-1)
+  ,fCurrentMCM(-1)
+  ,fCurrentADC(-1)
+  ,fContent(0)
+  ,fDCSFEEObj(0)
+  ,fDCSPTRObj(0)
+  ,fDCSGTUObj(0)
+  ,fCalDCSObj(0)
+  ,fLevel1Tag(-2)
+  ,fLevel2Tag(-2)
+  ,fInsideBoardInfo(false)
+  ,fTmu(0)
+  ,fCtpOpc(0)
+  ,fSegment(0)
+  ,fBoardInfo(0)
+{
+  // AliTRDSaxHandler copy constructor
+}
+
+//_____________________________________________________________________________
+AliTRDSaxHandler &AliTRDSaxHandler::operator=(const AliTRDSaxHandler &sh)
+{
+  // Assignment operator
+  if (&sh == this) return *this;
+  new (this) AliTRDSaxHandler(sh);
+  return *this;
+}
+
+//_____________________________________________________________________________
+AliTRDSaxHandler::~AliTRDSaxHandler()
+{
+  // AliTRDSaxHandler destructor
+  if (fFEEArr) {
+    delete fFEEArr;
+    fFEEArr    = 0x0;
+  }
+  if (fPTRArr) {
+    delete fPTRArr;
+    fPTRArr    = 0x0;
+  }
+  if (fDCSGTUObj) {
+    delete fDCSGTUObj;
+    fDCSGTUObj    = 0x0;
+  }
+  if (fCalDCSObj) {
+    delete fCalDCSObj;
+    fCalDCSObj = 0x0;
+  }
+}
+
+//_____________________________________________________________________________
+AliTRDCalDCSv2* AliTRDSaxHandler::GetCalDCSObj()
+{
+  // put the arrays in the global calibration object and return this
+
+  fCalDCSObj->SetFEEArr(fFEEArr);
+  fCalDCSObj->SetPTRArr(fPTRArr);
+  fCalDCSObj->SetGTUObj(fDCSGTUObj);
+  return fCalDCSObj;
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::ParseConfigName(TString cfgname) const
+{
+  // Evaluate the config name and set the individual parameters
+
+  // protect
+  if (!AliTRDcalibDB::Instance()) {
+    AliError("Could not create an instance of AliTRDcalibDB!");
+    return;
+  }
+
+  TString cfg = "", par = "", pars = "";
+  Int_t nPar = AliTRDcalibDB::Instance()->GetNumberOfParsDCS(cfgname);
+  if (nPar == 0) return;
+
+  for (Int_t i=1; i<=nPar; i++) {
+    // Get the configuration parameter
+    AliTRDcalibDB::Instance()->GetDCSConfigParOption(cfgname, i, 0, cfg);
+
+    // Set Parameters accordingly
+    if (i == AliTRDcalibDB::kFltrSet) fDCSFEEObj->SetFilterType(cfg);
+    if (i == AliTRDcalibDB::kTrigSet) fDCSFEEObj->SetTriggerSetup(cfg);
+    if (i == AliTRDcalibDB::kAddOpti) fDCSFEEObj->SetAddOptions(cfg);
+    if (i == AliTRDcalibDB::kTimebin) fDCSFEEObj->SetNumberOfTimeBins(AliTRDcalibDB::Instance()->ExtractTimeBinsFromString(cfg));
+    if (i == AliTRDcalibDB::kReadout) fDCSFEEObj->SetReadoutParam(cfg);
+    if (i == AliTRDcalibDB::kTrkMode) fDCSFEEObj->SetTrackletMode(cfg);
+
+    // Set options of parameters accordingly
+    Int_t nOpt = AliTRDcalibDB::Instance()->GetNumberOfOptsDCS(cfgname, i);
+    if (nOpt == 0) continue;
+
+    for (Int_t j=1; j<=nOpt; j++) {
+      // Get the parameter option
+      AliTRDcalibDB::Instance()->GetDCSConfigParOption(cfgname, i, j, par);
+
+      if (i == AliTRDcalibDB::kReadout) {
+       if (par.EqualTo("stat")) fDCSFEEObj->SetFastStatNoise(1);
+      }
+      if (i == AliTRDcalibDB::kTrkMode) {
+       if ((j > 1) && (par.Length() != 0)) pars += "-";
+       pars += par;
+      }
+      // SetTCFilterWeight, SetTCFilterShortDecPar, SetTCFilterLongDecPar might be filled here, too
+      // SetSingleHitThres, SetThreePadClustThres, SetSelectiveNoZS, SetTestPattern might be filled here, too
+    }
+
+    fDCSFEEObj->SetTrackletDef(pars);
+  }
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnStartDocument() const
+{
+  // if something should happen right at the beginning of the
+  // XML document, this must happen here
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnEndDocument() const
+{
+  // if something should happen at the end of the XML document
+  // this must be done here
+}
+
+//_____________________________________________________________________________
+bool AliTRDSaxHandler::CompareString(TString str, const char *str2)
+{
+  // compre strings, ignoring case
+  // returns true if they are the same, else false
+  return !(bool)str.CompareTo(str2,str.kIgnoreCase);
+}
+
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnStartElement(const char *name, const TList *attributes)
+{
+  // when a new XML element is found, it is processed here
+  fContent    = ""; // Technically <p> This <em>is</em> ok but would be a problem here</p>
+  Int_t dcsId = 0;
+  TString tagName  = name;
+  TString dcsTitle = "";
+
+  // set the current system if necessary
+  if (CompareString(tagName, "FEE")) fSystem = kInsideFEE;
+  if (CompareString(tagName, "PTR")) fSystem = kInsidePTR;
+  if (CompareString(tagName, "GTU")) {
+    fSystem = kInsideGTU;
+    fDCSGTUObj = new AliTRDCalDCSGTU(tagName,tagName);
+  }
+
+  if (fSystem == kInsideGTU) {
+    if (CompareString(tagName, "tgu")) fLevel1Tag = kInsideTgu;
+    if (CompareString(tagName, "board_info")) {
+      fInsideBoardInfo = true;
+      fBoardInfo = new AliTRDCalDCSGTUBoardInfo(tagName,tagName);
+    }
+    if (CompareString(tagName(0,tagName.Length()-3), "segment")) { 
+      fSegment = new AliTRDCalDCSGTUSegment(tagName,tagName);
+      fSegment->SetId(TString(tagName(8,2)).Atoi());
+      fLevel1Tag = kInsideSegment;
+    }
+    if (fLevel1Tag == kInsideTgu) {
+      if (CompareString(tagName, "ctp_opc"))   fCtpOpc = new AliTRDCalDCSGTUCtpOpc(tagName,tagName);
+    } else if (fLevel1Tag == kInsideSegment) {
+      if (CompareString(tagName, "smu")) {
+       fLevel2Tag = kInsideSmu;
+      }
+      if (CompareString(tagName(0,3), "tmu")) {
+       fTmu = new AliTRDCalDCSGTUTmu(tagName,tagName);
+       fTmu->SetId(TString(tagName(4,2)).Atoi());
+       fLevel2Tag = kInsideTmu;
+      }
+    }
+  } else if (fSystem == kInsideFEE) {
+    if (CompareString(tagName, "gaintbl")) fLevel1Tag = kInsideGainTable;
+  }
+
+  // set if we are inside rstate 
+  // (in principle not necessary - just to be more safe against stupid tags)
+  if (CompareString(tagName, "rstate")) fInsideRstate = 1;
+
+  // get the attributes of the element
+  TXMLAttr *attr;
+  TIter next(attributes);
+  while ((attr = (TXMLAttr*) next())) {
+    TString attribName = attr->GetName();
+    TString attribValue = attr->GetValue();
+    if (fSystem == kInsideFEE && fLevel1Tag == kInsideNone) {
+      if (CompareString(attribName, "id") && CompareString(tagName, "DCS")) {
+       dcsTitle = name;
+       dcsId = atoi(attr->GetValue());
+      }
+      if (CompareString(attribName, "roc") && CompareString(tagName, "ack")) {
+       if (attribValue.Atoi() != fDCSFEEObj->GetDCSid())
+         fDCSFEEObj->SetStatusBit(4); // consistency check
+      }
+      if (CompareString(attribName, "rob") && CompareString(tagName, "ro-board") && (fInsideRstate == 1)) {
+       fCurrentROB = attribValue.Atoi();
+      }
+      if (CompareString(attribName, "mcm") && CompareString(tagName, "m") && (fInsideRstate == 1)) {
+       fCurrentMCM = attribValue.Atoi();
+      }
+      if (CompareString(attribName, "sm") && CompareString(tagName, "DCS")) {
+       fCurrentSM = attribValue.Atoi(); // only for GTU/PTR
+      }
+      if (CompareString(attribName, "id") && CompareString(tagName, "STACK")) {// hmmmm not exist?
+       fCurrentStack = attribValue.Atoi(); // only for GTU/PTR
+      }
+    } else if (fSystem == kInsideFEE && fLevel1Tag == kInsideGainTable) {
+      if (CompareString(tagName, "roc") && CompareString(attribName, "type"))    fDCSFEEObj->SetGainTableRocType(attribValue);
+      if (CompareString(tagName, "roc") && CompareString(attribName, "serial"))  fDCSFEEObj->SetGainTableRocSerial(attribValue.Atoi());
+      if (CompareString(tagName, "mcm") && CompareString(attribName, "rob"))     fCurrentROB = attribValue.Atoi();
+      if (CompareString(tagName, "mcm") && CompareString(attribName, "pos"))     fCurrentMCM = attribValue.Atoi();
+      if (CompareString(tagName, "adc") && CompareString(attribName, "id"))      fCurrentADC = attribValue.Atoi();
+      
+    } else if (fSystem == kInsideGTU && fLevel1Tag == kInsideNone) {
+      if (CompareString(tagName, "publisher")) {
+       if (CompareString(attribName, "at"))         fDCSGTUObj->SetSORFlag(attribValue.Atoi());
+       if (CompareString(attribName, "serial"))     fDCSGTUObj->SetSerial(attribValue.Atoi());
+       if (CompareString(attribName, "runnr"))      fDCSGTUObj->SetRunNumber(attribValue.Atoi());
+      }
+    } else if (fSystem == kInsideGTU && fLevel1Tag == kInsideTgu) {
+      if (CompareString(tagName, "from")) {
+       if (CompareString(attribName, "at"))         fDCSGTUObj->GetTgu()->SetFromSORFlag(attribValue.Atoi());
+       if (CompareString(attribName, "runnr"))      fDCSGTUObj->GetTgu()->SetFromRunNumber(attribValue.Atoi());
+       if (CompareString(attribName, "child"))      fDCSGTUObj->GetTgu()->SetFromChild(attribValue.Atoi());
+      }
+      if (CompareString(tagName, "segmentmask") && CompareString(attribName, "value"))  fDCSGTUObj->GetTgu()->SetSegmentMask(attribValue);
+      if (CompareString(tagName, "busymask") && CompareString(attribName, "value"))     fDCSGTUObj->GetTgu()->SetBusyMask(attribValue);
+      if (CompareString(tagName, "contribmask") && CompareString(attribName, "value"))  fDCSGTUObj->GetTgu()->SetContribMask(attribValue);
+      
+      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "id"))         fCtpOpc->SetId(attribValue.Atoi());
+      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "opcode"))     fCtpOpc->SetOpcode(attribValue.Atoi());
+      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "direction"))  fCtpOpc->SetDirection(attribValue.Atoi());
+      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "inverted"))   fCtpOpc->SetInverted(attribValue.Atoi());
+      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "delay"))      fCtpOpc->SetDelay(attribValue.Atoi());
+      if (CompareString(tagName, "ctp_opc") && CompareString(attribName, "connected"))  fCtpOpc->SetConnected(attribValue.Atoi());
+      
+    } else if (fSystem == kInsideGTU && fLevel1Tag == kInsideSegment) {
+      if (CompareString(tagName, "from")) {
+       if (CompareString(attribName, "at"))         fSegment->SetFromSORFlag(attribValue.Atoi());
+       if (CompareString(attribName, "runnr"))      fSegment->SetFromRunNumber(attribValue.Atoi());
+       if (CompareString(attribName, "child"))      fSegment->SetFromChild(attribValue.Atoi());
+      }
+      if (fLevel2Tag == kInsideSmu) {
+       if (CompareString(tagName, "stackmask") && CompareString(attribName, "value"))     fSegment->SetSmuStackMask(attribValue);
+       if (CompareString(tagName, "tracklets") && CompareString(attribName, "send"))      fSegment->SetSmuTracklets(attribValue.Atoi());
+       if (CompareString(tagName, "tracks") && CompareString(attribName, "send"))         fSegment->SetSmuTracks(attribValue.Atoi());
+       if (CompareString(tagName, "idelay") && CompareString(attribName, "value"))        fSegment->SetSmuIdelay(attribValue.Atoi());
+       if (CompareString(tagName, "ttc_emulator") && CompareString(attribName, "enable")) fSegment->SetSmuTtcEmulatorEnable(attribValue.Atoi());
+       
+       if (CompareString(tagName, "trigger_window") && CompareString(attribName, "l1_low"))  
+         fSegment->SetSmuTriggerWindowL1Low(attribValue.Atoi());
+       if (CompareString(tagName, "trigger_window") && CompareString(attribName, "l1_high"))  
+         fSegment->SetSmuTriggerWindowL1High(attribValue.Atoi());
+       if (CompareString(tagName, "trigger_window") && CompareString(attribName, "l2_low"))  
+         fSegment->SetSmuTriggerWindowL2Low(attribValue.Atoi());
+       if (CompareString(tagName, "trigger_window") && CompareString(attribName, "l2_high"))  
+         fSegment->SetSmuTriggerWindowL2High(attribValue.Atoi());
+       
+      } else if (fLevel2Tag == kInsideTmu) {
+       if (CompareString(tagName, "linkmask") && CompareString(attribName, "value"))      fTmu->SetLinkMask(attribValue);
+       if (CompareString(tagName, "pattern_generator") && CompareString(attribName, "enable")) 
+         fTmu->SetPatternGeneratorEnable(attribValue.Atoi());
+       if (CompareString(tagName, "pattern_generator") && CompareString(attribName, "datawords")) 
+         fTmu->SetPatternGeneratorDataWords(attribValue.Atoi());
+       if (CompareString(tagName, "pattern_generator") && CompareString(attribName, "trackletwords")) 
+         fTmu->SetPatternGeneratorTrackletWords(attribValue.Atoi());
+      }
+    }
+    
+    if (fInsideBoardInfo) {
+      if (CompareString(tagName, "board_info") && CompareString(attribName, "board_id"))    fBoardInfo->SetId(attribValue);
+      if (CompareString(tagName, "board_info") && CompareString(attribName, "design_type")) fBoardInfo->SetType(attribValue.Atoi());
+      if (CompareString(tagName, "board_info") && CompareString(attribName, "pci_ga"))      fBoardInfo->SetPciGa(attribValue.Atoi());
+      if (CompareString(tagName, "hardware") && CompareString(attribName, "date"))          fBoardInfo->SetHwDate(attribValue);
+      if (CompareString(tagName, "hardware") && CompareString(attribName, "rev"))           fBoardInfo->SetHwRev(attribValue.Atoi());
+      if (CompareString(tagName, "hardware") && CompareString(attribName, "clean"))         fBoardInfo->SetHwClean(attribValue.Atoi());
+      if (CompareString(tagName, "software") && CompareString(attribName, "date"))          fBoardInfo->SetSwDate(attribValue);
+      if (CompareString(tagName, "software") && CompareString(attribName, "rev"))           fBoardInfo->SetSwRev(attribValue.Atoi());
+      if (CompareString(tagName, "software") && CompareString(attribName, "clean"))         fBoardInfo->SetSwClean(attribValue.Atoi());
+    }
+  }
+
+  // if there is a new DCS element put it in the correct array
+  if (CompareString(tagName, "DCS")) {
+    if (fSystem == kInsideFEE) {
+      fDCSFEEObj = new AliTRDCalDCSFEEv2();
+      fDCSFEEObj->SetDCSid(dcsId);
+    }
+    if (fSystem == kInsidePTR) {
+//       fDCSPTRObj = new AliTRDCalDCSPTR(name,dcsTitle);
+//       fDCSPTRObj->SetDCSid(dcsId);
+    }
+    if (fSystem == kInsideGTU) {
+//       fDCSGTUObj = new AliTRDCalDCSGTU(name,dcsTitle);
+//       fDCSGTUObj->SetDCSid(dcsId);
+    }
+  }
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnEndElement(const char *name)
+{
+  // do everything that needs to be done when an end tag of an element is found
+  TString tagName = name;
+  
+  // if done with this DCS board, put it in the correct array
+  // no check for </ack> necessary since this check is done during XML validation
+  if (CompareString(tagName, "DCS")) {
+    if (fSystem == kInsideFEE) {
+      Int_t detID = 0;
+      if (fDCSFEEObj->GetStatusBit() == 0) {
+       // if there were no errors (StatusBit==0) the following should match
+        detID = fDCSFEEObj->GetDCSid();
+        AliTRDgeometry aliGeo;
+        Int_t calDetID = aliGeo.GetDetector(fDCSFEEObj->GetLayer(),
+                                           fDCSFEEObj->GetStack(),
+                                           fDCSFEEObj->GetSM());
+       if (detID != calDetID) fDCSFEEObj->SetStatusBit(4);
+      } else {
+       // if the dcs board didn't properly respond, don't compare
+        detID = fDCSFEEObj->GetDCSid();
+      }
+      fFEEArr->AddAt(fDCSFEEObj,detID);
+    }
+    if (fSystem == kInsidePTR) {
+      fPTRArr->AddAt(fDCSPTRObj,fNDCSPTR);
+      fNDCSPTR++;
+    }
+//     if (fSystem == kInsideGTU) {
+//       fGTUArr->AddAt(fDCSGTUObj,fNDCSGTU);
+//       fNDCSGTU++;
+//     }
+    fCurrentSM = 99; // 99 for no SM set
+    fDCSFEEObj = 0;  // just to be sure
+    return;
+  }
+
+  // done with this stack? 
+  if (CompareString(tagName, "STACK")) {// TODO: errrrm ???? always 99?
+    fCurrentStack = 99; // 99 for no stack set
+  }
+
+  // outside of rstate again?
+  if (CompareString(tagName, "rstate")) {
+    fInsideRstate = 0;
+    fCurrentROB   = -1;
+    fCurrentMCM   = -1;
+  }
+  if (CompareString(tagName, "ro-board")) fCurrentROB = -1;
+  
+  // store informations of the FEE DCS-Board
+  if (fSystem == kInsideFEE) {
+    if (CompareString(tagName, "DNR"))            fDCSFEEObj->SetStatusBit(fContent.Atoi());
+    if (CompareString(tagName, "CFGTAG"))         fDCSFEEObj->SetConfigTag(fContent.Atoi());
+    if (CompareString(tagName, "CFGVRSN"))        fDCSFEEObj->SetConfigVersion(fContent);
+    if (CompareString(tagName, "SM-ID"))          fDCSFEEObj->SetSM(fContent.Atoi());
+    if (CompareString(tagName, "STACK-ID"))       fDCSFEEObj->SetStack(fContent.Atoi());
+    if (CompareString(tagName, "LAYER-ID"))       fDCSFEEObj->SetLayer(fContent.Atoi());
+    if (CompareString(tagName, "CFGNME")) {
+      fDCSFEEObj->SetConfigName(fContent);
+      ParseConfigName(fContent);
+    }
+    if (CompareString(tagName, "gaintbl")) {
+      fLevel1Tag = kInsideNone;
+      fCurrentROB = -1;
+      fCurrentMCM = -1;
+      fCurrentADC = -1;
+    }
+    if (fLevel1Tag == kInsideGainTable) {
+      if (CompareString(tagName, "name"))   fDCSFEEObj->SetGainTableName(fContent);
+      if (CompareString(tagName, "desc"))   fDCSFEEObj->SetGainTableDesc(fContent);
+      if (fCurrentROB>=0 && fCurrentMCM>=0) {
+       if (CompareString(tagName, "adcdac")) fDCSFEEObj->SetGainTableAdcdac(fCurrentROB, fCurrentMCM, fContent.Atoi());
+       if (fCurrentADC>=0) {
+         if (CompareString(tagName, "fgfn"))   fDCSFEEObj->SetGainTableFgfn(fCurrentROB, fCurrentMCM, fCurrentADC, fContent.Atoi());
+         if (CompareString(tagName, "fgan"))   fDCSFEEObj->SetGainTableFgan(fCurrentROB, fCurrentMCM, fCurrentADC, fContent.Atoi());
+       }
+      }
+    }
+    if (fInsideRstate == 1) {
+      if (fCurrentROB>=0 && fCurrentMCM>=0) {
+       if (CompareString(tagName, "gsm")) fDCSFEEObj->SetMCMGlobalState(fCurrentROB, fCurrentMCM, fContent.Atoi());
+        if (CompareString(tagName, "ni")) fDCSFEEObj->SetMCMStateNI(fCurrentROB, fCurrentMCM, fContent.Atoi());
+       if (CompareString(tagName, "ev")) fDCSFEEObj->SetMCMEventCnt(fCurrentROB, fCurrentMCM, fContent.Atoi());
+       if (CompareString(tagName, "ptrg")) fDCSFEEObj->SetMCMPtCnt(fCurrentROB, fCurrentMCM, fContent.Atoi());
+      }
+    }
+  }
+
+  if (fSystem == kInsideGTU) {
+//     if (CompareString(tagName, "run")) { 
+//       fDCSGTUObj->SetSORFlag(TString(fContent(fContent.Length()-1,1)).Atoi());
+//       fDCSGTUObj->SetRunNumber(TString(fContent(0,fContent.Length()-2)).Atoi());
+//     }
+//     if (CompareString(tagName, "serial"))         fDCSGTUObj->SetSerial(fContent.Atoi());
+    if (CompareString(tagName, "board_info")) {
+      fInsideBoardInfo = false;
+      if (fLevel1Tag == kInsideTgu)                                  fDCSGTUObj->GetTgu()->SetBoardInfo(fBoardInfo);
+      if (fLevel1Tag == kInsideSegment && fLevel2Tag == kInsideSmu)  fSegment->SetSmuBoardInfo(fBoardInfo);
+      if (fLevel1Tag == kInsideSegment && fLevel2Tag == kInsideTmu)  fTmu->SetBoardInfo(fBoardInfo);
+    }
+    if (CompareString(tagName, "dnr"))            fDCSGTUObj->SetDNR(fContent.Atoi());
+    if (CompareString(tagName, "tgu"))            fLevel1Tag = kInsideNone;
+    if (CompareString(tagName(0,tagName.Length()-3), "segment")) { 
+      fDCSGTUObj->GetSegmentArray()->Add(fSegment);
+      fLevel1Tag = kInsideNone;
+    }
+    if (fLevel1Tag == kInsideTgu) {
+      if (CompareString(tagName, "ctp_opc"))        fDCSGTUObj->GetTgu()->GetCtpOpcArray()->Add(fCtpOpc);
+    } else if (fLevel1Tag == kInsideSegment) {
+      if (CompareString(tagName, "smu"))          fLevel2Tag = kInsideNone;
+      if (CompareString(tagName(0,3), "tmu")) {
+       fSegment->GetTmuArray()->Add(fTmu);
+       fLevel2Tag = kInsideNone;
+      }
+    }
+  }
+
+  
+  // store pretrigger informations
+  if (fSystem == kInsidePTR) {
+    // no informations available yet
+  }
+//   // store GTU informations
+//   if (fSystem == kInsideGTU) {
+//     if (CompareString(tagName, "SMMASK"))
+//       fHandlerStatus = fDCSGTUObj->SetSMMask(fContent);
+//     if (CompareString(tagName, "LINKMASK")) 
+//       fHandlerStatus = fDCSGTUObj->SetLinkMask(fCurrentSM, fCurrentStack, fContent);
+//     if (CompareString(tagName, "STMASK"))
+//       fDCSGTUObj->SetStackMaskBit(fCurrentSM, fCurrentStack, fContent.Atoi());
+//   }
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnCharacters(const char *characters)
+{
+  // copy the the text content of an XML element
+  fContent = characters;
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnComment(const char* /*text*/) const
+{
+  // comments within the XML file are ignored
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnWarning(const char *text)
+{
+  // process warnings here
+  AliInfo(Form("Warning: %s",text));
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnError(const char *text)
+{
+  // process errors here
+  AliError(Form("Error: %s",text));
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnFatalError(const char *text)
+{
+  // process fatal errors here
+  AliError(Form("Fatal error: %s",text)); // use AliFatal?
+}
+
+//_____________________________________________________________________________
+void AliTRDSaxHandler::OnCdataBlock(const char* /*text*/, Int_t /*len*/) const
+{
+  // process character data blocks here
+  // not implemented and should not be used here
+}
+