]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpRegionalTrigger.cxx
Fix in AliMpSectorSegmentation::PadByPosition;
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRegionalTrigger.cxx
index 906378c0534d53ffa9b6cd58e2a60fe210128b50..ee1bf4d8b279c3afe8e4cbadf755ecd10aba2ba6 100644 (file)
@@ -111,97 +111,97 @@ AliMpRegionalTrigger::~AliMpRegionalTrigger()
 Bool_t AliMpRegionalTrigger::ReadData(istream& in)
 {
 /// Load the Regional trigger from ASCII data files
-/// and return its instance
+/// and fill objects. Return false if reading fails
+  
+  if ( !in.good() ) return kFALSE;
+   
+  Int_t localBoardId = 0;
+  TArrayI listInt;
+  UShort_t crateId;
+  Int_t nofBoards;
+  Int_t localBoardIndex(0);
+  char line[80];
+  // decode file and store in objects
+  while (!in.eof())
+  {
+    in.getline(line,80);
+    if (!strlen(line)) break;
+    TString crateName(AliMpHelper::Normalize(line));
     
+    in.getline(line,80);    
+    sscanf(line,"%hx",&crateId);
+
+    // skip data which are not stored in mapping object
+    // (mode, coincidence, mask)
+    in.getline(line,80);
+    in.getline(line,80);
+    in.getline(line,80);
+    
+    // read # local board
+    in.getline(line,80);
+    sscanf(line,"%d",&nofBoards);
+    
+    AliMpTriggerCrate* crate 
+      = (AliMpTriggerCrate*)(fTriggerCrates.GetValue(crateName.Data()));
+    if (!crate)  {
+      crate = new AliMpTriggerCrate(crateName.Data(), crateId);
+      fTriggerCrates.Add(crateName.Data(), crate);
+    }
 
-    AliMpLocalBoard* board = 0x0;
-    AliMpTriggerCrate* crate = 0x0;
-
-
-    Int_t localBoardId = 0;
-    TArrayI list;
-    UShort_t crateId, mask;
+    Char_t localBoardName[20];
+    Int_t slot;
+    UInt_t switches;
     
-    char line[80];
-   
-    while (!in.eof())
+    for ( Int_t i = 0; i < nofBoards; ++i ) 
     {
-      in.getline(line,80);
-      if (!strlen(line)) break;
-      TString crateName(AliMpHelper::Normalize(line));
+        in.getline(line,80);
+        sscanf(line,"%02d %s %03d %03x",&slot,localBoardName,&localBoardId,&switches);
+        AliMpLocalBoard* board = new AliMpLocalBoard(localBoardId, localBoardName, slot); 
+        board->SetSwitch(switches);
+        board->SetCrate(crateName);
+        
+        if (localBoardId > AliMpConstants::NofLocalBoards())
+          board->SetNotified(false); // copy cards
+        
+        crate->AddLocalBoard(localBoardId);
+        
+        // add  list of DEs for local board
+        listInt.Reset();
+        in.getline(line,80);
+        TString tmp(AliMpHelper::Normalize(line));
+        AliMpHelper::DecodeName(tmp,' ',listInt);
+        for (Int_t ii = 0; ii < listInt.GetSize(); ++ii) { 
+          if ( listInt[ii] ) board->AddDE(listInt[ii]);
+        }  
+         
+        // set copy number and transverse connector
+        in.getline(line,80);
+        TString tmp1 = AliMpHelper::Normalize(line);
+        AliMpHelper::DecodeName(tmp1,' ',listInt);
+        
+        board->SetInputXfrom(listInt[0]);
+        board->SetInputXto(listInt[1]);
+        
+        board->SetInputYfrom(listInt[2]);
+        board->SetInputYto(listInt[3]);
+        
+        board->SetTC(listInt[4]);
+        
+        // add local board into array
+        fLocalBoardArray.AddAt(board,localBoardIndex);
+        fLocalBoardMap.Add(board->GetId(),board);
       
-      in.getline(line,80);    
-      sscanf(line,"%hx",&crateId);
-  
-      // skip mode
-      in.getline(line,80);
-      
-      // skip coincidence
-      in.getline(line,80);
-      
-      // skip mask
-      in.getline(line,80);
-      sscanf(line,"%hx",&mask);
-      
-      crate = (AliMpTriggerCrate*)(fTriggerCrates.GetValue(crateName.Data()));
-      if (!crate) 
-      {
-        // cout << "Creating crate: " << crateName.Data() << endl;
-        crate = new AliMpTriggerCrate(crateName.Data(), crateId);
-        fTriggerCrates.Add(crateName.Data(), crate);
-      }
-      
-      Char_t localBoardName[20];
-      Int_t slot;
-      UInt_t switches;
-      
-      for ( Int_t i = 0; i < AliMpConstants::LocalBoardNofChannels(); ++i ) 
-      {
-        if ( (mask >> i ) & 0x1 )
-        {
-          in.getline(line,80);
-          sscanf(line,"%02d %s %03d %03x",&slot,localBoardName,&localBoardId,&switches);
-          // cout << "  Creating local board: " << localBoardId << endl;
-          board = new AliMpLocalBoard(localBoardId, localBoardName, slot); 
-          board->SetSwitch(switches);
-          board->SetCrate(crateName);
-          
-          if (localBoardId > AliMpConstants::NofLocalBoards())
-            board->SetNotified(false); // copy cards
-          
-          crate->AddLocalBoard(localBoardId);
-
-          // add  list of DEs for local board
-          list.Reset();
-          in.getline(line,80);
-          TString tmp(AliMpHelper::Normalize(line));
-          AliMpHelper::DecodeName(tmp,' ',list);
-          for (Int_t ii = 0; ii < list.GetSize(); ++ii) { 
-            if ( list[ii] ) board->AddDE(list[ii]);
-          }  
-
-          // set copy number and transverse connector
-          in.getline(line,80);
-          tmp = AliMpHelper::Normalize(line);
-          AliMpHelper::DecodeName(tmp,' ',list);
-    
-          board->SetInputXfrom(list[0]);
-          board->SetInputXto(list[1]);
-          
-          board->SetInputYfrom(list[2]);
-          board->SetInputYto(list[3]);
-          
-          board->SetTC(list[4]);
-          
-          // add local board into array
-          fLocalBoardArray.AddAt(board,board->GetId());
-          fLocalBoardMap.Add(board->GetId(),board);
-        }
-      }
+      ++localBoardIndex;
     }
-    
-    return kTRUE;
-}
+  }
+
+  AliDebug(1,Form("%d trigger crate created",fTriggerCrates.GetSize()));
+  AliDebug(1,Form("%d local board added to the map",fLocalBoardMap.GetSize()));
+  AliDebug(1,Form("%d local board referenced from the array",fLocalBoardArray.GetLast()+1));
+  
+  return kTRUE;
+}  
 
 //
 // public methods
@@ -213,31 +213,35 @@ Bool_t AliMpRegionalTrigger::ReadData(const TString& fileName)
 /// Load the Regional trigger from ASCII data files
 /// and return its instance
     
-    if ( fileName != "" ) {
-      AliDebugStream(2) << "Read data from file " << fileName.Data() << endl;
+    AliDebugStream(2) << "Read data from file " << fileName.Data() << endl;
     
-      TString inFileName(fileName);
-      inFileName = gSystem->ExpandPathName(inFileName.Data());
-      ifstream inFile(inFileName.Data(), ios::in);
-      if ( ! inFile.good() ) {
-        AliErrorStream()
-           << "Local Trigger Board Mapping File " << fileName.Data() << " not found" << endl;
-        return kFALSE;
-      }
-      
-      return ReadData(inFile);  
-    } 
-    else {
-      AliDebugStream(2) << "Read data from stream " << fileName.Data() << endl;
-      istream& in
-         = AliMpDataStreams::Instance()
-             ->CreateDataStream(AliMpFiles::LocalTriggerBoardMapping());
-             
-      Bool_t result = ReadData(in);
-      
-      delete &in;
-      return result;        
+    TString inFileName(fileName);
+    inFileName = gSystem->ExpandPathName(inFileName.Data());
+    ifstream inFile(inFileName.Data(), ios::in);
+    if ( ! inFile.good() ) {
+      AliErrorStream()
+         << "Local Trigger Board Mapping File " << fileName.Data() << " not found" << endl;
+      return kFALSE;
     }
+    
+    return ReadData(inFile);  
+}
+
+//______________________________________________________________________________
+Bool_t AliMpRegionalTrigger::ReadData(const AliMpDataStreams& dataStreams)
+{
+/// Load the Regional trigger from ASCII data files
+/// and return its instance
+    
+    AliDebugStream(2) << "Read data from stream " << endl;
+    istream& in
+       = dataStreams.
+           CreateDataStream(AliMpFiles::LocalTriggerBoardMapping());
+           
+    Bool_t result = ReadData(in);
+    
+    delete &in;
+    return result;        
 }
 
 //______________________________________________________________________________
@@ -285,7 +289,7 @@ Int_t AliMpRegionalTrigger::GetNofLocalBoards() const
 { 
     /// Return number of local boards
     
-    return fLocalBoardArray.GetSize()
+    return fLocalBoardArray.GetLast()+1
 }
 
 //______________________________________________________________________________
@@ -321,4 +325,10 @@ AliMpRegionalTrigger::LocalBoardId(Int_t index) const
   return -1;
 }
 
+//______________________________________________________________________________
+void AliMpRegionalTrigger::SetTriggerCratesOwner(Bool_t owner)
+{
+  /// Set ownership to trigger crates
 
+  fTriggerCrates.SetOwner(owner);
+}